8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt;
27
28 import java.awt.GraphicsConfiguration;
29 import java.awt.GraphicsDevice;
30 import java.awt.GraphicsEnvironment;
31 import java.awt.Toolkit;
32 import java.awt.peer.ComponentPeer;
33 import java.io.File;
34 import java.io.IOException;
35 import java.lang.ref.WeakReference;
36 import java.util.ArrayList;
37 import java.util.ListIterator;
38 import java.util.NoSuchElementException;
39 import java.util.StringTokenizer;
40 import sun.awt.DisplayChangedListener;
41 import sun.awt.SunDisplayChanger;
42 import sun.awt.windows.WPrinterJob;
43 import sun.awt.windows.WToolkit;
44 import sun.java2d.SunGraphicsEnvironment;
45 import sun.java2d.SurfaceManagerFactory;
46 import sun.java2d.WindowsSurfaceManagerFactory;
47 import sun.java2d.d3d.D3DGraphicsDevice;
76 * includes everything from the native GraphicsDevice elements to
77 * the DirectX rendering layer.
78 */
79 private static native void initDisplay();
80
81 private static boolean displayInitialized; // = false;
82 public static void initDisplayWrapper() {
83 if (!displayInitialized) {
84 displayInitialized = true;
85 initDisplay();
86 }
87 }
88
89 public Win32GraphicsEnvironment() {
90 }
91
92 protected native int getNumScreens();
93 protected native int getDefaultScreen();
94
95 public GraphicsDevice getDefaultScreenDevice() {
96 return getScreenDevices()[getDefaultScreen()];
97 }
98
99 /**
100 * Returns the number of pixels per logical inch along the screen width.
101 * In a system with multiple display monitors, this value is the same for
102 * all monitors.
103 * @returns number of pixels per logical inch in X direction
104 */
105 public native int getXResolution();
106 /**
107 * Returns the number of pixels per logical inch along the screen height.
108 * In a system with multiple display monitors, this value is the same for
109 * all monitors.
110 * @returns number of pixels per logical inch in Y direction
111 */
112 public native int getYResolution();
113
114
115 /*
116 * ----DISPLAY CHANGE SUPPORT----
117 */
118
119 // list of invalidated graphics devices (those which were removed)
120 private ArrayList<WeakReference<Win32GraphicsDevice>> oldDevices;
121 /*
122 * From DisplayChangeListener interface.
123 * Called from WToolkit and executed on the event thread when the
124 * display settings are changed.
125 */
126 @Override
127 public void displayChanged() {
128 // getNumScreens() will return the correct current number of screens
129 GraphicsDevice newDevices[] = new GraphicsDevice[getNumScreens()];
130 GraphicsDevice oldScreens[] = screens;
131 // go through the list of current devices and determine if they
132 // could be reused, or will have to be replaced
133 if (oldScreens != null) {
134 for (int i = 0; i < oldScreens.length; i++) {
135 if (!(screens[i] instanceof Win32GraphicsDevice)) {
136 // REMIND: can we ever have anything other than Win32GD?
137 assert (false) : oldScreens[i];
138 continue;
139 }
140 Win32GraphicsDevice gd = (Win32GraphicsDevice)oldScreens[i];
141 // devices may be invalidated from the native code when the
142 // display change happens (device add/removal also causes a
143 // display change)
144 if (!gd.isValid()) {
145 if (oldDevices == null) {
146 oldDevices =
147 new ArrayList<WeakReference<Win32GraphicsDevice>>();
148 }
149 oldDevices.add(new WeakReference<Win32GraphicsDevice>(gd));
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt;
27
28 import java.awt.AWTError;
29 import java.awt.GraphicsConfiguration;
30 import java.awt.GraphicsDevice;
31 import java.awt.GraphicsEnvironment;
32 import java.awt.Toolkit;
33 import java.awt.peer.ComponentPeer;
34 import java.io.File;
35 import java.io.IOException;
36 import java.lang.ref.WeakReference;
37 import java.util.ArrayList;
38 import java.util.ListIterator;
39 import java.util.NoSuchElementException;
40 import java.util.StringTokenizer;
41 import sun.awt.DisplayChangedListener;
42 import sun.awt.SunDisplayChanger;
43 import sun.awt.windows.WPrinterJob;
44 import sun.awt.windows.WToolkit;
45 import sun.java2d.SunGraphicsEnvironment;
46 import sun.java2d.SurfaceManagerFactory;
47 import sun.java2d.WindowsSurfaceManagerFactory;
48 import sun.java2d.d3d.D3DGraphicsDevice;
77 * includes everything from the native GraphicsDevice elements to
78 * the DirectX rendering layer.
79 */
80 private static native void initDisplay();
81
82 private static boolean displayInitialized; // = false;
83 public static void initDisplayWrapper() {
84 if (!displayInitialized) {
85 displayInitialized = true;
86 initDisplay();
87 }
88 }
89
90 public Win32GraphicsEnvironment() {
91 }
92
93 protected native int getNumScreens();
94 protected native int getDefaultScreen();
95
96 public GraphicsDevice getDefaultScreenDevice() {
97 GraphicsDevice[] screens = getScreenDevices();
98 int index = getDefaultScreen();
99 return screens[0 < index && index < screens.length ? index : 0];
100 }
101
102 /**
103 * Returns the number of pixels per logical inch along the screen width.
104 * In a system with multiple display monitors, this value is the same for
105 * all monitors.
106 * @returns number of pixels per logical inch in X direction
107 */
108 public native int getXResolution();
109 /**
110 * Returns the number of pixels per logical inch along the screen height.
111 * In a system with multiple display monitors, this value is the same for
112 * all monitors.
113 * @returns number of pixels per logical inch in Y direction
114 */
115 public native int getYResolution();
116
117
118 /*
119 * ----DISPLAY CHANGE SUPPORT----
120 */
121
122 // list of invalidated graphics devices (those which were removed)
123 private ArrayList<WeakReference<Win32GraphicsDevice>> oldDevices;
124 /*
125 * From DisplayChangeListener interface.
126 * Called from WToolkit and executed on the event thread when the
127 * display settings are changed.
128 */
129 @Override
130 public void displayChanged() {
131 // getNumScreens() will return the correct current number of screens
132 GraphicsDevice newDevices[] = new GraphicsDevice[getNumScreens()];
133 if (newDevices.length == 0) {
134 throw new AWTError("no screen devices");
135 }
136 GraphicsDevice oldScreens[] = screens;
137 // go through the list of current devices and determine if they
138 // could be reused, or will have to be replaced
139 if (oldScreens != null) {
140 for (int i = 0; i < oldScreens.length; i++) {
141 if (!(screens[i] instanceof Win32GraphicsDevice)) {
142 // REMIND: can we ever have anything other than Win32GD?
143 assert (false) : oldScreens[i];
144 continue;
145 }
146 Win32GraphicsDevice gd = (Win32GraphicsDevice)oldScreens[i];
147 // devices may be invalidated from the native code when the
148 // display change happens (device add/removal also causes a
149 // display change)
150 if (!gd.isValid()) {
151 if (oldDevices == null) {
152 oldDevices =
153 new ArrayList<WeakReference<Win32GraphicsDevice>>();
154 }
155 oldDevices.add(new WeakReference<Win32GraphicsDevice>(gd));
|