jview
Class CrossCursor

java.lang.Object
  extended by java.awt.Cursor
      extended by jview.CanvasCursor
          extended by jview.CrossCursor
All Implemented Interfaces:
MouseListener, MouseMotionListener, Serializable, EventListener, MouseInputListener, Initializable, PropertyAware, PropertyComposed
Direct Known Subclasses:
CrossCursor.Draw, DragCursor

public abstract class CrossCursor
extends CanvasCursor
implements MouseInputListener

A cursor-like application that supplies a cross-hair above the entire drawable area of a JShapeCanvas. If persitant marking is enabled with the KEY_PERSISTENT key, then clicking on the canvas adds a cross-hair on the location clicked to the shape canvas.

See Also:
Serialized Form

Nested Class Summary
static class CrossCursor.Draw
           
 
Field Summary
protected  Color cursorcolor
          The color of the cursor, cached for speed.
private  JLabel cursorcoordinates
          An extra label where the current coordinates should be writtn.
private static boolean DEFSHOWCOORDINATE
          The default cursor position marking.
private static int DEFXSHIFT
          The shift from the mouse position to basline of position, pixel.
private static int DEFYSHIFT
          The shift from the mouse position to basline of position, pixel.
static String KEY_ALLOWDRAG
          If true, dragging draws an outlining rectangle.
static String KEY_ANGLESIZE
          The half size of the bounding rectangle of the angle arc.
static String KEY_PERSISTENT
          If true, clicking adds permanent cross-hairs.
static String KEY_SHOWCOORDINATE
          If true, the current cursor position is marked.
static String KEY_SINGLEPERSIST
          If true, one a single persistent is active.
static String KEY_XSHIFT
          The shift from the mouse position to basline of position, pixel.
static String KEY_YSHIFT
          The shift from the mouse position to basline of position, pixel.
protected  Point lastcenter
          The center of the last cross drawn.
protected  String lastposition
          The last cursor position writtn.
protected  NumberFormat xformat
          If we have a decimal formatter on the canvas for x-labels.
protected  NumberFormat yformat
          If we have a decimal formatter on the canvas for y-labels.
 
Fields inherited from class jview.CanvasCursor
canvas, DEFCURSORCOLOR, KEY_COORDINATES, KEY_CURSORCOLOR, KEY_CURSORNAME, KEY_CURSORSIZE, NORMALIZED, NORMALIZEDACTION, SCREEN, SCREENACTION, USER, USERACTION
 
Fields inherited from class java.awt.Cursor
CROSSHAIR_CURSOR, CUSTOM_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, N_RESIZE_CURSOR, name, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, predefined, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Constructor Summary
protected CrossCursor(PropertySupplying prop)
          Constructs a new cross cursor from properties.
 
Method Summary
protected  void clearOnRepaint(Graphics2D g2d)
          Updates the canvas in its own thread.
protected  void drawCross(Graphics onto, Point center)
          Draw a cursor cross.
protected  void drawPosition(Graphics onto, String cor, Point center)
          Draws a position string.
 JLabel getCoordinateLabel()
          Returns the label the cursor displays its current coordinates in or null if not set.
protected  String getCoordinates(Point mouse)
          Converts the pixel coordinates to a single string.
protected  String getCoordinatesPair(String xcor, String ycor)
          Packs the x and y string together to form a single displayable string.
 void mouseEntered(MouseEvent me)
          When the mouse enters, we cache the up-left point and the size of the canvas, hoping that resizing events take only place when the mouse is not pointing within the canvas.
 void mouseExited(MouseEvent me)
          When the mouse exits the component, we check if we have everything deleted.
 void mouseMoved(MouseEvent me)
          When the mouse is moved, we check if we are inside the active rectangle.
 void setComposedProperties(PropertySupplying info)
          Compose with a PropertySupplying as we need subclassing Cursor.
 void setCoordinateFormat(NumberFormat forx, NumberFormat fory)
          Sets the formatters
 void setCoordinateLabel(JLabel coor)
          Sets an extra label for coordinate display.
 
Methods inherited from class jview.CanvasCursor
disableCanvas, enableCanvas, getActions, getComposedProperties, getCursorName, getCursorShape, getCustomized, getNormalizedAction, getScreenAction, getUserAction, init, isConsider, isMe, isWithin, repaintCanvas, setCursorName, setCursorShape
 
