1 /*
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 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.
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 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.List;
39
40
41 /**
42 * Concrete implementation of the interface <code>DesktopPeer</code> for
43 * the Gnome desktop on Linux and Unix platforms.
44 *
45 * @see DesktopPeer
46 */
47 public class XDesktopPeer implements DesktopPeer {
48
49 // supportedActions may be changed from native within an init() call
50 private static final List<Action> supportedActions
51 = new ArrayList<>(Arrays.asList(Action.OPEN, Action.MAIL, Action.BROWSE));
52
53 private static boolean nativeLibraryLoaded = false;
54 private static boolean initExecuted = false;
55
56 private static void initWithLock(){
57 XToolkit.awtLock();
58 try {
59 if (!initExecuted) {
60 nativeLibraryLoaded = init();
61 }
62 } finally {
63 initExecuted = true;
64 XToolkit.awtUnlock();
65 }
66 }
67
68 //package-private
69 XDesktopPeer(){
70 initWithLock();
71 }
72
73 static boolean isDesktopSupported() {
74 initWithLock();
75 return nativeLibraryLoaded && !supportedActions.isEmpty();
76 }
77
78 public boolean isSupported(Action type) {
79 return supportedActions.contains(type);
80 }
106 }
107
108 private void launch(URI uri) throws IOException {
109 byte[] uriByteArray = ( uri.toString() + '\0' ).getBytes();
110 boolean result = false;
111 XToolkit.awtLock();
112 try {
113 if (!nativeLibraryLoaded) {
114 throw new IOException("Failed to load native libraries.");
115 }
116 result = gnome_url_show(uriByteArray);
117 } finally {
118 XToolkit.awtUnlock();
119 }
120 if (!result) {
121 throw new IOException("Failed to show URI:" + uri);
122 }
123 }
124
125 private native boolean gnome_url_show(byte[] url);
126 private static native boolean init();
127 }
| 1 /*
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 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.
24 */
25
26 package sun.awt.X11;
27
28 import sun.awt.UNIXToolkit;
29
30 import java.io.File;
31 import java.io.IOException;
32 import java.net.MalformedURLException;
33 import java.net.URI;
34
35 import java.awt.Desktop.Action;
36 import java.awt.peer.DesktopPeer;
37 import java.util.ArrayList;
38 import java.util.Arrays;
39 import java.util.List;
40
41
42 /**
43 * Concrete implementation of the interface <code>DesktopPeer</code> for
44 * the Gnome desktop on Linux and Unix platforms.
45 *
46 * @see DesktopPeer
47 */
48 public class XDesktopPeer implements DesktopPeer {
49
50 // supportedActions may be changed from native within an init() call
51 private static final List<Action> supportedActions
52 = new ArrayList<>(Arrays.asList(Action.OPEN, Action.MAIL, Action.BROWSE));
53
54 private static boolean nativeLibraryLoaded = false;
55 private static boolean initExecuted = false;
56
57 private static void initWithLock(){
58 XToolkit.awtLock();
59 try {
60 if (!initExecuted) {
61 nativeLibraryLoaded = init(UNIXToolkit.getEnabledGtkVersion()
62 .getNumber(), UNIXToolkit.isGtkVerbose());
63 }
64 } finally {
65 initExecuted = true;
66 XToolkit.awtUnlock();
67 }
68 }
69
70 //package-private
71 XDesktopPeer(){
72 initWithLock();
73 }
74
75 static boolean isDesktopSupported() {
76 initWithLock();
77 return nativeLibraryLoaded && !supportedActions.isEmpty();
78 }
79
80 public boolean isSupported(Action type) {
81 return supportedActions.contains(type);
82 }
108 }
109
110 private void launch(URI uri) throws IOException {
111 byte[] uriByteArray = ( uri.toString() + '\0' ).getBytes();
112 boolean result = false;
113 XToolkit.awtLock();
114 try {
115 if (!nativeLibraryLoaded) {
116 throw new IOException("Failed to load native libraries.");
117 }
118 result = gnome_url_show(uriByteArray);
119 } finally {
120 XToolkit.awtUnlock();
121 }
122 if (!result) {
123 throw new IOException("Failed to show URI:" + uri);
124 }
125 }
126
127 private native boolean gnome_url_show(byte[] url);
128 private static native boolean init(int gtkVersion, boolean verbose);
129 }
|