jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8128 4980e459a3a7
child 9050 26c2c1de1631
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: 8128
diff changeset
     2
 * Copyright (c) 1997, 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: 3938
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: 3938
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: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
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.java2d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Graphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.font.TextAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.image.BufferedImage;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
    39
import java.awt.peer.ComponentPeer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.FilenameFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.io.InputStreamReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.text.AttributedCharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.NoSuchElementException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.util.TreeMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.util.concurrent.ConcurrentHashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.awt.DisplayChangedListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import sun.awt.FontConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import sun.awt.SunDisplayChanger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import sun.font.CompositeFontDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import sun.font.Font2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import sun.font.FontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
    65
import sun.font.FontManagerFactory;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
    66
import sun.font.FontManagerForSGE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import sun.font.NativeFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * This is an implementation of a GraphicsEnvironment object for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * default local GraphicsEnvironment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @see GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
public abstract class SunGraphicsEnvironment extends GraphicsEnvironment
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
    77
    implements DisplayChangedListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
    79
    public static boolean isOpenSolaris;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
    80
    private static Font defaultFont;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public SunGraphicsEnvironment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                    new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            public Object run() {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    86
                    String version = System.getProperty("os.version", "0.0");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    87
                    try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    88
                        float ver = Float.parseFloat(version);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    89
                        if (ver > 5.10f) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    90
                            File f = new File("/etc/release");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    91
                            FileInputStream fis = new FileInputStream(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    92
                            InputStreamReader isr
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    93
                                = new InputStreamReader(fis, "ISO-8859-1");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    94
                            BufferedReader br = new BufferedReader(isr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    95
                            String line = br.readLine();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    96
                            if (line.indexOf("OpenSolaris") >= 0) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    97
                                isOpenSolaris = true;
8128
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
    98
                            } else {
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
    99
                                /* We are using isOpenSolaris as meaning
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   100
                                 * we know the Solaris commercial fonts aren't
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   101
                                 * present. "Solaris Next" (03/10) did not
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   102
                                 * include these even though its was not
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   103
                                 * OpenSolaris. Need to revisit how this is
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   104
                                 * handled but for now as in 6ux, we'll use
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   105
                                 * the test for a standard font resource as
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   106
                                 * being an indicator as to whether we need
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   107
                                 * to treat this as OpenSolaris from a font
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   108
                                 * config perspective.
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   109
                                 */
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   110
                                String courierNew =
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   111
                                    "/usr/openwin/lib/X11/fonts/TrueType/CourierNew.ttf";
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   112
                                File courierFile = new File(courierNew);
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   113
                                isOpenSolaris = !courierFile.exists();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   114
                            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   115
                            fis.close();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   116
                        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   117
                    } catch (Exception e) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   118
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                /* Establish the default font to be used by SG2D etc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    protected GraphicsDevice[] screens;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Returns an array of all of the screen devices.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public synchronized GraphicsDevice[] getScreenDevices() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        GraphicsDevice[] ret = screens;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (ret == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            int num = getNumScreens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            ret = new GraphicsDevice[num];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            for (int i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                ret[i] = makeScreenDevice(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            screens = ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   146
    /**
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   147
     * Returns the number of screen devices of this graphics environment.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   148
     *
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   149
     * @return the number of screen devices of this graphics environment
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   150
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    protected abstract int getNumScreens();
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   152
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   153
    /**
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   154
     * Create and return the screen device with the specified number. The
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   155
     * device with number <code>0</code> will be the default device (returned
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   156
     * by {@link #getDefaultScreenDevice()}.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   157
     *
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   158
     * @param screennum the number of the screen to create
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   159
     *
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   160
     * @return the created screen device
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   161
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    protected abstract GraphicsDevice makeScreenDevice(int screennum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Returns the default screen graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public GraphicsDevice getDefaultScreenDevice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return getScreenDevices()[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Returns a Graphics2D object for rendering into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * given BufferedImage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @throws NullPointerException if BufferedImage argument is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public Graphics2D createGraphics(BufferedImage img) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            throw new NullPointerException("BufferedImage cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        SurfaceData sd = SurfaceData.getPrimarySurfaceData(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return new SunGraphics2D(sd, Color.white, Color.black, defaultFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
7947
236cfb73d510 6980204: closed/java/awt/font/LogicalFonts/MappingTest.java fails
prr
parents: 5506
diff changeset
   184
    public static FontManagerForSGE getFontManagerForSGE() {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   185
        FontManager fm = FontManagerFactory.getInstance();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   186
        return (FontManagerForSGE) fm;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Returns all fonts available in this environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public Font[] getAllFonts() {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   192
        FontManagerForSGE fm = getFontManagerForSGE();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   193
        Font[] installedFonts = fm.getAllInstalledFonts();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   194
        Font[] created = fm.getCreatedFonts();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (created == null || created.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return installedFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            int newlen = installedFonts.length + created.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            Font [] fonts = java.util.Arrays.copyOf(installedFonts, newlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            System.arraycopy(created, 0, fonts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                             installedFonts.length, created.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return fonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public String[] getAvailableFontFamilyNames(Locale requestedLocale) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   207
        FontManagerForSGE fm = getFontManagerForSGE();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   208
        String[] installed = fm.getInstalledFontFamilyNames(requestedLocale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        /* Use a new TreeMap as used in getInstalledFontFamilyNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
         * and insert all the keys in lower case, so that the sort order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         * is the same as the installed families. This preserves historical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         * behaviour and inserts new families in the right place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * It would have been marginally more efficient to directly obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * the tree map and just insert new entries, but not so much as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * to justify the extra internal interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         */
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   217
        TreeMap<String, String> map = fm.getCreatedFontFamilyNames();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (map == null || map.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return installed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            for (int i=0; i<installed.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                map.put(installed[i].toLowerCase(requestedLocale),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                        installed[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            String[] retval =  new String[map.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            Object [] keyNames = map.keySet().toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            for (int i=0; i < keyNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                retval[i] = (String)map.get(keyNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public String[] getAvailableFontFamilyNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return getAvailableFontFamilyNames(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Return the bounds of a GraphicsDevice, less its screen insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * See also java.awt.GraphicsEnvironment.getUsableBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public static Rectangle getUsableBounds(GraphicsDevice gd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        Rectangle usableBounds = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        usableBounds.x += insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        usableBounds.y += insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        usableBounds.width -= (insets.left + insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        usableBounds.height -= (insets.top + insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return usableBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * From the DisplayChangedListener interface; called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * when the display mode has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        // notify screens in device array to do display update stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        for (GraphicsDevice gd : getScreenDevices()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            if (gd instanceof DisplayChangedListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                ((DisplayChangedListener) gd).displayChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // notify SunDisplayChanger list (e.g. VolatileSurfaceManagers and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        // SurfaceDataProxies) about the display change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        displayChanger.notifyListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Part of the DisplayChangedListener interface:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * propagate this event to listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        displayChanger.notifyPaletteChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
1724
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   280
    /**
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   281
     * Returns true when the display is local, false for remote displays.
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   282
     *
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   283
     * @return true when the display is local, false for remote displays
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   284
     */
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   285
    public abstract boolean isDisplayLocal();
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   286
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * ----DISPLAY CHANGE SUPPORT----
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    protected SunDisplayChanger displayChanger = new SunDisplayChanger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Add a DisplayChangeListener to be notified when the display settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * are changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public void addDisplayChangedListener(DisplayChangedListener client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        displayChanger.add(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Remove a DisplayChangeListener from Win32GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public void removeDisplayChangedListener(DisplayChangedListener client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        displayChanger.remove(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * ----END DISPLAY CHANGE SUPPORT----
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   311
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   312
    /**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   313
     * Returns true if FlipBufferStrategy with COPIED buffer contents
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   314
     * is preferred for this peer's GraphicsConfiguration over
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   315
     * BlitBufferStrategy, false otherwise.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   316
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   317
     * The reason FlipBS could be preferred is that in some configurations
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   318
     * an accelerated copy to the screen is supported (like Direct3D 9)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   319
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   320
     * @return true if flip strategy should be used, false otherwise
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   321
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   322
    public boolean isFlipStrategyPreferred(ComponentPeer peer) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   323
        return false;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   324
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}