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