|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.java2d; |
|
|
|
import java.awt.AWTError; |
|
import java.awt.Color; |
|
import java.awt.Font; |
|
import java.awt.Graphics2D; |
|
import java.awt.GraphicsConfiguration; |
|
import java.awt.GraphicsDevice; |
|
import java.awt.GraphicsEnvironment; |
|
import java.awt.Insets; |
|
import java.awt.Rectangle; |
|
import java.awt.Toolkit; |
|
import java.awt.font.TextAttribute; |
|
import java.awt.image.BufferedImage; |
|
import java.awt.peer.ComponentPeer; |
|
import java.io.BufferedReader; |
|
import java.io.File; |
|
import java.io.FileInputStream; |
|
import java.io.FilenameFilter; |
|
import java.io.InputStreamReader; |
|
import java.io.IOException; |
|
import java.text.AttributedCharacterIterator; |
|
import java.util.ArrayList; |
|
import java.util.HashSet; |
|
import java.util.Iterator; |
|
import java.util.Locale; |
|
import java.util.Map; |
|
import java.util.NoSuchElementException; |
|
import java.util.Set; |
|
import java.util.StringTokenizer; |
|
import java.util.TreeMap; |
|
import java.util.Vector; |
|
import java.util.concurrent.ConcurrentHashMap; |
|
import sun.awt.AppContext; |
|
import sun.awt.DisplayChangedListener; |
|
import sun.awt.FontConfiguration; |
|
import sun.awt.SunDisplayChanger; |
|
import sun.font.CompositeFontDescriptor; |
|
import sun.font.Font2D; |
|
import sun.font.FontManager; |
|
import sun.font.FontManagerFactory; |
|
import sun.font.FontManagerForSGE; |
|
import sun.font.NativeFont; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public abstract class SunGraphicsEnvironment extends GraphicsEnvironment |
|
implements DisplayChangedListener { |
|
|
|
public static boolean isOpenSolaris; |
|
private static Font defaultFont; |
|
|
|
public SunGraphicsEnvironment() { |
|
java.security.AccessController.doPrivileged( |
|
new java.security.PrivilegedAction() { |
|
public Object run() { |
|
String version = System.getProperty("os.version", "0.0"); |
|
try { |
|
float ver = Float.parseFloat(version); |
|
if (ver > 5.10f) { |
|
File f = new File("/etc/release"); |
|
FileInputStream fis = new FileInputStream(f); |
|
InputStreamReader isr |
|
= new InputStreamReader(fis, "ISO-8859-1"); |
|
BufferedReader br = new BufferedReader(isr); |
|
String line = br.readLine(); |
|
if (line.indexOf("OpenSolaris") >= 0) { |
|
isOpenSolaris = true; |
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
String courierNew = |
|
"/usr/openwin/lib/X11/fonts/TrueType/CourierNew.ttf"; |
|
File courierFile = new File(courierNew); |
|
isOpenSolaris = !courierFile.exists(); |
|
} |
|
fis.close(); |
|
} |
|
} catch (Exception e) { |
|
} |
|
|
|
|
|
defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12); |
|
|
|
return null; |
|
} |
|
}); |
|
} |
|
|
|
protected GraphicsDevice[] screens; |
|
|
|
|
|
|
|
*/ |
|
public synchronized GraphicsDevice[] getScreenDevices() { |
|
GraphicsDevice[] ret = screens; |
|
if (ret == null) { |
|
int num = getNumScreens(); |
|
ret = new GraphicsDevice[num]; |
|
for (int i = 0; i < num; i++) { |
|
ret[i] = makeScreenDevice(i); |
|
} |
|
screens = ret; |
|
} |
|
return ret; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected abstract int getNumScreens(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected abstract GraphicsDevice makeScreenDevice(int screennum); |
|
|
|
|
|
|
|
*/ |
|
public GraphicsDevice getDefaultScreenDevice() { |
|
GraphicsDevice[] screens = getScreenDevices(); |
|
if (screens.length == 0) { |
|
throw new AWTError("no screen devices"); |
|
} |
|
return screens[0]; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Graphics2D createGraphics(BufferedImage img) { |
|
if (img == null) { |
|
throw new NullPointerException("BufferedImage cannot be null"); |
|
} |
|
SurfaceData sd = SurfaceData.getPrimarySurfaceData(img); |
|
return new SunGraphics2D(sd, Color.white, Color.black, defaultFont); |
|
} |
|
|
|
public static FontManagerForSGE getFontManagerForSGE() { |
|
FontManager fm = FontManagerFactory.getInstance(); |
|
return (FontManagerForSGE) fm; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static void useAlternateFontforJALocales() { |
|
getFontManagerForSGE().useAlternateFontforJALocales(); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public Font[] getAllFonts() { |
|
FontManagerForSGE fm = getFontManagerForSGE(); |
|
Font[] installedFonts = fm.getAllInstalledFonts(); |
|
Font[] created = fm.getCreatedFonts(); |
|
if (created == null || created.length == 0) { |
|
return installedFonts; |
|
} else { |
|
int newlen = installedFonts.length + created.length; |
|
Font [] fonts = java.util.Arrays.copyOf(installedFonts, newlen); |
|
System.arraycopy(created, 0, fonts, |
|
installedFonts.length, created.length); |
|
return fonts; |
|
} |
|
} |
|
|
|
public String[] getAvailableFontFamilyNames(Locale requestedLocale) { |
|
FontManagerForSGE fm = getFontManagerForSGE(); |
|
String[] installed = fm.getInstalledFontFamilyNames(requestedLocale); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
TreeMap<String, String> map = fm.getCreatedFontFamilyNames(); |
|
if (map == null || map.size() == 0) { |
|
return installed; |
|
} else { |
|
for (int i=0; i<installed.length; i++) { |
|
map.put(installed[i].toLowerCase(requestedLocale), |
|
installed[i]); |
|
} |
|
String[] retval = new String[map.size()]; |
|
Object [] keyNames = map.keySet().toArray(); |
|
for (int i=0; i < keyNames.length; i++) { |
|
retval[i] = (String)map.get(keyNames[i]); |
|
} |
|
return retval; |
|
} |
|
} |
|
|
|
public String[] getAvailableFontFamilyNames() { |
|
return getAvailableFontFamilyNames(Locale.getDefault()); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public static Rectangle getUsableBounds(GraphicsDevice gd) { |
|
GraphicsConfiguration gc = gd.getDefaultConfiguration(); |
|
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); |
|
Rectangle usableBounds = gc.getBounds(); |
|
|
|
usableBounds.x += insets.left; |
|
usableBounds.y += insets.top; |
|
usableBounds.width -= (insets.left + insets.right); |
|
usableBounds.height -= (insets.top + insets.bottom); |
|
|
|
return usableBounds; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void displayChanged() { |
|
|
|
for (GraphicsDevice gd : getScreenDevices()) { |
|
if (gd instanceof DisplayChangedListener) { |
|
((DisplayChangedListener) gd).displayChanged(); |
|
} |
|
} |
|
|
|
// notify SunDisplayChanger list (e.g. VolatileSurfaceManagers and |
|
|
|
displayChanger.notifyListeners(); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void paletteChanged() { |
|
displayChanger.notifyPaletteChanged(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public abstract boolean isDisplayLocal(); |
|
|
|
/* |
|
* ----DISPLAY CHANGE SUPPORT---- |
|
*/ |
|
|
|
protected SunDisplayChanger displayChanger = new SunDisplayChanger(); |
|
|
|
|
|
|
|
|
|
*/ |
|
public void addDisplayChangedListener(DisplayChangedListener client) { |
|
displayChanger.add(client); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void removeDisplayChangedListener(DisplayChangedListener client) { |
|
displayChanger.remove(client); |
|
} |
|
|
|
/* |
|
* ----END DISPLAY CHANGE SUPPORT---- |
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public boolean isFlipStrategyPreferred(ComponentPeer peer) { |
|
return false; |
|
} |
|
} |