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.14
Committed: Sun Aug 1 10:40:10 2004 UTC (19 years, 9 months ago) by tdb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.13: +2 -2 lines
Log Message:
Catch a lot of old URL's and update them. Also remove a couple of old files
that aren't used.

File Contents

# User Rev Content
1 tdb 1.11 /*
2     * i-scream central monitoring system
3 tdb 1.14 * http://www.i-scream.org
4 tdb 1.11 * Copyright (C) 2000-2002 i-scream
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     */
20    
21 ajm 1.2 //---PACKAGE DECLARATION---
22 tdb 1.10 package uk.org.iscream.cms.conient.datacomponents;
23 ajm 1.2
24     //---IMPORTS---
25 ajm 1.1 import javax.swing.JLabel;
26     import java.awt.GridLayout;
27     import java.util.Date;
28     import java.text.DateFormat;
29 ajm 1.9 import javax.swing.SwingUtilities;
30 tdb 1.13 import uk.org.iscream.cms.util.XMLPacket;
31 ajm 1.1
32 ajm 1.2 /**
33     * This is DataComponent specifically for converting
34     * time since epoc dates into a nice format.
35     *
36     * As this is essentially just string data we just
37     * extend StringDataComponent, intercepting the value
38     * to convert it.
39     *
40 tdb 1.11 * @author $Author: tdb $
41 tdb 1.14 * @version $Id: DateDataComponent.java,v 1.13 2003/02/05 19:35:04 tdb Exp $
42 ajm 1.2 */
43 ajm 1.1 public class DateDataComponent extends StringDataComponent {
44 ajm 1.2
45     //---FINAL ATTRIBUTES---
46    
47     //---STATIC METHODS---
48    
49     //---CONSTRUCTORS---
50    
51     /**
52     * Creates the component with a friendly name to be
53     * used as label, but as we're a very basic
54     * extension of StringDataComponent, we just construct
55     * that.
56     *
57     * @param name the friendly name
58 ajm 1.3 * @param attribute the data attribute we look after
59 ajm 1.2 */
60 ajm 1.3 public DateDataComponent(String name, String attribute) {
61     super(name, attribute);
62 ajm 1.1 }
63 ajm 1.2
64     //---PUBLIC METHODS---
65    
66     //---PRIVATE METHODS---
67    
68     //---ACCESSOR/MUTATOR METHODS---
69    
70     /**
71 ajm 1.9 * This takes the packet to obtain the value from, it then performs all
72     * approriate conversions and adds this class to the Swing Event
73     * Dispatching queue.
74 ajm 1.2 *
75     * In this case all we do is change string and pass it to our
76 ajm 1.5 * super class for displaying. Note that we need to *1000
77     * as the data standard is for time in seconds, but java likes
78     * milliseconds.
79 ajm 1.2 *
80 ajm 1.9 * @param packet the XMLPacket to get the data from
81 ajm 1.2 * @throws DataFormatException if there was a problem converting the data for display
82     */
83 ajm 1.9 public void setValue(XMLPacket packet) throws DataFormatException {
84     String value = packet.getParam(_attribute);
85 ajm 1.1 try {
86 ajm 1.9 if(!_ourCache.equals(value)) {
87     _ourCache = value;
88     _cache = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(Long.parseLong(value) * 1000));
89     SwingUtilities.invokeLater(this);
90 ajm 1.3 }
91 ajm 1.1 } catch (Exception e) {
92 ajm 1.3 throw new DataFormatException(value + " is an invalid data type for " + toString());
93 ajm 1.1 }
94     }
95 ajm 1.2
96     //---ATTRIBUTES---
97 ajm 1.3
98     /**
99 ajm 1.9 * Remembers what the last value was, so we
100 ajm 1.3 * only update if we have to.
101     */
102 ajm 1.9 String _ourCache = "";
103 ajm 1.2
104     //---STATIC ATTRIBUTES---
105    
106 ajm 1.5 }