84
85 /**
86 * Number of buttons.
87 * By default it's taken from the system. If system value does not
88 * fit into int type range, use our own MAX_BUTTONS_SUPPORT value.
89 */
90 protected static int numberOfButtons = 0;
91
92
93 /* XFree standard mention 24 buttons as maximum:
94 * http://www.xfree86.org/current/mouse.4.html
95 * We workaround systems supporting more than 24 buttons.
96 * Otherwise, we have to use long type values as masks
97 * which leads to API change.
98 * InputEvent.BUTTON_DOWN_MASK may contain only 21 masks due to
99 * the 4-bytes limit for the int type. (CR 6799099)
100 * One more bit is reserved for FIRST_HIGH_BIT.
101 */
102 public final static int MAX_BUTTONS_SUPPORTED = 20;
103
104 public SunToolkit() {
105 Runnable initEQ = new Runnable() {
106 public void run () {
107 EventQueue eventQueue;
108
109 String eqName = System.getProperty("AWT.EventQueueClass",
110 "java.awt.EventQueue");
111
112 try {
113 eventQueue = (EventQueue)Class.forName(eqName).newInstance();
114 } catch (Exception e) {
115 e.printStackTrace();
116 System.err.println("Failed loading " + eqName + ": " + e);
117 eventQueue = new EventQueue();
118 }
119 AppContext appContext = AppContext.getAppContext();
120 appContext.put(AppContext.EVENT_QUEUE_KEY, eventQueue);
121
122 PostEventQueue postEventQueue = new PostEventQueue(eventQueue);
123 appContext.put(POST_EVENT_QUEUE_KEY, postEventQueue);
124 }
125 };
126
127 initEQ.run();
128 }
129
130 public boolean useBufferPerWindow() {
131 return false;
132 }
133
134 public abstract WindowPeer createWindow(Window target)
135 throws HeadlessException;
136
137 public abstract FramePeer createFrame(Frame target)
138 throws HeadlessException;
139
140 public abstract DialogPeer createDialog(Dialog target)
141 throws HeadlessException;
142
143 public abstract ButtonPeer createButton(Button target)
144 throws HeadlessException;
145
146 public abstract TextFieldPeer createTextField(TextField target)
147 throws HeadlessException;
272 public static final void awtLockNotifyAll() {
273 AWT_LOCK_COND.signalAll();
274 }
275
276 public static final boolean isAWTLockHeldByCurrentThread() {
277 return AWT_LOCK.isHeldByCurrentThread();
278 }
279
280 /*
281 * Create a new AppContext, along with its EventQueue, for a
282 * new ThreadGroup. Browser code, for example, would use this
283 * method to create an AppContext & EventQueue for an Applet.
284 */
285 public static AppContext createNewAppContext() {
286 ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
287 // Create appContext before initialization of EventQueue, so all
288 // the calls to AppContext.getAppContext() from EventQueue ctor
289 // return correct values
290 AppContext appContext = new AppContext(threadGroup);
291
292 EventQueue eventQueue;
293 String eqName = System.getProperty("AWT.EventQueueClass",
294 "java.awt.EventQueue");
295 try {
296 eventQueue = (EventQueue)Class.forName(eqName).newInstance();
297 } catch (Exception e) {
298 System.err.println("Failed loading " + eqName + ": " + e);
299 eventQueue = new EventQueue();
300 }
301 appContext.put(AppContext.EVENT_QUEUE_KEY, eventQueue);
302
303 PostEventQueue postEventQueue = new PostEventQueue(eventQueue);
304 appContext.put(POST_EVENT_QUEUE_KEY, postEventQueue);
305
306 return appContext;
307 }
308
309 public static Field getField(final Class<?> klass, final String fieldName) {
310 return AccessController.doPrivileged(new PrivilegedAction<Field>() {
311 public Field run() {
312 try {
313 Field field = klass.getDeclaredField(fieldName);
314 assert (field != null);
315 field.setAccessible(true);
316 return field;
317 } catch (SecurityException e) {
318 assert false;
319 } catch (NoSuchFieldException e) {
320 assert false;
321 }
322 return null;
323 }//run
324 });
|
84
85 /**
86 * Number of buttons.
87 * By default it's taken from the system. If system value does not
88 * fit into int type range, use our own MAX_BUTTONS_SUPPORT value.
89 */
90 protected static int numberOfButtons = 0;
91
92
93 /* XFree standard mention 24 buttons as maximum:
94 * http://www.xfree86.org/current/mouse.4.html
95 * We workaround systems supporting more than 24 buttons.
96 * Otherwise, we have to use long type values as masks
97 * which leads to API change.
98 * InputEvent.BUTTON_DOWN_MASK may contain only 21 masks due to
99 * the 4-bytes limit for the int type. (CR 6799099)
100 * One more bit is reserved for FIRST_HIGH_BIT.
101 */
102 public final static int MAX_BUTTONS_SUPPORTED = 20;
103
104 private static void initEQ(AppContext appContext) {
105 EventQueue eventQueue;
106
107 String eqName = System.getProperty("AWT.EventQueueClass",
108 "java.awt.EventQueue");
109
110 try {
111 eventQueue = (EventQueue)Class.forName(eqName).newInstance();
112 } catch (Exception e) {
113 e.printStackTrace();
114 System.err.println("Failed loading " + eqName + ": " + e);
115 eventQueue = new EventQueue();
116 }
117 appContext.put(AppContext.EVENT_QUEUE_KEY, eventQueue);
118
119 PostEventQueue postEventQueue = new PostEventQueue(eventQueue);
120 appContext.put(POST_EVENT_QUEUE_KEY, postEventQueue);
121 }
122
123 public SunToolkit() {
124 // 7122796: Always create an EQ for the main AppContext
125 initEQ(AppContext.getMainAppContext());
126 }
127
128 public boolean useBufferPerWindow() {
129 return false;
130 }
131
132 public abstract WindowPeer createWindow(Window target)
133 throws HeadlessException;
134
135 public abstract FramePeer createFrame(Frame target)
136 throws HeadlessException;
137
138 public abstract DialogPeer createDialog(Dialog target)
139 throws HeadlessException;
140
141 public abstract ButtonPeer createButton(Button target)
142 throws HeadlessException;
143
144 public abstract TextFieldPeer createTextField(TextField target)
145 throws HeadlessException;
270 public static final void awtLockNotifyAll() {
271 AWT_LOCK_COND.signalAll();
272 }
273
274 public static final boolean isAWTLockHeldByCurrentThread() {
275 return AWT_LOCK.isHeldByCurrentThread();
276 }
277
278 /*
279 * Create a new AppContext, along with its EventQueue, for a
280 * new ThreadGroup. Browser code, for example, would use this
281 * method to create an AppContext & EventQueue for an Applet.
282 */
283 public static AppContext createNewAppContext() {
284 ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
285 // Create appContext before initialization of EventQueue, so all
286 // the calls to AppContext.getAppContext() from EventQueue ctor
287 // return correct values
288 AppContext appContext = new AppContext(threadGroup);
289
290 initEQ(appContext);
291
292 return appContext;
293 }
294
295 public static Field getField(final Class<?> klass, final String fieldName) {
296 return AccessController.doPrivileged(new PrivilegedAction<Field>() {
297 public Field run() {
298 try {
299 Field field = klass.getDeclaredField(fieldName);
300 assert (field != null);
301 field.setAccessible(true);
302 return field;
303 } catch (SecurityException e) {
304 assert false;
305 } catch (NoSuchFieldException e) {
306 assert false;
307 }
308 return null;
309 }//run
310 });
|