jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java
author mchung
Tue, 29 Sep 2009 16:03:03 -0700
changeset 3938 ef327bd847c0
parent 3928 be186a33df9b
child 5506 202f599c92aa
child 5579 1a5e995a710b
permissions -rw-r--r--
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes Summary: Replace calls to Logger with sun.util.logging.PlatformLogger Reviewed-by: prr, art, alexp, dcherepanov, igor, dav, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 557
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.FileReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.StreamTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.NetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.net.SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.net.UnknownHostException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.awt.motif.MFontConfiguration;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 557
diff changeset
    46
import sun.font.FcFontConfiguration;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.font.Font2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.font.FontManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.font.NativeFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.java2d.SunGraphicsEnvironment;
557
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents: 2
diff changeset
    51
import sun.java2d.SurfaceManagerFactory;
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents: 2
diff changeset
    52
import sun.java2d.UnixSurfaceManagerFactory;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    53
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * This is an implementation of a GraphicsEnvironment object for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * default local GraphicsEnvironment used by the Java Runtime Environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * for X11 environments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class X11GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    extends SunGraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
{
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    66
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11GraphicsEnvironment");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    67
    private static final PlatformLogger screenLog = PlatformLogger.getLogger("sun.awt.screen.X11GraphicsEnvironment");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static Boolean xinerState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                          new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                System.loadLibrary("awt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                 * Note: The MToolkit object depends on the static initializer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                 * of X11GraphicsEnvironment to initialize the connection to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                 * the X11 server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                if (!isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    // first check the OGL system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                    boolean glxRequested = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    String prop = System.getProperty("sun.java2d.opengl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    if (prop != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                        if (prop.equals("true") || prop.equals("t")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                            glxRequested = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                        } else if (prop.equals("True") || prop.equals("T")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                            glxRequested = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                            glxVerbose = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    // initialize the X11 display connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    initDisplay(glxRequested);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    // only attempt to initialize GLX if it was requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    if (glxRequested) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                        glxAvailable = initGLX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                        if (glxVerbose && !glxAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                            System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                "Could not enable OpenGL " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                "pipeline (GLX 1.3 not available)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         });
557
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents: 2
diff changeset
   112
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents: 2
diff changeset
   113
        // Install the correct surface manager factory.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents: 2
diff changeset
   114
        SurfaceManagerFactory.setInstance(new UnixSurfaceManagerFactory());
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents: 2
diff changeset
   115
2
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 static boolean glxAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private static boolean glxVerbose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static native boolean initGLX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public static boolean isGLXAvailable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return glxAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public static boolean isGLXVerbose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return glxVerbose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Checks if Shared Memory extension can be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Returns:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *   -1 if server doesn't support MITShm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *    1 if server supports it and it can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *    0 otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static native int checkShmExt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private static  native String getDisplayString();
1724
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 889
diff changeset
   141
    private Boolean isDisplayLocal;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * This should only be called from the static initializer, so no need for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * the synchronized keyword.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private static native void initDisplay(boolean glxRequested);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public X11GraphicsEnvironment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    protected native int getNumScreens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected GraphicsDevice makeScreenDevice(int screennum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return new X11GraphicsDevice(screennum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    protected native int getDefaultScreenNum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Returns the default screen graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public GraphicsDevice getDefaultScreenDevice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return getScreenDevices()[getDefaultScreenNum()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
1724
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 889
diff changeset
   166
    public boolean isDisplayLocal() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (isDisplayLocal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            SunToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                if (isDisplayLocal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    isDisplayLocal = Boolean.valueOf(_isDisplayLocal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                SunToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return isDisplayLocal.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private static boolean _isDisplayLocal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        String isRemote = (String)java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            new sun.security.action.GetPropertyAction("sun.java2d.remote"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (isRemote != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return isRemote.equals("false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        int shm = checkShmExt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (shm != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return (shm == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        // If XServer doesn't support ShMem extension,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // try the other way
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        String display = getDisplayString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        int ind = display.indexOf(':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        final String hostName = display.substring(0, ind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (ind <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            // ':0' case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        Boolean result = (Boolean)java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                InetAddress remAddr[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                Enumeration locals = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                Enumeration interfaces = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    interfaces = NetworkInterface.getNetworkInterfaces();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    remAddr = InetAddress.getAllByName(hostName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    if (remAddr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        return Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    System.err.println("Unknown host: " + hostName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    return Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                } catch (SocketException e1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    System.err.println(e1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    return Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                for (; interfaces.hasMoreElements();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    locals = ((NetworkInterface)interfaces.nextElement()).getInetAddresses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    for (; locals.hasMoreElements();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                        for (int i = 0; i < remAddr.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                            if (locals.nextElement().equals(remAddr[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                                return Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                return Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return result.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Returns face name for default font, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * no face names are used for CompositeFontDescriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * for this platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public String getDefaultFontFaceName() {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 557
diff changeset
   250
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    private static native boolean pRunningXinerama();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    private static native Point getXineramaCenterPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Override for Xinerama case: call new Solaris API for getting the correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * centering point from the windowing system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public Point getCenterPoint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (runningXinerama()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            Point p = getXineramaCenterPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return super.getCenterPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Override for Xinerama case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public Rectangle getMaximumWindowBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (runningXinerama()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            return getXineramaWindowBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            return super.getMaximumWindowBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public boolean runningXinerama() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (xinerState == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            // pRunningXinerama() simply returns a global boolean variable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            // so there is no need to synchronize here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            xinerState = Boolean.valueOf(pRunningXinerama());
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   287
            if (screenLog.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   288
                screenLog.finer("Running Xinerama: " + xinerState);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return xinerState.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Return the bounds for a centered Window on a system running in Xinerama
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Calculations are based on the assumption of a perfectly rectangular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * display area (display edges line up with one another, and displays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * have consistent width and/or height).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * The bounds to return depend on the arrangement of displays and on where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Windows are to be centered.  There are two common situations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * 1) The center point lies at the center of the combined area of all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *    displays.  In this case, the combined area of all displays is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *    returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * 2) The center point lies at the center of a single display.  In this case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *    the user most likely wants centered Windows to be constrained to that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *    single display.  The boundaries of the one display are returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * It is possible for the center point to be at both the center of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * entire display space AND at the center of a single monitor (a square of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * 9 monitors, for instance).  In this case, the entire display area is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Because the center point is arbitrarily settable by the user, it could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * fit neither of the cases above.  The fallback case is to simply return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * the combined area for all screens.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    protected Rectangle getXineramaWindowBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        Point center = getCenterPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        Rectangle unionRect, tempRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        GraphicsDevice[] gds = getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        Rectangle centerMonitorRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // if center point is at the center of all monitors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        // return union of all bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        //  MM*MM     MMM       M
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        //            M*M       *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        //            MMM       M
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        // if center point is at center of a single monitor (but not of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        // monitors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        // return bounds of single monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        // MMM         MM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        // MM*         *M
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // else, center is in some strange spot (such as on the border between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        // monitors), and we should just return the union of all monitors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        // MM          MMM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        // MM          MMM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        unionRect = getUsableBounds(gds[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        for (i = 0; i < gds.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            tempRect = getUsableBounds(gds[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if (centerMonitorRect == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                // add a pixel or two for fudge-factor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                (tempRect.width / 2) + tempRect.x > center.x - 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                (tempRect.height / 2) + tempRect.y > center.y - 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                (tempRect.width / 2) + tempRect.x < center.x + 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                (tempRect.height / 2) + tempRect.y < center.y + 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                centerMonitorRect = tempRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            unionRect = unionRect.union(tempRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        // first: check for center of all monitors (video wall)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        // add a pixel or two for fudge-factor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if ((unionRect.width / 2) + unionRect.x > center.x - 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            (unionRect.height / 2) + unionRect.y > center.y - 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            (unionRect.width / 2) + unionRect.x < center.x + 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            (unionRect.height / 2) + unionRect.y < center.y + 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   371
            if (screenLog.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   372
                screenLog.finer("Video Wall: center point is at center of all displays.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            return unionRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        // next, check if at center of one monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (centerMonitorRect != null) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   379
            if (screenLog.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   380
                screenLog.finer("Center point at center of a particular " +
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   381
                                "monitor, but not of the entire virtual display.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            return centerMonitorRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        // otherwise, the center is at some weird spot: return unionRect
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   387
        if (screenLog.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   388
            screenLog.finer("Center point is somewhere strange - return union of all bounds.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        return unionRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * From the DisplayChangedListener interface; devices do not need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * to react to this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
}