1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.org.iscream.conient.datacomponents; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import javax.swing.JLabel; |
6 |
import java.awt.GridLayout; |
7 |
import javax.swing.JProgressBar; |
8 |
import javax.swing.SwingUtilities; |
9 |
import uk.org.iscream.util.XMLPacket; |
10 |
|
11 |
/** |
12 |
* This is DataComponent specifically for |
13 |
* displaying Disk information. It displays |
14 |
* a value/total type display using a JProgessBar. |
15 |
* |
16 |
* It does this by extending the StorageDataComponent. |
17 |
* |
18 |
* @author $Author: ajm4 $ |
19 |
* @version $Id: DiskFreeDataComponent.java,v 1.5 2001/03/15 01:05:46 ajm4 Exp $ |
20 |
*/ |
21 |
public class DiskDataComponent extends StorageDataComponent { |
22 |
|
23 |
//---FINAL ATTRIBUTES--- |
24 |
|
25 |
/** |
26 |
* The current CVS revision of this class |
27 |
*/ |
28 |
public final String REVISION = "$Revision: 1.5 $"; |
29 |
|
30 |
//---STATIC METHODS--- |
31 |
|
32 |
//---CONSTRUCTORS--- |
33 |
|
34 |
/** |
35 |
* Creates the component with a friendly name to be |
36 |
* used as label |
37 |
* |
38 |
* @param name the friendly name |
39 |
* @param attribute the data attribute we look after |
40 |
* @param maxAttribute the data attribute to obtain the maximum value from |
41 |
* @param mountAttribute the data attribute to obtain the disk mount point |
42 |
* @param devAttribute the data attribute to obtain the disk device |
43 |
* @param unit the string representation of the units eg, "Mb" or "Kb" |
44 |
* @param divider the amount that the given value should be multiplied by to reach the given units |
45 |
* @param mountPoint the component that will supply the mount point for this disk |
46 |
* @param device the component that will supply the device for this disk |
47 |
*/ |
48 |
public DiskDataComponent(String name, String attribute, String maxAttribute, String mountAttribute, String deviceAttribute, String unit, int divider) { |
49 |
super(name, attribute, maxAttribute, unit, divider); |
50 |
_mountAttribute = mountAttribute; |
51 |
_deviceAttribute = deviceAttribute; |
52 |
} |
53 |
|
54 |
//---PUBLIC METHODS--- |
55 |
|
56 |
/** |
57 |
* This run method updates any Swing components |
58 |
* The setValue() method adds this component |
59 |
* to the Swing Event Dispatching Queue to |
60 |
* run this method. |
61 |
*/ |
62 |
public void run() { |
63 |
super.run(); |
64 |
setLabel(); |
65 |
} |
66 |
|
67 |
//---PRIVATE METHODS--- |
68 |
|
69 |
private void setLabel() { |
70 |
_label.setText(_name + " on " + _mountCache + " (" + _deviceCache + ") : "); |
71 |
} |
72 |
|
73 |
//---ACCESSOR/MUTATOR METHODS--- |
74 |
|
75 |
/** |
76 |
* This takes the packet to obtain the value from, it then performs all |
77 |
* approriate conversions and adds this class to the Swing Event |
78 |
* Dispatching queue. |
79 |
* |
80 |
* @param packet the XMLPacket to get the data from |
81 |
* @throws DataFormatException if there was a problem converting the data for display |
82 |
*/ |
83 |
public void setValue(XMLPacket packet) throws DataFormatException { |
84 |
super.setValue(packet); |
85 |
String mountvalue = packet.getParam(_mountAttribute); |
86 |
String devicevalue = packet.getParam(_deviceAttribute); |
87 |
|
88 |
if (!_mountCache.equals(mountvalue) || !_deviceCache.equals(devicevalue)) { |
89 |
_mountCache = mountvalue; |
90 |
_deviceCache = devicevalue; |
91 |
SwingUtilities.invokeLater(this); |
92 |
} |
93 |
} |
94 |
|
95 |
//---ATTRIBUTES--- |
96 |
|
97 |
/** |
98 |
* Holds the last value of the mountPoint |
99 |
*/ |
100 |
private String _mountCache = ""; |
101 |
|
102 |
/** |
103 |
* Hold the last value for the device |
104 |
*/ |
105 |
private String _deviceCache = ""; |
106 |
|
107 |
/** |
108 |
* The device attribute that this component is concerned with |
109 |
*/ |
110 |
private String _deviceAttribute; |
111 |
|
112 |
/** |
113 |
* The mount attribute that this component is concerned with |
114 |
*/ |
115 |
private String _mountAttribute; |
116 |
|
117 |
//---STATIC ATTRIBUTES--- |
118 |
|
119 |
} |