src/java.desktop/share/classes/sun/awt/TracedEventQueue.java
branchJDK-8200758-branch
changeset 57100 489b1afd0ec8
parent 57099 9a85a7a076ad
parent 53193 184c51e48260
child 57101 2c738ab1d1cf
equal deleted inserted replaced
57099:9a85a7a076ad 57100:489b1afd0ec8
     1 /*
       
     2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * 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  * @author  Thomas Ball
       
    37  */
       
    38 
       
    39 package sun.awt;
       
    40 
       
    41 import java.awt.EventQueue;
       
    42 import java.awt.AWTEvent;
       
    43 import java.awt.Toolkit;
       
    44 import java.util.StringTokenizer;
       
    45 
       
    46 public class TracedEventQueue extends EventQueue {
       
    47 
       
    48     // Determines whether any event tracing is enabled.
       
    49     static boolean trace = false;
       
    50 
       
    51     // The list of event IDs to ignore when tracing.
       
    52     static int[] suppressedIDs = null;
       
    53 
       
    54     static {
       
    55         String s = Toolkit.getProperty("AWT.IgnoreEventIDs", "");
       
    56         if (s.length() > 0) {
       
    57             StringTokenizer st = new StringTokenizer(s, ",");
       
    58             int nIDs = st.countTokens();
       
    59             suppressedIDs = new int[nIDs];
       
    60             for (int i = 0; i < nIDs; i++) {
       
    61                 String idString = st.nextToken();
       
    62                 try {
       
    63                     suppressedIDs[i] = Integer.parseInt(idString);
       
    64                 } catch (NumberFormatException e) {
       
    65                     System.err.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 }