1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79: import ;
80: import ;
81: import ;
82: import ;
83: import ;
84: import ;
85: import ;
86: import ;
87: import ;
88: import ;
89: import ;
90: import ;
91: import ;
92: import ;
93: import ;
94: import ;
95: import ;
96: import ;
97: import ;
98: import ;
99: import ;
100: import ;
101: import ;
102: import ;
103: import ;
104: import ;
105: import ;
106: import ;
107: import ;
108: import ;
109: import ;
110: import ;
111: import ;
112: import ;
113: import ;
114: import ;
115: import ;
116: import ;
117: import ;
118: import ;
119: import ;
120: import ;
121: import ;
122: import ;
123: import ;
124: import ;
125:
126: import ;
127:
128: public class QtToolkit extends ClasspathToolkit
129: {
130: public static EventQueue eventQueue = null;
131: public static QtRepaintThread repaintThread = null;
132: public static MainQtThread guiThread = null;
133: public static QtGraphicsEnvironment graphicsEnv = null;
134:
135: private static void initToolkit()
136: {
137: eventQueue = new EventQueue();
138: repaintThread = new QtRepaintThread();
139: if (Configuration.INIT_LOAD_LIBRARY)
140: System.loadLibrary("qtpeer");
141:
142: String theme = null;
143: try
144: {
145: String style = System.getProperty("qtoptions.style");
146: if(style != null)
147: theme = style;
148: }
149: catch(SecurityException e)
150: {
151: }
152: catch(IllegalArgumentException e)
153: {
154: }
155:
156: boolean doublebuffer = true;
157: try
158: {
159: String style = System.getProperty("qtoptions.nodoublebuffer");
160: if(style != null)
161: doublebuffer = false;
162: }
163: catch(SecurityException e)
164: {
165: }
166: catch(IllegalArgumentException e)
167: {
168: }
169:
170: guiThread = new MainQtThread( theme, doublebuffer );
171: guiThread.start();
172: repaintThread.start();
173: }
174:
175:
178: public QtToolkit()
179: {
180: if( guiThread == null )
181: initToolkit();
182:
183: while (!guiThread.isRunning());
184:
185: if( graphicsEnv == null )
186: graphicsEnv = new QtGraphicsEnvironment( this );
187: }
188:
189: native String[] nativeFontFamilies();
190:
191: native int numScreens();
192:
193: native int defaultScreen();
194:
195:
196:
197: public synchronized native void beep();
198:
199: public int checkImage(Image image, int w, int h, ImageObserver observer)
200: {
201: if(image instanceof QtImage)
202: return ((QtImage)image).checkImage(observer);
203:
204: return ImageObserver.ERROR;
205: }
206:
207: protected ButtonPeer createButton( Button target )
208: {
209: return new QtButtonPeer( this, target );
210: }
211:
212: protected CanvasPeer createCanvas(Canvas target)
213: {
214: return new QtCanvasPeer( this, target );
215: }
216:
217: protected CheckboxPeer createCheckbox(Checkbox target)
218: {
219: return new QtCheckboxPeer( this, target );
220: }
221:
222: protected ChoicePeer createChoice(Choice target)
223: {
224: return new QtChoicePeer( this, target );
225: }
226:
227: protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target)
228: {
229: return new QtMenuItemPeer( this, target );
230: }
231:
232: public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge)
233: {
234: throw new RuntimeException("Not implemented");
235: }
236:
237: protected FramePeer createFrame(Frame target)
238: {
239: return new QtFramePeer( this, target );
240: }
241:
242: protected FileDialogPeer createFileDialog(FileDialog target)
243: {
244: return new QtFileDialogPeer( this, target );
245: }
246:
247: public Image createImage(ImageProducer producer)
248: {
249: return new QtImage( producer );
250: }
251:
252: public Image createImage(byte[] imageData,
253: int imageOffset,
254: int imageLength)
255: {
256: byte[] dataCopy = new byte[imageLength];
257: System.arraycopy(imageData, imageOffset, dataCopy, 0, imageLength);
258: return new QtImage( dataCopy );
259: }
260:
261: public Image createImage(String filename)
262: {
263: return new QtImage( filename );
264: }
265:
266: public Image createImage(URL url)
267: {
268: return new QtImage( url );
269: }
270:
271: protected TextFieldPeer createTextField(TextField target)
272: {
273: return new QtTextFieldPeer(this,target);
274: }
275:
276: protected LabelPeer createLabel(Label target)
277: {
278: return new QtLabelPeer( this, target );
279: }
280:
281: protected ListPeer createList(List target)
282: {
283: return new QtListPeer( this, target );
284: }
285:
286: protected ScrollbarPeer createScrollbar(Scrollbar target)
287: {
288: return new QtScrollbarPeer( this, target );
289: }
290:
291: protected ScrollPanePeer createScrollPane(ScrollPane target)
292: {
293: return new QtScrollPanePeer( this, target );
294: }
295:
296: protected TextAreaPeer createTextArea(TextArea target)
297: {
298: return new QtTextAreaPeer( this, target );
299: }
300:
301: protected PanelPeer createPanel(Panel target)
302: {
303: return new QtPanelPeer( this, target);
304: }
305:
306: protected WindowPeer createWindow(Window target)
307: {
308: return new QtWindowPeer( this, target );
309: }
310:
311: protected DialogPeer createDialog(Dialog target)
312: {
313: return new QtDialogPeer( this, target );
314: }
315:
316: protected MenuBarPeer createMenuBar(MenuBar target)
317: {
318: return new QtMenuBarPeer( this, target );
319: }
320:
321: protected MenuPeer createMenu(Menu target)
322: {
323: return new QtMenuPeer( this, target );
324: }
325:
326: protected PopupMenuPeer createPopupMenu(PopupMenu target)
327: {
328: return new QtPopupMenuPeer( this, target );
329: }
330:
331: protected MenuItemPeer createMenuItem(MenuItem target)
332: {
333: return new QtMenuItemPeer( this, target );
334: }
335:
336:
339: public AWTEventListener[] getAWTEventListeners()
340: {
341: return null;
342: }
343:
344:
347: public AWTEventListener[] getAWTEventListeners(long mask)
348: {
349: return null;
350: }
351:
352: public ColorModel getColorModel()
353: {
354: return new DirectColorModel(32,
355: 0x00FF0000,
356: 0x0000FF00,
357: 0x000000FF,
358: 0xFF000000);
359: }
360:
361:
364: public String[] getFontList()
365: {
366: String[] builtIn = new String[] { "Dialog",
367: "DialogInput",
368: "Monospaced",
369: "Serif",
370: "SansSerif" };
371: String[] nat = nativeFontFamilies();
372: String[] allFonts = new String[ nat.length + 5 ];
373: System.arraycopy(builtIn, 0, allFonts, 0, 5);
374: System.arraycopy(nat, 0, allFonts, 5, nat.length);
375: return allFonts;
376: }
377:
378: public FontMetrics getFontMetrics(Font font)
379: {
380: return new QtFontMetrics(font);
381: }
382:
383: protected FontPeer getFontPeer(String name,
384: int style)
385: {
386: Map attrs = new HashMap ();
387: ClasspathFontPeer.copyStyleToAttrs(style, attrs);
388: ClasspathFontPeer.copySizeToAttrs(12, attrs);
389: return getClasspathFontPeer (name, attrs);
390: }
391:
392: public Image getImage(String filename)
393: {
394: return new QtImage(filename);
395: }
396:
397: public Image getImage(URL url)
398: {
399: return createImage( url );
400: }
401:
402: public PrintJob getPrintJob(Frame frame,
403: String jobtitle,
404: Properties props)
405: {
406: throw new RuntimeException("Not implemented");
407: }
408:
409: public Clipboard getSystemClipboard()
410: {
411: throw new RuntimeException("Not implemented");
412: }
413:
414: protected EventQueue getSystemEventQueueImpl()
415: {
416: return eventQueue;
417: }
418:
419: public native Dimension getScreenSize();
420:
421: public native int getScreenResolution();
422:
423: public Map mapInputMethodHighlight(InputMethodHighlight highlight)
424: {
425: return null;
426: }
427:
428: public boolean prepareImage(Image image, int w, int h, ImageObserver observer)
429: {
430: if(image instanceof QtImage)
431: return true;
432: return false;
433: }
434:
435: public native void sync();
436:
437:
438:
439: public GraphicsEnvironment getLocalGraphicsEnvironment()
440: {
441: return graphicsEnv;
442: }
443:
444: public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs)
445: {
446: return new QtFontPeer (name, attrs);
447: }
448:
449: public ClasspathTextLayoutPeer getClasspathTextLayoutPeer(AttributedString str,
450: FontRenderContext frc)
451: {
452: return null;
453: }
454:
455:
456: public Font createFont(int format, InputStream stream)
457: {
458: throw new UnsupportedOperationException();
459: }
460:
461:
462: public RobotPeer createRobot (GraphicsDevice screen) throws AWTException
463: {
464: throw new UnsupportedOperationException();
465: }
466:
467: public EmbeddedWindowPeer createEmbeddedWindow(EmbeddedWindow w)
468: {
469:
470: return null;
471: }
472: }