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.8
Committed: Thu Mar 15 01:05:46 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.7: +2 -2 lines
Log Message:
The whole bally lot now is under uk.org.iscream ;p

File Contents

# User Rev Content
1 ajm 1.2 //---PACKAGE DECLARATION---
2 ajm 1.8 package uk.org.iscream.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    
10 ajm 1.2 /**
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 ajm 1.7 * @author $Author: ajm4 $
19 ajm 1.8 * @version $Id: DateDataComponent.java,v 1.7 2001/02/06 00:09:36 ajm4 Exp $
20 ajm 1.2 */
21 ajm 1.1 public class DateDataComponent extends StringDataComponent {
22 ajm 1.2
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 ajm 1.3 * @param attribute the data attribute we look after
37 ajm 1.2 */
38 ajm 1.3 public DateDataComponent(String name, String attribute) {
39     super(name, attribute);
40 ajm 1.1 }
41 ajm 1.2
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 ajm 1.5 * 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 ajm 1.2 *
58     * @param value the value for this data component
59     * @throws DataFormatException if there was a problem converting the data for display
60     */
61 ajm 1.1 public void setValue(String value) throws DataFormatException {
62     try {
63 ajm 1.3 if(!_cache.equals(value)) {
64     _cache = value;
65 ajm 1.6 value = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(Long.parseLong(value) * 1000));
66 ajm 1.3 super.setValue(value);
67     }
68 ajm 1.1 } catch (Exception e) {
69 ajm 1.3 throw new DataFormatException(value + " is an invalid data type for " + toString());
70 ajm 1.1 }
71     }
72 ajm 1.2
73     //---ATTRIBUTES---
74 ajm 1.3
75     /**
76     * Remebers what the last value was, so we
77     * only update if we have to.
78     */
79     String _cache = "";
80 ajm 1.2
81     //---STATIC ATTRIBUTES---
82    
83 ajm 1.5 }