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