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