author | ohair |
Wed, 06 Apr 2011 22:06:11 -0700 | |
changeset 9035 | 1255eb81cc2f |
parent 8369 | d835f77a7f86 |
child 23010 | 6dadb192ad81 |
child 23243 | 43e5bc27297f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
8369
diff
changeset
|
2 |
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 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; |
|
8369
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
47 |
private static boolean initExecuted = false; |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
48 |
|
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
49 |
private static void initWithLock(){ |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
50 |
XToolkit.awtLock(); |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
51 |
try { |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
52 |
if (!initExecuted) { |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
53 |
nativeLibraryLoaded = init(); |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
54 |
} |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
55 |
} finally { |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
56 |
initExecuted = true; |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
57 |
XToolkit.awtUnlock(); |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
58 |
} |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
59 |
} |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
60 |
|
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
61 |
//package-private |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
62 |
XDesktopPeer(){ |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
63 |
initWithLock(); |
2 | 64 |
} |
65 |
||
66 |
static boolean isDesktopSupported() { |
|
8369
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
67 |
initWithLock(); |
2 | 68 |
return nativeLibraryLoaded; |
69 |
} |
|
70 |
||
71 |
public boolean isSupported(Action type) { |
|
72 |
return type != Action.PRINT && type != Action.EDIT; |
|
73 |
} |
|
74 |
||
75 |
public void open(File file) throws IOException { |
|
76 |
try { |
|
77 |
launch(file.toURI()); |
|
78 |
} catch (MalformedURLException e) { |
|
79 |
throw new IOException(file.toString()); |
|
80 |
} |
|
81 |
} |
|
82 |
||
83 |
public void edit(File file) throws IOException { |
|
84 |
throw new UnsupportedOperationException("The current platform " + |
|
85 |
"doesn't support the EDIT action."); |
|
86 |
} |
|
87 |
||
88 |
public void print(File file) throws IOException { |
|
89 |
throw new UnsupportedOperationException("The current platform " + |
|
90 |
"doesn't support the PRINT action."); |
|
91 |
} |
|
92 |
||
93 |
public void mail(URI uri) throws IOException { |
|
94 |
launch(uri); |
|
95 |
} |
|
96 |
||
97 |
public void browse(URI uri) throws IOException { |
|
98 |
launch(uri); |
|
99 |
} |
|
100 |
||
101 |
private void launch(URI uri) throws IOException { |
|
8369
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
102 |
byte[] uriByteArray = ( uri.toString() + '\0' ).getBytes(); |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
103 |
boolean result = false; |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
104 |
XToolkit.awtLock(); |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
105 |
try { |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
106 |
if (!nativeLibraryLoaded) { |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
107 |
throw new IOException("Failed to load native libraries."); |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
108 |
} |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
109 |
result = gnome_url_show(uriByteArray); |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
110 |
} finally { |
d835f77a7f86
6994933: java.awt.Desktop feature is "intermittently" supported on Solaris. Really unexpected behavior.
dav
parents:
5506
diff
changeset
|
111 |
XToolkit.awtUnlock(); |
2 | 112 |
} |
113 |
if (!result) { |
|
114 |
throw new IOException("Failed to show URI:" + uri); |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
private native boolean gnome_url_show(byte[] url); |
|
119 |
private static native boolean init(); |
|
120 |
} |