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

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2 ajm 1.3 package uk.org.iscream.conient.datacomponents;
3 ajm 1.1
4     //---IMPORTS---
5     import javax.swing.JLabel;
6     import java.awt.GridLayout;
7     import java.util.Date;
8     import java.text.DateFormat;
9 ajm 1.3 import uk.org.iscream.util.DateUtils;
10 ajm 1.1
11     /**
12     * This is DataComponent specifically for converting
13     * uptime into a nice format.
14     *
15     * As this is essentially just string data we just
16     * extend StringDataComponent, intercepting the value
17     * to convert it.
18     *
19     * @author $Author: ajm4 $
20 ajm 1.3 * @version $Id: UptimeDataComponent.java,v 1.2 2001/02/06 00:41:38 ajm4 Exp $
21 ajm 1.1 */
22     public class UptimeDataComponent extends StringDataComponent {
23    
24     //---FINAL ATTRIBUTES---
25    
26     //---STATIC METHODS---
27    
28     //---CONSTRUCTORS---
29    
30     /**
31     * Creates the component with a friendly name to be
32     * used as label, but as we're a very basic
33     * extension of StringDataComponent, we just construct
34     * that.
35     *
36     * @param name the friendly name
37     * @param attribute the data attribute we look after
38     */
39     public UptimeDataComponent(String name, String attribute) {
40     super(name, attribute);
41     }
42    
43     //---PUBLIC METHODS---
44    
45     //---PRIVATE METHODS---
46    
47     //---ACCESSOR/MUTATOR METHODS---
48    
49     /**
50     * This takes the String value of the parameter that this component
51     * is monitoring direct from the packet, it then performs all
52     * approriate conversions and displays the data.
53     *
54     * In this case all we do is change string and pass it to our
55     * super class for displaying. Note that we need to *1000
56     * as the data standard is for time in seconds, but java likes
57     * milliseconds.
58     *
59     * @param value the value for this data component
60     * @throws DataFormatException if there was a problem converting the data for display
61     */
62     public void setValue(String value) throws DataFormatException {
63     try {
64     if(!_cache.equals(value)) {
65     _cache = value;
66 ajm 1.2 value = DateUtils.formatTime(Long.parseLong(value), "%DAYS% days %HOURS% hours %MINS% mins");
67 ajm 1.1 super.setValue(value);
68     }
69     } catch (Exception e) {
70     throw new DataFormatException(value + " is an invalid data type for " + toString());
71     }
72     }
73    
74     //---ATTRIBUTES---
75    
76     /**
77     * Remebers what the last value was, so we
78     * only update if we have to.
79     */
80     String _cache = "";
81    
82     //---STATIC ATTRIBUTES---
83    
84     }