http://www.jpicedt.org

jpicedt.graphic.toolkit
Class DefaultSelectionHandler

java.lang.Object
  extended by jpicedt.graphic.model.AbstractElement
      extended by jpicedt.graphic.model.BranchElement
          extended by jpicedt.graphic.model.PicGroup
              extended by jpicedt.graphic.toolkit.DefaultSelectionHandler
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.EventListener, DrawingListener, Element, PicObjectConstants, SelectionHandler, ActionFactory, CustomizerFactory, ViewConstants

public class DefaultSelectionHandler
extends PicGroup
implements SelectionHandler, DrawingListener, ViewConstants, PicObjectConstants

Stores references to selected Element's.

This handler has the same capabilities as jpicedt.graphic.model.PicGroup, except that it does not belong to any jpicedt.graphic.model.Drawing.RootElement. Hence it is guaranteed that this handler will NEVER notify the parent document (=the hosting Drawing) when content gets added to/removed from it, since it has no parent. This design choice is aimed at avoiding redundant event generation, since (for instance) deleting a selected element would then trigger the same DrawingEvent twice (one on behalf of this handler, the other one on behalf of the hosting Drawing). Content modifying method are overriden so as to reflect this.

Since:
jPicEdt 1.4
Version:
$Id: DefaultSelectionHandler.java,v 1.9.2.1 2007/09/02 11:56:28 reynal Exp $
Author:
Sylvain Reynal

Nested Class Summary
 
Nested classes/interfaces inherited from class jpicedt.graphic.model.PicGroup
PicGroup.GroupPointIterator
 
Field Summary
static java.lang.String GLOBAL_MODE
          Highlighting mode corresponding to the selection-handler behaving as if it were a PicGroup, hence its 8 control-points only are highlighted
static java.lang.String LOCAL_MODE
          Highlighting mode corresponding to each Element belonging to the selection is highlighted
 
Fields inherited from class jpicedt.graphic.model.PicGroup
FIRST_PT, LAST_PT, LL, LM, LR, ML, MR, UL, UM, UR
 
Fields inherited from class jpicedt.graphic.model.BranchElement
changeLock, children, ptsX, ptsY
 
Fields inherited from class jpicedt.graphic.model.AbstractElement
attributeSet, parent, view
 
Fields inherited from interface jpicedt.graphic.view.ViewConstants
BARBELL_SIZE, CLICK_DISTANCE
 
Fields inherited from interface jpicedt.graphic.model.PicObjectConstants
ARROW_GLOBAL_SCALE_LENGTH, ARROW_GLOBAL_SCALE_WIDTH, ARROW_INSET_SCALE, ARROW_LENGTH_SCALE, ARROW_WIDTH_LINEWIDTH_SCALE, ARROW_WIDTH_MINIMUM_MM, BRACKET_LENGTH_SCALE, CROSSHATCH, CROSSHATCH_FILLED, DASH_OPAQUE, DASH_TRANSPARENT, DASH1, DASH2, DASH3, DASHED, DIMEN, DOT_SEP, DOT_SEP1, DOT_SEP2, DOT_SEP3, DOTTED, DOUBLE_COLOR, DOUBLE_LINE, DOUBLE_SEP, FILL_COLOR, FILL_STYLE, HATCH_ANGLE, HATCH_COLOR, HATCH_SEP, HATCH_WIDTH, HLINES, HLINES_FILLED, INNER, LEFT_ARROW, LINE_COLOR, LINE_STYLE, LINE_WIDTH, MIDDLE, NONE, OUTER, OVER_STRIKE, OVER_STRIKE_COLOR, OVER_STRIKE_WIDTH, POLYDOTS_ANGLE, POLYDOTS_CIRCLE, POLYDOTS_DISK, POLYDOTS_PENTAGON, POLYDOTS_PENTAGON_FILLED, POLYDOTS_PLUS, POLYDOTS_SCALE_H, POLYDOTS_SCALE_V, POLYDOTS_SIZE_LINEWIDTH_SCALE, POLYDOTS_SIZE_MINIMUM_MM, POLYDOTS_SQUARE, POLYDOTS_SQUARE_FILLED, POLYDOTS_STYLE, POLYDOTS_SUPERIMPOSE, POLYDOTS_TRIANGLE, POLYDOTS_TRIANGLE_FILLED, PS_POINT, PST_CUSTOM, RBRACKET_LENGTH_SCALE, RIGHT_ARROW, SHADOW, SHADOW_ANGLE, SHADOW_COLOR, SHADOW_SIZE, SOLID, TBAR_WIDTH_LINEWIDTH_SCALE, TBAR_WIDTH_MINIMUM_MM, TEXT_BOX_CIRCLE, TEXT_BOX_NO_FRAME, TEXT_BOX_OVAL, TEXT_BOX_RECTANGLE, TEXT_FRAME, TEXT_HALIGN_CENTER, TEXT_HALIGN_LEFT, TEXT_HALIGN_RIGHT, TEXT_HOR_ALIGN, TEXT_ROTATION, TEXT_VALIGN_BASELINE, TEXT_VALIGN_BOTTOM, TEXT_VALIGN_CENTER, TEXT_VALIGN_TOP, TEXT_VERT_ALIGN, VLINES, VLINES_FILLED
 
Constructor Summary
DefaultSelectionHandler(EditorKit kit)
          construct a new selection handler for this editor kit, with SelectionHandlerView as the default view.
 
Method Summary
 void _changedUpdate(DrawingEvent e)
           
 void addChild(Element child)
          overriden so that the parent of the added element isn't set to this, and its view is left unchanged.
 void addToSelection(Element e)
          Add the given Element to the current selection
 Element[] asArray()
          Return the selected elements wrapped in an array (may be a convenience call to asCollection)
 java.util.Collection asCollection()
          Return the selected elements wrapped in a Collection
 void changedUpdate(DrawingEvent e)
          Implementation of DrawingListener interface aimed at keeping this selection-handler always synchronized with the Drawing, especially when the Drawing content gets modified directly throught the Drawing API (as opposed to using selection-related methods in PECanvas).
 void delete(Drawing dr)
          Delete all selected Element's from the given Drawing, and remove the reference to them from the SelectionHandler.
 java.util.Iterator elements()
          Return an iterator over the selected Element's
protected  void fireChangedUpdate(DrawingEvent.EventType eventType)
          Called each time this DefaultSelectionHandler changes.
 java.lang.String getHighlightingMode()
          Return the current highlighting mode
 Element getParent()
          Gets the parent of the element.
 HitInfo hitTest(PEMouseEvent me)
          hitTest on the content of the selection only
 boolean isSelected(Element e, boolean includeAncestors)
          Return whether the given Element is selected or not
 void paint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D allocation, double scale)
          paint the selection handler highlighting
 void removeAllChildren()
          overriden so as to leave children parent and view unchanged.
 void removeChild(Element child)
          overriden so as to leave child's parent and view unchanged.
 void replaceSelection(Element e)
          Replace the current selection with the given element.
 void selectAll(Drawing d)
          Select all Element's in the given drawing.
 void setHighlightingMode(java.lang.String mode)
          set the current highlighting mode ; this influences the way the Highligther is painted, but also the result returned by HitTest.
 void sort()
          Sort selected elements according to their z-ordering in the given drawing
 void toggleHighlightingMode()
          Toggle the current highlighting mode
 java.lang.String toString()
          Returns a String representing the group for debugging use only.
 void unSelect(Element e)
          Unselect the given Element, ie remove it from the current selection.
 void unSelectAll()
          Unselect all Element's in the given drawing.
 
Methods inherited from class jpicedt.graphic.model.PicGroup
anchorPointsIterator, clone, createActions, createCustomizer, getFirstPointIndex, getLastPointIndex, getName, getPointX, getPointY, setPoint
 
Methods inherited from class jpicedt.graphic.model.BranchElement
add, addAll, addChild, bringBackward, bringForward, bringToBack, bringToFront, children, clear, contains, contains, containsAll, containsClass, createFilteredCollection, equals, forwardChangedUpdate, getAllowsChildren, getBoundingBox, getChildAt, getChildCount, getChildIndex, getPoint, isEmpty, isToBack, isToFront, iterator, remove, removeAll, removeView, replaceChild, retainAll, rotate, scale, scale, setAttribute, setAttributeSet, setPoint, setViewFromFactory, shear, size, toArray, toArray, translate, updateBoundingBox
 
Methods inherited from class jpicedt.graphic.model.AbstractElement
getAttribute, getAttributeSet, getDrawing, getView, setParent
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jpicedt.graphic.SelectionHandler
containsClass, createFilteredCollection, size
 
Methods inherited from interface java.util.Collection
hashCode
 

Field Detail

LOCAL_MODE

public static final java.lang.String LOCAL_MODE
Highlighting mode corresponding to each Element belonging to the selection is highlighted

See Also:
Constant Field Values

GLOBAL_MODE

public static final java.lang.String GLOBAL_MODE
Highlighting mode corresponding to the selection-handler behaving as if it were a PicGroup, hence its 8 control-points only are highlighted

See Also:
Constant Field Values
Constructor Detail

DefaultSelectionHandler

public DefaultSelectionHandler(EditorKit kit)
construct a new selection handler for this editor kit, with SelectionHandlerView as the default view. Highlighting mode is GLOBAL by default.

Method Detail

setHighlightingMode

public void setHighlightingMode(java.lang.String mode)
set the current highlighting mode ; this influences the way the Highligther is painted, but also the result returned by HitTest.

Parameters:
mode - or LOCAL_MODE or GLOBAL_MODE

getHighlightingMode

public java.lang.String getHighlightingMode()
Return the current highlighting mode


toggleHighlightingMode

public void toggleHighlightingMode()
Toggle the current highlighting mode


paint

public void paint(java.awt.Graphics2D g,
                  java.awt.geom.Rectangle2D allocation,
                  double scale)
paint the selection handler highlighting


hitTest

public HitInfo hitTest(PEMouseEvent me)
hitTest on the content of the selection only


elements

public java.util.Iterator elements()
Description copied from interface: SelectionHandler
Return an iterator over the selected Element's

Specified by:
elements in interface SelectionHandler
Returns:
an iterator over the selected Element's

asCollection

public java.util.Collection asCollection()
Description copied from interface: SelectionHandler
Return the selected elements wrapped in a Collection

Specified by:
asCollection in interface SelectionHandler
Returns:
the selected elements wrapped in a Collection

asArray

public Element[] asArray()
Description copied from interface: SelectionHandler
Return the selected elements wrapped in an array (may be a convenience call to asCollection)

Specified by:
asArray in interface SelectionHandler
Returns:
the selected elements wrapped in an array (convenience call to asCollection)

isSelected

public boolean isSelected(Element e,
                          boolean includeAncestors)
Description copied from interface: SelectionHandler
Return whether the given Element is selected or not

Specified by:
isSelected in interface SelectionHandler
Parameters:
includeAncestors - if true, return true if this Element or one of its ancestors is selected.
Returns:
whether the given Element is selected or not

selectAll

public void selectAll(Drawing d)
Select all Element's in the given drawing.

Specified by:
selectAll in interface SelectionHandler

unSelectAll

public void unSelectAll()
Unselect all Element's in the given drawing.

Specified by:
unSelectAll in interface SelectionHandler

addToSelection

public void addToSelection(Element e)
Add the given Element to the current selection

Specified by:
addToSelection in interface SelectionHandler

replaceSelection

public void replaceSelection(Element e)
Replace the current selection with the given element. This is a convenience call to unSelectAll then addToSelection.

Specified by:
replaceSelection in interface SelectionHandler

unSelect

public void unSelect(Element e)
Unselect the given Element, ie remove it from the current selection.

Specified by:
unSelect in interface SelectionHandler

delete

public void delete(Drawing dr)
Delete all selected Element's from the given Drawing, and remove the reference to them from the SelectionHandler.

Specified by:
delete in interface SelectionHandler

addChild

public void addChild(Element child)
overriden so that the parent of the added element isn't set to this, and its view is left unchanged.

Overrides:
addChild in class BranchElement

removeChild

public void removeChild(Element child)
overriden so as to leave child's parent and view unchanged.

Overrides:
removeChild in class BranchElement
Parameters:
child - if child is the selection-handler itself, call removeAllChildren().

removeAllChildren

public void removeAllChildren()
overriden so as to leave children parent and view unchanged.

Overrides:
removeAllChildren in class BranchElement

getParent

public Element getParent()
Gets the parent of the element.

Specified by:
getParent in interface Element
Overrides:
getParent in class AbstractElement
Returns:
the current Drawing.RootElement attached to the hosting editor-kit ; used mainly by the attached view to fetch its container.

sort

public void sort()
Sort selected elements according to their z-ordering in the given drawing


fireChangedUpdate

protected void fireChangedUpdate(DrawingEvent.EventType eventType)
Called each time this DefaultSelectionHandler changes. This implementation is overriden from AbstractElement so as to update the associated View only, i.e. there is no event being forwarded to the parent (which here is the Drawing.RootElement, see e.g. getParent()). The point is that this method gets called whenever setPoint/scale/translate/... is called on the selection-handler, which indirectly triggers a DrawingEvent on behalf of the selected elements themselves. Hence it doesn't make sense to post these events twice.
If subclasser are willing to override this method, they should call super.fireChangeUpdate.

Overrides:
fireChangedUpdate in class AbstractElement
Parameters:
type - the event type

toString

public java.lang.String toString()
Returns a String representing the group for debugging use only.

Overrides:
toString in class PicGroup

_changedUpdate

public void _changedUpdate(DrawingEvent e)

changedUpdate

public void changedUpdate(DrawingEvent e)
Implementation of DrawingListener interface aimed at keeping this selection-handler always synchronized with the Drawing, especially when the Drawing content gets modified directly throught the Drawing API (as opposed to using selection-related methods in PECanvas).

This method is invoked when an element changed in the Drawing.

If this is a REMOVE event type, and if the removed children (of the changed Element) were selected, we remove these children from the selection as well, ie we always keep the content of the selection-handler synchronized with the associated Drawing.

Specified by:
changedUpdate in interface DrawingListener

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org