|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| Track.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* EJTools, the Enterprise Java Tools
|
|
| 3 |
*
|
|
| 4 |
* Distributable under LGPL license.
|
|
| 5 |
* See terms of license at www.gnu.org.
|
|
| 6 |
*/
|
|
| 7 |
package org.ejtools.graph;
|
|
| 8 |
|
|
| 9 |
import java.awt.Color;
|
|
| 10 |
import java.awt.Graphics;
|
|
| 11 |
import java.awt.GridBagConstraints;
|
|
| 12 |
import java.awt.GridBagLayout;
|
|
| 13 |
import java.awt.Insets;
|
|
| 14 |
import java.awt.geom.Point2D;
|
|
| 15 |
import java.beans.PropertyChangeEvent;
|
|
| 16 |
import java.beans.PropertyChangeListener;
|
|
| 17 |
import java.text.DecimalFormat;
|
|
| 18 |
import java.text.NumberFormat;
|
|
| 19 |
import java.util.Calendar;
|
|
| 20 |
import java.util.Collection;
|
|
| 21 |
import java.util.Vector;
|
|
| 22 |
|
|
| 23 |
import javax.swing.BorderFactory;
|
|
| 24 |
import javax.swing.JComponent;
|
|
| 25 |
import javax.swing.JLabel;
|
|
| 26 |
import javax.swing.JPanel;
|
|
| 27 |
import javax.swing.border.BevelBorder;
|
|
| 28 |
|
|
| 29 |
/**
|
|
| 30 |
* Description of the Class
|
|
| 31 |
*
|
|
| 32 |
* @author Laurent Etiemble
|
|
| 33 |
* @version $Revision: 1.11 $
|
|
| 34 |
* @todo Javadoc to complete
|
|
| 35 |
*/
|
|
| 36 |
public class Track implements GraphElement, LabelElement |
|
| 37 |
{
|
|
| 38 |
/** Description of the Field */
|
|
| 39 |
protected Color color = Color.black;
|
|
| 40 |
/** Description of the Field */
|
|
| 41 |
protected TrackLabel component;
|
|
| 42 |
/** Description of the Field */
|
|
| 43 |
protected NumberFormat format = new DecimalFormat("0"); |
|
| 44 |
/** Description of the Field */
|
|
| 45 |
protected String label;
|
|
| 46 |
/** Description of the Field */
|
|
| 47 |
protected String name;
|
|
| 48 |
/** Description of the Field */
|
|
| 49 |
protected Vector points = new Vector(); |
|
| 50 |
/** Description of the Field */
|
|
| 51 |
protected Range xr = new Range(Double.MAX_VALUE, Double.MIN_VALUE); |
|
| 52 |
/** Description of the Field */
|
|
| 53 |
protected Range yr = new Range(Double.MAX_VALUE, Double.MIN_VALUE); |
|
| 54 |
|
|
| 55 |
|
|
| 56 |
/**
|
|
| 57 |
* Constructor for the Track object
|
|
| 58 |
*
|
|
| 59 |
* @param name Description of the Parameter
|
|
| 60 |
*/
|
|
| 61 | 0 |
public Track(String name)
|
| 62 |
{
|
|
| 63 | 0 |
this.name = name;
|
| 64 | 0 |
this.label = name;
|
| 65 | 0 |
this.component = new TrackLabel(this.name); |
| 66 |
} |
|
| 67 |
|
|
| 68 |
|
|
| 69 |
/**
|
|
| 70 |
* Adds a feature to the Point attribute of the Track object
|
|
| 71 |
*
|
|
| 72 |
* @param value The feature to be added to the Value attribute
|
|
| 73 |
*/
|
|
| 74 | 0 |
public void addValue(double value) |
| 75 |
{
|
|
| 76 | 0 |
long time = Calendar.getInstance().getTime().getTime();
|
| 77 |
|
|
| 78 | 0 |
synchronized (this) |
| 79 |
{
|
|
| 80 | 0 |
Point2D.Double point = new Point2D.Double(time, value);
|
| 81 | 0 |
this.points.add(point);
|
| 82 | 0 |
this.xr.put(time);
|
| 83 | 0 |
this.yr.put(value);
|
| 84 | 0 |
this.setLabel(this.name + " : " + this.format.format(value)); |
| 85 |
} |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
|
|
| 89 |
/** Description of the Method */
|
|
| 90 | 0 |
public void clear() |
| 91 |
{
|
|
| 92 | 0 |
this.points.clear();
|
| 93 |
} |
|
| 94 |
|
|
| 95 |
|
|
| 96 |
/**
|
|
| 97 |
* @param graphics Description of the Parameter
|
|
| 98 |
* @param scaleX Description of the Parameter
|
|
| 99 |
* @param offsetX Description of the Parameter
|
|
| 100 |
* @param scaleY Description of the Parameter
|
|
| 101 |
* @param offsetY Description of the Parameter
|
|
| 102 |
*/
|
|
| 103 | 0 |
public void draw(Graphics graphics, double scaleX, double offsetX, double scaleY, double offsetY) |
| 104 |
{
|
|
| 105 | 0 |
graphics.setColor(this.color);
|
| 106 |
|
|
| 107 | 0 |
int x1 = 0;
|
| 108 | 0 |
int y1 = 0;
|
| 109 | 0 |
int x2 = 0;
|
| 110 | 0 |
int y2 = 0;
|
| 111 | 0 |
Point2D point = null;
|
| 112 |
|
|
| 113 | 0 |
if (this.points.size() > 1) |
| 114 |
{
|
|
| 115 | 0 |
point = (Point2D) this.points.get(0);
|
| 116 | 0 |
x1 = (int) (point.getX() * scaleX + offsetX);
|
| 117 | 0 |
y1 = (int) (point.getY() * scaleY + offsetY);
|
| 118 | 0 |
for (int i = 1; i < this.points.size(); i++) |
| 119 |
{
|
|
| 120 | 0 |
point = (Point2D) this.points.get(i);
|
| 121 | 0 |
x2 = (int) (point.getX() * scaleX + offsetX);
|
| 122 | 0 |
y2 = (int) (point.getY() * scaleY + offsetY);
|
| 123 | 0 |
if (x2 > 0)
|
| 124 |
{
|
|
| 125 | 0 |
graphics.drawLine(x1, y1, x2, y2); |
| 126 |
} |
|
| 127 | 0 |
x1 = x2; |
| 128 | 0 |
y1 = y2; |
| 129 |
} |
|
| 130 |
} |
|
| 131 |
} |
|
| 132 |
|
|
| 133 |
|
|
| 134 |
/**
|
|
| 135 |
* @return The color value
|
|
| 136 |
*/
|
|
| 137 | 0 |
public Color getColor()
|
| 138 |
{
|
|
| 139 | 0 |
return this.color; |
| 140 |
} |
|
| 141 |
|
|
| 142 |
|
|
| 143 |
/**
|
|
| 144 |
* @return The component value
|
|
| 145 |
*/
|
|
| 146 | 0 |
public JComponent getComponent()
|
| 147 |
{
|
|
| 148 | 0 |
return this.component; |
| 149 |
} |
|
| 150 |
|
|
| 151 |
|
|
| 152 |
/**
|
|
| 153 |
* Gets the points attribute of the Track object
|
|
| 154 |
*
|
|
| 155 |
* @return The points value
|
|
| 156 |
*/
|
|
| 157 | 0 |
public Collection getPoints()
|
| 158 |
{
|
|
| 159 | 0 |
return (Collection) this.points.clone(); |
| 160 |
} |
|
| 161 |
|
|
| 162 |
|
|
| 163 |
/**
|
|
| 164 |
* @return The xRange value
|
|
| 165 |
*/
|
|
| 166 | 0 |
public Range getXRange()
|
| 167 |
{
|
|
| 168 | 0 |
return this.xr; |
| 169 |
} |
|
| 170 |
|
|
| 171 |
|
|
| 172 |
/**
|
|
| 173 |
* @return The yRange value
|
|
| 174 |
*/
|
|
| 175 | 0 |
public Range getYRange()
|
| 176 |
{
|
|
| 177 | 0 |
return this.yr; |
| 178 |
} |
|
| 179 |
|
|
| 180 |
|
|
| 181 |
/**
|
|
| 182 |
* Sets the color.
|
|
| 183 |
*
|
|
| 184 |
* @param color The color to set
|
|
| 185 |
*/
|
|
| 186 | 0 |
public void setColor(Color color) |
| 187 |
{
|
|
| 188 | 0 |
this.color = color;
|
| 189 | 0 |
this.component.propertyChange(new PropertyChangeEvent(this, "color", "", this.color)); |
| 190 |
} |
|
| 191 |
|
|
| 192 |
|
|
| 193 |
/**
|
|
| 194 |
* Sets the label.
|
|
| 195 |
*
|
|
| 196 |
* @param label The label to set
|
|
| 197 |
*/
|
|
| 198 | 0 |
public void setLabel(String label) |
| 199 |
{
|
|
| 200 | 0 |
this.label = label;
|
| 201 | 0 |
this.component.propertyChange(new PropertyChangeEvent(this, "label", "", this.label)); |
| 202 |
} |
|
| 203 |
|
|
| 204 |
|
|
| 205 |
/**
|
|
| 206 |
* Sets the name.
|
|
| 207 |
*
|
|
| 208 |
* @param name The name to set
|
|
| 209 |
*/
|
|
| 210 | 0 |
public void setName(String name) |
| 211 |
{
|
|
| 212 | 0 |
this.name = name;
|
| 213 |
} |
|
| 214 |
|
|
| 215 |
|
|
| 216 |
/**
|
|
| 217 |
* Description of the Class
|
|
| 218 |
*
|
|
| 219 |
* @author Administrator
|
|
| 220 |
* @version $Revision: 1.11 $
|
|
| 221 |
*/
|
|
| 222 |
private class TrackLabel extends JPanel implements PropertyChangeListener |
|
| 223 |
{
|
|
| 224 |
/** Description of the Field */
|
|
| 225 |
protected JPanel colorPanel = new JPanel(); |
|
| 226 |
/** Description of the Field */
|
|
| 227 |
protected JLabel label = new JLabel(); |
|
| 228 |
|
|
| 229 |
|
|
| 230 |
/**
|
|
| 231 |
* Constructor for CustomJLabel.
|
|
| 232 |
*
|
|
| 233 |
* @param text
|
|
| 234 |
*/
|
|
| 235 | 0 |
public TrackLabel(String text)
|
| 236 |
{
|
|
| 237 | 0 |
super();
|
| 238 | 0 |
this.setLayout(new GridBagLayout()); |
| 239 |
|
|
| 240 | 0 |
GridBagConstraints constraints = new GridBagConstraints();
|
| 241 | 0 |
constraints.insets = new Insets(1, 1, 1, 1);
|
| 242 |
|
|
| 243 | 0 |
constraints.weightx = 0.0d; |
| 244 | 0 |
this.add(this.colorPanel, constraints); |
| 245 | 0 |
this.colorPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
|
| 246 |
|
|
| 247 | 0 |
constraints.weightx = 1.0d; |
| 248 | 0 |
constraints.fill = GridBagConstraints.HORIZONTAL; |
| 249 | 0 |
this.add(this.label, constraints); |
| 250 | 0 |
this.label.setText(text);
|
| 251 | 0 |
this.label.setToolTipText(text);
|
| 252 |
} |
|
| 253 |
|
|
| 254 |
|
|
| 255 |
/** Constructor for CustomJLabel. */
|
|
| 256 | 0 |
public TrackLabel() { }
|
| 257 |
|
|
| 258 |
|
|
| 259 |
/**
|
|
| 260 |
* @param evt Description of the Parameter
|
|
| 261 |
*/
|
|
| 262 | 0 |
public void propertyChange(PropertyChangeEvent evt) |
| 263 |
{
|
|
| 264 | 0 |
if ("label".equals(evt.getPropertyName())) |
| 265 |
{
|
|
| 266 | 0 |
String text = (String) evt.getNewValue(); |
| 267 | 0 |
this.label.setText(text);
|
| 268 | 0 |
this.label.setToolTipText(text);
|
| 269 |
} |
|
| 270 | 0 |
if ("color".equals(evt.getPropertyName())) |
| 271 |
{
|
|
| 272 | 0 |
this.colorPanel.setBackground((Color) evt.getNewValue());
|
| 273 |
} |
|
| 274 |
} |
|
| 275 |
|
|
| 276 |
|
|
| 277 |
/**
|
|
| 278 |
* Description of the Method
|
|
| 279 |
*
|
|
| 280 |
* @return Description of the Return Value
|
|
| 281 |
*/
|
|
| 282 | 0 |
public String toString()
|
| 283 |
{
|
|
| 284 | 0 |
return this.label.getText(); |
| 285 |
} |
|
| 286 |
} |
|
| 287 |
} |
|
| 288 |
|
|
||||||||||