org.geotoolkit.gui.swing.image
Class ColorRamp

Object
  extended by Component
      extended by Container
          extended by JComponent
              extended by ColorRamp
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class ColorRamp
extends JComponent

A color ramp with a graduation. The colors can be specified with a SampleDimension, an array of Colors or an IndexColorModel object, and the graduation is specified with a Graduation object. The resulting ColorRamp object is usually painted together with a remote sensing image.

 

 

Since:
1.1
Version:
3.16
Author:
Martin Desruisseaux (MPO, IRD)
See Also:
Serialized Form
Module:
display/geotk-widgets-swing (download)    View source code for this class

Nested Class Summary
 
Nested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ColorRamp()
          Constructs an initially empty color ramp.
ColorRamp(Coverage coverage)
          Constructs a color ramp for the specified coverage.
 
Method Summary
 void addNotify()
          Notifies this component that it now has a parent component.
protected  Graduation createGraduation(Graduation reuse, SampleDimension band, double minimum, double maximum)
          Returns a graduation for the specified sample dimension, minimum and maximum values.
 Color[] getColors()
          Returns the colors painted by this ColorRamp.
 Graduation getGraduation()
          Returns the graduation to paint over colors.
 int getOrientation()
          Returns the component's orientation (horizontal or vertical).
 boolean isInterpolationEnabled()
          Returns true if the colors are interpolated at rendering time.
 boolean isLabelVisibles()
          Tests if graduation labels are paint on top of the colors ramp.
 void removeNotify()
          Notifies this component that it no longer has a parent component.
 boolean setColors(Color... colors)
          Sets the colors to paint.
 boolean setColors(Coverage coverage)
          Sets the graduation and the colors from a coverage.
 boolean setColors(IndexColorModel model)
          Sets the colors to paint from an IndexColorModel.
 boolean setColors(int... colors)
          Sets the colors to paint as an array of ARGB values.
 boolean setColors(SampleDimension band)
          Sets the graduation and the colors from a sample dimension.
 void setForeground(Color color)
          Sets the label colors.
 boolean setGraduation(Graduation graduation)
          Sets the graduation to paint on top of the color bar.
 void setInterpolationEnabled(boolean enabled)
          Sets whatever the colors should be interpolated at rendering time.
 void setLabelVisibles(boolean visible)
          Sets whatever the graduation labels should be painted on top of the colors ramp.
 void setOrientation(int orient)
          Sets the component's orientation (horizontal or vertical).
 BufferedImage toImage()
          Returns an image representation for this color ramp.
 String toString()
          Returns a string representation for this color ramp.
 
Methods inherited from class JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, 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, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, 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 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, imageUpdate, 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, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ColorRamp

public ColorRamp()
Constructs an initially empty color ramp. Colors can be set using one of the setColors(...) methods.


ColorRamp

public ColorRamp(Coverage coverage)
Constructs a color ramp for the specified coverage.

Parameters:
coverage - The coverage for which to create a color ramp.
Method Detail

getGraduation

public Graduation getGraduation()
Returns the graduation to paint over colors. If the graduation is not yet defined, then this method returns null.

Returns:
The graduation to draw.

setGraduation

public boolean setGraduation(Graduation graduation)
Sets the graduation to paint on top of the color bar. The graduation can be set also by a call to setColors(SampleDimension) and setColors(Coverage). This method will fire a property change event with the "graduation" name.

The graduation minimum and maximum values should be both inclusive.

Parameters:
graduation - The new graduation, or null if none.
Returns:
true if this object changed as a result of this call.

getColors

public Color[] getColors()
Returns the colors painted by this ColorRamp.

Returns:
The colors (never null).

setColors

public boolean setColors(Color... colors)
Sets the colors to paint. If the new colors are different than the old ones, then this method fires a property change event named "colors" with values of type Color[].

Parameters:
colors - The colors to paint, or null if none.
Returns:
true if the state of this ColorRamp changed as a result of this call.
See Also:
setColors(Coverage), setColors(SampleDimension), setColors(IndexColorModel), getColors(), getGraduation()

setColors

public boolean setColors(int... colors)
Sets the colors to paint as an array of ARGB values. This method performs the same work than setColors(Color[]), but is more efficient if the colors were already available as an array of ARGB values.

If the new colors are different than the old ones, then this method fires a property change event named "colors" with values of type Color[] - not int[].

Parameters:
colors - The colors to paint, or null if none.
Returns:
true if the state of this ColorRamp changed as a result of this call.
Since:
3.09

