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/DateDataComponent.java
Revision: 1.10
Committed: Tue May 29 17:41:32 2001 UTC (22 years, 11 months ago) by tdb
Branch: MAIN
Changes since 1.9: +3 -3 lines
Log Message:
The last of the central monitoring system packages to be changed to the newer
structure. It has changed from;

uk.org.iscream.conient.*

to;

uk.org.iscream.cms.conient.*

This is in keeping with the new style of packaging.

File Contents

# User Rev Content
1 ajm 1.2 //---PACKAGE DECLARATION---
2 tdb 1.10 package uk.org.iscream.cms.conient.datacomponents;
3 ajm 1.2
4     //---IMPORTS---
5 ajm 1.1 import javax.swing.JLabel;
6     import java.awt.GridLayout;
7     import java.util.Date;
8     import java.text.DateFormat;
9 ajm 1.9 import javax.swing.SwingUtilities;
10 tdb 1.10 import uk.org.iscream.cms.server.util.XMLPacket;
11 ajm 1.1
12 ajm 1.2 /**
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 ajm 1.7 * @author $Author: ajm4 $
21 tdb 1.10 * @version $Id: DateDataComponent.java,v 1.9 2001/03/18 14:43:39 ajm4 Exp $
22 ajm 1.2 */
23 ajm 1.1 public class DateDataComponent extends StringDataComponent {
24 ajm 1.2
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 ajm 1.3 * @param attribute the data attribute we look after
39 ajm 1.2 */
40 ajm 1.3 public DateDataComponent(String name, String attribute) {
41     super(name, attribute);
42 ajm 1.1 }
43 ajm 1.2
44     //---PUBLIC METHODS---
45    
46     //---PRIVATE METHODS---
47    
48     //---ACCESSOR/MUTATOR METHODS---
49    
50     /**
51 ajm 1.9 * 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 ajm 1.2 *
55     * In this case all we do is change string and pass it to our
56 ajm 1.5 * 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 ajm 1.2 *
60 ajm 1.9 * @param packet the XMLPacket to get the data from
61 ajm 1.2 * @throws DataFormatException if there was a problem converting the data for display
62     */
63 ajm 1.9 public void setValue(XMLPacket packet) throws DataFormatException {
64     String value = packet.getParam(_attribute);
65 ajm 1.1 try {
66 ajm 1.9 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 ajm 1.3 }
71 ajm 1.1 } catch (Exception e) {
72 ajm 1.3 throw new DataFormatException(value + " is an invalid data type for " + toString());
73 ajm 1.1 }
74     }
75 ajm 1.2
76     //---ATTRIBUTES---
77 ajm 1.3
78     /**
79 ajm 1.9 * Remembers what the last value was, so we
80 ajm 1.3 * only update if we have to.
81     */
82 ajm 1.9 String _ourCache = "";
83 ajm 1.2
84     //---STATIC ATTRIBUTES---
85    
86 ajm 1.5 }