Package hec.gfx2d
Class ColorBarIcon
java.lang.Object
javax.swing.ImageIcon
hec.gfx2d.PlotIconBase
hec.gfx2d.ColorBarIcon
- All Implemented Interfaces:
Serializable
,Accessible
,Icon
A bar that is colored to represent the state of a time series
data set. The left end of the bar corresponds to the start
of the time window, while the right end corresponds to the end.
This class implements Icon. An example is using this icon in conjunction with a Button (i.e., as the argument for the constructor of the button). It is a good idea to make this button short and wide (i.e., long and narrow) for best representation of the data. ColorBarIcon will either work with integer or double data.
Examples:
Suppose that you have a data quality set where there is either missing (represented as a 0, and is to show up as red), questionable (represented as 1, and is yellow) or valid data (a 2, green).
int colorValues[] = new int[3]; colorValues[0] = 0; // red colorValues[1] = 1; // yellow colorValues[2] = 2; // green Color colors[3] = new Color[3]; color[0] = Color.red; color[1] = Color.yellow; color[2] = Color.green; ColorBarIcon colorBarIcon = new ColorBarIcon(); JButton colorButton = new JButton(colorBarIcon); colorButton.setBounds( ... // plus other JButton stuff! colorBarIcon.setColorValues(colorValues, colors); colorBarIcon.setData(myQuality); // where myQuality is an int[] // All done! (to update with a new data set, just call setData again, then repaintIf the data is doubles, then you can compare for data less than specific values. For example, you might have flows less than 1000. to be green, 1000 to 1500 is yellow, and above 1500 is red. Then:
double colorValues[] = new double[3]; colorValues[0] = 1000.; // data < 1000. green colorValues[1] = 1500.; // yellow colorValues[2] = 10000; // red (actually any number above 10000 will also be red!) Color colors[] = new Color[3]; colors[0] = Color.green; colors[1] = Color.yellow; colors[2] = Color.red; ColorBarIcon colorBarIcon = new ColorBarIcon(); JButton colorButton = new JButton(colorBarIcon); colorButton.setBounds( ... // plus other JButton stuff! colorBarIcon.setColorValues(colorValues, colors); colorBarIcon.setData(myData); // where myData is double[]You can decide some other behavior by overriding the function determineColor() or determineColorPosition().
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.ImageIcon
ImageIcon.AccessibleImageIcon
-
Field Summary
Fields inherited from class hec.gfx2d.PlotIconBase
_accumulationType, _backgroundColor, _borderColor, _cumulativeInterval, _dataContainerList, _dataSetNames, _dimension, _fixedDimension, _maxXSet, _maxYSet, _minXSet, _minYSet, _noDataColor, _selected, _size, _xLoc, _yLoc, UNDEFINED, UNDEFINED_MAX, UNDEFINED_MIN
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int
void
protected void
protected int
determineColorPosition
(int loc) Returns a int position pointer to the Color array that corresponds Override this class for different behavior.static Line2D
protected void
void
void
void
setColorValues
(double[] colorValues, Color[] colors) Set double values to correspond to colors.void
setColorValues
(int[] colorValues, Color[] colors) Set integer values to correspond to colors.void
setData
(int[] times, double[] values) Set the data to be represented.void
setData
(int[] times, int[] values) Set the data to be represented.Methods inherited from class hec.gfx2d.PlotIconBase
accumulate, addData, addData, getColorSettings, getCumulativeInterval, getDataContainer, getDataContainerList, getDataSetName, getDataSetNames, getIconHeight, getIconWidth, getLastValue, getRectangle, hasData, setColorSettings, setCumulative, setData, setData, setDataContainerList, setDataSetName, setDataSetNames, setSelected, setSize, setTsDataSetNames, setXLimits, setXLimits, setYLimits
Methods inherited from class javax.swing.ImageIcon
getAccessibleContext, getDescription, getImage, getImageLoadStatus, getImageObserver, loadImage, setDescription, setImage, setImageObserver, toString
-
Constructor Details
-
ColorBarIcon
public ColorBarIcon()
-
-
Method Details
-
setData
public void setData(int[] times, int[] values) Set the data to be represented. This will also update the data. The first argument is typically times, but does not have to be. The data is not duplicated, but a pointer is kept. -
setData
public void setData(int[] times, double[] values) Set the data to be represented. This will also update the data. The first argument is typically times, but does not have to be. The data is not duplicated, but a pointer is kept. -
clearData
public void clearData()- Overrides:
clearData
in classPlotIconBase
-
setColorValues
Set integer values to correspond to colors. The data is not duplicated, but a pointer is kept. -
setColorValues
Set double values to correspond to colors. The data is not duplicated, but a pointer is kept. -
determineColorPosition
protected int determineColorPosition(int loc) Returns a int position pointer to the Color array that corresponds Override this class for different behavior. -
arrayLength
protected int arrayLength() -
recompute
public void recompute() -
paintIcon
-
paintColorBar
-
computeLine
protected void computeLine() -
modLine2D
-