KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > uihandler > UIHandler


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.uihandler;
21
22 import java.awt.Window JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.beans.PropertyChangeListener JavaDoc;
26 import java.beans.PropertyChangeSupport JavaDoc;
27 import java.util.Queue JavaDoc;
28 import java.util.concurrent.Callable JavaDoc;
29 import java.util.logging.Handler JavaDoc;
30 import java.util.logging.Level JavaDoc;
31 import java.util.logging.LogRecord JavaDoc;
32 import javax.swing.JButton JavaDoc;
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.SwingUtilities JavaDoc;
35 import org.openide.awt.Mnemonics;
36 import org.openide.util.NbBundle;
37
38 /**
39  *
40  * @author Jaroslav Tulach
41  */

42 public class UIHandler extends Handler JavaDoc
43 implements ActionListener JavaDoc, Runnable JavaDoc, Callable JavaDoc<JButton JavaDoc> {
44     private final Queue JavaDoc<LogRecord JavaDoc> logs;
45     private final boolean exceptionOnly;
46     static final PropertyChangeSupport JavaDoc SUPPORT = new PropertyChangeSupport JavaDoc(UIHandler.class);
47     private static int MAX_LOGS = 1000;
48     
49     public UIHandler(Queue JavaDoc<LogRecord JavaDoc> l, boolean exceptionOnly) {
50         setLevel(Level.FINEST);
51         logs = l;
52         this.exceptionOnly = exceptionOnly;
53     }
54
55     static void registerCallback(PropertyChangeListener JavaDoc l) {
56         SUPPORT.addPropertyChangeListener(l);
57     }
58     
59     
60     public void publish(LogRecord JavaDoc record) {
61         if (exceptionOnly && record.getThrown() == null) {
62             return;
63         }
64         
65         synchronized (UIHandler.class) {
66             if (logs.size() > MAX_LOGS) {
67                 for (int i = 0; i < 100; i++) {
68                     logs.poll();
69                 }
70             }
71             if (!logs.contains(record)) {
72                 logs.add(record);
73             }
74         }
75         
76         SUPPORT.firePropertyChange(null, null, null);
77     }
78
79     public void flush() {
80     }
81
82     public void close() throws SecurityException JavaDoc {
83     }
84     
85     public void run() {
86         Installer.displaySummary("ERROR_URL", true); // NOI18N
87
}
88
89     private JButton JavaDoc button;
90     public JButton JavaDoc call() throws Exception JavaDoc {
91         if (button == null) {
92             button = new JButton JavaDoc();
93             Mnemonics.setLocalizedText(button, NbBundle.getMessage(UIHandler.class, "MSG_SubmitButton")); // NOI18N
94
button.addActionListener(this);
95         }
96         return button;
97     }
98
99     public void actionPerformed(ActionEvent JavaDoc ev) {
100         JComponent JavaDoc c = (JComponent JavaDoc)ev.getSource();
101         Window JavaDoc w = SwingUtilities.windowForComponent(c);
102         if (w != null) {
103             w.dispose();
104         }
105         run();
106     }
107 }
108
Popular Tags