Class DefaultSelectionHandler
- java.lang.Object
-
- jpicedt.graphic.model.AbstractElement
-
- jpicedt.graphic.model.BranchElement
-
- jpicedt.graphic.model.PicGroup
-
- 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
Fields Modifier and Type Field Description static java.lang.StringGLOBAL_MODEHighlighting mode corresponding to the selection-handler behaving as if it were a PicGroup, hence its 8 control-points only are highlightedstatic java.lang.StringLOCAL_MODEHighlighting 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.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
-
Fields inherited from interface jpicedt.graphic.view.ViewConstants
BARBELL_SIZE, CLICK_DISTANCE
-
-
Constructor Summary
Constructors Constructor Description DefaultSelectionHandler(EditorKit kit)construct a new selection handler for this editor kit, with SelectionHandlerView as the default view.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void_changedUpdate(DrawingEvent e)voidaddChild(Element child)overriden so that the parent of the added element isn't set to this, and its view is left unchanged.voidaddToSelection(Element e)Add the given Element to the current selectionElement[]asArray()Return the selected elements wrapped in an array (may be a convenience call to asCollection)java.util.CollectionasCollection()Return the selected elements wrapped in a CollectionvoidchangedUpdate(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).voiddelete(Drawing dr)Delete all selected Element's from the given Drawing, and remove the reference to them from the SelectionHandler.java.util.Iteratorelements()Return an iterator over the selected Element'sprotected voidfireChangedUpdate(DrawingEvent.EventType eventType)Called each time this DefaultSelectionHandler changes.java.lang.StringgetHighlightingMode()Return the current highlighting modeElementgetParent()Gets the parent of the element.HitInfohitTest(PEMouseEvent me)hitTest on the content of the selection onlybooleanisSelected(Element e, boolean includeAncestors)Return whether the given Element is selected or notvoidpaint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D allocation, double scale)paint the selection handler highlightingvoidremoveAllChildren()overriden so as to leave children parent and view unchanged.voidremoveChild(Element child)overriden so as to leave child's parent and view unchanged.voidreplaceSelection(Element e)Replace the current selection with the given element.voidselectAll(Drawing d)Select all Element's in the given drawing.voidsetHighlightingMode(java.lang.String mode)set the current highlighting mode ; this influences the way the Highligther is painted, but also the result returned by HitTest.voidsort()Sort selected elements according to their z-ordering in the given drawingvoidtoggleHighlightingMode()Toggle the current highlighting modejava.lang.StringtoString()Returns a String representing the group for debugging use only.voidunSelect(Element e)Unselect the given Element, ie remove it from the current selection.voidunSelectAll()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 java.util.Collection
hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Methods inherited from interface jpicedt.graphic.SelectionHandler
containsClass, createFilteredCollection, size
-
-
-
-
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:SelectionHandlerReturn an iterator over the selected Element's- Specified by:
elementsin interfaceSelectionHandler- Returns:
- an iterator over the selected Element's
-
asCollection
public java.util.Collection asCollection()
Description copied from interface:SelectionHandlerReturn the selected elements wrapped in a Collection- Specified by:
asCollectionin interfaceSelectionHandler- Returns:
- the selected elements wrapped in a Collection
-
asArray
public Element[] asArray()
Description copied from interface:SelectionHandlerReturn the selected elements wrapped in an array (may be a convenience call to asCollection)- Specified by:
asArrayin interfaceSelectionHandler- Returns:
- the selected elements wrapped in an array (convenience call to asCollection)
-
isSelected
public boolean isSelected(Element e, boolean includeAncestors)
Description copied from interface:SelectionHandlerReturn whether the given Element is selected or not- Specified by:
isSelectedin interfaceSelectionHandler- 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:
selectAllin interfaceSelectionHandler
-
unSelectAll
public void unSelectAll()
Unselect all Element's in the given drawing.- Specified by:
unSelectAllin interfaceSelectionHandler
-
addToSelection
public void addToSelection(Element e)
Add the given Element to the current selection- Specified by:
addToSelectionin interfaceSelectionHandler
-
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:
replaceSelectionin interfaceSelectionHandler
-
unSelect
public void unSelect(Element e)
Unselect the given Element, ie remove it from the current selection.- Specified by:
unSelectin interfaceSelectionHandler
-
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:
deletein interfaceSelectionHandler
-
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:
addChildin classBranchElement
-
removeChild
public void removeChild(Element child)
overriden so as to leave child's parent and view unchanged.- Overrides:
removeChildin classBranchElement- 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:
removeAllChildrenin classBranchElement
-
getParent
public Element getParent()
Gets the parent of the element.- Specified by:
getParentin interfaceElement- Overrides:
getParentin classAbstractElement- 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 callsuper.fireChangeUpdate.- Overrides:
fireChangedUpdatein classAbstractElement- Parameters:
type- the event type
-
toString
public java.lang.String toString()
Returns a String representing the group for debugging use only.
-
_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:
changedUpdatein interfaceDrawingListener
-
-