1 19 20 package org.netbeans.modules.exceptions; 21 import java.awt.EventQueue ; 22 import java.io.IOException ; 23 import java.util.LinkedList ; 24 import java.util.logging.Handler ; 25 import java.util.logging.Level ; 26 import java.util.logging.LogRecord ; 27 import java.util.logging.Logger ; 28 import org.netbeans.modules.exceptions.listeners.WinFocusListener; 29 import org.netbeans.modules.exceptions.listeners.TopComponentListener; 30 import org.netbeans.modules.exceptions.listeners.UIHandler; 31 import org.netbeans.modules.exceptions.listeners.WMPropertyListener; 32 import org.openide.windows.WindowManager; 33 34 38 public class Collector { 39 public static final int MAX_LOGS = 100; 40 private static LinkedList <LogRecord > queue = new LinkedList <LogRecord >(); 41 private static TopComponentListener tcListener; 42 private static WMPropertyListener wmListener; 43 private static WinFocusListener focListener; 44 private static Handler uiHandler; 45 private static Collector myInstance; 46 private final static String prop_name = "netbeans.exception.report.min.level"; private String old_property; 48 49 private Collector() { 50 51 } 52 53 public static synchronized Collector getDefault(){ 54 if (myInstance == null){ 55 myInstance = new Collector(); 56 } 57 return myInstance; 58 } 59 60 public void start(){ 61 old_property = System.getProperty(prop_name); 63 System.setProperty(prop_name, "1001"); 65 Logger.getLogger("").addHandler(ExceptionsHandler.getInstance()); 67 Logger log = Logger.getLogger("org.netbeans.ui"); log.setLevel(Level.FINEST); 69 uiHandler = new UIHandler(this); 70 log.addHandler(uiHandler); 71 72 75 tcListener = new TopComponentListener(); 77 try { 78 wmListener = new WMPropertyListener(); 80 } catch (IOException ex) { 81 java.util.logging.Logger.getLogger(Collector.class.getName()).log(java.util.logging.Level.SEVERE, 82 ex.getMessage(), ex); 83 } 84 focListener = new WinFocusListener(); 86 final WinFocusListener fListener = focListener; 87 final WindowManager wManager = WindowManager.getDefault(); 88 89 wManager.addPropertyChangeListener(wmListener); 90 wManager.getRegistry().addPropertyChangeListener(tcListener); 91 92 EventQueue.invokeLater(new Runnable () { 93 94 public void run() { 95 wManager.getMainWindow().addWindowFocusListener(fListener); 96 } 97 }); 98 } 99 100 public synchronized void write(LogRecord rec){ 101 if (queue.size() > MAX_LOGS) { 102 queue.remove(); 103 } 104 queue.add(rec); 105 } 106 107 public LinkedList <LogRecord > getQueue(){ 108 return queue; 109 } 110 111 public void close(){ 112 113 Logger.getLogger("org.netbeans.ui").removeHandler(uiHandler); 115 Logger.getLogger("").removeHandler(ExceptionsHandler.getInstance()); if (old_property!= null) { 117 System.setProperty(prop_name, old_property); 118 } 119 } 120 } 121 | Popular Tags |