Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class ncsa.horizon.awt.color.CurveEditMode

java.lang.Object
  |
  +--java.awt.event.MouseAdapter
        |
        +--ncsa.horizon.awt.color.CurveEditMode
Subclasses:
DisabledEditMode, FreeHandEditMode, MutateEditMode, ThreeMrkUpdEditMode

public abstract class CurveEditMode
extends java.awt.event.MouseAdapter
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.ComponentListener, java.lang.Cloneable
a driver for graphically editing an array of integers in some special way.

This class is used by the CurveEditCanvas to edit its integer array data. Implementations of this abstract class support a specialized way of editing the data. This is usually based on markers that the user can create and move around by clicking on the canvas. The positions of the markers influence the values of the curve around it in some way. Whether how many markers are used is implementation-dependent.

To operate properly, this class must be given a reference to the component where the curve will be displayed and edited (e.g. the CurveEditCanvas). This is done either via a constructor or the setComponent() method. This mode will scale the plot of the data to fill up the size of the component.

Either of two abstract subclasses may be useful when implementing a specialized CurveEditMode. First, subclassing the ThreeMrkUpdEditMode is useful when the value of the curve is dependent only on the two (or at most three) surrounding Markers. The SawtoothEditMode, in which the curve is a set of line segments connecting the markers, is an example of such a implemention. The MutateEditMode can be subclassed when editing is done by tweaking a transform on the original curve data. The OffsetEditMode, in which the curve can be moved up and down, is such a mode.

See Also:
FreeHandEditMode, OffsetEditMode, SawtoothEditMode

Field Summary
MarkerChain chain
           
int[] curvedata
           
Marker grabbed
           
int maxmarkers
           
 
Constructor Summary
CurveEditMode(int[] data, int start, int len, int min, int max, java.awt.Component component, MarkerChain markers)
          initialize the mode.
CurveEditMode(int[] data, int max, java.awt.Component component)
          initialize the mode.
CurveEditMode(int[] data, int max, java.awt.Component component, MarkerChain markers)
          initialize the mode.
CurveEditMode()
           
 
Method Summary
void addActionListener(java.awt.event.ActionListener l)
          set a listener to be notified when the curve has been updated.
void addMarker(int x, int y)
          add a marker at the given position and update the curve accordingly.
java.lang.Object clone()
          clone this mode.
void componentHidden(java.awt.event.ComponentEvent ev)
           
void componentMoved(java.awt.event.ComponentEvent ev)
           
void componentResized(java.awt.event.ComponentEvent ev)
           
void componentShown(java.awt.event.ComponentEvent ev)
           
java.awt.Point curveToDisplay(int x, int y)
          map a position in the curve to a position in the component where the curve will be painted.
java.awt.Point curveToDisplay(java.awt.Point p)
          map a position in the curve to a position in the component where the curve will be painted.
java.awt.Point displayToCurve(int x, int y)
          map a position in the component where the curve is painted to an index and value in the curve array.
java.awt.Point displayToCurve(java.awt.Point p)
          map a position in the component where the curve is painted to an index and value in the curve array.
void dragMarker(int x, int y)
          drag the currently grabbed marker to the given position and update the curve accordingly.
void drawData(java.awt.Graphics g)
          draw the data in the curve to the current graphics context
void drawMarkers(java.awt.Graphics g)
          draw the markers into a given graphics context
void dropMarker(int x, int y)
          drop the currently grabbed marker.
int[] getData()
          return the curve array currently being edited
java.awt.Rectangle getDataDomain()
          return the editable domain of the array as a rectangle.
int getDataEnd()
          return the ending index of the interval within the curve array that is being edited.
int getDataStart()
          return the starting index of the interval within the curve array that is being edited.
MarkerChain getMarkers()
          return the collection of markers currently in use.
void grabNearestMarker(int x, int y)
          grab the nearest marker to the given position
void grabOrCreateMarker(int x, int y)
          grab or create a marker at the given position.
void mouseDragged(java.awt.event.MouseEvent ev)
          react to a mouse drag within the display component.
void mouseMoved(java.awt.event.MouseEvent ev)
          react to a mouse move within the display component.
void mousePressed(java.awt.event.MouseEvent ev)
          react to a mouse button press within the display component.
void mouseReleased(java.awt.event.MouseEvent ev)
          react to a mouse move within the display component.
void notifyListeners()
          alert listeners that the curve has been updated.
void removeActionListener(java.awt.event.ActionListener l)
          remove a listener
