< prev index next >

src/java.desktop/unix/classes/sun/awt/X11/XDesktopPeer.java

Print this page


   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, 2016, 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 sun.awt.UNIXToolkit;
  30 
  31 import java.io.File;
  32 import java.io.IOException;
  33 import java.net.MalformedURLException;
  34 import java.net.URI;
  35 
  36 import java.awt.Desktop.Action;
  37 import java.awt.peer.DesktopPeer;
  38 import java.util.ArrayList;
  39 import java.util.Arrays;
  40 import java.util.List;
  41 
  42 
  43 /**
  44  * Concrete implementation of the interface <code>DesktopPeer</code> for
  45  * the Gnome desktop on Linux and Unix platforms.
  46  *
  47  * @see DesktopPeer
  48  */
  49 public class XDesktopPeer implements DesktopPeer {
  50 
  51     // supportedActions may be changed from native within an init() call
  52     private static final List<Action> supportedActions
  53             = new ArrayList<>(Arrays.asList(Action.OPEN, Action.MAIL, Action.BROWSE));
  54 
  55     private static boolean nativeLibraryLoaded = false;
  56     private static boolean initExecuted = false;
  57 
  58     private static void initWithLock(){
  59         XToolkit.awtLock();
  60         try {
  61             if (!initExecuted) {
  62                 nativeLibraryLoaded = init(UNIXToolkit.getEnabledGtkVersion()
  63                         .ordinal(), UNIXToolkit.isGtkVerbose());
  64             }
  65         } finally {
  66             initExecuted = true;
  67             XToolkit.awtUnlock();
  68         }
  69     }
  70 
  71     //package-private
  72     XDesktopPeer(){
  73         initWithLock();
  74     }
  75 
  76     static boolean isDesktopSupported() {
  77         initWithLock();
  78         return nativeLibraryLoaded && !supportedActions.isEmpty();
  79     }
  80 
  81     public boolean isSupported(Action type) {
  82         return supportedActions.contains(type);
  83     }


 109     }
 110 
 111     private void launch(URI uri) throws IOException {
 112         byte[] uriByteArray = ( uri.toString() + '\0' ).getBytes();
 113         boolean result = false;
 114         XToolkit.awtLock();
 115         try {
 116             if (!nativeLibraryLoaded) {
 117                 throw new IOException("Failed to load native libraries.");
 118             }
 119             result = gnome_url_show(uriByteArray);
 120         } finally {
 121             XToolkit.awtUnlock();
 122         }
 123         if (!result) {
 124             throw new IOException("Failed to show URI:" + uri);
 125         }
 126     }
 127 
 128     private native boolean gnome_url_show(byte[] url);
 129     private static native boolean init(int gtkVersion, boolean verbose);
 130 }
< prev index next >