1 | |
package org.jtheque.utils; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.slf4j.LoggerFactory; |
20 | |
|
21 | |
import java.awt.Desktop; |
22 | |
import java.io.File; |
23 | |
import java.io.IOException; |
24 | |
import java.net.URI; |
25 | |
import java.net.URISyntaxException; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public final class DesktopUtils { |
33 | |
|
34 | |
|
35 | |
|
36 | |
private DesktopUtils() { |
37 | 0 | super(); |
38 | 0 | } |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public static void mail() { |
44 | 0 | if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.MAIL)) { |
45 | |
try { |
46 | 0 | Desktop.getDesktop().mail(); |
47 | 0 | } catch (IOException e) { |
48 | 0 | LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open mailer", e); |
49 | 0 | } |
50 | |
} |
51 | 0 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public static void mail(DesktopMail mail) { |
59 | 0 | if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.MAIL)) { |
60 | |
try { |
61 | 0 | Desktop.getDesktop().mail(mail.getURI()); |
62 | 0 | } catch (IOException e) { |
63 | 0 | LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open mailer", e); |
64 | 0 | } catch (URISyntaxException e) { |
65 | 0 | LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open mailer", e); |
66 | 0 | } |
67 | |
} |
68 | 0 | } |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public static void open(File file) { |
76 | 0 | if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { |
77 | |
try { |
78 | 0 | Desktop.getDesktop().open(file); |
79 | 0 | } catch (IOException e) { |
80 | 0 | LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open file", e); |
81 | 0 | } |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public static void browse(String url) { |
91 | 0 | if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { |
92 | |
try { |
93 | 0 | Desktop.getDesktop().browse(new URI(url)); |
94 | 0 | } catch (IOException e) { |
95 | 0 | LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open browser", e); |
96 | 0 | } catch (URISyntaxException e) { |
97 | 0 | LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open browser", e); |
98 | 0 | } |
99 | |
} |
100 | 0 | } |
101 | |
} |