1 4 package org.oddjob.monitor.view; 5 6 import java.awt.BorderLayout ; 7 import java.awt.GridBagConstraints ; 8 import java.awt.GridBagLayout ; 9 import java.awt.Insets ; 10 import java.util.Observable ; 11 import java.util.Observer ; 12 13 import javax.swing.JLabel ; 14 import javax.swing.JPanel ; 15 import javax.swing.JScrollPane ; 16 import javax.swing.JTextArea ; 17 import javax.swing.JTextField ; 18 import javax.swing.SwingUtilities ; 19 20 import org.oddjob.monitor.model.StateModel; 21 22 25 public class StatePanel extends JPanel implements Observer { 26 27 private final JTextField stateField = new JTextField (20); 28 29 private final JTextField timeField = new JTextField (20); 30 31 private final JTextArea exceptionField = new JTextArea (); 32 33 public StatePanel() { 34 35 stateField.setEditable(false); 36 timeField.setEditable(false); 37 exceptionField.setEditable(false); 38 exceptionField.setLineWrap(false); 39 JPanel main = new JPanel (); 40 41 JLabel l1 = new JLabel ("State", JLabel.TRAILING); 42 JLabel l2 = new JLabel ("Time", JLabel.TRAILING); 43 JLabel l3 = new JLabel ("Exception", JLabel.TRAILING); 44 45 JScrollPane scl = new JScrollPane (); 46 scl.setViewportView(exceptionField); 47 48 main.setLayout(new GridBagLayout ()); 49 50 GridBagConstraints c = new GridBagConstraints (); 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 (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 (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 formScroll = new JScrollPane (); 87 formScroll.setViewportView(main); 88 89 setLayout(new BorderLayout ()); 90 add(formScroll, BorderLayout.CENTER); 91 92 101 } 102 103 106 public void update(Observable o, Object arg) { 107 final StateModel model = (StateModel) o; 108 109 SwingUtilities.invokeLater(new Runnable () { 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 |