2
|
1 |
/*
|
|
2 |
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.awt.X11;
|
|
27 |
|
|
28 |
|
|
29 |
import java.io.File;
|
|
30 |
import java.io.IOException;
|
|
31 |
import java.net.MalformedURLException;
|
|
32 |
import java.net.URI;
|
|
33 |
|
|
34 |
import java.awt.Desktop.Action;
|
|
35 |
import java.awt.peer.DesktopPeer;
|
|
36 |
|
|
37 |
|
|
38 |
/**
|
|
39 |
* Concrete implementation of the interface <code>DesktopPeer</code> for
|
|
40 |
* the Gnome desktop on Linux and Unix platforms.
|
|
41 |
*
|
|
42 |
* @see DesktopPeer
|
|
43 |
*/
|
|
44 |
public class XDesktopPeer implements DesktopPeer {
|
|
45 |
|
|
46 |
private static boolean nativeLibraryLoaded = false;
|
|
47 |
static {
|
|
48 |
nativeLibraryLoaded = init();
|
|
49 |
}
|
|
50 |
|
|
51 |
static boolean isDesktopSupported() {
|
|
52 |
return nativeLibraryLoaded;
|
|
53 |
}
|
|
54 |
|
|
55 |
public boolean isSupported(Action type) {
|
|
56 |
return type != Action.PRINT && type != Action.EDIT;
|
|
57 |
}
|
|
58 |
|
|
59 |
public void open(File file) throws IOException {
|
|
60 |
try {
|
|
61 |
launch(file.toURI());
|
|
62 |
} catch (MalformedURLException e) {
|
|
63 |
throw new IOException(file.toString());
|
|
64 |
}
|
|
65 |
}
|
|
66 |
|
|
67 |
public void edit(File file) throws IOException {
|
|
68 |
throw new UnsupportedOperationException("The current platform " +
|
|
69 |
"doesn't support the EDIT action.");
|
|
70 |
}
|
|
71 |
|
|
72 |
public void print(File file) throws IOException {
|
|
73 |
throw new UnsupportedOperationException("The current platform " +
|
|
74 |
"doesn't support the PRINT action.");
|
|
75 |
}
|
|
76 |
|
|
77 |
public void mail(URI uri) throws IOException {
|
|
78 |
launch(uri);
|
|
79 |
}
|
|
80 |
|
|
81 |
public void browse(URI uri) throws IOException {
|
|
82 |
launch(uri);
|
|
83 |
}
|
|
84 |
|
|
85 |
private void launch(URI uri) throws IOException {
|
|
86 |
if (!nativeLibraryLoaded) {
|
|
87 |
throw new IOException("Failed to load native libraries.");
|
|
88 |
}
|
|
89 |
|
|
90 |
byte[] uriByteArray = ( uri.toString() + '\0' ).getBytes();
|
|
91 |
boolean result = gnome_url_show(uriByteArray);
|
|
92 |
if (!result) {
|
|
93 |
throw new IOException("Failed to show URI:" + uri);
|
|
94 |
}
|
|
95 |
}
|
|
96 |
|
|
97 |
private native boolean gnome_url_show(byte[] url);
|
|
98 |
private static native boolean init();
|
|
99 |
}
|