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.11
Committed: Sat May 18 18:15:56 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.10: +21 -2 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

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