1 19 20 package org.netbeans.modules.uihandler; 21 22 import java.awt.Window ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.beans.PropertyChangeListener ; 26 import java.beans.PropertyChangeSupport ; 27 import java.util.Queue ; 28 import java.util.concurrent.Callable ; 29 import java.util.logging.Handler ; 30 import java.util.logging.Level ; 31 import java.util.logging.LogRecord ; 32 import javax.swing.JButton ; 33 import javax.swing.JComponent ; 34 import javax.swing.SwingUtilities ; 35 import org.openide.awt.Mnemonics; 36 import org.openide.util.NbBundle; 37 38 42 public class UIHandler extends Handler 43 implements ActionListener , Runnable , Callable <JButton > { 44 private final Queue <LogRecord > logs; 45 private final boolean exceptionOnly; 46 static final PropertyChangeSupport SUPPORT = new PropertyChangeSupport (UIHandler.class); 47 private static int MAX_LOGS = 1000; 48 49 public UIHandler(Queue <LogRecord > l, boolean exceptionOnly) { 50 setLevel(Level.FINEST); 51 logs = l; 52 this.exceptionOnly = exceptionOnly; 53 } 54 55 static void registerCallback(PropertyChangeListener l) { 56 SUPPORT.addPropertyChangeListener(l); 57 } 58 59 60 public void publish(LogRecord 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 { 83 } 84 85 public void run() { 86 Installer.displaySummary("ERROR_URL", true); } 88 89 private JButton button; 90 public JButton call() throws Exception { 91 if (button == null) { 92 button = new JButton (); 93 Mnemonics.setLocalizedText(button, NbBundle.getMessage(UIHandler.class, "MSG_SubmitButton")); button.addActionListener(this); 95 } 96 return button; 97 } 98 99 public void actionPerformed(ActionEvent ev) { 100 JComponent c = (JComponent )ev.getSource(); 101 Window w = SwingUtilities.windowForComponent(c); 102 if (w != null) { 103 w.dispose(); 104 } 105 run(); 106 } 107 } 108 | Popular Tags |