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