144 * Dummy runnable to wake up EDT from getNextEvent() after 145 push/pop is performed 146 */ 147 private final static Runnable dummyRunnable = new Runnable() { 148 public void run() { 149 } 150 }; 151 152 private EventDispatchThread dispatchThread; 153 154 private final ThreadGroup threadGroup = 155 Thread.currentThread().getThreadGroup(); 156 private final ClassLoader classLoader = 157 Thread.currentThread().getContextClassLoader(); 158 159 /* 160 * The time stamp of the last dispatched InputEvent or ActionEvent. 161 */ 162 private long mostRecentEventTime = System.currentTimeMillis(); 163 164 /** 165 * The modifiers field of the current event, if the current event is an 166 * InputEvent or ActionEvent. 167 */ 168 private WeakReference currentEvent; 169 170 /* 171 * Non-zero if a thread is waiting in getNextEvent(int) for an event of 172 * a particular ID to be posted to the queue. 173 */ 174 private volatile int waitForID; 175 176 private final String name = "AWT-EventQueue-" + threadInitNumber.getAndIncrement(); 177 178 private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventQueue"); 179 180 static { 181 AWTAccessor.setEventQueueAccessor( 182 new AWTAccessor.EventQueueAccessor() { 183 public Thread getDispatchThread(EventQueue eventQueue) { 1111 ((SentEvent)entry.event).dispose(); 1112 } 1113 if (prev == null) { 1114 queues[i].head = entry.next; 1115 } else { 1116 prev.next = entry.next; 1117 } 1118 uncacheEQItem(entry); 1119 } else { 1120 prev = entry; 1121 } 1122 entry = entry.next; 1123 } 1124 queues[i].tail = prev; 1125 } 1126 } finally { 1127 pushPopLock.unlock(); 1128 } 1129 } 1130 1131 static void setCurrentEventAndMostRecentTime(AWTEvent e) { 1132 Toolkit.getEventQueue().setCurrentEventAndMostRecentTimeImpl(e); 1133 } 1134 private void setCurrentEventAndMostRecentTimeImpl(AWTEvent e) { 1135 pushPopLock.lock(); 1136 try { 1137 if (Thread.currentThread() != dispatchThread) { 1138 return; 1139 } 1140 1141 currentEvent = new WeakReference(e); 1142 1143 // This series of 'instanceof' checks should be replaced with a 1144 // polymorphic type (for example, an interface which declares a 1145 // getWhen() method). However, this would require us to make such 1146 // a type public, or to place it in sun.awt. Both of these approaches 1147 // have been frowned upon. So for now, we hack. 1148 // 1149 // In tiger, we will probably give timestamps to all events, so this 1150 // will no longer be an issue. 1151 long mostRecentEventTime2 = Long.MIN_VALUE; 1152 if (e instanceof InputEvent) { 1153 InputEvent ie = (InputEvent)e; 1154 mostRecentEventTime2 = ie.getWhen(); 1155 } else if (e instanceof InputMethodEvent) { 1156 InputMethodEvent ime = (InputMethodEvent)e; 1157 mostRecentEventTime2 = ime.getWhen(); 1158 } else if (e instanceof ActionEvent) { 1159 ActionEvent ae = (ActionEvent)e; 1160 mostRecentEventTime2 = ae.getWhen(); 1161 } else if (e instanceof InvocationEvent) { 1162 InvocationEvent ie = (InvocationEvent)e; 1163 mostRecentEventTime2 = ie.getWhen(); 1164 } 1165 mostRecentEventTime = Math.max(mostRecentEventTime, mostRecentEventTime2); 1166 } finally { 1167 pushPopLock.unlock(); 1168 } 1169 } 1170 1171 /** 1172 * Causes <code>runnable</code> to have its <code>run</code> 1173 * method called in the {@link #isDispatchThread dispatch thread} of 1174 * {@link Toolkit#getSystemEventQueue the system EventQueue}. | 144 * Dummy runnable to wake up EDT from getNextEvent() after 145 push/pop is performed 146 */ 147 private final static Runnable dummyRunnable = new Runnable() { 148 public void run() { 149 } 150 }; 151 152 private EventDispatchThread dispatchThread; 153 154 private final ThreadGroup threadGroup = 155 Thread.currentThread().getThreadGroup(); 156 private final ClassLoader classLoader = 157 Thread.currentThread().getContextClassLoader(); 158 159 /* 160 * The time stamp of the last dispatched InputEvent or ActionEvent. 161 */ 162 private long mostRecentEventTime = System.currentTimeMillis(); 163 164 /* 165 * The time stamp of the last KeyEvent . 166 */ 167 private long mostRecentKeyEventTime = System.currentTimeMillis(); 168 169 /** 170 * The modifiers field of the current event, if the current event is an 171 * InputEvent or ActionEvent. 172 */ 173 private WeakReference currentEvent; 174 175 /* 176 * Non-zero if a thread is waiting in getNextEvent(int) for an event of 177 * a particular ID to be posted to the queue. 178 */ 179 private volatile int waitForID; 180 181 private final String name = "AWT-EventQueue-" + threadInitNumber.getAndIncrement(); 182 183 private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventQueue"); 184 185 static { 186 AWTAccessor.setEventQueueAccessor( 187 new AWTAccessor.EventQueueAccessor() { 188 public Thread getDispatchThread(EventQueue eventQueue) { 1116 ((SentEvent)entry.event).dispose(); 1117 } 1118 if (prev == null) { 1119 queues[i].head = entry.next; 1120 } else { 1121 prev.next = entry.next; 1122 } 1123 uncacheEQItem(entry); 1124 } else { 1125 prev = entry; 1126 } 1127 entry = entry.next; 1128 } 1129 queues[i].tail = prev; 1130 } 1131 } finally { 1132 pushPopLock.unlock(); 1133 } 1134 } 1135 1136 synchronized long getMostRecentKeyEventTime() { 1137 return mostRecentKeyEventTime; 1138 } 1139 1140 static void setCurrentEventAndMostRecentTime(AWTEvent e) { 1141 Toolkit.getEventQueue().setCurrentEventAndMostRecentTimeImpl(e); 1142 } 1143 private void setCurrentEventAndMostRecentTimeImpl(AWTEvent e) { 1144 pushPopLock.lock(); 1145 try { 1146 if (Thread.currentThread() != dispatchThread) { 1147 return; 1148 } 1149 1150 currentEvent = new WeakReference(e); 1151 1152 // This series of 'instanceof' checks should be replaced with a 1153 // polymorphic type (for example, an interface which declares a 1154 // getWhen() method). However, this would require us to make such 1155 // a type public, or to place it in sun.awt. Both of these approaches 1156 // have been frowned upon. So for now, we hack. 1157 // 1158 // In tiger, we will probably give timestamps to all events, so this 1159 // will no longer be an issue. 1160 long mostRecentEventTime2 = Long.MIN_VALUE; 1161 if (e instanceof InputEvent) { 1162 InputEvent ie = (InputEvent)e; 1163 mostRecentEventTime2 = ie.getWhen(); 1164 if (e instanceof KeyEvent) { 1165 mostRecentKeyEventTime = ie.getWhen(); 1166 } 1167 } else if (e instanceof InputMethodEvent) { 1168 InputMethodEvent ime = (InputMethodEvent)e; 1169 mostRecentEventTime2 = ime.getWhen(); 1170 } else if (e instanceof ActionEvent) { 1171 ActionEvent ae = (ActionEvent)e; 1172 mostRecentEventTime2 = ae.getWhen(); 1173 } else if (e instanceof InvocationEvent) { 1174 InvocationEvent ie = (InvocationEvent)e; 1175 mostRecentEventTime2 = ie.getWhen(); 1176 } 1177 mostRecentEventTime = Math.max(mostRecentEventTime, mostRecentEventTime2); 1178 } finally { 1179 pushPopLock.unlock(); 1180 } 1181 } 1182 1183 /** 1184 * Causes <code>runnable</code> to have its <code>run</code> 1185 * method called in the {@link #isDispatchThread dispatch thread} of 1186 * {@link Toolkit#getSystemEventQueue the system EventQueue}. |