0N/A/*
3909N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d;
0N/A
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Font;
0N/Aimport java.awt.Graphics2D;
0N/Aimport java.awt.GraphicsConfiguration;
0N/Aimport java.awt.GraphicsDevice;
0N/Aimport java.awt.GraphicsEnvironment;
0N/Aimport java.awt.Insets;
0N/Aimport java.awt.Rectangle;
0N/Aimport java.awt.Toolkit;
0N/Aimport java.awt.font.TextAttribute;
0N/Aimport java.awt.image.BufferedImage;
430N/Aimport java.awt.peer.ComponentPeer;
0N/Aimport java.io.BufferedReader;
0N/Aimport java.io.File;
0N/Aimport java.io.FileInputStream;
0N/Aimport java.io.FilenameFilter;
0N/Aimport java.io.InputStreamReader;
0N/Aimport java.io.IOException;
0N/Aimport java.text.AttributedCharacterIterator;
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.HashSet;
0N/Aimport java.util.Iterator;
0N/Aimport java.util.Locale;
0N/Aimport java.util.Map;
0N/Aimport java.util.NoSuchElementException;
0N/Aimport java.util.Set;
0N/Aimport java.util.StringTokenizer;
0N/Aimport java.util.TreeMap;
0N/Aimport java.util.Vector;
0N/Aimport java.util.concurrent.ConcurrentHashMap;
0N/Aimport sun.awt.AppContext;
0N/Aimport sun.awt.DisplayChangedListener;
0N/Aimport sun.awt.FontConfiguration;
0N/Aimport sun.awt.SunDisplayChanger;
0N/Aimport sun.font.CompositeFontDescriptor;
0N/Aimport sun.font.Font2D;
0N/Aimport sun.font.FontManager;
1686N/Aimport sun.font.FontManagerFactory;
1686N/Aimport sun.font.FontManagerForSGE;
0N/Aimport sun.font.NativeFont;
0N/A
0N/A/**
0N/A * This is an implementation of a GraphicsEnvironment object for the
0N/A * default local GraphicsEnvironment.
0N/A *
0N/A * @see GraphicsDevice
0N/A * @see GraphicsConfiguration
0N/A */
0N/Apublic abstract class SunGraphicsEnvironment extends GraphicsEnvironment
1686N/A implements DisplayChangedListener {
0N/A
1686N/A public static boolean isOpenSolaris;
1686N/A private static Font defaultFont;
0N/A
0N/A public SunGraphicsEnvironment() {
0N/A java.security.AccessController.doPrivileged(
0N/A new java.security.PrivilegedAction() {
0N/A public Object run() {
426N/A String version = System.getProperty("os.version", "0.0");
426N/A try {
426N/A float ver = Float.parseFloat(version);
426N/A if (ver > 5.10f) {
426N/A File f = new File("/etc/release");
426N/A FileInputStream fis = new FileInputStream(f);
426N/A InputStreamReader isr
426N/A = new InputStreamReader(fis, "ISO-8859-1");
426N/A BufferedReader br = new BufferedReader(isr);
426N/A String line = br.readLine();
426N/A if (line.indexOf("OpenSolaris") >= 0) {
426N/A isOpenSolaris = true;
3441N/A } else {
3441N/A /* We are using isOpenSolaris as meaning
3441N/A * we know the Solaris commercial fonts aren't
3441N/A * present. "Solaris Next" (03/10) did not
3441N/A * include these even though its was not
3441N/A * OpenSolaris. Need to revisit how this is
3441N/A * handled but for now as in 6ux, we'll use
3441N/A * the test for a standard font resource as
3441N/A * being an indicator as to whether we need
3441N/A * to treat this as OpenSolaris from a font
3441N/A * config perspective.
3441N/A */
3441N/A String courierNew =
3441N/A "/usr/openwin/lib/X11/fonts/TrueType/CourierNew.ttf";
3441N/A File courierFile = new File(courierNew);
3441N/A isOpenSolaris = !courierFile.exists();
426N/A }
426N/A fis.close();
426N/A }
426N/A } catch (Exception e) {
426N/A }
0N/A
0N/A /* Establish the default font to be used by SG2D etc */
0N/A defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
0N/A
0N/A return null;
0N/A }
0N/A });
0N/A }
0N/A
0N/A protected GraphicsDevice[] screens;
0N/A
0N/A /**
0N/A * Returns an array of all of the screen devices.
0N/A */
0N/A public synchronized GraphicsDevice[] getScreenDevices() {
0N/A GraphicsDevice[] ret = screens;
0N/A if (ret == null) {
0N/A int num = getNumScreens();
0N/A ret = new GraphicsDevice[num];
0N/A for (int i = 0; i < num; i++) {
0N/A ret[i] = makeScreenDevice(i);
0N/A }
0N/A screens = ret;
0N/A }
0N/A return ret;
0N/A }
0N/A
1686N/A /**
1686N/A * Returns the number of screen devices of this graphics environment.
1686N/A *
1686N/A * @return the number of screen devices of this graphics environment
1686N/A */
0N/A protected abstract int getNumScreens();
1686N/A
1686N/A /**
1686N/A * Create and return the screen device with the specified number. The
1686N/A * device with number <code>0</code> will be the default device (returned
1686N/A * by {@link #getDefaultScreenDevice()}.
1686N/A *
1686N/A * @param screennum the number of the screen to create
1686N/A *
1686N/A * @return the created screen device
1686N/A */
0N/A protected abstract GraphicsDevice makeScreenDevice(int screennum);
0N/A
0N/A /**
0N/A * Returns the default screen graphics device.
0N/A */
0N/A public GraphicsDevice getDefaultScreenDevice() {
0N/A return getScreenDevices()[0];
0N/A }
0N/A
0N/A /**
0N/A * Returns a Graphics2D object for rendering into the
0N/A * given BufferedImage.
0N/A * @throws NullPointerException if BufferedImage argument is null
0N/A */
0N/A public Graphics2D createGraphics(BufferedImage img) {
0N/A if (img == null) {
0N/A throw new NullPointerException("BufferedImage cannot be null");
0N/A }
0N/A SurfaceData sd = SurfaceData.getPrimarySurfaceData(img);
0N/A return new SunGraphics2D(sd, Color.white, Color.black, defaultFont);
0N/A }
0N/A
3358N/A public static FontManagerForSGE getFontManagerForSGE() {
1686N/A FontManager fm = FontManagerFactory.getInstance();
1686N/A return (FontManagerForSGE) fm;
0N/A }
3819N/A
3819N/A /* Modifies the behaviour of a subsequent call to preferLocaleFonts()
3819N/A * to use Mincho instead of Gothic for dialoginput in JA locales
3819N/A * on windows. Not needed on other platforms.
3819N/A *
3819N/A * DO NOT MOVE OR RENAME OR OTHERWISE ALTER THIS METHOD.
3819N/A * ITS USED BY SOME NON-JRE INTERNAL CODE.
3819N/A */
3819N/A public static void useAlternateFontforJALocales() {
3819N/A getFontManagerForSGE().useAlternateFontforJALocales();
3819N/A }
3819N/A
0N/A /**
0N/A * Returns all fonts available in this environment.
0N/A */
0N/A public Font[] getAllFonts() {
1686N/A FontManagerForSGE fm = getFontManagerForSGE();
1686N/A Font[] installedFonts = fm.getAllInstalledFonts();
1686N/A Font[] created = fm.getCreatedFonts();
0N/A if (created == null || created.length == 0) {
0N/A return installedFonts;
0N/A } else {
0N/A int newlen = installedFonts.length + created.length;
0N/A Font [] fonts = java.util.Arrays.copyOf(installedFonts, newlen);
0N/A System.arraycopy(created, 0, fonts,
0N/A installedFonts.length, created.length);
0N/A return fonts;
0N/A }
0N/A }
0N/A
0N/A public String[] getAvailableFontFamilyNames(Locale requestedLocale) {
1686N/A FontManagerForSGE fm = getFontManagerForSGE();
1686N/A String[] installed = fm.getInstalledFontFamilyNames(requestedLocale);
0N/A /* Use a new TreeMap as used in getInstalledFontFamilyNames
0N/A * and insert all the keys in lower case, so that the sort order
0N/A * is the same as the installed families. This preserves historical
0N/A * behaviour and inserts new families in the right place.
0N/A * It would have been marginally more efficient to directly obtain
0N/A * the tree map and just insert new entries, but not so much as
0N/A * to justify the extra internal interface.
0N/A */
1686N/A TreeMap<String, String> map = fm.getCreatedFontFamilyNames();
0N/A if (map == null || map.size() == 0) {
0N/A return installed;
0N/A } else {
0N/A for (int i=0; i<installed.length; i++) {
0N/A map.put(installed[i].toLowerCase(requestedLocale),
0N/A installed[i]);
0N/A }
0N/A String[] retval = new String[map.size()];
0N/A Object [] keyNames = map.keySet().toArray();
0N/A for (int i=0; i < keyNames.length; i++) {
0N/A retval[i] = (String)map.get(keyNames[i]);
0N/A }
0N/A return retval;
0N/A }
0N/A }
0N/A
0N/A public String[] getAvailableFontFamilyNames() {
0N/A return getAvailableFontFamilyNames(Locale.getDefault());
0N/A }
0N/A
0N/A /**
0N/A * Return the bounds of a GraphicsDevice, less its screen insets.
0N/A * See also java.awt.GraphicsEnvironment.getUsableBounds();
0N/A */
0N/A public static Rectangle getUsableBounds(GraphicsDevice gd) {
0N/A GraphicsConfiguration gc = gd.getDefaultConfiguration();
0N/A Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
0N/A Rectangle usableBounds = gc.getBounds();
0N/A
0N/A usableBounds.x += insets.left;
0N/A usableBounds.y += insets.top;
0N/A usableBounds.width -= (insets.left + insets.right);
0N/A usableBounds.height -= (insets.top + insets.bottom);
0N/A
0N/A return usableBounds;
0N/A }
0N/A
0N/A /**
0N/A * From the DisplayChangedListener interface; called
0N/A * when the display mode has been changed.
0N/A */
0N/A public void displayChanged() {
0N/A // notify screens in device array to do display update stuff
0N/A for (GraphicsDevice gd : getScreenDevices()) {
0N/A if (gd instanceof DisplayChangedListener) {
0N/A ((DisplayChangedListener) gd).displayChanged();
0N/A }
0N/A }
0N/A
0N/A // notify SunDisplayChanger list (e.g. VolatileSurfaceManagers and
0N/A // SurfaceDataProxies) about the display change event
0N/A displayChanger.notifyListeners();
0N/A }
0N/A
0N/A /**
0N/A * Part of the DisplayChangedListener interface:
0N/A * propagate this event to listeners
0N/A */
0N/A public void paletteChanged() {
0N/A displayChanger.notifyPaletteChanged();
0N/A }
0N/A
760N/A /**
760N/A * Returns true when the display is local, false for remote displays.
760N/A *
760N/A * @return true when the display is local, false for remote displays
760N/A */
760N/A public abstract boolean isDisplayLocal();
760N/A
0N/A /*
0N/A * ----DISPLAY CHANGE SUPPORT----
0N/A */
0N/A
0N/A protected SunDisplayChanger displayChanger = new SunDisplayChanger();
0N/A
0N/A /**
0N/A * Add a DisplayChangeListener to be notified when the display settings
0N/A * are changed.
0N/A */
0N/A public void addDisplayChangedListener(DisplayChangedListener client) {
0N/A displayChanger.add(client);
0N/A }
0N/A
0N/A /**
0N/A * Remove a DisplayChangeListener from Win32GraphicsEnvironment
0N/A */
0N/A public void removeDisplayChangedListener(DisplayChangedListener client) {
0N/A displayChanger.remove(client);
0N/A }
0N/A
0N/A /*
0N/A * ----END DISPLAY CHANGE SUPPORT----
0N/A */
430N/A
430N/A /**
430N/A * Returns true if FlipBufferStrategy with COPIED buffer contents
430N/A * is preferred for this peer's GraphicsConfiguration over
430N/A * BlitBufferStrategy, false otherwise.
430N/A *
430N/A * The reason FlipBS could be preferred is that in some configurations
430N/A * an accelerated copy to the screen is supported (like Direct3D 9)
430N/A *
430N/A * @return true if flip strategy should be used, false otherwise
430N/A */
430N/A public boolean isFlipStrategyPreferred(ComponentPeer peer) {
430N/A return false;
430N/A }
0N/A}