Methods inherited from class java.awt.Cursor
getDefaultCursor, getName, getPredefinedCursor, getSystemCustomCursor, getType, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.event.MouseListener
mouseClicked, mousePressed, mouseReleased
 
Methods inherited from interface java.awt.event.MouseMotionListener
mouseDragged
 

Field Detail

KEY_PERSISTENT

public static final String KEY_PERSISTENT
If true, clicking adds permanent cross-hairs.

See Also:
Constant Field Values

KEY_SINGLEPERSIST

public static final String KEY_SINGLEPERSIST
If true, one a single persistent is active.

See Also:
Constant Field Values

KEY_ALLOWDRAG

public static final String KEY_ALLOWDRAG
If true, dragging draws an outlining rectangle.

See Also:
Constant Field Values

KEY_SHOWCOORDINATE

public static final String KEY_SHOWCOORDINATE
If true, the current cursor position is marked.

See Also:
Constant Field Values

KEY_XSHIFT

public static final String KEY_XSHIFT
The shift from the mouse position to basline of position, pixel.

See Also:
Constant Field Values

KEY_YSHIFT

public static final String KEY_YSHIFT
The shift from the mouse position to basline of position, pixel.

See Also:
Constant Field Values

KEY_ANGLESIZE

public static final String KEY_ANGLESIZE
The half size of the bounding rectangle of the angle arc.

See Also:
Constant Field Values

DEFSHOWCOORDINATE

private static final boolean DEFSHOWCOORDINATE
The default cursor position marking.

See Also:
Constant Field Values

DEFXSHIFT

private static final int DEFXSHIFT
The shift from the mouse position to basline of position, pixel.

See Also:
Constant Field Values

DEFYSHIFT

private static final int DEFYSHIFT
The shift from the mouse position to basline of position, pixel.

See Also:
Constant Field Values

lastcenter

protected Point lastcenter
The center of the last cross drawn.


lastposition

protected String lastposition
The last cursor position writtn.


xformat

protected NumberFormat xformat
If we have a decimal formatter on the canvas for x-labels.


yformat

protected NumberFormat yformat
If we have a decimal formatter on the canvas for y-labels.


cursorcolor

protected Color cursorcolor
The color of the cursor, cached for speed.


cursorcoordinates

private JLabel cursorcoordinates
An extra label where the current coordinates should be writtn.

Constructor Detail

CrossCursor

protected CrossCursor(PropertySupplying prop)
Constructs a new cross cursor from properties. Needs to register the JShapeCanvas manually.

Method Detail

setComposedProperties

public void setComposedProperties(PropertySupplying info)
Compose with a PropertySupplying as we need subclassing Cursor.

Specified by:
setComposedProperties in interface PropertyAware
Overrides:
setComposedProperties in class CanvasCursor

setCoordinateFormat

public void setCoordinateFormat(NumberFormat forx,
                                NumberFormat fory)
Sets the formatters


setCoordinateLabel

public void setCoordinateLabel(JLabel coor)
Sets an extra label for coordinate display.


getCoordinateLabel

public JLabel getCoordinateLabel()
Returns the label the cursor displays its current coordinates in or null if not set.


mouseEntered

public void mouseEntered(MouseEvent me)
When the mouse enters, we cache the up-left point and the size of the canvas, hoping that resizing events take only place when the mouse is not pointing within the canvas.

Specified by:
mouseEntered in interface MouseListener

mouseMoved

public void mouseMoved(MouseEvent me)
When the mouse is moved, we check if we are inside the active rectangle. If so, we draw an extended crosshair spanning the entire active area.

Specified by:
mouseMoved in interface MouseMotionListener

mouseExited

public void mouseExited(MouseEvent me)
When the mouse exits the component, we check if we have everything deleted.

Specified by:
mouseExited in interface MouseListener

getCoordinatesPair

protected String getCoordinatesPair(String xcor,
                                    String ycor)
Packs the x and y string together to form a single displayable string.


getCoordinates

protected String getCoordinates(Point mouse)
Converts the pixel coordinates to a single string. If we have a Morphing instance, transfer it into coordinate space.


drawCross

protected void drawCross(Graphics onto,
                         Point center)
Draw a cursor cross. If this method is called, the active rectangle is always set.


drawPosition

protected void drawPosition(Graphics onto,
                            String cor,
                            Point center)
Draws a position string.


clearOnRepaint

protected void clearOnRepaint(Graphics2D g2d)
Updates the canvas in its own thread.

Overrides:
clearOnRepaint in class CanvasCursor