1 2 23 24 package net.fenyo.gnetwatch.GUI; 25 26 import java.io.*; 27 import java.lang.reflect.*; 28 29 import javax.swing.*; 30 import java.awt.*; 31 import java.util.*; 32 33 import net.fenyo.gnetwatch.*; 34 import net.fenyo.gnetwatch.activities.*; 35 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 39 44 45 public class AwtGUI implements Runnable { 46 private static Log log = LogFactory.getLog(AwtGUI.class); 47 48 private final Config config; 49 50 private Thread repaint_thread; 51 private java.util.List <JFrame> frame_list = new ArrayList<JFrame>(); 52 53 57 public AwtGUI(final Config config) { 59 this.config = config; 60 } 61 62 67 public void dropFrame(final JFrame frame) { 69 synchronized (frame_list) { 70 frame_list.remove(frame); 71 } 72 frame.dispose(); 73 } 74 75 80 public void createAwtGUI() { 82 JFrame.setDefaultLookAndFeelDecorated(false); 83 createRepaintThread(); 84 } 85 86 91 private void createRepaintThread() { 93 repaint_thread = new Thread (this, "Repaint Thread"); 94 repaint_thread.start(); 95 } 96 97 103 private void _createFrame(final JFrame frame, final BasicComponent component) { 105 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 106 frame.getContentPane().add(component); 107 108 frame.pack(); 110 frame.setVisible(true); 111 frame.toFront(); 112 } 113 114 120 public JFrame createFrame(final String name, final BasicComponent component) throws InterruptedException , InvocationTargetException { 122 final JFrame frame = new JFrame(name); 123 frame.addWindowListener(component); 124 javax.swing.SwingUtilities.invokeAndWait(new Runnable () { 125 public void run() { 126 _createFrame(frame, component); 127 } 128 }); 129 synchronized (frame_list) { 130 frame_list.add(frame); 131 } 132 return frame; 133 } 134 135 140 public void run() { 142 while (!config.isEnd()) 143 try { 144 Thread.sleep(20); 145 synchronized (frame_list) { 146 for (final Frame frame : frame_list) frame.repaint(); 147 } 148 } catch (final InterruptedException ex) { 149 } 151 } 152 153 159 public void end() throws InterruptedException { 161 repaint_thread.interrupt(); 163 repaint_thread.join(); 164 165 synchronized (frame_list) { 166 for (final Frame frame : frame_list) frame.dispose(); 167 } 168 } 169 } 170 | Popular Tags |