01: /*
02: * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * 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: import java.io.File;
29: import java.io.IOException;
30: import java.net.MalformedURLException;
31: import java.net.URI;
32:
33: import java.awt.Desktop.Action;
34: import java.awt.peer.DesktopPeer;
35:
36: /**
37: * Concrete implementation of the interface <code>DesktopPeer</code> for
38: * the Gnome desktop on Linux and Unix platforms.
39: *
40: * @see DesktopPeer
41: */
42: public class XDesktopPeer implements DesktopPeer {
43:
44: private static boolean nativeLibraryLoaded = false;
45: static {
46: nativeLibraryLoaded = init();
47: }
48:
49: static boolean isDesktopSupported() {
50: return nativeLibraryLoaded;
51: }
52:
53: public boolean isSupported(Action type) {
54: return type != Action.PRINT && type != Action.EDIT;
55: }
56:
57: public void open(File file) throws IOException {
58: try {
59: launch(file.toURI());
60: } catch (MalformedURLException e) {
61: throw new IOException(file.toString());
62: }
63: }
64:
65: public void edit(File file) throws IOException {
66: throw new UnsupportedOperationException("The current platform "
67: + "doesn't support the EDIT action.");
68: }
69:
70: public void print(File file) throws IOException {
71: throw new UnsupportedOperationException("The current platform "
72: + "doesn't support the PRINT action.");
73: }
74:
75: public void mail(URI uri) throws IOException {
76: launch(uri);
77: }
78:
79: public void browse(URI uri) throws IOException {
80: launch(uri);
81: }
82:
83: private void launch(URI uri) throws IOException {
84: if (!nativeLibraryLoaded) {
85: throw new IOException("Failed to load native libraries.");
86: }
87:
88: byte[] uriByteArray = (uri.toString() + '\0').getBytes();
89: boolean result = gnome_url_show(uriByteArray);
90: if (!result) {
91: throw new IOException("Failed to show URI:" + uri);
92: }
93: }
94:
95: private native boolean gnome_url_show(byte[] url);
96:
97: private static native boolean init();
98: }
|