Package hec.gfx2d

Class ColorBarIcon

All Implemented Interfaces:
Serializable, Accessible, Icon

public class ColorBarIcon extends PlotIconBase
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 repaint
 
If 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:
  • 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 class PlotIconBase
    • setColorValues

      public void setColorValues(int[] colorValues, Color[] colors)
      Set integer values to correspond to colors. The data is not duplicated, but a pointer is kept.
    • setColorValues

      public void setColorValues(double[] colorValues, Color[] colors)
      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

      public void paintIcon(Component c, Graphics g, int x, int y)
      Specified by:
      paintIcon in interface Icon
      Overrides:
      paintIcon in class ImageIcon
    • paintColorBar

      protected void paintColorBar(Graphics2D g2)
    • computeLine

      protected void computeLine()
    • modLine2D

      public static Line2D modLine2D(Line2D oldLine2D, double point, int pointLocation)