Class JGradientColorMap
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
JGradientColorMap
class provides a gradient colour map.
A gradient colour map provides a visual display of a bar with a certain specified spectrum:
Bone:
Copper:
Discontinuous blue-white-green:
Discontinuous dark-red-yellow:
Black and white:
Gray scale:
Gray scale (trimmed):
Green-red diverging:
Hot:
Jet:
Hue/saturation/brightness (HSB):
Separated red/green/blue:
Red:
Green:
Blue:
Yellow:
Cyan:
Magenta:
Ultralight pastel:
Light pastel:
Dark pastel:
Greens:
Blues:
Yellow browns:
Violet purples:
Deep space:
Blue-white:
Custom:
Dependent on the colours specified.
Random:
A random selection of colours.
A gradient colour map can have four orientations (see JGradientColorMap.EOrientation
):
- horizontal left to right (tick marks are supported),
- horizontal right to left (tick marks are supported),
- vertical bottom to top
- and vertical top to bottom.
This class has also one method that can be used to derive a Color
that
is linearly interpolated across the specified spectrum:
Color interpolatedColor = myGradientColorMap.interpolate(0.6);
This corresponds to the following interpolation scheme (dependent on the colour map):
The value can also be indicated on the colour map itself.
All documentation is written in British English, except for the API-code, which was kept in American English for compatability with the Java API interface.
Note that this class cannot be subclassed!
- Version:
- 01/11/2016
- Author:
- Sven Maerivoet
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal class
A container class for a custom colour map component.static enum
The various supported colour maps.static enum
The supported horizontal and vertical orientations for the gradient colour map.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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
ConstructorsConstructorDescriptionConstructs aJGradientColorMap
object.JGradientColorMap
(JGradientColorMap.EColorMap colorMap) Constructs aJGradientColorMap
object with a specified colour map.JGradientColorMap
(JGradientColorMap.EOrientation orientation, int width, int height) Constructs aJGradientColorMap
object with the specified orientation and size.JGradientColorMap
(JGradientColorMap.EOrientation orientation, JGradientColorMap.EColorMap colorMap, int width, int height) Constructs aJGradientColorMap
object with the specified orientation and size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears all components from the custom colour map.convertToComponents
(int nrOfComponents) Converts the current colour map to a specified number of components.void
Disables the indication of values.void
Enables the indication of values.Returns all components of the custom colour map.Returns the colour map that is used.void
indicateValue
(double value) Instructs to indicate the specified valueinterpolate
(double u) Derives aColor
that is linearly interpolated across a spectrum.void
final void
Loads the custom colour map's components from a plain-text file.final void
Loads the random colour map's components from a plain-text file.final void
Saves the custom colour map's components to a plain-text file.final void
Saves the random colour map's components to a plain-text file.void
removeCustomColorMapComponent
(int id) Removes a component from the custom colour map.void
setAllCustomColorMapComponents
(TreeMap<Integer, JGradientColorMap.CustomColorMapComponent> colorMapComponents) Sets all components of the custom colour map.void
setColorMap
(JGradientColorMap.EColorMap colorMap) Changes the colour map that is used.void
setCustomColorMapComponent
(int id, double level, Color color) Adds or updates a component in the custom colour map.void
setMaximumSize
(Dimension dimension) void
setMinimumSize
(Dimension dimension) void
setPreferredSize
(Dimension dimension) void
setRandomColorMap
(int nrOfRandomColors) Sets up a random colour map.void
setTickMarks
(double lowerTickValue, String lowerTickValuePrefix, double higherTickValue, String higherTickValuePrefix, String tickValuePrefix, String tickValueSuffix, int nrOfTickMarks, int nrOfDecimals) Sets the optional tick marks for the gradient colour map.final void
streamLoadCustomColorMapComponents
(DataInputStream dataInputStream) Loads the custom colour map's components from a file as a stream.final void
streamLoadRandomColorMapComponents
(DataInputStream dataInputStream) Loads the random colour map's components from a file as a stream.final void
streamSaveCustomColorMapComponents
(DataOutputStream dataOutputStream) Saves the custom colour map's components to a plain-text file.final void
streamSaveRandomColorMapComponents
(DataOutputStream dataOutputStream) Saves the random colour map's components to a file as a stream.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, 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, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, list, list, paintComponents, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, 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, hasFocus, imageUpdate, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, list, list, list, paintAll, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
JGradientColorMap
public JGradientColorMap()Constructs aJGradientColorMap
object.The gradient colour map has by default a horizontal orientation (going from left to right) with a width of 100 pixels and a height of 20 pixels; the jet colour map is used by default.
-
JGradientColorMap
Constructs aJGradientColorMap
object with the specified orientation and size.The jet colour map is used by default.
- Parameters:
orientation
- the orientation of the gradient colour map (JGradientColorMap.EOrientation
)width
- the width of the gradient colour map (expressed in pixels)height
- the height of the gradient colour map (expressed in pixels)
-
JGradientColorMap
Constructs aJGradientColorMap
object with a specified colour map.The gradient colour map has by default a horizontal orientation (going from left to right) with a width of 100 pixels and a height of 20 pixels.
- Parameters:
colorMap
- the colour map to use
-
JGradientColorMap
public JGradientColorMap(JGradientColorMap.EOrientation orientation, JGradientColorMap.EColorMap colorMap, int width, int height) Constructs aJGradientColorMap
object with the specified orientation and size.- Parameters:
orientation
- the orientation of the gradient colour map (JGradientColorMap.EOrientation
)colorMap
- the colour map to usewidth
- the width of the gradient colour map (expressed in pixels)height
- the height of the gradient colour map (expressed in pixels)
-
-
Method Details
-
setColorMap
Changes the colour map that is used.- Parameters:
colorMap
- the colour map to use
-
setRandomColorMap
public void setRandomColorMap(int nrOfRandomColors) Sets up a random colour map.- Parameters:
nrOfRandomColors
- the number of random colours to be used
-
getColorMap
Returns the colour map that is used.- Returns:
- the colour map that is used
-
setTickMarks
public void setTickMarks(double lowerTickValue, String lowerTickValuePrefix, double higherTickValue, String higherTickValuePrefix, String tickValuePrefix, String tickValueSuffix, int nrOfTickMarks, int nrOfDecimals) Sets the optional tick marks for the gradient colour map.Note that these tick marks only appear on horizontally-oriented gradient colour maps.
- Parameters:
lowerTickValue
- the value associated with the left colourlowerTickValuePrefix
- the prefix label for the value associated with the left colourhigherTickValue
- the value associated with the right colourhigherTickValuePrefix
- the prefix label for the value associated with the right colourtickValuePrefix
- the prefix label for each valuetickValueSuffix
- the suffix label for each valuenrOfTickMarks
- the number of tick marks to producenrOfDecimals
- the number of decimals to retain in the values beneath the tick marks
-
indicateValue
public void indicateValue(double value) Instructs to indicate the specified value- Parameters:
value
- the value to indicate
-
enableValueIndication
public void enableValueIndication()Enables the indication of values. -
disableValueIndication
public void disableValueIndication()Disables the indication of values. -
getMinimumSize
- Overrides:
getMinimumSize
in classJComponent
-
setMinimumSize
- Overrides:
setMinimumSize
in classJComponent
-
getMaximumSize
- Overrides:
getMaximumSize
in classJComponent
-
setMaximumSize
- Overrides:
setMaximumSize
in classJComponent
-
getPreferredSize
- Overrides:
getPreferredSize
in classJComponent
-
setPreferredSize
- Overrides:
setPreferredSize
in classJComponent
-
paintComponent
- Overrides:
paintComponent
in classJComponent
-
setCustomColorMapComponent
Adds or updates a component in the custom colour map.- Parameters:
id
- the ID of the componentlevel
- the level of the component (between 0.0 and 1.0)color
- theColor
to associate with the component
-
removeCustomColorMapComponent
public void removeCustomColorMapComponent(int id) Removes a component from the custom colour map.- Parameters:
id
- the ID of the component
-
clearAllCustomColorMapComponents
public void clearAllCustomColorMapComponents()Clears all components from the custom colour map. -
setAllCustomColorMapComponents
public void setAllCustomColorMapComponents(TreeMap<Integer, JGradientColorMap.CustomColorMapComponent> colorMapComponents) Sets all components of the custom colour map.- Parameters:
colorMapComponents
- aTreeMap
containing all the custom colour map components
-
getAllCustomColorMapComponents
Returns all components of the custom colour map.- Returns:
- a
TreeMap
containing all the custom colour map components
-
convertToComponents
public TreeMap<Integer,JGradientColorMap.CustomColorMapComponent> convertToComponents(int nrOfComponents) Converts the current colour map to a specified number of components.- Parameters:
nrOfComponents
- the specified number of components- Returns:
- the converted colour map
-
plainTextLoadRandomColorMapComponents
public final void plainTextLoadRandomColorMapComponents(TextFileParser tfp) throws FileParseException Loads the random colour map's components from a plain-text file.- Parameters:
tfp
- a reference to the file parser- Throws:
FileParseException
- in case a parse error occurs
-
streamLoadRandomColorMapComponents
public final void streamLoadRandomColorMapComponents(DataInputStream dataInputStream) throws IOException Loads the random colour map's components from a file as a stream.- Parameters:
dataInputStream
- a data inputstream- Throws:
IOException
- in case a parse error occurs
-
plainTextSaveRandomColorMapComponents
public final void plainTextSaveRandomColorMapComponents(TextFileWriter tfw) throws FileWriteException Saves the random colour map's components to a plain-text file.- Parameters:
tfw
- a reference to the file writer- Throws:
FileWriteException
- in case a write error occurs
-
streamSaveRandomColorMapComponents
public final void streamSaveRandomColorMapComponents(DataOutputStream dataOutputStream) throws IOException Saves the random colour map's components to a file as a stream.- Parameters:
dataOutputStream
- a data outputstream- Throws:
IOException
- in case a write error occurs
-
plainTextLoadCustomColorMapComponents
public final void plainTextLoadCustomColorMapComponents(TextFileParser tfp) throws FileParseException Loads the custom colour map's components from a plain-text file.- Parameters:
tfp
- a reference to the file parser- Throws:
FileParseException
- in case a parse error occurs
-
streamLoadCustomColorMapComponents
public final void streamLoadCustomColorMapComponents(DataInputStream dataInputStream) throws IOException Loads the custom colour map's components from a file as a stream.- Parameters:
dataInputStream
- a data inputstream- Throws:
IOException
- in case a parse error occurs
-
plainTextSaveCustomColorMapComponents
public final void plainTextSaveCustomColorMapComponents(TextFileWriter tfw) throws FileWriteException Saves the custom colour map's components to a plain-text file.- Parameters:
tfw
- a reference to the file writer- Throws:
FileWriteException
- in case a write error occurs
-
streamSaveCustomColorMapComponents
public final void streamSaveCustomColorMapComponents(DataOutputStream dataOutputStream) throws IOException Saves the custom colour map's components to a plain-text file.- Parameters:
dataOutputStream
- a data outputstream- Throws:
IOException
- in case a write error occurs
-
interpolate
Derives aColor
that is linearly interpolated across a spectrum.Note that the value of
u
is clipped in the interval [0,1].- Parameters:
u
- the value to use when interpolating the spectrum- Returns:
- a linearly interpolated value across a spectrum
-