jview
Class ShapeCursor

java.lang.Object
  extended by java.awt.Cursor
      extended by jview.CanvasCursor
          extended by jview.CrossCursor
              extended by jview.DragCursor
                  extended by jview.ZoomCursor
                      extended by jview.ShapeCursor
All Implemented Interfaces:
MouseListener, MouseMotionListener, MouseWheelListener, Serializable, EventListener, MouseInputListener, Initializable, PropertyAware, PropertyComposed, PostUpdate

public class ShapeCursor
extends ZoomCursor
implements PostUpdate

This class stores a list of shapes, that can be selected, changed in size etc. It does so by listening to clicks on the canvas, as well as drags and mouse-wheel events.

See Also:
Serialized Form

Nested Class Summary
static class ShapeCursor.Test
          A test class for testing the layout
 
Nested classes/interfaces inherited from class jview.CrossCursor
CrossCursor.Draw
 
Field Summary
private  List<ShapeDraw> active
          List of normalized shapes that have been added for selection lookup.
private  boolean changed
          The boolean that gets true if a selected shape changed.
static Color DEFDRAWCOLOR
          The color, a shape is drawn after adding.
static boolean DEFISFILLED
          If the principal shape is filled.
static boolean DEFISSCREENSHAPE
          If the principal shape is on-screen.
private static double DEFOFFSET
          The maximal offset for erasing in normalized space.
static Color DEFSELECTCOLOR
          The highlight color, i.e.
static String DEFSHAPE
          The principal shape, parsable from a string.
