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.8 by tdb, Sat May 18 18:15:56 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21 < package uk.org.iscream.conient.datacomponents;
21 > package uk.org.iscream.cms.conient.datacomponents;
22  
23   //---IMPORTS---
24   import javax.swing.JLabel;
# Line 7 | Line 26 | import javax.swing.JTextField;
26   import java.awt.Color;
27   import java.awt.GridLayout;
28   import javax.swing.SwingUtilities;
29 + import uk.org.iscream.cms.server.util.XMLPacket;
30  
31   /**
32   * This is the most basic of DataComponents.
# Line 42 | Line 62 | public class ServiceDataComponent extends VisibleDataC
62       * @param name the friendly name
63       * @param attribute the data attribute we look after
64       */
65 <    public ServiceDataComponent(String name, String attribute, StringDataComponent serviceStatus) {
65 >    public ServiceDataComponent(String name, String attribute, String statusAttribute) {
66          _name = name;
67 <        _serviceStatus = serviceStatus;
67 >        _statusAttribute = statusAttribute;
68          _attribute = attribute;
69 <        setLayout(new GridLayout(1,1));
69 >        setLayout(new GridLayout(1,2));
70 >        _label = new JLabel(_name + ": ");
71 >        _label.setHorizontalAlignment(JLabel.RIGHT);
72          _item = new JTextField("", DEFAULT_TEXT_LENGTH);
73 <        _item.setHorizontalAlignment(JTextField.CENTER);
73 >        _item.setHorizontalAlignment(JTextField.LEFT);
74          _item.setEditable(false);
75          _item.setText("-uninitialised-");
76 +        add(_label);
77          add(_item);
78 +        setVisible(false);
79      }
80  
81   //---PUBLIC METHODS---
# Line 63 | Line 87 | public class ServiceDataComponent extends VisibleDataC
87       * run this method.
88       */
89      public void run() {
90 <        if (_serviceStatusValue.equals("0")) {
91 <            _item.setBackground(Color.green);
92 <            _item.setText(_name + "[OK] : " + _cache);
90 >        if(!isVisible()) {
91 >            setVisible(true);
92 >        }
93 >        if (_statusCache.equals("0")) {
94 >            _item.setForeground(Color.black);
95 >            _item.setText("[OK] : " + _cache);
96          } else {
97 <            _item.setBackground(Color.red);
98 <            _item.setText(_name + "[FAILED] : " + _cache);
97 >            _item.setForeground(Color.red);
98 >            _item.setText("[FAILED] : " + _cache);
99          }
100 +        _item.setCaretPosition(0);
101      }
102      
103      /**
# Line 87 | Line 115 | public class ServiceDataComponent extends VisibleDataC
115   //---ACCESSOR/MUTATOR METHODS---
116  
117      /**
118 <     * This takes the String value of the parameter that this component
91 <     * is monitoring direct from the packet, it then performs all
118 >     * This takes the packet to obtain the value from, it then performs all
119       * approriate conversions and adds this class to the Swing Event
120       * Dispatching queue.
121       *
122 <     * @param value the value for this data component
122 >     * @param packet the XMLPacket to get the data from
123       * @throws DataFormatException if there was a problem converting the data for display
124       */
125 <    public void setValue(String value) throws DataFormatException {
125 >    public void setValue(XMLPacket packet) throws DataFormatException {
126 >        String value = packet.getParam(_attribute);
127 >        String statusvalue = packet.getParam(_statusAttribute);
128          try {
129 <            if((!_cache.equals(value) || !_serviceStatusValue.equals(_serviceStatus.getValue())) && !_serviceStatus.getValue().equals("")) {
129 >            if(!_cache.equals(value) || !_statusCache.equals(statusvalue)) {
130                  _cache = value;
131 <                _serviceStatusValue = _serviceStatus.getValue();
131 >                _statusCache = statusvalue;
132                  SwingUtilities.invokeLater(this);
133              }
134          } catch (Exception e) {
# Line 130 | Line 159 | public class ServiceDataComponent extends VisibleDataC
159      protected String _attribute;
160  
161      /**
162 +     * The service status attribute that this component is concerned with
163 +     */
164 +    protected String _statusAttribute;
165 +
166 +    /**
167       * The friendly label for this component
168       */
169      protected JLabel _label;
170      
171      /**
172 <     * Remebers what the last value was, so we
172 >     * Remembers what the last value was, so we
173       * only update if we have to.
174       */    
175 <    String _cache = "";
175 >    protected String _cache = "";
176      
177 +        /**
178 +     * Remembers what the last value was, so we
179 +     * only update if we have to.
180 +     */    
181 +    protected String _statusCache = "";
182 +    
183      /**
184       * The length of the JTextField
185       */
# Line 149 | Line 189 | public class ServiceDataComponent extends VisibleDataC
189       * Just a normal label to display our value as a String
190       */
191      protected JTextField _item;
152
153    private StringDataComponent _serviceStatus;
154    private String _serviceStatusValue = "";
155
156    
192  
193   //---STATIC ATTRIBUTES---
194  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines