Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/X11/XDesktopPeer.java
32288 views
/*1* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt.X11;2627import sun.awt.UNIXToolkit;2829import java.io.File;30import java.io.IOException;31import java.net.MalformedURLException;32import java.net.URI;3334import java.awt.Desktop.Action;35import java.awt.peer.DesktopPeer;36import java.util.ArrayList;37import java.util.Arrays;38import java.util.List;394041/**42* Concrete implementation of the interface <code>DesktopPeer</code> for43* the Gnome desktop on Linux and Unix platforms.44*45* @see DesktopPeer46*/47public class XDesktopPeer implements DesktopPeer {4849// supportedActions may be changed from native within an init() call50private static final List<Action> supportedActions51= new ArrayList<>(Arrays.asList(Action.OPEN, Action.MAIL, Action.BROWSE));5253private static boolean nativeLibraryLoaded = false;54private static boolean initExecuted = false;5556private static void initWithLock(){57XToolkit.awtLock();58try {59if (!initExecuted) {60nativeLibraryLoaded = init(UNIXToolkit.getEnabledGtkVersion()61.getNumber(), UNIXToolkit.isGtkVerbose());62}63} finally {64initExecuted = true;65XToolkit.awtUnlock();66}67}6869//package-private70XDesktopPeer(){71initWithLock();72}7374static boolean isDesktopSupported() {75initWithLock();76return nativeLibraryLoaded && !supportedActions.isEmpty();77}7879public boolean isSupported(Action type) {80return supportedActions.contains(type);81}8283public void open(File file) throws IOException {84try {85launch(file.toURI());86} catch (MalformedURLException e) {87throw new IOException(file.toString());88}89}9091public void edit(File file) throws IOException {92throw new UnsupportedOperationException("The current platform " +93"doesn't support the EDIT action.");94}9596public void print(File file) throws IOException {97throw new UnsupportedOperationException("The current platform " +98"doesn't support the PRINT action.");99}100101public void mail(URI uri) throws IOException {102launch(uri);103}104105public void browse(URI uri) throws IOException {106launch(uri);107}108109private void launch(URI uri) throws IOException {110byte[] uriByteArray = ( uri.toString() + '\0' ).getBytes();111boolean result = false;112XToolkit.awtLock();113try {114if (!nativeLibraryLoaded) {115throw new IOException("Failed to load native libraries.");116}117result = gnome_url_show(uriByteArray);118} finally {119XToolkit.awtUnlock();120}121if (!result) {122throw new IOException("Failed to show URI:" + uri);123}124}125126private native boolean gnome_url_show(byte[] url);127private static native boolean init(int gtkVersion, boolean verbose);128}129130131