01: /*
02: * Copyright 1997 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: /**
27: * An EventQueue subclass which adds selective tracing of events as they
28: * are posted to an EventQueue. Tracing is globally enabled and disabled
29: * by the AWT.TraceEventPosting property in awt.properties. <P>
30: *
31: * The optional AWT.NoTraceIDs property defines a list of AWTEvent IDs
32: * which should not be traced, such as MouseEvent.MOUSE_MOVED or PaintEvents.
33: * This list is declared by specifying the decimal value of each event's ID,
34: * separated by commas.
35: *
36: * @version 1.15 05/05/07
37: * @author Thomas Ball
38: */package sun.awt;
39:
40: import java.awt.EventQueue;
41: import java.awt.AWTEvent;
42: import java.awt.Toolkit;
43: import java.util.StringTokenizer;
44:
45: public class TracedEventQueue extends EventQueue {
46:
47: // Determines whether any event tracing is enabled.
48: static boolean trace = false;
49:
50: // The list of event IDs to ignore when tracing.
51: static int suppressedIDs[] = null;
52:
53: static {
54: String s = Toolkit.getProperty("AWT.IgnoreEventIDs", "");
55: if (s.length() > 0) {
56: StringTokenizer st = new StringTokenizer(s, ",");
57: int nIDs = st.countTokens();
58: suppressedIDs = new int[nIDs];
59: for (int i = 0; i < nIDs; i++) {
60: String idString = st.nextToken();
61: try {
62: suppressedIDs[i] = Integer.parseInt(idString);
63: } catch (NumberFormatException e) {
64: System.err
65: .println("Bad ID listed in AWT.IgnoreEventIDs "
66: + "in awt.properties: \""
67: + idString + "\" -- skipped");
68: suppressedIDs[i] = 0;
69: }
70: }
71: } else {
72: suppressedIDs = new int[0];
73: }
74: }
75:
76: public void postEvent(AWTEvent theEvent) {
77: boolean printEvent = true;
78: int id = theEvent.getID();
79: for (int i = 0; i < suppressedIDs.length; i++) {
80: if (id == suppressedIDs[i]) {
81: printEvent = false;
82: break;
83: }
84: }
85: if (printEvent) {
86: System.out.println(Thread.currentThread().getName() + ": "
87: + theEvent);
88: }
89: super.postEvent(theEvent);
90: }
91: }
|