setColors

public boolean setColors(IndexColorModel model)
Sets the colors to paint from an IndexColorModel. The default implementation fetches the ARGB values from the index color model and invokes setColors(int[]).

Parameters:
model - The colors to paint, or null if none.
Returns:
true if the state of this ColorRamp changed as a result of this call.
See Also:
setColors(Coverage), setColors(SampleDimension), setColors(Color[]), getColors(), getGraduation()

setColors

public boolean setColors(SampleDimension band)
Sets the graduation and the colors from a sample dimension. The default implementation fetches the palette and the minimum and maximum values from the supplied band, and then invokes setColors and setGraduation.

Parameters:
band - The sample dimension, or null if none.
Returns:
true if the state of this ColorRamp changed as a result of this call.
See Also:
setColors(Coverage), setColors(SampleDimension), setColors(IndexColorModel), setColors(Color[]), getColors(), getGraduation()

setColors

public boolean setColors(Coverage coverage)
Sets the graduation and the colors from a coverage. The default implementation fetches the visible sample dimension from the specified coverage, and then invokes setColors and setGraduation.

Parameters:
coverage - The coverage, or null.
Returns:
true if the state of this ColorRamp changed as a result of this call.
See Also:
setColors(IndexColorModel), setColors(SampleDimension), getColors(), getGraduation()

isInterpolationEnabled

public boolean isInterpolationEnabled()
Returns true if the colors are interpolated at rendering time. If false, only the colors given to the setColors(...) method will be used: the color ramp will be painted using rectangles of uniform colors. If true, then a linear interpolation will be used between every colors given to the setColors(...) method.

Returns:
Whatever the colors will be interpolated at rendering time.
Since:
3.16

setInterpolationEnabled

public void setInterpolationEnabled(boolean enabled)
Sets whatever the colors should be interpolated at rendering time. If this method is never invoked, then the default value is true.

Parameters:
enabled - Whatever the colors will be interpolated at rendering time.
Since:
3.16

getOrientation

public int getOrientation()
Returns the component's orientation (horizontal or vertical). It should be one of the following constants: SwingConstants.HORIZONTAL or SwingConstants.VERTICAL.

Returns:
The component orientation.

setOrientation

public void setOrientation(int orient)
Sets the component's orientation (horizontal or vertical).

Parameters:
orient - SwingConstants.HORIZONTAL or SwingConstants.VERTICAL.

isLabelVisibles

public boolean isLabelVisibles()
Tests if graduation labels are paint on top of the colors ramp. Default value is true.

Returns:
true if graduation labels are drawn.

setLabelVisibles

public void setLabelVisibles(boolean visible)
Sets whatever the graduation labels should be painted on top of the colors ramp.

Parameters:
visible - true if graduation labels should be drawn.

setForeground

public void setForeground(Color color)
Sets the label colors. A null value reset the automatic color.

Overrides:
setForeground in class JComponent
Parameters:
color - The new label color, or null for the default.
See Also:
Component.getForeground()

createGraduation

protected Graduation createGraduation(Graduation reuse,
                                      SampleDimension band,
                                      double minimum,
                                      double maximum)
Returns a graduation for the specified sample dimension, minimum and maximum values. If the supplied reuse object is non-null and is of the appropriate class, then this method can return reuse without creating a new graduation object. Otherwise this method must returns a graduation of the appropriate class, usually NumberGraduation or LogarithmicNumberGraduation.

In every cases, this method must set graduations minimum, maximum and unit according the values given in arguments.

Parameters:
reuse - The graduation to reuse if possible.
band - The sample dimension to create graduation for.
minimum - The minimal geophysics value to appear in the graduation.
maximum - The maximal geophysics value to appear in the graduation.
Returns:
A graduation for the supplied sample dimension.

toImage

public BufferedImage toImage()
Returns an image representation for this color ramp. The image size will be this widget size.

Returns:
The color ramp as a buffered image.
Since:
2.4

toString

public String toString()
Returns a string representation for this color ramp.

Overrides:
toString in class Component

addNotify

public void addNotify()
Notifies this component that it now has a parent component. This method is invoked by Swing and shouldn't be directly used.

Overrides:
addNotify in class JComponent

removeNotify

public void removeNotify()
Notifies this component that it no longer has a parent component. This method is invoked by Swing and shouldn't be directly used.

Overrides:
removeNotify in class JComponent


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.