KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > SwingUtility


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.swing;
18
19 import java.util.HashSet JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import javax.swing.SwingUtilities JavaDoc;
23
24 import org.openide.windows.IOProvider;
25
26 /**
27  * @author Greg Hinkle (ghinkle@users.sourceforge.net), Mar 4, 2004
28  * @version $Revision: 480 $($Author: ghinkl $ / $Date: 2004-10-05 01:17:41 -0400 (Tue, 05 Oct 2004) $)
29  */

30 public class SwingUtility {
31
32     static Set JavaDoc alertedSet = new HashSet JavaDoc();
33
34     public static void eventThreadAlert() {
35         if (SwingUtilities.isEventDispatchThread()) {
36             StackTraceElement JavaDoc[] elements = new Exception JavaDoc().getStackTrace();
37             for (int i = elements.length-1; i >= 0; i--) {
38                 StackTraceElement JavaDoc element = elements[i];
39                 if (element.getClassName().startsWith("org.mc4j")) {
40
41                     if (alertedSet.isEmpty()) {
42                         IOProvider.getDefault().getIO("MC4J Errors",false).getOut().println(
43                             "This panel lists places within MC4J where calls are being made " +
44                             "to a server from within the AWT Event Thread. These calls are " +
45                             "not safe because long duration calls may cause the application to " +
46                             "be unresponsive.");
47                     }
48                     if (!alertedSet.contains(element)) {
49                         alertedSet.add(element);
50                         IOProvider.getDefault().getIO("MC4J Errors",false).getOut().println(
51                             "Inappropriate call from Awt-EventThread at " +
52                             element.getClassName() + "." +
53                             element.getMethodName() + "(" +
54                             element.getFileName() + ":" +
55                             element.getLineNumber() + ")");
56                         break;
57                     }
58                 }
59             }
60         }
61     }
62 }
63
Popular Tags