1 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
|
|
package uk.ac.ukc.iscream.conient.datacomponents; |
3 |
|
|
|
4 |
|
|
//---IMPORTS--- |
5 |
|
|
import javax.swing.JLabel; |
6 |
|
|
import java.awt.GridLayout; |
7 |
|
|
import java.util.Date; |
8 |
|
|
import java.text.DateFormat; |
9 |
|
|
import uk.ac.ukc.iscream.util.DateUtils; |
10 |
|
|
|
11 |
|
|
/** |
12 |
|
|
* This is DataComponent specifically for converting |
13 |
|
|
* uptime into a nice format. |
14 |
|
|
* |
15 |
|
|
* As this is essentially just string data we just |
16 |
|
|
* extend StringDataComponent, intercepting the value |
17 |
|
|
* to convert it. |
18 |
|
|
* |
19 |
|
|
* @author $Author: ajm4 $ |
20 |
|
|
* @version $Id: DateDataComponent.java,v 1.6 2001/01/29 17:02:32 ajm4 Exp $ |
21 |
|
|
*/ |
22 |
|
|
public class UptimeDataComponent extends StringDataComponent { |
23 |
|
|
|
24 |
|
|
//---FINAL ATTRIBUTES--- |
25 |
|
|
|
26 |
|
|
//---STATIC METHODS--- |
27 |
|
|
|
28 |
|
|
//---CONSTRUCTORS--- |
29 |
|
|
|
30 |
|
|
/** |
31 |
|
|
* Creates the component with a friendly name to be |
32 |
|
|
* used as label, but as we're a very basic |
33 |
|
|
* extension of StringDataComponent, we just construct |
34 |
|
|
* that. |
35 |
|
|
* |
36 |
|
|
* @param name the friendly name |
37 |
|
|
* @param attribute the data attribute we look after |
38 |
|
|
*/ |
39 |
|
|
public UptimeDataComponent(String name, String attribute) { |
40 |
|
|
super(name, attribute); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
//---PUBLIC METHODS--- |
44 |
|
|
|
45 |
|
|
//---PRIVATE METHODS--- |
46 |
|
|
|
47 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
48 |
|
|
|
49 |
|
|
/** |
50 |
|
|
* This takes the String value of the parameter that this component |
51 |
|
|
* is monitoring direct from the packet, it then performs all |
52 |
|
|
* approriate conversions and displays the data. |
53 |
|
|
* |
54 |
|
|
* In this case all we do is change string and pass it to our |
55 |
|
|
* super class for displaying. Note that we need to *1000 |
56 |
|
|
* as the data standard is for time in seconds, but java likes |
57 |
|
|
* milliseconds. |
58 |
|
|
* |
59 |
|
|
* @param value the value for this data component |
60 |
|
|
* @throws DataFormatException if there was a problem converting the data for display |
61 |
|
|
*/ |
62 |
|
|
public void setValue(String value) throws DataFormatException { |
63 |
|
|
try { |
64 |
|
|
if(!_cache.equals(value)) { |
65 |
|
|
_cache = value; |
66 |
|
|
value = DateUtils.formatTime(Long.parseLong(value), "%DAYS% days %HOURS% hours %MINS% mins %SECS% secs"); |
67 |
|
|
super.setValue(value); |
68 |
|
|
} |
69 |
|
|
} catch (Exception e) { |
70 |
|
|
throw new DataFormatException(value + " is an invalid data type for " + toString()); |
71 |
|
|
} |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
//---ATTRIBUTES--- |
75 |
|
|
|
76 |
|
|
/** |
77 |
|
|
* Remebers what the last value was, so we |
78 |
|
|
* only update if we have to. |
79 |
|
|
*/ |
80 |
|
|
String _cache = ""; |
81 |
|
|
|
82 |
|
|
//---STATIC ATTRIBUTES--- |
83 |
|
|
|
84 |
|
|
} |