1 |
tdb |
1.6 |
/* |
2 |
|
|
* i-scream central monitoring system |
3 |
tdb |
1.9 |
* http://www.i-scream.org |
4 |
tdb |
1.6 |
* Copyright (C) 2000-2002 i-scream |
5 |
|
|
* |
6 |
|
|
* This program is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU General Public License |
8 |
|
|
* as published by the Free Software Foundation; either version 2 |
9 |
|
|
* of the License, or (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
|
|
*/ |
20 |
|
|
|
21 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
22 |
tdb |
1.5 |
package uk.org.iscream.cms.conient.datacomponents; |
23 |
ajm |
1.1 |
|
24 |
|
|
//---IMPORTS--- |
25 |
|
|
import javax.swing.JLabel; |
26 |
|
|
import java.awt.GridLayout; |
27 |
|
|
import java.util.Date; |
28 |
|
|
import java.text.DateFormat; |
29 |
ajm |
1.4 |
import javax.swing.SwingUtilities; |
30 |
tdb |
1.8 |
import uk.org.iscream.cms.util.DateUtils; |
31 |
|
|
import uk.org.iscream.cms.util.XMLPacket; |
32 |
ajm |
1.1 |
|
33 |
|
|
/** |
34 |
|
|
* This is DataComponent specifically for converting |
35 |
|
|
* uptime into a nice format. |
36 |
|
|
* |
37 |
|
|
* As this is essentially just string data we just |
38 |
|
|
* extend StringDataComponent, intercepting the value |
39 |
|
|
* to convert it. |
40 |
|
|
* |
41 |
tdb |
1.6 |
* @author $Author: tdb $ |
42 |
tdb |
1.9 |
* @version $Id: UptimeDataComponent.java,v 1.8 2003/02/05 19:35:04 tdb Exp $ |
43 |
ajm |
1.1 |
*/ |
44 |
|
|
public class UptimeDataComponent extends StringDataComponent { |
45 |
|
|
|
46 |
|
|
//---FINAL ATTRIBUTES--- |
47 |
|
|
|
48 |
|
|
//---STATIC METHODS--- |
49 |
|
|
|
50 |
|
|
//---CONSTRUCTORS--- |
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* Creates the component with a friendly name to be |
54 |
|
|
* used as label, but as we're a very basic |
55 |
|
|
* extension of StringDataComponent, we just construct |
56 |
|
|
* that. |
57 |
|
|
* |
58 |
|
|
* @param name the friendly name |
59 |
|
|
* @param attribute the data attribute we look after |
60 |
|
|
*/ |
61 |
|
|
public UptimeDataComponent(String name, String attribute) { |
62 |
|
|
super(name, attribute); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
//---PUBLIC METHODS--- |
66 |
|
|
|
67 |
|
|
//---PRIVATE METHODS--- |
68 |
|
|
|
69 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
70 |
|
|
|
71 |
|
|
/** |
72 |
ajm |
1.4 |
* This takes the packet to obtain the value from, it then performs all |
73 |
|
|
* approriate conversions and adds this class to the Swing Event |
74 |
|
|
* Dispatching queue. |
75 |
ajm |
1.1 |
* |
76 |
|
|
* In this case all we do is change string and pass it to our |
77 |
|
|
* super class for displaying. Note that we need to *1000 |
78 |
|
|
* as the data standard is for time in seconds, but java likes |
79 |
|
|
* milliseconds. |
80 |
|
|
* |
81 |
ajm |
1.4 |
* @param packet the XMLPacket to get the data from |
82 |
ajm |
1.1 |
* @throws DataFormatException if there was a problem converting the data for display |
83 |
|
|
*/ |
84 |
ajm |
1.4 |
public void setValue(XMLPacket packet) throws DataFormatException { |
85 |
|
|
String value = packet.getParam(_attribute); |
86 |
ajm |
1.1 |
try { |
87 |
ajm |
1.4 |
if(!_ourCache.equals(value)) { |
88 |
|
|
_ourCache = value; |
89 |
|
|
_cache = DateUtils.formatTime(Long.parseLong(value), "%DAYS% days %HOURS% hours %MINS% mins"); |
90 |
|
|
SwingUtilities.invokeLater(this); |
91 |
ajm |
1.1 |
} |
92 |
|
|
} catch (Exception e) { |
93 |
|
|
throw new DataFormatException(value + " is an invalid data type for " + toString()); |
94 |
|
|
} |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
//---ATTRIBUTES--- |
98 |
|
|
|
99 |
|
|
/** |
100 |
ajm |
1.4 |
* Remembers what the last value was, so we |
101 |
ajm |
1.1 |
* only update if we have to. |
102 |
|
|
*/ |
103 |
ajm |
1.4 |
String _ourCache = ""; |
104 |
ajm |
1.1 |
|
105 |
|
|
//---STATIC ATTRIBUTES--- |
106 |
|
|
|
107 |
|
|
} |