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