KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > view > StatePanel


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.monitor.view;
5
6 import java.awt.BorderLayout JavaDoc;
7 import java.awt.GridBagConstraints JavaDoc;
8 import java.awt.GridBagLayout JavaDoc;
9 import java.awt.Insets JavaDoc;
10 import java.util.Observable JavaDoc;
11 import java.util.Observer JavaDoc;
12
13 import javax.swing.JLabel JavaDoc;
14 import javax.swing.JPanel JavaDoc;
15 import javax.swing.JScrollPane JavaDoc;
16 import javax.swing.JTextArea JavaDoc;
17 import javax.swing.JTextField JavaDoc;
18 import javax.swing.SwingUtilities JavaDoc;
19
20 import org.oddjob.monitor.model.StateModel;
21
22 /**
23  *
24  */

25 public class StatePanel extends JPanel JavaDoc implements Observer JavaDoc {
26
27     private final JTextField JavaDoc stateField = new JTextField JavaDoc(20);
28
29     private final JTextField JavaDoc timeField = new JTextField JavaDoc(20);
30
31     private final JTextArea JavaDoc exceptionField = new JTextArea JavaDoc();
32
33     public StatePanel() {
34
35         stateField.setEditable(false);
36         timeField.setEditable(false);
37         exceptionField.setEditable(false);
38         exceptionField.setLineWrap(false);
39         JPanel JavaDoc main = new JPanel JavaDoc();
40         
41         JLabel JavaDoc l1 = new JLabel JavaDoc("State", JLabel.TRAILING);
42         JLabel JavaDoc l2 = new JLabel JavaDoc("Time", JLabel.TRAILING);
43         JLabel JavaDoc l3 = new JLabel JavaDoc("Exception", JLabel.TRAILING);
44         
45         JScrollPane JavaDoc scl = new JScrollPane JavaDoc();
46         scl.setViewportView(exceptionField);
47         
48         main.setLayout(new GridBagLayout JavaDoc());
49         
50         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
51         c.weightx = 0.0;
52         c.weighty = 0.0;
53         c.fill = GridBagConstraints.HORIZONTAL;
54         c.anchor = GridBagConstraints.NORTH;
55         c.insets = new Insets JavaDoc(3, 15, 3, 5);
56         
57         c.gridx = 0;
58         c.gridy = 0;
59         main.add(l1, c);
60         
61         c.gridx = 0;
62         c.gridy = 1;
63         main.add(l2, c);
64         
65         c.gridx = 0;
66         c.gridy = 2;
67         main.add(l3, c);
68                 
69         c.insets = new Insets JavaDoc(3, 5, 3, 5);
70         c.weightx = 1.0;
71         
72         c.gridx = 1;
73         c.gridy = 0;
74         main.add(stateField, c);
75
76         c.gridx = 1;
77         c.gridy = 1;
78         main.add(timeField, c);
79
80         c.fill = GridBagConstraints.BOTH;
81         c.weighty = 1.0;
82         c.gridx = 1;
83         c.gridy = 2;
84         main.add(scl, c);
85
86         JScrollPane JavaDoc formScroll = new JScrollPane JavaDoc();
87         formScroll.setViewportView(main);
88         
89         setLayout(new BorderLayout JavaDoc());
90         add(formScroll, BorderLayout.CENTER);
91         
92 // c.insets = new Insets(0, 0, 0, 0);
93
// c.gridx = 2;
94
// c.gridy = 0;
95
// c.gridheight = GridBagConstraints.REMAINDER;
96
// c.weightx = 1.0;
97
// c.weighty = 0.0;
98
// JComponent padding1 = new JPanel();
99
// add(padding1, c);
100

101     }
102     
103     /* (non-Javadoc)
104      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
105      */

106     public void update(Observable JavaDoc o, Object JavaDoc arg) {
107         final StateModel model = (StateModel) o;
108         
109         SwingUtilities.invokeLater(new Runnable JavaDoc() {
110             public void run() {
111                 stateField.setText(model.getState());
112                 timeField.setText(model.getTime());
113                 exceptionField.setText(model.getException());
114             }
115         });
116     }
117     
118 }
119
Popular Tags