void setComponent(java.awt.Component c)
          set the component that will be using this mode.
void setData(int[] data, int start, int len, int min, int max)
          set the curve array to edit.
void setData(int[] data, java.awt.Rectangle domain)
          set the curve array to edit.
void setData(int[] data, int max)
          set the curve array to edit.
void setMarkerChain(MarkerChain markers)
          set the set of markers to be used by this mode
void setMarkers(MarkerChain mc)
          set the markers to be used by this mode.
void snapMarkersToCurve()
          move the markers vertically so as to line up with the current values in the curve array.
void unsetComponent(java.awt.Component c)
          unset the component using this mode.
void updateCurve(int[] curvedata, int st, int count)
          update the given array
void updateCurveFor(int curvemin, int curvemax)
          update the values in the curve between the given values
 
Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseEntered, mouseExited, mousePressed, mouseReleased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

chain

protected MarkerChain chain

curvedata

protected int[] curvedata

maxmarkers

protected int maxmarkers

grabbed

protected Marker grabbed
Constructor Detail

CurveEditMode

public CurveEditMode(int[] data,
                     int start,
                     int len,
                     int min,
                     int max,
                     java.awt.Component component,
                     MarkerChain markers)
initialize the mode.
Parameters:
data - the array of data to edit
start - the first index in the array that can be edited
len - the number of elements in the data that can be edited
min - the minimum value an array element can have
max - the maximum value an array element can have
component - the component that will receive mouse events from the user
markers - the set of markers to use.

CurveEditMode

public CurveEditMode(int[] data,
                     int max,
                     java.awt.Component component)
initialize the mode. The mode will be allowed to edit all of the values in the array. The minimum value an element can hold is assumed to be zero. The mode will create its own set of markers as necessary.
Parameters:
data - the array of data to edit
max - the maximum value an array element can have
component - the component that will receive mouse events from the user

CurveEditMode

public CurveEditMode(int[] data,
                     int max,
                     java.awt.Component component,
                     MarkerChain markers)
initialize the mode. The mode will be allowed to edit all of the values in the array. The minimum value an element can hold is assumed to be zero.
Parameters:
data - the array of data to edit
max - the maximum value an array element can have
component - the component that will receive mouse events from the user
markers - the set of markers to use.

CurveEditMode

public CurveEditMode()
Method Detail

setMarkerChain

public void setMarkerChain(MarkerChain markers)
set the set of markers to be used by this mode

drawMarkers

public void drawMarkers(java.awt.Graphics g)
draw the markers into a given graphics context

drawData

public void drawData(java.awt.Graphics g)
draw the data in the curve to the current graphics context

updateCurveFor

protected void updateCurveFor(int curvemin,
                              int curvemax)
update the values in the curve between the given values
Parameters:
curvemin - the start index of the interval to update
curvemax - the end index of the interval to update; that is, the index just after the last value to update.

addMarker

public void addMarker(int x,
                      int y)
add a marker at the given position and update the curve accordingly.

dragMarker

public void dragMarker(int x,
                       int y)
drag the currently grabbed marker to the given position and update the curve accordingly.

dropMarker

public void dropMarker(int x,
                       int y)
drop the currently grabbed marker. (That is, ungrab it.)

grabNearestMarker

public void grabNearestMarker(int x,
                              int y)
grab the nearest marker to the given position

grabOrCreateMarker

public void grabOrCreateMarker(int x,
                               int y)
grab or create a marker at the given position. If a marker overlaps with the position, it is grabbed; otherwise, a new marker is inserted and grabbed at that position.

getMarkers

public MarkerChain getMarkers()
return the collection of markers currently in use. Changes made to the MarkerChain by other objects (e.g. other CurveEditMode objects) will be seen by this class.

setMarkers

public void setMarkers(MarkerChain mc)
set the markers to be used by this mode. Changes made to the MarkerChain by other objects (e.g. other CurveEditMode objects) will be seen by this class.

snapMarkersToCurve

public void snapMarkersToCurve()
move the markers vertically so as to line up with the current values in the curve array.

getData

public int[] getData()
return the curve array currently being edited

getDataStart

public int getDataStart()
return the starting index of the interval within the curve array that is being edited.

getDataEnd

public int getDataEnd()
return the ending index of the interval within the curve array that is being edited. This index points to the element just after last element being edited.

getDataDomain

public java.awt.Rectangle getDataDomain()
return the editable domain of the array as a rectangle. The x and width values give the starting index and number of elements that are editable. The y value represents the minimum value the curve can have, while the height represents the maximum minus the minimum.

