visad.util
Class BaseRGBMap

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 visad.util.ColorMap
                      extended by visad.util.BaseRGBMap
All Implemented Interfaces:
MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, ControlListener
Direct Known Subclasses:
RGBAMap, RGBMap

public class BaseRGBMap
extends ColorMap
implements ControlListener, MouseListener, MouseMotionListener

An extensible RGB colormap with no interpolation between the internally stored values. Click and drag with the left mouse button to draw the color curves. Click with the right or middle mouse button to alternate between the color curves.

Since:
Visad Utility Library, 0.5
Version:
$Revision: 1.22 $, $Date: 2002-09-19 21:08:42 $
Author:
Nick Rasmussen nick@cae.wisc.edu
See Also:
Serialized Form

Nested Class Summary
 
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
static int DEFAULT_RESOLUTION
          default resolution
static boolean USE_COLOR_CURSORS
          change this to true to use color cursors
 
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
BaseRGBMap(BaseColorControl ctl)
          Construct a colormap from the specified control.
BaseRGBMap(boolean hasAlpha)
          Construct a BaseRGBMap with the default resolution
BaseRGBMap(float[][] vals)
          Construct a colormap initialized with the supplied tuples
BaseRGBMap(float[][] vals, boolean hasAlpha)
          Deprecated. hasAlpha isn't really necessary.
BaseRGBMap(int resolution, boolean hasAlpha)
          Construct a colormap with the specified resolution
 
