jdk/src/solaris/classes/sun/awt/X11/XDesktopPeer.java
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--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Desktop.Action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.peer.DesktopPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Concrete implementation of the interface <code>DesktopPeer</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * the Gnome desktop on Linux and Unix platforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @see DesktopPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class XDesktopPeer implements DesktopPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return nativeLibraryLoaded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public boolean isSupported(Action type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return type != Action.PRINT && type != Action.EDIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public void open(File file) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            launch(file.toURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            throw new IOException(file.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public void edit(File file) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        throw new UnsupportedOperationException("The current platform " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            "doesn't support the EDIT action.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void print(File file) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        throw new UnsupportedOperationException("The current platform " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            "doesn't support the PRINT action.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public void mail(URI uri) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        launch(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public void browse(URI uri) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        launch(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (!result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            throw new IOException("Failed to show URI:" + uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private native boolean gnome_url_show(byte[] url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private static native boolean init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
}