Mercurial > hg > blitz_stable
comparison src/org/dancres/blitz/tools/dash/DashBoardFrame.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children | 77db38eb3042 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.tools.dash; | |
2 | |
3 import java.awt.BorderLayout; | |
4 import java.awt.FlowLayout; | |
5 import java.awt.Dimension; | |
6 import java.awt.event.WindowAdapter; | |
7 import java.awt.event.WindowEvent; | |
8 import java.util.HashMap; | |
9 import java.util.Map; | |
10 | |
11 import java.util.logging.Logger; | |
12 import java.util.logging.Level; | |
13 | |
14 import javax.swing.JComponent; | |
15 import javax.swing.JFrame; | |
16 import javax.swing.JLabel; | |
17 import javax.swing.JOptionPane; | |
18 import javax.swing.JPanel; | |
19 import javax.swing.UIManager; | |
20 import javax.swing.plaf.metal.MetalLookAndFeel; | |
21 import javax.swing.SwingUtilities; | |
22 import javax.swing.ImageIcon; | |
23 | |
24 import org.dancres.blitz.remote.StatsAdmin; | |
25 import org.dancres.blitz.stats.Stat; | |
26 | |
27 public class DashBoardFrame extends JFrame | |
28 implements Runnable{ | |
29 | |
30 static final Logger theLogger = | |
31 Logger.getLogger("org.dancres.blitz.tools.dash.DashBoardFrame"); | |
32 | |
33 private StatsAdmin _admin; | |
34 private DashBoard _dashBoard; | |
35 private JLabel _status; | |
36 private Thread _updater; | |
37 private boolean _exitOnClose; | |
38 private StatsTableModel _allStats=new StatsTableModel(); | |
39 | |
40 public DashBoardFrame(String title,StatsAdmin admin,boolean exitOnClose){ | |
41 super(title); | |
42 | |
43 // System.out.println("Blitz Dashboard: Developed in association with Inca X (www.incax.com)"); | |
44 | |
45 _admin=admin; | |
46 _exitOnClose=exitOnClose; | |
47 setResizable(false); | |
48 | |
49 if (exitOnClose) { | |
50 try{ | |
51 String lfClassName=UIManager.getSystemLookAndFeelClassName(); | |
52 String uiClass = "javax.swing.plaf.metal.MetalLookAndFeel"; | |
53 if(uiClass.equals(lfClassName)){ | |
54 MetalLookAndFeel.setCurrentTheme(new BlitzTheme()); | |
55 } | |
56 | |
57 UIManager.setLookAndFeel(lfClassName); | |
58 ImageIcon icon=new ImageIcon(getClass().getResource("images/blitz.gif")); | |
59 setIconImage(icon.getImage()); | |
60 | |
61 }catch(Exception ex){ | |
62 theLogger.log(Level.SEVERE, "Exception in close", ex); | |
63 } | |
64 } | |
65 | |
66 setSize(740,140); | |
67 | |
68 //add listener to intterupt thread on close | |
69 addWindowListener( new WindowAdapter(){ | |
70 public void windowClosing(WindowEvent evt){ | |
71 closeWin(); | |
72 | |
73 } | |
74 | |
75 }); | |
76 | |
77 getContentPane().add(createUI(),BorderLayout.CENTER); | |
78 | |
79 _updater=new Thread(this); | |
80 _updater.start(); | |
81 } | |
82 | |
83 public Dimension getPreferredSize() { | |
84 return new Dimension(740, 140); | |
85 } | |
86 | |
87 private void closeWin(){ | |
88 dispose(); | |
89 _updater.interrupt(); | |
90 | |
91 if(_exitOnClose){ | |
92 System.exit(0); | |
93 } | |
94 } | |
95 //added so the ServiceUI WindowListener gets notified | |
96 private void postWindowClosingEvent(){ | |
97 dispatchEvent(new WindowEvent(this,WindowEvent.WINDOW_CLOSING)); | |
98 } | |
99 | |
100 //creates the UI for this application | |
101 private JComponent createUI(){ | |
102 | |
103 _dashBoard=new DashBoard(this); | |
104 _dashBoard.init(_admin); | |
105 return _dashBoard; | |
106 | |
107 } | |
108 private JComponent createStatusBar(){ | |
109 _status=new JLabel(); | |
110 JPanel p=new JPanel(); | |
111 p.setLayout( new FlowLayout(FlowLayout.LEFT)); | |
112 p.add(_status); | |
113 p.setPreferredSize(new Dimension(740, 140)); | |
114 return p; | |
115 } | |
116 public void run(){ | |
117 while(!_updater.isInterrupted()){ | |
118 try{ | |
119 //need to be configurable | |
120 Thread.sleep(1500); | |
121 Map lookup=new HashMap(); | |
122 | |
123 Stat[] stats = _admin.getStats(); | |
124 _dashBoard.update(stats); | |
125 //now pass on to main global view | |
126 | |
127 }catch(InterruptedException ex){ | |
128 // System.out.println("Updater thread exiting"); | |
129 return; | |
130 }catch(java.rmi.ConnectException ex){ | |
131 JOptionPane.showMessageDialog(this,ex.getMessage()); | |
132 postWindowClosingEvent(); | |
133 | |
134 }catch(java.rmi.NoSuchObjectException ex){ | |
135 JOptionPane.showMessageDialog(this,ex.getMessage()); | |
136 postWindowClosingEvent(); | |
137 | |
138 }catch(Exception ex){ | |
139 int ok=JOptionPane.showConfirmDialog(this, | |
140 ""+ex.getMessage()+"\n\nDo you want to continue monitoring stats?" | |
141 ,"Error", | |
142 JOptionPane.YES_NO_OPTION); | |
143 | |
144 if(ok==JOptionPane.NO_OPTION){ | |
145 postWindowClosingEvent(); | |
146 } | |
147 theLogger.log(Level.INFO, "Exception in update", ex); | |
148 } | |
149 } | |
150 } | |
151 } |