1 |
/* GraphicsEnvironment.java -- information about the graphics environment |
/* GraphicsEnvironment.java -- information about the graphics environment |
2 |
Copyright (C) 2002, 2004 Free Software Foundation, Inc. |
Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
39 |
package java.awt; |
package java.awt; |
40 |
|
|
41 |
import gnu.java.awt.ClasspathToolkit; |
import gnu.java.awt.ClasspathToolkit; |
42 |
|
import gnu.classpath.SystemProperties; |
43 |
import java.awt.image.BufferedImage; |
import java.awt.image.BufferedImage; |
44 |
import java.util.Locale; |
import java.util.Locale; |
45 |
|
|
56 |
*/ |
*/ |
57 |
public abstract class GraphicsEnvironment |
public abstract class GraphicsEnvironment |
58 |
{ |
{ |
59 |
|
private static GraphicsEnvironment localGraphicsEnvironment; |
60 |
|
|
61 |
/** |
/** |
62 |
* The environment must be obtained from a factory or query method, hence |
* The environment must be obtained from a factory or query method, hence |
63 |
* this constructor is protected. |
* this constructor is protected. |
67 |
} |
} |
68 |
|
|
69 |
/** |
/** |
70 |
* Returns the local graphics environment. |
* Returns the local graphics environment. If the java.awt.graphicsenv |
71 |
|
* system property is set, it instantiates the specified class, |
72 |
|
* otherwise it assume that the awt toolkit is a ClasspathToolkit |
73 |
|
* and delegates to it to create the instance. |
74 |
* |
* |
|
* XXX Not implemented in Classpath yet. |
|
75 |
* @return the local environment |
* @return the local environment |
76 |
*/ |
*/ |
77 |
public static GraphicsEnvironment getLocalGraphicsEnvironment() |
public static GraphicsEnvironment getLocalGraphicsEnvironment() |
78 |
{ |
{ |
79 |
ClasspathToolkit tk; |
if (localGraphicsEnvironment != null) |
80 |
tk = ((ClasspathToolkit) Toolkit.getDefaultToolkit ()); |
return localGraphicsEnvironment; |
81 |
return tk.getLocalGraphicsEnvironment (); |
|
82 |
|
String graphicsenv = SystemProperties.getProperty("java.awt.graphicsenv", |
83 |
|
null); |
84 |
|
if (graphicsenv != null) |
85 |
|
{ |
86 |
|
try |
87 |
|
{ |
88 |
|
// We intentionally use the bootstrap class loader. |
89 |
|
localGraphicsEnvironment = (GraphicsEnvironment) |
90 |
|
Class.forName(graphicsenv).newInstance(); |
91 |
|
return localGraphicsEnvironment; |
92 |
|
} |
93 |
|
catch (Exception x) |
94 |
|
{ |
95 |
|
throw (InternalError) |
96 |
|
new InternalError("Unable to instantiate java.awt.graphicsenv") |
97 |
|
.initCause(x); |
98 |
|
} |
99 |
|
} |
100 |
|
else |
101 |
|
{ |
102 |
|
ClasspathToolkit tk; |
103 |
|
tk = ((ClasspathToolkit) Toolkit.getDefaultToolkit()); |
104 |
|
localGraphicsEnvironment = tk.getLocalGraphicsEnvironment(); |
105 |
|
return localGraphicsEnvironment; |
106 |
|
} |
107 |
} |
} |
108 |
|
|
109 |
/** |
/** |
112 |
* Windows Toolkit (java.awt) throw a {@link HeadlessException} if this |
* Windows Toolkit (java.awt) throw a {@link HeadlessException} if this |
113 |
* returns true. |
* returns true. |
114 |
* |
* |
115 |
* XXX For now, Classpath assumes that it is never headless. |
* This method returns true if the java.awt.headless property is set |
116 |
|
* to "true". |
117 |
* |
* |
118 |
* @return true if the environment is headless, meaning that graphics are |
* @return true if the environment is headless, meaning that graphics are |
119 |
* unsupported |
* unsupported |
121 |
*/ |
*/ |
122 |
public static boolean isHeadless() |
public static boolean isHeadless() |
123 |
{ |
{ |
124 |
// XXX Should be: getLocalGraphicsEnvironment().isHeadlessInstance(); |
String headless = SystemProperties.getProperty("java.awt.headless", null); |
125 |
return false; |
return "true".equalsIgnoreCase(headless); |
126 |
} |
} |
127 |
|
|
128 |
/** |
/** |
129 |
* Check if the given environment is headless, meaning that it does not |
* Check if the given environment is headless, meaning that it does not |
130 |
* support a display, keyboard, or mouse. Many methods in the Abstract |
* support a display, keyboard, or mouse. Many methods in the Abstract |
131 |
* Windows Toolkit (java.awt) throw a {@link HeadlessException} if this |
* Windows Toolkit (java.awt) throw a {@link HeadlessException} if this |
132 |
* returns true. This default implementation returns false, so subclasses |
* returns true. This default implementation returns isHeadless(), so |
133 |
* need only override it if they are headless. |
* subclasses need only override it if they differ. |
134 |
* |
* |
135 |
* @return true if the environment is headless, meaning that graphics are |
* @return true if the environment is headless, meaning that graphics are |
136 |
* unsupported |
* unsupported |
138 |
*/ |
*/ |
139 |
public boolean isHeadlessInstance() |
public boolean isHeadlessInstance() |
140 |
{ |
{ |
141 |
return false; |
return isHeadless(); |
142 |
} |
} |
143 |
|
|
144 |
/** |
/** |