Method Summary
 void controlChanged(ControlEvent evt)
          If the color data in the Control associated with this widget's Control has changed, update the data in the ColorMap.
 float[][] getColorMap()
          Get the color map (as an array of float tuples.
 int getMapDimension()
          Get the dimension of the map
 int getMapResolution()
          Get the resolution of the map
 Dimension getPreferredSize()
          Return the preferred size of this map, taking into account the resolution.
 float[] getRGBTuple(float value)
          Implementation of the abstract function in ColorMap WARNING: This is a really slow way to get a color, so don't use it inside a loop.
 float[][] getRGBTuples(float startVal, float endVal, int num)
          Implementation of the abstract function in ColorMap WARNING: This is a really slow way to get a color, so don't use it inside a loop.
 float[] getTuple(float value)
          Returns the tuple at a floating point value val WARNING: This is a really slow way to get a color, so don't use it inside a loop.
 float[][] getTuples(float firstVal, float lastVal, int num)
          Returns the tuple at a floating point value val
 void mouseClicked(MouseEvent evt)
          Present to implement MouseListener, currently ignored
 void mouseDragged(MouseEvent evt)
          Updates the associated Control
 void mouseEntered(MouseEvent evt)
          MouseListener, currently ignored
 void mouseExited(MouseEvent evt)
          MouseListener method, currently ignored
 void mouseMoved(MouseEvent evt)
          MouseMovementListener method, currently ignored
 void mousePressed(MouseEvent evt)
          Updates the associated Control
 void mouseReleased(MouseEvent evt)
          Listens for releases of the right mouse button, and changes the active color
 void paint(Graphics g)
          Repaints the entire JPanel
protected  void sendUpdate(int left, int right)
          Redraw the between the left and right colors
 void setPreferredSize(Dimension pref)
          Override the widget's calculation for the preferred size of this map.
 void setValues(float[][] newVal)
          Sets the values of the internal array after the map has been created.
 void update(Graphics g)
          Repaints the modified areas of the JPanel
 
Methods inherited from class visad.util.ColorMap
addColorChangeListener, getColor, getColors, notifyListeners, removeColorChangeListener
 
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, 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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction
 
Methods inherited from class java.awt.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 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, 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, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

USE_COLOR_CURSORS

public static boolean USE_COLOR_CURSORS
change this to true to use color cursors


DEFAULT_RESOLUTION

public static final int DEFAULT_RESOLUTION
default resolution

See Also:
Constant Field Values
Constructor Detail

BaseRGBMap

public BaseRGBMap(boolean hasAlpha)
           throws RemoteException,
                  VisADException
Construct a BaseRGBMap with the default resolution

Parameters:
hasAlpha - set to true is this map has an alpha component
Throws:
RemoteException
VisADException

BaseRGBMap

public BaseRGBMap(int resolution,
                  boolean hasAlpha)
           throws RemoteException,
                  VisADException
Construct a colormap with the specified resolution

Parameters:
resolution - the length of the array
hasAlpha - set to true is this map has an alpha component
Throws:
RemoteException
VisADException

BaseRGBMap

public BaseRGBMap(float[][] vals,
                  boolean hasAlpha)
           throws RemoteException,
                  VisADException
Deprecated. hasAlpha isn't really necessary.

Construct a colormap initialized with the supplied tuples

Parameters:
vals - the tuples used to initialize the colormap
hasAlpha - true if the colormap should have an ALPHA component.
Throws:
RemoteException
VisADException

BaseRGBMap

public BaseRGBMap(float[][] vals)
           throws RemoteException,
                  VisADException
Construct a colormap initialized with the supplied tuples

Parameters:
vals - the tuples used to initialize the colormap See setValues() for constraints on the vals array.
Throws:
RemoteException
VisADException

BaseRGBMap

public BaseRGBMap(BaseColorControl ctl)
Construct a colormap from the specified control.

Parameters:
ctl - control to use as data source
Method Detail

setValues

public void setValues(float[][] newVal)
               throws RemoteException,
                      VisADException
Sets the values of the internal array after the map has been created. The table should be float[resolution][dimension] where dimension is either 3 (for an RGB table) or 4 (if the table also has an alpha component) and resolution is the number of colors in the table, which must be greater than 4.

Parameters:
newVal - the color tuples used to initialize the map.
Throws:
RemoteException
VisADException

getMapResolution

public int getMapResolution()
Get the resolution of the map

Specified by:
getMapResolution in class ColorMap
Returns:
the number of colors in the map.

getMapDimension

public int getMapDimension()
Get the dimension of the map

Specified by:
getMapDimension in class ColorMap
Returns:
either 3 or 4

getColorMap

public float[][] getColorMap()
Get the color map (as an array of float tuples.

Specified by:
getColorMap in class ColorMap
Returns:
a copy of the color map

getTuples

public float[][] getTuples(float firstVal,
                           float lastVal,
                           int num)
Returns the tuple at a floating point value val

Specified by:
getTuples in class ColorMap
Parameters:
firstVal - the location to start.
lastVal - the location to finish.
num - the number of tuples to return.
Returns:
The array of 3 or 4 element arrays.

getTuple

public float[] getTuple(float value)
Returns the tuple at a floating point value val WARNING: This is a really slow way to get a color, so don't use it inside a loop.

Specified by:
getTuple in class ColorMap
Parameters:
value - the location to return.
Returns:
The 3 or 4 element array.

getRGBTuples

public float[][] getRGBTuples(float startVal,
                              float endVal,
                              int num)
Implementation of the abstract function in ColorMap WARNING: This is a really slow way to get a color, so don't use it inside a loop.

Specified by:
getRGBTuples in class ColorMap
Parameters:
startVal - the first value to translate
endVal - the last value to translate
num - the number of values (including the two endpoints) to be returned.

getRGBTuple

public float[] getRGBTuple(float value)
Implementation of the abstract function in ColorMap WARNING: This is a really slow way to get a color, so don't use it inside a loop.

Specified by:
getRGBTuple in class ColorMap
Parameters:
value - a floating point number between 0 and 1
Returns:
an RGB tuple of floating point numbers in the range 0 to 1

sendUpdate

protected void sendUpdate(int left,
                          int right)
Redraw the between the left and right colors

Parameters:
left - the left edge of the changed area (in the range 0.0-1.0)
right - the right edge of the changed area

mouseClicked

public void mouseClicked(MouseEvent evt)
Present to implement MouseListener, currently ignored

Specified by:
mouseClicked in interface MouseListener
Parameters:
evt - ignored

mouseEntered

public void mouseEntered(MouseEvent evt)
MouseListener, currently ignored

Specified by:
mouseEntered in interface MouseListener
Parameters:
evt - ignored

mouseExited

public void mouseExited(MouseEvent evt)
MouseListener method, currently ignored

Specified by:
mouseExited in interface MouseListener
Parameters:
evt - ignored

mousePressed

public void mousePressed(MouseEvent evt)
Updates the associated Control

Specified by:
mousePressed in interface MouseListener
Parameters:
evt - the mouse press event

mouseReleased

public void mouseReleased(MouseEvent evt)
Listens for releases of the right mouse button, and changes the active color

Specified by:
mouseReleased in interface MouseListener
Parameters:
evt - the release event

mouseDragged

public void mouseDragged(MouseEvent evt)
Updates the associated Control

Specified by:
mouseDragged in interface MouseMotionListener
Parameters:
evt - the drag event

mouseMoved

public void mouseMoved(MouseEvent evt)
MouseMovementListener method, currently ignored

Specified by:
mouseMoved in interface MouseMotionListener
Parameters:
evt - ignored

paint

public void paint(Graphics g)
Repaints the entire JPanel

Overrides:
paint in class JComponent
Parameters:
g - The Graphics to update.

update

public void update(Graphics g)
Repaints the modified areas of the JPanel

Overrides:
update in class JComponent
Parameters:
g - The Graphics to update.

getPreferredSize

public Dimension getPreferredSize()
Return the preferred size of this map, taking into account the resolution.

Overrides:
getPreferredSize in class JComponent
Returns:
preferred size.

setPreferredSize

public void setPreferredSize(Dimension pref)
Override the widget's calculation for the preferred size of this map.

Overrides:
setPreferredSize in class JComponent
Parameters:
pref - preferred size.

controlChanged

public void controlChanged(ControlEvent evt)
                    throws RemoteException,
                           VisADException
If the color data in the Control associated with this widget's Control has changed, update the data in the ColorMap.

Specified by:
controlChanged in interface ControlListener
Parameters:
evt - Data from the changed Control.
Throws:
RemoteException
VisADException