001: /*
002: *
003: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025:
026: package java.awt;
027:
028: import java.awt.im.InputMethodHighlight;
029: import java.awt.image.ColorModel;
030: import java.awt.image.ImageObserver;
031: import java.awt.image.ImageProducer;
032: import sun.awt.image.ByteArrayImageSource;
033:
034: import sun.awt.SunToolkit;
035:
036: /** The toolkit used by this AWT implementation based on the Qt library.
037: @version 1.8, 11/27/01
038: */
039:
040: class QtToolkit extends SunToolkit {
041: // private EventQueue eventQueue = new EventQueue();
042: private QtGraphicsEnvironment localEnv = new QtGraphicsEnvironment();
043: private QtGraphicsConfiguration defaultGC = (QtGraphicsConfiguration) localEnv.defaultScreenDevice
044: .getDefaultConfiguration();
045:
046: public QtToolkit() {
047: super ();
048: }
049:
050: Graphics getGraphics(Window window) {
051: return new QtGraphics(window);
052: }
053:
054: GraphicsEnvironment getLocalGraphicsEnvironment() {
055: return localEnv;
056: }
057:
058: /**
059: * Returns the screen resolution in dots-per-inch.
060: * @return this toolkit's screen resolution, in dots-per-inch.
061: * @since JDK1.0
062: */
063: public native int getScreenResolution();
064:
065: /**
066: * Determines the color model of this toolkit's screen.
067: * <p>
068: * <code>ColorModel</code> is an class that
069: * encapsulates the ability to translate between the
070: * pixel values of an image and its red, green, blue,
071: * and alpha components.
072: * <p>
073: * This toolkit method is called by the
074: * <code>getColorModel</code> method
075: * of the <code>Component</code> class.
076: * @return the color model of this toolkit's screen.
077: * @see java.awt.image.ColorModel
078: * @see java.awt.Component#getColorModel
079: * @since JDK1.0
080: */
081: public ColorModel getColorModel() {
082:
083: return GraphicsEnvironment.getLocalGraphicsEnvironment()
084: .getDefaultScreenDevice().getDefaultConfiguration()
085: .getColorModel();
086: }
087:
088: /**
089: * Returns the names of the available fonts in this toolkit.<p>
090: * For 1.1, the following font names are deprecated (the replacement
091: * name follows):
092: * <ul>
093: * <li>TimesRoman (use Serif)
094: * <li>Helvetica (use SansSerif)
095: * <li>Courier (use Monospaced)
096: * </ul><p>
097: * The ZapfDingbats font is also deprecated in 1.1, but only as a
098: * separate fontname. Unicode defines the ZapfDingbat characters
099: * starting at \u2700, and as of 1.1 Java supports those characters.
100: * @return the names of the available fonts in this toolkit.
101: * @since JDK1.0
102: */
103: public String[] getFontList() {
104: return QtFontMetrics.getFontList();
105: }
106:
107: /**
108: * Gets the screen metrics of the font.
109: * @param font a font.
110: * @return the screen metrics of the specified font in this toolkit.
111: * @since JDK1.0
112: */
113: public FontMetrics getFontMetrics(Font font) {
114: return QtFontMetrics.getFontMetrics(font, true);
115: }
116:
117: /**
118: * Synchronizes this toolkit's graphics state. Some window systems
119: * may do buffering of graphics events.
120: * <p>
121: * This method ensures that the display is up-to-date. It is useful
122: * for animation.
123: * @since JDK1.0
124: */
125: public void sync() { /* localEnv.sync(); */
126: }
127:
128: /**
129: * Prepares an image for rendering.
130: * <p>
131: * If the values of the width and height arguments are both
132: * <code>-1</code>, this method prepares the image for rendering
133: * on the default screen; otherwise, this method prepares an image
134: * for rendering on the default screen at the specified width and height.
135: * <p>
136: * The image data is downloaded asynchronously in another thread,
137: * and an appropriately scaled screen representation of the image is
138: * generated.
139: * <p>
140: * This method is called by components <code>prepareImage</code>
141: * methods.
142: * <p>
143: * Information on the flags returned by this method can be found
144: * with the definition of the <code>ImageObserver</code> interface.
145:
146: * @param image the image for which to prepare a
147: * screen representation.
148: * @param width the width of the desired screen
149: * representation, or <code>-1</code>.
150: * @param height the height of the desired screen
151: * representation, or <code>-1</code>.
152: * @param observer the <code>ImageObserver</code>
153: * object to be notified as the
154: * image is being prepared.
155: * @return <code>true</code> if the image has already been
156: * fully prepared; <code>false</code> otherwise.
157: * @see java.awt.Component#prepareImage(java.awt.Image,
158: * java.awt.image.ImageObserver)
159: * @see java.awt.Component#prepareImage(java.awt.Image,
160: * int, int, java.awt.image.ImageObserver)
161: * @see java.awt.image.ImageObserver
162: * @since JDK1.0
163: */
164: public boolean prepareImage(Image image, int width, int height,
165: ImageObserver observer) {
166:
167: if (image == null)
168: throw new NullPointerException("image can't be null");
169:
170: if (!(image instanceof QtImage)) {
171: return false;
172: }
173:
174: QtImage qtimg = (QtImage) image;
175:
176: return qtimg.prepareImage(width, height, observer);
177: }
178:
179: /**
180: * Indicates the construction status of a specified image that is
181: * being prepared for display.
182: * <p>
183: * If the values of the width and height arguments are both
184: * <code>-1</code>, this method returns the construction status of
185: * a screen representation of the specified image in this toolkit.
186: * Otherwise, this method returns the construction status of a
187: * scaled representation of the image at the specified width
188: * and height.
189: * <p>
190: * This method does not cause the image to begin loading.
191: * An application must call <code>prepareImage</code> to force
192: * the loading of an image.
193: * <p>
194: * This method is called by the component's <code>checkImage</code>
195: * methods.
196: * <p>
197: * Information on the flags returned by this method can be found
198: * with the definition of the <code>ImageObserver</code> interface.
199: * @param image the image whose status is being checked.
200: * @param width the width of the scaled version whose status is
201: * being checked, or <code>-1</code>.
202: * @param height the height of the scaled version whose status
203: * is being checked, or <code>-1</code>.
204: * @param observer the <code>ImageObserver</code> object to be
205: * notified as the image is being prepared.
206: * @return the bitwise inclusive <strong>OR</strong> of the
207: * <code>ImageObserver</code> flags for the
208: * image data that is currently available.
209: * @see java.awt.Toolkit#prepareImage(java.awt.Image,
210: * int, int, java.awt.image.ImageObserver)
211: * @see java.awt.Component#checkImage(java.awt.Image,
212: * java.awt.image.ImageObserver)
213: * @see java.awt.Component#checkImage(java.awt.Image,
214: * int, int, java.awt.image.ImageObserver)
215: * @see java.awt.image.ImageObserver
216: * @since JDK1.0
217: */
218: public int checkImage(Image image, int width, int height,
219: ImageObserver observer) {
220:
221: if (image == null)
222: throw new NullPointerException("image can't be null");
223:
224: if (!(image instanceof QtImage)) {
225: return ImageObserver.ALLBITS;
226: }
227:
228: QtImage qtimg = (QtImage) image;
229:
230: return qtimg.getStatus(observer);
231: }
232:
233: /**
234: * Creates an image with the specified image producer.
235: * @param producer the image producer to be used.
236: * @return an image with the specified image producer.
237: * @see java.awt.Image
238: * @see java.awt.image.ImageProducer
239: * @see java.awt.Component#createImage(java.awt.image.ImageProducer)
240: * @since JDK1.0
241: */
242: public Image createImage(ImageProducer producer) {
243: if (producer == null)
244: throw new NullPointerException("Specify valid producer");
245: return new QtImage(producer);
246: }
247:
248: /**
249: * Creates an image which decodes the image stored in the specified
250: * byte array, and at the specified offset and length.
251: * The data must be in some image format, such as GIF or JPEG,
252: * that is supported by this toolkit.
253: * @param imagedata an array of bytes, representing
254: * image data in a supported image format.
255: * @param imageoffset the offset of the beginning
256: * of the data in the array.
257: * @param imagelength the length of the data in the array.
258: * @return an image.
259: * @since JDK1.1
260: */
261: public Image createImage(byte[] imagedata, int imageoffset,
262: int imagelength) {
263:
264: if (imagedata == null)
265: throw new NullPointerException("Must supply image data");
266:
267: boolean isBadData = (imageoffset + imagelength > imagedata.length
268: || imagelength <= 0 || imagedata.length == 0);
269:
270: ImageProducer ip = new ByteArrayImageSource(imagedata,
271: imageoffset, imagelength);
272: Image newImage = new QtImage(ip, isBadData);
273:
274: return newImage;
275: }
276:
277: Image createImage(Component component, int width, int height) {
278: float size = (float) width * height;
279:
280: if (width <= 0 || height <= 0) {
281: throw new IllegalArgumentException("Width (" + width
282: + ") and height (" + height + ") must be > 0");
283: }
284: if (size >= Integer.MAX_VALUE) {
285: throw new IllegalArgumentException("Dimensions (width="
286: + width + " height=" + height + ") are too large");
287: }
288:
289: return new QtOffscreenImage(component, width, height, defaultGC);
290: }
291:
292: /**
293: * Emits an audio beep.
294: * @since JDK1.1
295: */
296: public native void beep();
297:
298: /* abstract method from SunToolkit */
299: public String getDefaultCharacterEncoding() {
300: return ""; // not needed for pbp
301: }
302:
303: protected int getScreenWidth() {
304: Rectangle dims = GraphicsEnvironment
305: .getLocalGraphicsEnvironment().getDefaultScreenDevice()
306: .getDefaultConfiguration().getBounds();
307: return dims.width;
308: }
309:
310: protected int getScreenHeight() {
311: Rectangle dims = GraphicsEnvironment
312: .getLocalGraphicsEnvironment().getDefaultScreenDevice()
313: .getDefaultConfiguration().getBounds();
314: return dims.height;
315: }
316:
317: private native void hideNative();
318:
319: /**
320: * Show the specified window in a multi-vm environment
321: */
322: public void activate(Window window) {
323: if (window == null) {
324: return;
325: }
326: window.setVisible(true);
327: }
328:
329: /**
330: * Hide the specified window in a multi-vm environment
331: */
332: public void deactivate(Window window) {
333: if (window == null) {
334: return;
335: }
336: window.setVisible(false);
337: hideNative();
338: }
339: }
|