ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/datacomponents/ServiceDataComponent.java
(Generate patch)

Comparing projects/cms/source/conient/uk/org/iscream/cms/conient/datacomponents/ServiceDataComponent.java (file contents):
Revision 1.2 by ajm, Thu Mar 15 01:05:46 2001 UTC vs.
Revision 1.6 by ajm, Mon Mar 19 13:56:22 2001 UTC

# Line 7 | Line 7 | import javax.swing.JTextField;
7   import java.awt.Color;
8   import java.awt.GridLayout;
9   import javax.swing.SwingUtilities;
10 + import uk.org.iscream.util.XMLPacket;
11  
12   /**
13   * This is the most basic of DataComponents.
# Line 42 | Line 43 | public class ServiceDataComponent extends VisibleDataC
43       * @param name the friendly name
44       * @param attribute the data attribute we look after
45       */
46 <    public ServiceDataComponent(String name, String attribute, StringDataComponent serviceStatus) {
46 >    public ServiceDataComponent(String name, String attribute, String statusAttribute) {
47          _name = name;
48 <        _serviceStatus = serviceStatus;
48 >        _statusAttribute = statusAttribute;
49          _attribute = attribute;
50 <        setLayout(new GridLayout(1,1));
50 >        setLayout(new GridLayout(1,2));
51 >        _label = new JLabel(_name + ": ");
52 >        _label.setHorizontalAlignment(JLabel.RIGHT);
53          _item = new JTextField("", DEFAULT_TEXT_LENGTH);
54 <        _item.setHorizontalAlignment(JTextField.CENTER);
54 >        _item.setHorizontalAlignment(JTextField.LEFT);
55          _item.setEditable(false);
56          _item.setText("-uninitialised-");
57 +        add(_label);
58          add(_item);
59 +        setVisible(false);
60      }
61  
62   //---PUBLIC METHODS---
# Line 63 | Line 68 | public class ServiceDataComponent extends VisibleDataC
68       * run this method.
69       */
70      public void run() {
71 <        if (_serviceStatusValue.equals("0")) {
72 <            _item.setBackground(Color.green);
73 <            _item.setText(_name + "[OK] : " + _cache);
71 >        if(!isVisible()) {
72 >            setVisible(true);
73 >        }
74 >        if (_statusCache.equals("0")) {
75 >            _item.setForeground(Color.black);
76 >            _item.setText("[OK] : " + _cache);
77          } else {
78 <            _item.setBackground(Color.red);
79 <            _item.setText(_name + "[FAILED] : " + _cache);
78 >            _item.setForeground(Color.red);
79 >            _item.setText("[FAILED] : " + _cache);
80          }
81 +        _item.setCaretPosition(0);
82      }
83      
84      /**
# Line 87 | Line 96 | public class ServiceDataComponent extends VisibleDataC
96   //---ACCESSOR/MUTATOR METHODS---
97  
98      /**
99 <     * This takes the String value of the parameter that this component
91 <     * is monitoring direct from the packet, it then performs all
99 >     * This takes the packet to obtain the value from, it then performs all
100       * approriate conversions and adds this class to the Swing Event
101       * Dispatching queue.
102       *
103 <     * @param value the value for this data component
103 >     * @param packet the XMLPacket to get the data from
104       * @throws DataFormatException if there was a problem converting the data for display
105       */
106 <    public void setValue(String value) throws DataFormatException {
106 >    public void setValue(XMLPacket packet) throws DataFormatException {
107 >        String value = packet.getParam(_attribute);
108 >        String statusvalue = packet.getParam(_statusAttribute);
109          try {
110 <            if((!_cache.equals(value) || !_serviceStatusValue.equals(_serviceStatus.getValue())) && !_serviceStatus.getValue().equals("")) {
110 >            if(!_cache.equals(value) || !_statusCache.equals(statusvalue)) {
111                  _cache = value;
112 <                _serviceStatusValue = _serviceStatus.getValue();
112 >                _statusCache = statusvalue;
113                  SwingUtilities.invokeLater(this);
114              }
115          } catch (Exception e) {
# Line 130 | Line 140 | public class ServiceDataComponent extends VisibleDataC
140      protected String _attribute;
141  
142      /**
143 +     * The service status attribute that this component is concerned with
144 +     */
145 +    protected String _statusAttribute;
146 +
147 +    /**
148       * The friendly label for this component
149       */
150      protected JLabel _label;
151      
152      /**
153 <     * Remebers what the last value was, so we
153 >     * Remembers what the last value was, so we
154       * only update if we have to.
155       */    
156 <    String _cache = "";
156 >    protected String _cache = "";
157      
158 +        /**
159 +     * Remembers what the last value was, so we
160 +     * only update if we have to.
161 +     */    
162 +    protected String _statusCache = "";
163 +    
164      /**
165       * The length of the JTextField
166       */
# Line 149 | Line 170 | public class ServiceDataComponent extends VisibleDataC
170       * Just a normal label to display our value as a String
171       */
172      protected JTextField _item;
152
153    private StringDataComponent _serviceStatus;
154    private String _serviceStatusValue = "";
155
156    
173  
174   //---STATIC ATTRIBUTES---
175  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines