Class ColorTableCanvas

All Implemented Interfaces:
KeyListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class ColorTableCanvas extends JPanel implements MouseMotionListener, MouseListener, KeyListener
This class provides the guts of the color table editor. The actual ColorTableCanvas is a JPanel that draws the color bar in the editor. This class also provides the gui components that are wrapped the canvas itself.
See Also:
  • Field Details

    • PROP_COLORTABLE

      public static final String PROP_COLORTABLE
      Name of property for the property event listener when color table has changed
      See Also:
    • PROP_RANGE

      public static final String PROP_RANGE
      Name of property for the property event listener when range has changed
      See Also:
    • PROP_CANCEL

      public static final String PROP_CANCEL
      Name of property for the property event listener when cancel was pressed
      See Also:
    • PROP_CLOSE

      public static final String PROP_CLOSE
      Name of property for the property event listener when window was closed
      See Also:
    • normalCursor

      public static final Cursor normalCursor
      The normal cursor_
    • paintCursor

      public static Cursor paintCursor
      _more_
  • Constructor Details

    • ColorTableCanvas

      public ColorTableCanvas()
      Create me
    • ColorTableCanvas

      public ColorTableCanvas(ColorTableEditor editor, ColorTable table)
      Create me
      Parameters:
      editor - The editor I am part of
      table - The color table to edit
  • Method Details

    • init

      public void init(ColorTable newTable)
      Init me
      Parameters:
      newTable - The color table to edit
    • setColorTable

      public void setColorTable(ColorTable newTable)
      GOt a new colortable
      Parameters:
      newTable - The new table
    • getContents

      public JPanel getContents()
      Get the main GUI contents.
      Returns:
      The GUI
    • setTransparency

      public void setTransparency()
      Set the transparency on the currently selected breakpoint
    • setName

      public void setName(String name)
      Set the name of the CT
      Overrides:
      setName in class Component
      Parameters:
      name - The name
    • setMinMax

      protected void setMinMax()
      Set the range from the text fields
    • setRange

      protected void setRange(double min, double max)
      Set the range
      Parameters:
      min - Range min
      max - Range max
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener listener)
      Add the listener
      Overrides:
      addPropertyChangeListener in class Container
      Parameters:
      listener - The listener
    • isStandAlone

      public boolean isStandAlone()
      Do we have listeners
      Returns:
      Do we have listeners
    • getCurrentColorTable

      public ColorTable getCurrentColorTable()
      Get the currently edited CT
      Returns:
      The CT
    • doClose

      public void doClose()
      Send the close event
    • doApply

      public void doApply()
      Send the table and range changed events
    • doCancel

      public void doCancel()
      Cancel and send the cancel event
    • tableChanged

      public void tableChanged()
      Propagate the table changed event
    • tableChanged

      public void tableChanged(boolean force)
      Propagate the table changed event
      Parameters:
      force - If true then send the change no matter what
    • rangeChanged

      public void rangeChanged()
      Propagate the range changed event
    • setPropagateChanges

      public void setPropagateChanges(boolean v)
      Should we propagate changes
      Parameters:
      v - The flag
    • colorsChanged

      public void colorsChanged()
      The colors have changed. Repaint and update the GUI.
    • addColor

      public void addColor(boolean start, int cnt)
      Add cnt number of color slots
      Parameters:
      start - At start or end
      cnt - How many to add
    • removeColor

      public void removeColor(boolean start, int cnt)
      Remove cnt number of color slots
      Parameters:
      start - At start or end
      cnt - How many to remove
    • keyPressed

      public void keyPressed(KeyEvent e)
      Catch the key pressed event
      Specified by:
      keyPressed in interface KeyListener
      Parameters:
      e - The event
    • keyReleased

      public void keyReleased(KeyEvent e)
      Noop
      Specified by:
      keyReleased in interface KeyListener
      Parameters:
      e - The event
    • keyTyped

      public void keyTyped(KeyEvent e)
      Noop
      Specified by:
      keyTyped in interface KeyListener
      Parameters:
      e - The event
    • mouseMoved

      public void mouseMoved(MouseEvent e)
      Noop
      Specified by:
      mouseMoved in interface MouseMotionListener
      Parameters:
      e - The event
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      Noop
      Specified by:
      mouseEntered in interface MouseListener
      Parameters:
      e - The event
    • mouseExited

      public void mouseExited(MouseEvent e)
      Noop
      Specified by:
      mouseExited in interface MouseListener
      Parameters:
      e - The event
    • getPaintCursor

      public Cursor getPaintCursor()
      Get the paint brush cursor
      Returns:
      paint brush cursor
    • checkCursor

      public void checkCursor(MouseEvent e)
      set the cursor
      Parameters:
      e - event
    • isInBox

      public boolean isInBox(MouseEvent event)
      Is the mouse in the color box
      Parameters:
      event - event
      Returns:
      is in box
    • reallyInBox

      public boolean reallyInBox(MouseEvent event)
    • mousePressed

      public void mousePressed(MouseEvent event)
      Mouse was pressed
      Specified by:
      mousePressed in interface MouseListener
      Parameters:
      event - The event
    • mouseDragged

      public void mouseDragged(MouseEvent event)
      The mouse was dragged
      Specified by:
      mouseDragged in interface MouseMotionListener
      Parameters:
      event - The event
    • mouseReleased

      public void mouseReleased(MouseEvent event)
      Catch the event
      Specified by:
      mouseReleased in interface MouseListener
      Parameters:
      event - The event
    • mouseClicked

      public void mouseClicked(MouseEvent event)
      Catch the event
      Specified by:
      mouseClicked in interface MouseListener
      Parameters:
      event - The event
    • addBreakpointAtData

      public void addBreakpointAtData()
      Add a new breakpoint, prompting the user at what data value it shoudl be placed
    • addBreakpointAtData

      public void addBreakpointAtData(ColorTable.Breakpoint bp)
      Add a new breakpoint the given index. If indexinvalid input: '<'0 then prompt the user at what data value it shoudl be placed
      Parameters:
      bp - the sample breakpoint
    • insertBreakpoint

      public void insertBreakpoint(double percent)
      Insert a new BP at percent along the line
      Parameters:
      percent - Where to insert
    • debug

      public void debug()
      Debug println
    • removeBreakpoint

      public void removeBreakpoint()
      Remove the currently selected BP
    • lockUnlockBreakpoint

      public void lockUnlockBreakpoint(ColorTable.Breakpoint bp)
      change the lock status on the BP
      Parameters:
      bp - the breakpoint to lock/unlock
    • addBreakpointBeginning

      public void addBreakpointBeginning()
      Add BP at the start
    • addBreakpointEnd

      public void addBreakpointEnd()
      Add BP at the end
    • setColor

      public void setColor(Color c)
      Set the color at the current BP
      Parameters:
      c - The color
    • boxWidth

      public int boxWidth()
      What is the width of the color box
      Returns:
      Color box width
    • xToPercent

      public double xToPercent(int x)
      Map x location to percent along color box
      Parameters:
      x - X location
      Returns:
      Percent along color box
    • percentToX

      public int percentToX(double percent)
      Map percent along color box to x location
      Parameters:
      percent - Percent along color box
      Returns:
      X location
    • percentToValue

      public double percentToValue(double percent)
      Get the value of the point percent along the color box
      Parameters:
      percent - Percent along the color box
      Returns:
      Value
    • interpolateAll

      public void interpolateAll()
      Interpolate color from end to end
    • interpolateLeft

      public void interpolateLeft()
      Interpolate color left
    • interpolateRight

      public void interpolateRight()
      Interpolate color right
    • interpolateTransAll

      public void interpolateTransAll()
      Interpolate transparency from end to end
    • interpolateTransLeft

      public void interpolateTransLeft()
      Interpolate transparency left
    • interpolateTransRight

      public void interpolateTransRight()
      Interpolate transparency right
    • interpolateBrightnessAll

      public void interpolateBrightnessAll()
      Interpolate transparency from end to end
    • interpolateBrightnessLeft

      public void interpolateBrightnessLeft()
      Interpolate transparency left
    • interpolateBrightnessRight

      public void interpolateBrightnessRight()
      Interpolate transparency right
    • replicate

      public void replicate()
      replicate
    • invert

      public void invert()
      invert the color table
    • interpolate

      public void interpolate(ColorTable.Breakpoint from, ColorTable.Breakpoint to)
      Do a linear interpolation of the colors in the range defined by the given breakpoints.
      Parameters:
      from - starting breakpoint
      to - ending breakpoint
    • interpolate

      public void interpolate(int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor)
      Do a linear interpolation between the given colors
      Parameters:
      lowerColorIndex - Where to start
      upperColorIndex - Where to end
      lowerColor - The lower color
      upperColor - The upper color
    • newInterpolate

      public void newInterpolate(int colorSpace, int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor)
    • oldInterpolate

      public void oldInterpolate(int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor)
    • interpolateTrans

      public void interpolateTrans(ColorTable.Breakpoint from, ColorTable.Breakpoint to)
      Do a linear interpolation of the colors in the range defined by the given breakpoints.
      Parameters:
      from - starting breakpoint
      to - ending breakpoint
    • interpolateTrans

      public void interpolateTrans(int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor)
      Do a linear interpolation of transparency between the given colors
      Parameters:
      lowerColorIndex - Where to start
      upperColorIndex - Where to end
      lowerColor - The lower color
      upperColor - The upper color
    • interpolateBrightness

      public void interpolateBrightness(ColorTable.Breakpoint from, ColorTable.Breakpoint to)
      Do a linear interpolation of the colors in the range defined by the given breakpoints.
      Parameters:
      from - starting breakpoint
      to - ending breakpoint
    • interpolateBrightness

      public void interpolateBrightness(int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor)
      Do a linear interpolation of transparency between the given colors
      Parameters:
      lowerColorIndex - Where to start
      upperColorIndex - Where to end
      lowerColor - The lower color
      upperColor - The upper color
    • fillLeft

      public void fillLeft()
      Fill to the left of the selected BP
    • fillRight

      public void fillRight()
      Fill to the right of the selected BP
    • fill

      public void fill(Color color, ColorTable.Breakpoint from, ColorTable.Breakpoint to)
      Fill with the given color between the 2 BPs.
      Parameters:
      color - The fill color
      from - The lower end
      to - The upper end
    • fillAll

      public void fillAll()
      Fill with the given color between the 2 BPs.
    • fillFromTo

      public void fillFromTo(Color color, int lowerIndex, int upperIndex)
      Fill with the given color between the 2 indices.
      Parameters:
      color - The fill color
      lowerIndex - The lower index
      upperIndex - The upper index
    • transLeft

      public void transLeft()
      Set the transparency to the left of the current BP
    • transRight

      public void transRight()
      Set the transparency to the right of the current BP
    • transAll

      public void transAll()
      Set the transparency between the 2 BPs
    • setTransparency

      public void setTransparency(ColorTable.Breakpoint from, ColorTable.Breakpoint to)
      Set the transparency between the 2 BPs
      Parameters:
      from - The lower BP
      to - The upper BP
    • setTransparencyFromTo

      public void setTransparencyFromTo(int lowerIndex, int upperIndex)
      Set the transparency between the 2 indices
      Parameters:
      lowerIndex - The lower index
      upperIndex - The upper index
    • brightLeft

      public void brightLeft()
      Set the transparency to the left of the current BP
    • brightRight

      public void brightRight()
      Set the transparency to the right of the current BP
    • setBrightness

      public void setBrightness(ColorTable.Breakpoint from, ColorTable.Breakpoint to)
      Set the transparency between the 2 BPs
      Parameters:
      from - The lower BP
      to - The upper BP
    • brightAll

      public void brightAll()
      Set the transparency between the 2 BPs
    • setBrightnessFromTo

      public void setBrightnessFromTo(int lowerIndex, int upperIndex)
      Set the transparency between the 2 indices
      Parameters:
      lowerIndex - The lower index
      upperIndex - The upper index
    • getColorBox

      public Rectangle getColorBox()
      Get the bounding box of the color box
      Returns:
      The color box
    • getColorBox

      public Rectangle getColorBox(Rectangle bounds)
      Get the bounding box of the color box
      Parameters:
      bounds - The bounds around the color box
      Returns:
      The color box
    • percentToColorIndex

      public int percentToColorIndex(double percent)
      Map percent along the color box to the index in the color list
      Parameters:
      percent - Percent along the color box
      Returns:
      Color index
    • percentToColor

      public Color percentToColor(double percent)
      Map the percent along the color box to the color
      Parameters:
      percent - Along color box
      Returns:
      The color
    • paintColors

      public void paintColors(Graphics g)
      Paint the color box
      Parameters:
      g - The graphics
    • paintColors

      public static void paintColors(Graphics g, Rectangle box, List<Color> colorList, boolean doLines, boolean doCheckerboard, List<Float> scales)
      Paint the color box
      Parameters:
      g - The graphics
      box - _more_
      colorList - _more_
      doLines - _more_
      doCheckerboard - _more_
      scales - _more_
    • paintColors

      public static void paintColors(Graphics g, Rectangle box, List<Color> colorList, boolean doLines, boolean doCheckerboard, boolean doTransparency, List<Float> scales)
    • repaint

      public void repaint()
      Repaint
      Overrides:
      repaint in class Component
    • paint

      public void paint(Graphics g)
      Paint
      Overrides:
      paint in class JComponent
      Parameters:
      g - The graphics
    • paintInner

      public void paintInner(Graphics g)
      Really paint
      Parameters:
      g - The graphics
    • imageUpdate

      public boolean imageUpdate(Image img, int flags, int x, int y, int width, int height)
      Image update method
      Specified by:
      imageUpdate in interface ImageObserver
      Overrides:
      imageUpdate in class Component
      Parameters:
      img - the image
      flags - flags
      x - x position
      y - y position
      width - width
      height - height
      Returns:
      true if successful
    • getIcon

      public static Icon getIcon(ColorTable ct)
      Create and return an ImageIcon that represents this color table. If there were any errors then return null.
      Parameters:
      ct - The CT
      Returns:
      The icon
    • getIcon

      public static Icon getIcon(ColorTable ct, int width, int height)
      _more_
      Parameters:
      ct - _more_
      width - _more_
      height - _more_
      Returns:
      _more_
    • getImage

      public static Image getImage(ColorTable ct, int width, int height)
    • getImage

      public static Image getImage(ColorTable ct, int width, int height, boolean includeAlpha)