Package ucar.unidata.ui.colortable
Class ColorTableCanvas
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass CanvasCommand takes a snapshot of the state of the canvasstatic classClass ColorListCommandstatic classClass ColorTableCommand is used when the CT is changed and we can undo it using this classNested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CursorThe normal cursor_static Cursor_more_static final StringName of property for the property event listener when cancel was pressedstatic final StringName of property for the property event listener when window was closedstatic final StringName of property for the property event listener when color table has changedstatic final StringName of property for the property event listener when range has changedFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionCreate meColorTableCanvas(ColorTableEditor editor, ColorTable table) Create me -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a new breakpoint, prompting the user at what data value it shoudl be placedvoidAdd a new breakpoint the given index.voidAdd BP at the startvoidAdd BP at the endvoidaddColor(boolean start, int cnt) Add cnt number of color slotsvoidAdd the listenerintboxWidth()What is the width of the color boxvoidSet the transparency between the 2 BPsvoidSet the transparency to the left of the current BPvoidSet the transparency to the right of the current BPvoidset the cursorvoidThe colors have changed.voiddebug()Debug printlnvoiddoApply()Send the table and range changed eventsvoiddoCancel()Cancel and send the cancel eventvoiddoClose()Send the close eventvoidfill(Color color, ColorTable.Breakpoint from, ColorTable.Breakpoint to) Fill with the given color between the 2 BPs.voidfillAll()Fill with the given color between the 2 BPs.voidfillFromTo(Color color, int lowerIndex, int upperIndex) Fill with the given color between the 2 indices.voidfillLeft()Fill to the left of the selected BPvoidFill to the right of the selected BPGet the bounding box of the color boxgetColorBox(Rectangle bounds) Get the bounding box of the color boxGet the main GUI contents.Get the currently edited CTstatic IcongetIcon(ColorTable ct) Create and return an ImageIcon that represents this color table.static IcongetIcon(ColorTable ct, int width, int height) _more_static ImagegetImage(ColorTable ct, int width, int height) static ImagegetImage(ColorTable ct, int width, int height, boolean includeAlpha) Get the paint brush cursorbooleanimageUpdate(Image img, int flags, int x, int y, int width, int height) Image update methodvoidinit(ColorTable newTable) Init mevoidinsertBreakpoint(double percent) Insert a new BP at percent along the linevoidinterpolate(int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor) Do a linear interpolation between the given colorsvoidDo a linear interpolation of the colors in the range defined by the given breakpoints.voidInterpolate color from end to endvoidinterpolateBrightness(int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor) Do a linear interpolation of transparency between the given colorsvoidDo a linear interpolation of the colors in the range defined by the given breakpoints.voidInterpolate transparency from end to endvoidInterpolate transparency leftvoidInterpolate transparency rightvoidInterpolate color leftvoidInterpolate color rightvoidinterpolateTrans(int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor) Do a linear interpolation of transparency between the given colorsvoidDo a linear interpolation of the colors in the range defined by the given breakpoints.voidInterpolate transparency from end to endvoidInterpolate transparency leftvoidInterpolate transparency rightvoidinvert()invert the color tablebooleanisInBox(MouseEvent event) Is the mouse in the color boxbooleanDo we have listenersvoidCatch the key pressed eventvoidNoopvoidNoopvoidchange the lock status on the BPvoidmouseClicked(MouseEvent event) Catch the eventvoidmouseDragged(MouseEvent event) The mouse was draggedvoidNoopvoidNoopvoidNoopvoidmousePressed(MouseEvent event) Mouse was pressedvoidmouseReleased(MouseEvent event) Catch the eventvoidnewInterpolate(int colorSpace, int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor) voidoldInterpolate(int lowerColorIndex, int upperColorIndex, Color lowerColor, Color upperColor) voidPaintvoidPaint the color boxstatic voidpaintColors(Graphics g, Rectangle box, List<Color> colorList, boolean doLines, boolean doCheckerboard, boolean doTransparency, List<Float> scales) static voidpaintColors(Graphics g, Rectangle box, List<Color> colorList, boolean doLines, boolean doCheckerboard, List<Float> scales) Paint the color boxvoidReally paintpercentToColor(double percent) Map the percent along the color box to the colorintpercentToColorIndex(double percent) Map percent along the color box to the index in the color listdoublepercentToValue(double percent) Get the value of the point percent along the color boxintpercentToX(double percent) Map percent along color box to x locationvoidPropagate the range changed eventbooleanreallyInBox(MouseEvent event) voidRemove the currently selected BPvoidremoveColor(boolean start, int cnt) Remove cnt number of color slotsvoidrepaint()RepaintvoidreplicatevoidSet the transparency between the 2 BPsvoidsetBrightnessFromTo(int lowerIndex, int upperIndex) Set the transparency between the 2 indicesvoidSet the color at the current BPvoidsetColorTable(ColorTable newTable) GOt a new colortableprotected voidSet the range from the text fieldsvoidSet the name of the CTvoidsetPropagateChanges(boolean v) Should we propagate changesprotected voidsetRange(double min, double max) Set the rangevoidSet the transparency on the currently selected breakpointvoidSet the transparency between the 2 BPsvoidsetTransparencyFromTo(int lowerIndex, int upperIndex) Set the transparency between the 2 indicesvoidPropagate the table changed eventvoidtableChanged(boolean force) Propagate the table changed eventvoidtransAll()Set the transparency between the 2 BPsvoidSet the transparency to the left of the current BPvoidSet the transparency to the right of the current BPdoublexToPercent(int x) Map x location to percent along color boxMethods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, updateMethods 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, transferFocusDownCycle, validate, validateTreeMethods 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
PROP_COLORTABLE
Name of property for the property event listener when color table has changed- See Also:
-
PROP_RANGE
Name of property for the property event listener when range has changed- See Also:
-
PROP_CANCEL
Name of property for the property event listener when cancel was pressed- See Also:
-
PROP_CLOSE
Name of property for the property event listener when window was closed- See Also:
-
normalCursor
The normal cursor_ -
paintCursor
_more_
-
-
Constructor Details
-
ColorTableCanvas
public ColorTableCanvas()Create me -
ColorTableCanvas
Create me- Parameters:
editor- The editor I am part oftable- The color table to edit
-
-
Method Details
-
init
Init me- Parameters:
newTable- The color table to edit
-
setColorTable
GOt a new colortable- Parameters:
newTable- The new table
-
getContents
Get the main GUI contents.- Returns:
- The GUI
-
setTransparency
public void setTransparency()Set the transparency on the currently selected breakpoint -
setName
Set the name of the CT -
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 minmax- Range max
-
addPropertyChangeListener
Add the listener- Overrides:
addPropertyChangeListenerin classContainer- Parameters:
listener- The listener
-
isStandAlone
public boolean isStandAlone()Do we have listeners- Returns:
- Do we have listeners
-
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 endcnt- How many to add
-
removeColor
public void removeColor(boolean start, int cnt) Remove cnt number of color slots- Parameters:
start- At start or endcnt- How many to remove
-
keyPressed
Catch the key pressed event- Specified by:
keyPressedin interfaceKeyListener- Parameters:
e- The event
-
keyReleased
Noop- Specified by:
keyReleasedin interfaceKeyListener- Parameters:
e- The event
-
keyTyped
Noop- Specified by:
keyTypedin interfaceKeyListener- Parameters:
e- The event
-
mouseMoved
Noop- Specified by:
mouseMovedin interfaceMouseMotionListener- Parameters:
e- The event
-
mouseEntered
Noop- Specified by:
mouseEnteredin interfaceMouseListener- Parameters:
e- The event
-
mouseExited
Noop- Specified by:
mouseExitedin interfaceMouseListener- Parameters:
e- The event
-
getPaintCursor
Get the paint brush cursor- Returns:
- paint brush cursor
-
checkCursor
set the cursor- Parameters:
e- event
-
isInBox
Is the mouse in the color box- Parameters:
event- event- Returns:
- is in box
-
reallyInBox
-
mousePressed
Mouse was pressed- Specified by:
mousePressedin interfaceMouseListener- Parameters:
event- The event
-
mouseDragged
The mouse was dragged- Specified by:
mouseDraggedin interfaceMouseMotionListener- Parameters:
event- The event
-
mouseReleased
Catch the event- Specified by:
mouseReleasedin interfaceMouseListener- Parameters:
event- The event
-
mouseClicked
Catch the event- Specified by:
mouseClickedin interfaceMouseListener- Parameters:
event- The event
-
addBreakpointAtData
public void addBreakpointAtData()Add a new breakpoint, prompting the user at what data value it shoudl be placed -
addBreakpointAtData
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
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
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
Do a linear interpolation of the colors in the range defined by the given breakpoints.- Parameters:
from- starting breakpointto- 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 startupperColorIndex- Where to endlowerColor- The lower colorupperColor- The upper color
-
newInterpolate
-
oldInterpolate
-
interpolateTrans
Do a linear interpolation of the colors in the range defined by the given breakpoints.- Parameters:
from- starting breakpointto- 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 startupperColorIndex- Where to endlowerColor- The lower colorupperColor- The upper color
-
interpolateBrightness
Do a linear interpolation of the colors in the range defined by the given breakpoints.- Parameters:
from- starting breakpointto- 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 startupperColorIndex- Where to endlowerColor- The lower colorupperColor- 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
Fill with the given color between the 2 BPs.- Parameters:
color- The fill colorfrom- The lower endto- The upper end
-
fillAll
public void fillAll()Fill with the given color between the 2 BPs. -
fillFromTo
Fill with the given color between the 2 indices.- Parameters:
color- The fill colorlowerIndex- The lower indexupperIndex- 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
Set the transparency between the 2 BPs- Parameters:
from- The lower BPto- The upper BP
-
setTransparencyFromTo
public void setTransparencyFromTo(int lowerIndex, int upperIndex) Set the transparency between the 2 indices- Parameters:
lowerIndex- The lower indexupperIndex- 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
Set the transparency between the 2 BPs- Parameters:
from- The lower BPto- 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 indexupperIndex- The upper index
-
getColorBox
Get the bounding box of the color box- Returns:
- The color box
-
getColorBox
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
Map the percent along the color box to the color- Parameters:
percent- Along color box- Returns:
- The color
-
paintColors
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 graphicsbox- _more_colorList- _more_doLines- _more_doCheckerboard- _more_scales- _more_
-
paintColors
-
repaint
public void repaint()Repaint -
paint
Paint- Overrides:
paintin classJComponent- Parameters:
g- The graphics
-
paintInner
Really paint- Parameters:
g- The graphics
-
imageUpdate
Image update method- Specified by:
imageUpdatein interfaceImageObserver- Overrides:
imageUpdatein classComponent- Parameters:
img- the imageflags- flagsx- x positiony- y positionwidth- widthheight- height- Returns:
- true if successful
-
getIcon
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
_more_- Parameters:
ct- _more_width- _more_height- _more_- Returns:
- _more_
-
getImage
-
getImage
-