setData

public void setData(int[] data,
                    int start,
                    int len,
                    int min,
                    int max)
set the curve array to edit.
Parameters:
data - the array of data to edit
start - the first index in the array that can be edited
len - the number of elements in the data that can be edited
min - the minimum value an array element can have
max - the maximum value an array element can have

setData

public void setData(int[] data,
                    java.awt.Rectangle domain)
set the curve array to edit.
Parameters:
data - the array of data to edit
domain - the domain within data that can be edited. The input rectangle should conform to the convention used by getDataDomain().

setData

public void setData(int[] data,
                    int max)
set the curve array to edit. The mode will be allowed to edit all of the values in the array. The minimum value an element can hold is assumed to be zero.
Parameters:
data - the array of data to edit
max - the maximum value an array element can have

setComponent

public void setComponent(java.awt.Component c)
set the component that will be using this mode. Normally, this is a CurveEditMode object. This component will receive the mouse events generated by the user to edit the curve. Furthermore, this mode will assume that this is the component where the curve will be drawn when it determines the proper scaling to apply to the plotting process.

unsetComponent

public void unsetComponent(java.awt.Component c)
unset the component using this mode. Normally, this is a CurveEditMode object. This method will cause this mode to stop listening to mouse events generated by the component.

updateCurve

protected abstract void updateCurve(int[] curvedata,
                                    int st,
                                    int count)
update the given array
Parameters:
curvedata - the data array to update
st - the starting index to update
count - the number of elements to update.

curveToDisplay

public java.awt.Point curveToDisplay(int x,
                            int y)
map a position in the curve to a position in the component where the curve will be painted.
Parameters:
x - an index in the curve array
y - the array value at the index
Returns:
Point the position in the component's coordinate system

curveToDisplay

public java.awt.Point curveToDisplay(java.awt.Point p)
map a position in the curve to a position in the component where the curve will be painted.
Parameters:
p.x - an index in the curve array
p.y - the array value at the index
Returns:
Point the position in the component's coordinate system

displayToCurve

public java.awt.Point displayToCurve(int x,
                            int y)
map a position in the component where the curve is painted to an index and value in the curve array.
Parameters:
x - the x position in the component's coordinate system
y - the y position in the component's coordinate system
Returns:
Point the index (as the x field) and value (as the y field) of the curve corresponding to the given point.

displayToCurve

public java.awt.Point displayToCurve(java.awt.Point p)
map a position in the component where the curve is painted to an index and value in the curve array.
Parameters:
p - the position in the component's coordinate system
Returns:
Point the index (as the x field) and value (as the y field) of the curve corresponding to the given point.

mousePressed

public void mousePressed(java.awt.event.MouseEvent ev)
react to a mouse button press within the display component. This implementation calls grabOrCreateMarker().
Specified by:
mousePressed(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener
Overrides:
mousePressed in class java.awt.event.MouseAdapter

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent ev)
react to a mouse drag within the display component. This implementation calls dragMarker().
Specified by:
mouseDragged(java.awt.event.MouseEvent) in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent ev)
react to a mouse move within the display component. This implementation does nothing.
Specified by:
mouseMoved(java.awt.event.MouseEvent) in interface java.awt.event.MouseMotionListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent ev)
react to a mouse move within the display component. This implementation calls dropMarker and notifies action listeners of this class.
Specified by:
mouseReleased(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class java.awt.event.MouseAdapter

notifyListeners

protected void notifyListeners()
alert listeners that the curve has been updated. This is usually necessary to cause the display component to be updated.

addActionListener

public void addActionListener(java.awt.event.ActionListener l)
set a listener to be notified when the curve has been updated.

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)
remove a listener

componentResized

public void componentResized(java.awt.event.ComponentEvent ev)
Description copied from interface:
 
Specified by:
componentResized(java.awt.event.ComponentEvent) in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent ev)
Description copied from interface:
 
Specified by:
componentMoved(java.awt.event.ComponentEvent) in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent ev)
Description copied from interface:
 
Specified by:
componentShown(java.awt.event.ComponentEvent) in interface java.awt.event.ComponentListener

componentHidden

public void componentHidden(java.awt.event.ComponentEvent ev)
Description copied from interface:
 
Specified by:
componentHidden(java.awt.event.ComponentEvent) in interface java.awt.event.ComponentListener

clone

public java.lang.Object clone()
clone this mode. The result will not have any listeners attached to it.
Overrides:
clone in class java.lang.Object

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD