OSDN Git Service

* java/awt/AWTKeyStroke.java (vktable): Now package-private.
[pf3gnuchains/gcc-fork.git] / libjava / java / awt / GraphicsDevice.java
1 /* GraphicsDevice.java -- information about a graphics device
2    Copyright (C) 2002, 2005  Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37
38
39 package java.awt;
40
41 /**
42  * This describes a graphics device available to the given environment. This
43  * includes screen and printer devices, and the different configurations for
44  * each device. Also, this allows you to create virtual devices which operate
45  * over a multi-screen environment.
46  *
47  * @author Eric Blake (ebb9@email.byu.edu)
48  * @see GraphicsEnvironment
49  * @see GraphicsConfiguration
50  * @since 1.3
51  * @status updated to 1.4
52  */
53 public abstract class GraphicsDevice
54 {
55   /** Device is a raster screen. */
56   public static final int TYPE_RASTER_SCREEN = 0;
57
58   /** Device is a printer. */
59   public static final int TYPE_PRINTER = 1;
60
61   /** Device is an image buffer not visible to the user. */
62   public static final int TYPE_IMAGE_BUFFER = 2;
63
64   /** The current full-screen window, or null if there is none. */
65   private Window full_screen;
66
67   /**
68    * The bounds of the fullscreen window before it has been switched to full
69    * screen.
70    */
71   private Rectangle fullScreenOldBounds;
72
73   /** The current display mode, or null if unknown. */
74   private DisplayMode mode;
75
76   /**
77    * The default constructor.
78    *
79    * @see GraphicsEnvironment#getScreenDevices()
80    * @see GraphicsEnvironment#getDefaultScreenDevice()
81    * @see GraphicsConfiguration#getDevice()
82    */
83   protected GraphicsDevice()
84   {
85   }
86
87   /**
88    * Returns the type of the device.
89    *
90    * @return the device type
91    * @see #TYPE_RASTER_SCREEN
92    * @see #TYPE_PRINTER
93    * @see #TYPE_IMAGE_BUFFER
94    */
95   public abstract int getType();
96
97   /**
98    * Returns an identification string for the device. This can be
99    * vendor-specific, and may be useful for debugging.
100    *
101    * @return the identification
102    */
103   public abstract String getIDstring();
104
105   /**
106    * Return all configurations valid for this device.
107    *
108    * @return an array of configurations
109    */
110   public abstract GraphicsConfiguration[] getConfigurations();
111
112   /**
113    * Return the default configuration for this device.
114    *
115    * @return the default configuration
116    */
117   public abstract GraphicsConfiguration getDefaultConfiguration();
118
119   /**
120    * Return the best configuration, according to the criteria in the given
121    * template.
122    *
123    * @param template the template to adjust by
124    * @return the best configuration
125    * @throws NullPointerException if template is null
126    */
127   public GraphicsConfiguration getBestConfiguration
128     (GraphicsConfigTemplate template)
129   {
130     return template.getBestConfiguration(getConfigurations());
131   }
132
133   /**
134    * Returns true if the device supports full-screen exclusive mode. The
135    * default implementation returns true; subclass it if this is not the case.
136    *
137    * @return true if full screen support is available
138    * @since 1.4
139    */
140   public boolean isFullScreenSupported()
141   {
142     return true;
143   }
144
145   /**
146    * Toggle the given window between full screen and normal mode. The previous
147    * full-screen window, if different, is restored; if the given window is
148    * null, no window will be full screen. If
149    * <code>isFullScreenSupported()</code> returns true, full screen mode is
150    * considered to be exclusive, which implies:<ul>
151    * <li>Windows cannot overlap the full-screen window. All other application
152    *     windows will always appear beneath the full-screen window in the
153    *     Z-order.</li>
154    * <li>Input method windows are disabled. It is advisable to call
155    *     <code>Component.enableInputMethods(false)</code> to make a component
156    *     a non-client of the input method framework.</li>
157    * </ul><br>
158    * If <code>isFullScreenSupported()</code> returns false, full-screen
159    * exclusive mode is simulated by resizing the window to the size of the
160    * screen and positioning it at (0,0). This is also what this method does.
161    * If a device supports real fullscreen mode then it should override this
162    * method as well as #isFullScreenSupported and #getFullScreenWindow.
163    *
164    * @param w the window to toggle
165    * @see #isFullScreenSupported()
166    * @see getFullScreenWindow()
167    * @see setDisplayMode(DisplayMode)
168    * @see Component#enableInputMethods(boolean)
169    * @since 1.4
170    */
171   public synchronized void setFullScreenWindow(Window w)
172   {
173     // Restore the previous window to normal mode and release the reference.
174     if (full_screen != null)
175       {
176         full_screen.setBounds(fullScreenOldBounds);
177       }
178
179     full_screen = null;
180
181     // If w != null, make it full-screen.
182     if (w != null)
183       {
184         fullScreenOldBounds = w.getBounds();
185         full_screen = w;
186         DisplayMode dMode = getDisplayMode();
187         full_screen.setBounds(0, 0, dMode.getWidth(), dMode.getHeight());
188         full_screen.requestFocus();
189         full_screen.setLocationRelativeTo(null);
190       }
191   }
192
193   /**
194    * Returns the current full-screen window of the device, or null if no
195    * window is full-screen.
196    *
197    * @return the full-screen window
198    * @see #setFullScreenWindow(Window)
199    * @since 1.4
200    */
201   public Window getFullScreenWindow()
202   {
203     return full_screen;
204   }
205
206   /**
207    * Returns whether this device supports low-level display changes. This may
208    * depend on whether full-screen exclusive mode is available.
209    *
210    * XXX The default implementation returns false for now.
211    *
212    * @return true if display changes are supported
213    * @see #setDisplayMode(DisplayMode)
214    * @since 1.4
215    */
216   public boolean isDisplayChangeSupported()
217   {
218     return false;
219   }
220
221   /**
222    * Sets the display mode. This may be dependent on the availability of
223    * full-screen exclusive mode.
224    *
225    * @param mode the new mode
226    * @throws IllegalArgumentException if the new mode is not in getDisplayModes
227    * @throws UnsupportedOperationException if ! isDisplayChangeSupported()
228    * @see #getDisplayMode()
229    * @see #getDisplayModes()
230    * @see #isDisplayChangeSupported()
231    * @since 1.4
232    */
233   public void setDisplayMode(DisplayMode mode)
234   {
235     DisplayMode[] array = getDisplayModes();
236     if (! isDisplayChangeSupported())
237       throw new UnsupportedOperationException();
238     int i = array == null ? 0 : array.length;
239     while (--i >= 0)
240       if (array[i].equals(mode))
241         break;
242     if (i < 0)
243       throw new IllegalArgumentException();
244     this.mode = mode;
245   }
246
247   /**
248    * Returns the current display mode of this device, or null if unknown.
249    *
250    * @return the current display mode
251    * @see #setDisplayMode(DisplayMode)
252    * @see #getDisplayModes()
253    * @since 1.4
254    */
255   public DisplayMode getDisplayMode()
256   {
257     return mode;
258   }
259
260   /**
261    * Return an array of all available display modes. This implementation
262    * returns a 0-length array, so subclasses must override this.
263    *
264    * @return the array of available modes
265    * @since 1.4
266    */
267   public DisplayMode[] getDisplayModes()
268   {
269     return new DisplayMode[0];
270   }
271
272   /**
273    * Return the number of bytes available in accelerated memory on this
274    * device. The device may support creation or caching on a first-come,
275    * first-served basis, depending on the operating system and driver.
276    * Memory may be a finite resource, and because of multi-threading, you
277    * are not guaranteed that the result of this method ensures your image
278    * will successfully be put in accelerated memory. A negative result means
279    * the memory is unlimited. The default implementation assumes no special
280    * memory is available, and returns 0.
281    *
282    * @return the size of accelerated memory available
283    * @see VolatileImage#flush()
284    * @see ImageCapabilities#isAccelerated()
285    */
286   public int getAvailableAcceleratedMemory()
287   {
288     return 0;
289   }
290 } // class GraphicsDevice