[Ejtools-cvs] libraries/graph/src/main/org/ejtools/graph Track.java,1.10,1.11
Brought to you by:
letiemble
|
From: <let...@us...> - 2003-11-27 00:53:35
|
Update of /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph In directory sc8-pr-cvs1:/tmp/cvs-serv10226/graph/src/main/org/ejtools/graph Modified Files: Track.java Log Message: Address Todo #800900 Address Todo #803019 Remove @created tags Index: Track.java =================================================================== RCS file: /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/Track.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Track.java 15 Sep 2003 22:11:22 -0000 1.10 --- Track.java 27 Nov 2003 00:53:31 -0000 1.11 *************** *** 1,288 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph; ! ! import java.awt.Color; ! import java.awt.Graphics; ! import java.awt.GridBagConstraints; ! import java.awt.GridBagLayout; ! import java.awt.Insets; ! import java.awt.geom.Point2D; ! import java.beans.PropertyChangeEvent; ! import java.beans.PropertyChangeListener; ! import java.text.DecimalFormat; ! import java.text.NumberFormat; ! import java.util.Calendar; ! import java.util.Collection; ! import java.util.Vector; ! ! import javax.swing.BorderFactory; ! import javax.swing.JComponent; ! import javax.swing.JLabel; ! import javax.swing.JPanel; ! import javax.swing.border.BevelBorder; ! ! /** ! * Description of the Class ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class Track implements GraphElement, LabelElement ! { ! /** Description of the Field */ ! protected Color color = Color.black; ! /** Description of the Field */ ! protected TrackLabel component; ! /** Description of the Field */ ! protected NumberFormat format = new DecimalFormat("0"); ! /** Description of the Field */ ! protected String label; ! /** Description of the Field */ ! protected String name; ! /** Description of the Field */ ! protected Vector points = new Vector(); ! /** Description of the Field */ ! protected Range xr = new Range(Double.MAX_VALUE, Double.MIN_VALUE); ! /** Description of the Field */ ! protected Range yr = new Range(Double.MAX_VALUE, Double.MIN_VALUE); ! ! ! /** ! * Constructor for the Track object ! * ! * @param name Description of the Parameter ! */ ! public Track(String name) ! { ! this.name = name; ! this.label = name; ! this.component = new TrackLabel(this.name); ! } ! ! ! /** ! * Adds a feature to the Point attribute of the Track object ! * ! * @param value The feature to be added to the Value attribute ! */ ! public void addValue(double value) ! { ! long time = Calendar.getInstance().getTime().getTime(); ! ! synchronized (this) ! { ! Point2D.Double point = new Point2D.Double(time, value); ! this.points.add(point); ! this.xr.put(time); ! this.yr.put(value); ! this.setLabel(this.name + " : " + this.format.format(value)); ! } ! } ! ! ! /** Description of the Method */ ! public void clear() ! { ! this.points.clear(); ! } ! ! ! /** ! * @param graphics Description of the Parameter ! * @param scaleX Description of the Parameter ! * @param offsetX Description of the Parameter ! * @param scaleY Description of the Parameter ! * @param offsetY Description of the Parameter ! */ ! public void draw(Graphics graphics, double scaleX, double offsetX, double scaleY, double offsetY) ! { ! graphics.setColor(this.color); ! ! int x1 = 0; ! int y1 = 0; ! int x2 = 0; ! int y2 = 0; ! Point2D point = null; ! ! if (this.points.size() > 1) ! { ! point = (Point2D) this.points.get(0); ! x1 = (int) (point.getX() * scaleX + offsetX); ! y1 = (int) (point.getY() * scaleY + offsetY); ! for (int i = 1; i < this.points.size(); i++) ! { ! point = (Point2D) this.points.get(i); ! x2 = (int) (point.getX() * scaleX + offsetX); ! y2 = (int) (point.getY() * scaleY + offsetY); ! if (x2 > 0) ! { ! graphics.drawLine(x1, y1, x2, y2); ! } ! x1 = x2; ! y1 = y2; ! } ! } ! } ! ! ! /** ! * @return The color value ! */ ! public Color getColor() ! { ! return this.color; ! } ! ! ! /** ! * @return The component value ! */ ! public JComponent getComponent() ! { ! return this.component; ! } ! ! ! /** ! * Gets the points attribute of the Track object ! * ! * @return The points value ! */ ! public Collection getPoints() ! { ! return (Collection) this.points.clone(); ! } ! ! ! /** ! * @return The xRange value ! */ ! public Range getXRange() ! { ! return this.xr; ! } ! ! ! /** ! * @return The yRange value ! */ ! public Range getYRange() ! { ! return this.yr; ! } ! ! ! /** ! * Sets the color. ! * ! * @param color The color to set ! */ ! public void setColor(Color color) ! { ! this.color = color; ! this.component.propertyChange(new PropertyChangeEvent(this, "color", "", this.color)); ! } ! ! ! /** ! * Sets the label. ! * ! * @param label The label to set ! */ ! public void setLabel(String label) ! { ! this.label = label; ! this.component.propertyChange(new PropertyChangeEvent(this, "label", "", this.label)); ! } ! ! ! /** ! * Sets the name. ! * ! * @param name The name to set ! */ ! public void setName(String name) ! { ! this.name = name; ! } ! ! ! /** ! * Description of the Class ! * ! * @author Administrator ! * @created 13 novembre 2002 ! * @version $Revision$ ! */ ! private class TrackLabel extends JPanel implements PropertyChangeListener ! { ! /** Description of the Field */ ! protected JPanel colorPanel = new JPanel(); ! /** Description of the Field */ ! protected JLabel label = new JLabel(); ! ! ! /** ! * Constructor for CustomJLabel. ! * ! * @param text ! */ ! public TrackLabel(String text) ! { ! super(); ! this.setLayout(new GridBagLayout()); ! ! GridBagConstraints constraints = new GridBagConstraints(); ! constraints.insets = new Insets(1, 1, 1, 1); ! ! constraints.weightx = 0.0d; ! this.add(this.colorPanel, constraints); ! this.colorPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); ! ! constraints.weightx = 1.0d; ! constraints.fill = GridBagConstraints.HORIZONTAL; ! this.add(this.label, constraints); ! this.label.setText(text); ! this.label.setToolTipText(text); ! } ! ! ! /** Constructor for CustomJLabel. */ ! public TrackLabel() { } ! ! ! /** ! * @param evt Description of the Parameter ! */ ! public void propertyChange(PropertyChangeEvent evt) ! { ! if ("label".equals(evt.getPropertyName())) ! { ! String text = (String) evt.getNewValue(); ! this.label.setText(text); ! this.label.setToolTipText(text); ! } ! if ("color".equals(evt.getPropertyName())) ! { ! this.colorPanel.setBackground((Color) evt.getNewValue()); ! } ! } ! ! ! /** ! * Description of the Method ! * ! * @return Description of the Return Value ! */ ! public String toString() ! { ! return this.label.getText(); ! } ! } ! } --- 1,287 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph; ! ! import java.awt.Color; ! import java.awt.Graphics; ! import java.awt.GridBagConstraints; ! import java.awt.GridBagLayout; ! import java.awt.Insets; ! import java.awt.geom.Point2D; ! import java.beans.PropertyChangeEvent; ! import java.beans.PropertyChangeListener; ! import java.text.DecimalFormat; ! import java.text.NumberFormat; ! import java.util.Calendar; ! import java.util.Collection; ! import java.util.Vector; ! ! import javax.swing.BorderFactory; ! import javax.swing.JComponent; ! import javax.swing.JLabel; ! import javax.swing.JPanel; ! import javax.swing.border.BevelBorder; ! ! /** ! * Description of the Class ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class Track implements GraphElement, LabelElement ! { ! /** Description of the Field */ ! protected Color color = Color.black; ! /** Description of the Field */ ! protected TrackLabel component; ! /** Description of the Field */ ! protected NumberFormat format = new DecimalFormat("0"); ! /** Description of the Field */ ! protected String label; ! /** Description of the Field */ ! protected String name; ! /** Description of the Field */ ! protected Vector points = new Vector(); ! /** Description of the Field */ ! protected Range xr = new Range(Double.MAX_VALUE, Double.MIN_VALUE); ! /** Description of the Field */ ! protected Range yr = new Range(Double.MAX_VALUE, Double.MIN_VALUE); ! ! ! /** ! * Constructor for the Track object ! * ! * @param name Description of the Parameter ! */ ! public Track(String name) ! { ! this.name = name; ! this.label = name; ! this.component = new TrackLabel(this.name); ! } ! ! ! /** ! * Adds a feature to the Point attribute of the Track object ! * ! * @param value The feature to be added to the Value attribute ! */ ! public void addValue(double value) ! { ! long time = Calendar.getInstance().getTime().getTime(); ! ! synchronized (this) ! { ! Point2D.Double point = new Point2D.Double(time, value); ! this.points.add(point); ! this.xr.put(time); ! this.yr.put(value); ! this.setLabel(this.name + " : " + this.format.format(value)); ! } ! } ! ! ! /** Description of the Method */ ! public void clear() ! { ! this.points.clear(); ! } ! ! ! /** ! * @param graphics Description of the Parameter ! * @param scaleX Description of the Parameter ! * @param offsetX Description of the Parameter ! * @param scaleY Description of the Parameter ! * @param offsetY Description of the Parameter ! */ ! public void draw(Graphics graphics, double scaleX, double offsetX, double scaleY, double offsetY) ! { ! graphics.setColor(this.color); ! ! int x1 = 0; ! int y1 = 0; ! int x2 = 0; ! int y2 = 0; ! Point2D point = null; ! ! if (this.points.size() > 1) ! { ! point = (Point2D) this.points.get(0); ! x1 = (int) (point.getX() * scaleX + offsetX); ! y1 = (int) (point.getY() * scaleY + offsetY); ! for (int i = 1; i < this.points.size(); i++) ! { ! point = (Point2D) this.points.get(i); ! x2 = (int) (point.getX() * scaleX + offsetX); ! y2 = (int) (point.getY() * scaleY + offsetY); ! if (x2 > 0) ! { ! graphics.drawLine(x1, y1, x2, y2); ! } ! x1 = x2; ! y1 = y2; ! } ! } ! } ! ! ! /** ! * @return The color value ! */ ! public Color getColor() ! { ! return this.color; ! } ! ! ! /** ! * @return The component value ! */ ! public JComponent getComponent() ! { ! return this.component; ! } ! ! ! /** ! * Gets the points attribute of the Track object ! * ! * @return The points value ! */ ! public Collection getPoints() ! { ! return (Collection) this.points.clone(); ! } ! ! ! /** ! * @return The xRange value ! */ ! public Range getXRange() ! { ! return this.xr; ! } ! ! ! /** ! * @return The yRange value ! */ ! public Range getYRange() ! { ! return this.yr; ! } ! ! ! /** ! * Sets the color. ! * ! * @param color The color to set ! */ ! public void setColor(Color color) ! { ! this.color = color; ! this.component.propertyChange(new PropertyChangeEvent(this, "color", "", this.color)); ! } ! ! ! /** ! * Sets the label. ! * ! * @param label The label to set ! */ ! public void setLabel(String label) ! { ! this.label = label; ! this.component.propertyChange(new PropertyChangeEvent(this, "label", "", this.label)); ! } ! ! ! /** ! * Sets the name. ! * ! * @param name The name to set ! */ ! public void setName(String name) ! { ! this.name = name; ! } ! ! ! /** ! * Description of the Class ! * ! * @author Administrator ! * @version $Revision$ ! */ ! private class TrackLabel extends JPanel implements PropertyChangeListener ! { ! /** Description of the Field */ ! protected JPanel colorPanel = new JPanel(); ! /** Description of the Field */ ! protected JLabel label = new JLabel(); ! ! ! /** ! * Constructor for CustomJLabel. ! * ! * @param text ! */ ! public TrackLabel(String text) ! { ! super(); ! this.setLayout(new GridBagLayout()); ! ! GridBagConstraints constraints = new GridBagConstraints(); ! constraints.insets = new Insets(1, 1, 1, 1); ! ! constraints.weightx = 0.0d; ! this.add(this.colorPanel, constraints); ! this.colorPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); ! ! constraints.weightx = 1.0d; ! constraints.fill = GridBagConstraints.HORIZONTAL; ! this.add(this.label, constraints); ! this.label.setText(text); ! this.label.setToolTipText(text); ! } ! ! ! /** Constructor for CustomJLabel. */ ! public TrackLabel() { } ! ! ! /** ! * @param evt Description of the Parameter ! */ ! public void propertyChange(PropertyChangeEvent evt) ! { ! if ("label".equals(evt.getPropertyName())) ! { ! String text = (String) evt.getNewValue(); ! this.label.setText(text); ! this.label.setToolTipText(text); ! } ! if ("color".equals(evt.getPropertyName())) ! { ! this.colorPanel.setBackground((Color) evt.getNewValue()); ! } ! } ! ! ! /** ! * Description of the Method ! * ! * @return Description of the Return Value ! */ ! public String toString() ! { ! return this.label.getText(); ! } ! } ! } |