private  Shape draw
          The selected shape as it is drawn (i.e.
private  Shape generic
          The generic shape this cursor supports at the moment.
static String KEY_DRAWCOLOR
          The color, a shape is drawn after adding.
static String KEY_ISFILLED
          If the principal shape is filled.
static String KEY_ISSCREENSHAPE
          If this is true, the generic shape is a on-screen representation.
static String KEY_OFFSET
          The select distance, normalized.
static String KEY_SELECTCOLOR
          The highlight color, i.e.
static String KEY_SHAPE
          The principal shape, parsable from a string.
private  ShapeDraw normgen
          The normalized generic shape, equal to generic if not pixelized.
private  ShapeDraw selected
          The current active shape, normalized.
private static String SHAPE
          The name for cursor objects added to the underlying canvas.
static String SHAPEADDED
          The name of the shape-added property.
static String SHAPEDELETED
          The name of the shape-deleteded property.
static String SHAPESELECT
          The name of the shape-select property.
 
Fields inherited from class jview.ZoomCursor
DEFCURSORNAME, KEY_ALLOWSHIFT, KEY_ALLOWWHEEL, KEY_SHIFTFACTOR, KEY_WHEELZOOM, RETRACE, REVERT
 
Fields inherited from class jview.DragCursor
KEY_ANGLESIZE, KEY_SHOWANGLE, KEY_SHOWDELTAX, KEY_SHOWDELTAY, KEY_SHOWDISTANCE, KEY_SHOWSTART
 
Fields inherited from class jview.CrossCursor
cursorcolor, KEY_ALLOWDRAG, KEY_PERSISTENT, KEY_SHOWCOORDINATE, KEY_SINGLEPERSIST, KEY_XSHIFT, KEY_YSHIFT, lastcenter, lastposition, xformat, yformat
 
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
ShapeCursor(PropertySupplying prop)
          Constructs a new shape cursor that can be assigned to JNormalizedCanvas.
 
Method Summary
 void complete(Graphics g)
          This method is called directly before component.update.
private  Shape createGenericShape(PropertySupplying info)
          Returns the generic shape this cursor controls in normalized coordinates.
 void disableCanvas()
          We remove ourselfs from the post-drawing.
 void enableCanvas(JNormalizedCanvas root)
          Assigns the JShapeCanvas to the cursor.
 Shape getGenericShape()
          Returns the current generic shape, as set prior to eventual normalization.
 void init()
          Initializes the zoom cursor.
 void mouseClicked(MouseEvent me)
          Clicking close to a shape activates this shape, otherwise a new shape is generated.
 void mouseMoved(MouseEvent me)
          Mouse moving move also the currently selected shape, if there is one.
 void mouseWheelMoved(MouseWheelEvent we)
          Grabs mouse wheel events.
private  void paintShape(Shape screen, Graphics onto)
          Draw the shape in the XOR color.
private  void rescaleShape(double zx, double zy, Graphics onto)
          Rescales the current active shape after a drag or a mouse-wheel.
 void reset()
          Clears any last draws.
private static ShapeDraw scan(List<ShapeDraw> recent, Point2D within, double maxdist)
          Scans in normalized coordinates whether we have a shape recently added.
 void setComposedProperties(PropertySupplying info)
          Compose with a PropertySupplying as we need subclassing Cursor.
 void setGenericShape(Shape gen, boolean pixel, boolean filled)
          Sets the generic shape.
private  ShapeDraw toNormalized(Shape screen, boolean fill)
          After shifting and scaling, we have a shape in screen coordinates that should be transferred to normalized coordinates so that we can add it to the underlying canvas.
 
Methods inherited from class jview.ZoomCursor
dragSelect, getActions, getRetraceAction, getRevertAction, mouseDragged, mousePressed, mouseReleased, zoomFactor
 
Methods inherited from class jview.DragCursor
clearOnRepaint, mouseEntered
 
Methods inherited from class jview.CrossCursor
drawCross, drawPosition, getCoordinateLabel, getCoordinates, getCoordinatesPair, mouseExited, setCoordinateFormat, setCoordinateLabel
 
Methods inherited from class jview.CanvasCursor
getComposedProperties, getCursorName, getCursorShape, getCustomized, getNormalizedAction, getScreenAction, getUserAction, 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
 

Field Detail

SHAPEDELETED

public static final String SHAPEDELETED
The name of the shape-deleteded property.

See Also:
Constant Field Values

SHAPEADDED

public static final String SHAPEADDED
The name of the shape-added property.

See Also:
Constant Field Values

SHAPESELECT

public static final String SHAPESELECT
The name of the shape-select property.

See Also:
Constant Field Values

KEY_SELECTCOLOR

public static final String KEY_SELECTCOLOR
The highlight color, i.e. the color a shape is drawn if selected.

See Also:
Constant Field Values

KEY_DRAWCOLOR

public static final String KEY_DRAWCOLOR
The color, a shape is drawn after adding.

See Also:
Constant Field Values

KEY_SHAPE

public static final String KEY_SHAPE
The principal shape, parsable from a string. Normalized.

See Also:
Constant Field Values

KEY_ISFILLED

public static final String KEY_ISFILLED
If the principal shape is filled.

See Also:
Constant Field Values

KEY_OFFSET

public static final String KEY_OFFSET
The select distance, normalized.

See Also:
Constant Field Values

KEY_ISSCREENSHAPE

public static final String KEY_ISSCREENSHAPE
If this is true, the generic shape is a on-screen representation.

See Also:
Constant Field Values

DEFSELECTCOLOR

public static final Color DEFSELECTCOLOR
The highlight color, i.e. the color a shape is drawn if selected.


DEFDRAWCOLOR

public static final Color DEFDRAWCOLOR
The color, a shape is drawn after adding.


DEFSHAPE

public static final String DEFSHAPE
The principal shape, parsable from a string. Normalized.

See Also:
Constant Field Values

DEFISFILLED

public static final boolean DEFISFILLED
If the principal shape is filled.

See Also:
Constant Field Values

DEFISSCREENSHAPE

public static final boolean DEFISSCREENSHAPE
If the principal shape is on-screen.

See Also:
Constant Field Values

DEFOFFSET

private static final double DEFOFFSET
The maximal offset for erasing in normalized space.

See Also:
Constant Field Values

generic

private Shape generic
The generic shape this cursor supports at the moment.


normgen

private ShapeDraw normgen
The normalized generic shape, equal to generic if not pixelized.


active

private List<ShapeDraw> active
List of normalized shapes that have been added for selection lookup.


selected

private ShapeDraw selected
The current active shape, normalized.


draw

private Shape draw
The selected shape as it is drawn (i.e. sized and translated).


changed

private boolean changed
The boolean that gets true if a selected shape changed.


SHAPE

private static String SHAPE
The name for cursor objects added to the underlying canvas.

Constructor Detail

ShapeCursor

public ShapeCursor(PropertySupplying prop)
Constructs a new shape cursor that can be assigned to JNormalizedCanvas.

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 ZoomCursor

init

public void init()
Initializes the zoom cursor. Here, the pop-up menu and the undo-zoom list is generated.

Specified by:
init in interface Initializable
Overrides:
init in class ZoomCursor

enableCanvas

public void enableCanvas(JNormalizedCanvas root)
Assigns the JShapeCanvas to the cursor. This method must always be called prior to activation of the cursor, i.e. adding it as a mouse listener.

Overrides:
enableCanvas in class CanvasCursor

disableCanvas

public void disableCanvas()
We remove ourselfs from the post-drawing.

Overrides:
disableCanvas in class CanvasCursor

mouseClicked

public void mouseClicked(MouseEvent me)
Clicking close to a shape activates this shape, otherwise a new shape is generated. If we have already a selected shape, its current state is considered to be the final one.

Specified by:
mouseClicked in interface MouseListener
Overrides:
mouseClicked in class ZoomCursor

complete

public void complete(Graphics g)
Description copied from interface: PostUpdate
This method is called directly before component.update.

Specified by:
complete in interface PostUpdate

createGenericShape

private Shape createGenericShape(PropertySupplying info)
Returns the generic shape this cursor controls in normalized coordinates.


setGenericShape

public void setGenericShape(Shape gen,
                            boolean pixel,
                            boolean filled)
Sets the generic shape.


getGenericShape

public Shape getGenericShape()
Returns the current generic shape, as set prior to eventual normalization. Only possibility to glimpse at the generic shape's class, as affine transformation destroys this info.


reset

public void reset()
Clears any last draws.


mouseMoved

public void mouseMoved(MouseEvent me)
Mouse moving move also the currently selected shape, if there is one. Never forget to delete the old draw before...

Specified by:
mouseMoved in interface MouseMotionListener
Overrides:
mouseMoved in class CrossCursor

mouseWheelMoved

public void mouseWheelMoved(MouseWheelEvent we)
Grabs mouse wheel events. If the user pulls the wheel towards him, zoom level is increased, pushing away zooms out. If during this process the shift key is pressed, only the x-axis zooms, if the ctrl key is pressed, only y is zoomed. In a shape cursor, the selected shape is zoomed.

Specified by:
mouseWheelMoved in interface MouseWheelListener
Overrides:
mouseWheelMoved in class ZoomCursor

rescaleShape

private void rescaleShape(double zx,
                          double zy,
                          Graphics onto)
Rescales the current active shape after a drag or a mouse-wheel. Always acts in user space.


toNormalized

private ShapeDraw toNormalized(Shape screen,
                               boolean fill)
After shifting and scaling, we have a shape in screen coordinates that should be transferred to normalized coordinates so that we can add it to the underlying canvas.


paintShape

private void paintShape(Shape screen,
                        Graphics onto)
Draw the shape in the XOR color. Already screen space.


scan

private static ShapeDraw scan(List<ShapeDraw> recent,
                              Point2D within,
                              double maxdist)
Scans in normalized coordinates whether we have a shape recently added.