ucar.unidata.ui.colortable
Class ColorTableCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by ucar.unidata.ui.colortable.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:
Serialized Form

Nested Class Summary
static class ColorTableCanvas.CanvasCommand
          Class CanvasCommand takes a snapshot of the state of the canvas
static class ColorTableCanvas.ColorListCommand
          Class ColorListCommand
static class ColorTableCanvas.ColorTableCommand
          Class ColorTableCommand is used when the CT is changed and we can undo it using this class
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String PROP_CANCEL
          Name of property for the property event listener when cancel was pressed
static String PROP_CLOSE
          Name of property for the property event listener when window was closed
static String PROP_COLORTABLE
          Name of property for the property event listener when color table has changed
static String PROP_RANGE
          Name of property for the property event listener when range has changed
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ColorTableCanvas()
          Create me
ColorTableCanvas(ColorTableEditor editor, ColorTable table)
          Create me
 
Method Summary
 void addBreakpointAtData()
          Add a new breakpoint, prompting the user at what data value it shoudl be placed
 void addBreakpointAtData(ColorTable.Breakpoint bp)
          Add a new breakpoint the given index.
 void addBreakpointBeginning()
          Add BP at the start
 void addBreakpointEnd()
          Add BP at the end
 void addColor(boolean start, int cnt)
          Add cnt number of color slots
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add the listener
 int boxWidth()
          What is the width of the color box
 void brightAll()
          Set the transparency between the 2 BPs
 void brightLeft()
          Set the transparency to the left of the current BP
 void brightRight()
          Set the transparency to the right of the current BP
 void colorsChanged()
          The colors have changed.
 void debug()
          Debug println
 void doApply()
          Send the table and range changed events
 void doCancel()
          Cancel and send the cancel event
 void doClose()
          Send the close event
 void fill(Color color, ColorTable.Breakpoint from, ColorTable.Breakpoint to)
          Fill with the given color between the 2 BPs.
 void fillAll()
          Fill with the given color between the 2 BPs.
 void fillFromTo(Color color, int lowerIndex, int upperIndex)
          Fill with the given color between the 2 indices.
 void fillLeft()
          Fill to the left of the selected BP
 void fillRight()
          Fill to the right of the selected BP
 Rectangle getColorBox()
          Get the bounding box of the color box
 Rectangle getColorBox(Rectangle bounds)
          Get the bounding box of the color box
 JPanel getContents()
          Get the main GUI contents.
 ColorTable getCurrentColorTable()
          Get the currently edited CT
static Icon getIcon(ColorTable ct)
          Create and return an ImageIcon that represents this color table.
 boolean imageUpdate(Image img, int flags, int x, int y, int width, int height)
          Image update method
 void init(ColorTable newTable)
          Init me
 void insertBreakpoint(double percent)
          Insert a new BP at percent along the line
 void interpolate(ColorTable.Breakpoint from, ColorTable.Breakpoint to)
          Do a linear interpolation of the colors in the range defined by the given breakpoints.
 void interpolate(int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor)
          Do a linear interpolation between the given colors
 void interpolateAll()
          Interpolate color from end to end
 void interpolateLeft()
          Interpolate color left
 void interpolateRight()
          Interpolate color right
 void interpolateTrans(ColorTable.Breakpoint from, ColorTable.Breakpoint to)
          Do a linear interpolation of the colors in the range defined by the given breakpoints.
 void interpolateTrans(int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor)
          Do a linear interpolation of transparency between the given colors
 void interpolateTransAll()
          Interpolate transparency from end to end
 void interpolateTransLeft()
          Interpolate transparency left
 void interpolateTransRight()
          Interpolate transparency right
 boolean isStandAlone()
          Do we have listeners
 void keyPressed(KeyEvent e)
          Catch the key pressed event
 void keyReleased(KeyEvent e)
          Noop
 void keyTyped(KeyEvent e)
          Noop
 void lockUnlockBreakpoint(ColorTable.Breakpoint bp)
          change the lock status on the BP
 void mouseClicked(MouseEvent event)
          Catch the event
 void mouseDragged(MouseEvent event)
          The mouse was dragged
 void mouseEntered(MouseEvent e)
          Noop
 void mouseExited(MouseEvent e)
          Noop
 void mouseMoved(MouseEvent e)
          Noop
 void mousePressed(MouseEvent event)
          Mouse was pressed
 void mouseReleased(MouseEvent event)
          Catch the event
 void paint(Graphics g)
          Paint
 void paintColors(Graphics g)
          Paint the color box
 void paintInner(Graphics g)
          Really paint
 Color percentToColor(double percent)
          Map the percent along the color box to the color
 int percentToColorIndex(double percent)
          Map percent along the color box to the index in the color list
 double percentToValue(double percent)
          Get the value of the point percent along the color box
 int percentToX(double percent)
          Map percent along color box to x location
 void rangeChanged()
          Propagate the range changed event
 void removeBreakpoint()
          Remove the currently selected BP
 void removeColor(boolean start, int cnt)
          Remove cnt number of color slots
 void repaint()
          Repaint
 void replicate()
          replicate
 void setBrightness(ColorTable.Breakpoint from, ColorTable.Breakpoint to)
          Set the transparency between the 2 BPs
 void setBrightnessFromTo(int lowerIndex, int upperIndex)
          Set the transparency between the 2 indices
 void setColor(Color c)
          Set the color at the current BP
 void setColorTable(ColorTable newTable)
          GOt a new colortable
protected  void setMinMax()
          Set the range from the text fields
 void setName(String name)
          Set the name of the CT
 void setPropagateChanges(boolean v)
          Should we propagate changes
protected  void setRange(double min, double max)
          Set the range
 void setTransparency()
          Set the transparency on the currently selected breakpoint
 void setTransparency(ColorTable.Breakpoint from, ColorTable.Breakpoint to)
          Set the transparency between the 2 BPs
 void setTransparencyFromTo(int lowerIndex, int upperIndex)
          Set the transparency between the 2 indices
 void tableChanged()
          Propagate the table changed event
 void tableChanged(boolean force)
          Propagate the table changed event
 void transAll()
          Set the transparency between the 2 BPs
 void transLeft()
          Set the transparency to the left of the current BP
 void transRight()
          Set the transparency to the right of the current BP
 double xToPercent(int x)
          Map x location to percent along color box
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROP_COLORTABLE

public static final String PROP_COLORTABLE
Name of property for the property event listener when color table has changed

See Also:
Constant Field Values

PROP_RANGE

public static final String PROP_RANGE
Name of property for the property event listener when range has changed

See Also:
Constant Field Values

PROP_CANCEL

public static final String PROP_CANCEL
Name of property for the property event listener when cancel was pressed

See Also:
Constant Field Values

PROP_CLOSE

public static final String PROP_CLOSE
Name of property for the property event listener when window was closed

See Also:
Constant Field Values
Constructor Detail

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 Detail

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:</