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:
Iterable<Element>, Collection<Element>, EventListener, List<Element>, DrawingListener, Element, SelectionHandler, ActionFactory, CustomizerFactory

public class DefaultSelectionHandler
extends PicGroup
implements SelectionHandler, DrawingListener

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.23 2013/03/27 06:58:26 vincentb1 Exp $
Author:
Sylvain Reynal

Nested Class Summary
 
Nested classes/interfaces inherited from class jpicedt.graphic.model.PicGroup
PicGroup.GroupPointIterator
 
Nested classes/interfaces inherited from class jpicedt.graphic.model.BranchElement
BranchElement.CompoundMode
 
Field Summary
 
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, compoundMode, DEFAULT_LIFTPEN, isPathClosed, liftPen, ptsX, ptsY, shape
 
Fields inherited from class jpicedt.graphic.model.AbstractElement
attributeSet, name, parent, view
 
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)
           
 boolean add(Element child)
          overriden so that the parent of the added element isn't set to this, and its view is left unchanged.
 void add(int position, Element child)
          Convenient call to add(child).
 boolean addAll(Collection<? extends Element> c)
          Appends all the elements in the given collection that are instance of Element as children of this BranchElement.
 boolean addAll(int index, Collection<? extends Element> c)
          Commodité d'appel de addAll(c).
 Element[] asArray()
          Return the selected elements wrapped in an array (may be a convenience call to asCollection)
 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 clear()
          overriden so as to leave children parent and view unchanged.
 void delete(Drawing dr)
          Delete all selected Element's from the given Drawing, and remove the reference to them from the SelectionHandler.
protected  void fireChangedUpdate(DrawingEvent.EventType eventType)
          Called each time this DefaultSelectionHandler changes.
 String getName()
          Return a non-localised string representing this element's name.
 BranchElement getParent()
          Gets the parent of the element.
 HitInfo hitTest(PEMouseEvent me)
          hitTest on the content of the selection only
 boolean intersect(Rectangle2D r, ArrayList<Element> list)
           
 void paint(Graphics2D g, Rectangle2D allocation, double scale)
          paint the selection handler highlighting
 Element remove(int index)
          Remove the child with the given index from this BranchElement.
 boolean remove(Object child)
          Overriden so as to leave child's parent and view unchanged.
 void replace(Element e)
          Replace the current selection with the given element.
 void replace(Element oldE, Element newE)
          La méthode correspondante de PicGroup est surchargée pour ne pas affecter les vues.
 void selectAll(Drawing d)
          Select all Element's in the given drawing.
 void setCompoundMode(BranchElement.CompoundMode m)
          If s is true, the associated view will attempt to paint this BranchElement as a single path made up by piecing childrens' shapes (aka PSTricks' pscustom).
 void sort()
          Sort selected elements according to their z-ordering in the given drawing
 String toString()
          Returns a String representing the group for debugging use only.
 
Methods inherited from class jpicedt.graphic.model.PicGroup
anchorPointsIterator, clone, createActions, createCustomizer, getCtrlPtX, getCtrlPtY, getDefaultName, getFirstPointIndex, getHighlightingMode, getLastPointIndex, setCtrlPt, setHighlightingMode, toggleHighlightingMode, unGroup
 
Methods inherited from class jpicedt.graphic.model.BranchElement
bringBackward, bringForward, bringToBack, bringToFront, closePath, contains, containsAll, containsClass, createFilteredCollection, createShape, equals, forwardChangedUpdate, get, getBoundingBox, getCompoundMode, getCtrlPt, getCtrlPtSubset, getLiftPen, hashCode, indexOf, isEmpty, isPathClosed, isToBack, isToFront, iterator, lastIndexOf, listIterator, listIterator, mirror, openPath, removeAll, removeView, retainAll, rotate, scale, set, setAttribute, setAttributeSet, setCtrlPt, setLiftPen, setViewFromFactory, shear, shear, size, subList, syncArrowGeometry, toArray, toArray, toggleCompoundMode, togglePathClosure, translate, updateBoundingBox
 
Methods inherited from class jpicedt.graphic.model.AbstractElement
getAttribute, getAttributeSet, getDrawing, getView, pullOutOfGroup, replaceBy, scale, scale, scale, setName, setParent
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jpicedt.graphic.SelectionHandler
containsClass, createFilteredCollection, getCtrlPtSubset
 
Methods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, isEmpty, iterator, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface jpicedt.graphic.model.Element
createShape, getAttribute, getAttributeSet, getBoundingBox, getCtrlPt, getCtrlPtSubset, getDrawing, getView, mirror, removeView, replaceBy, rotate, scale, scale, scale, scale, setAttribute, setAttributeSet, setCtrlPt, setParent, setViewFromFactory, shear, shear, syncArrowGeometry, translate
 

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 LOCAL by default.

Method Detail

getName

public String getName()
Description copied from interface: Element
Return a non-localised string representing this element's name. This may be used by a UI to display some information related to this element, or by a localizer to fetch a i18n'd string.

Specified by:
getName in interface Element
Overrides:
getName in class AbstractElement
Returns:
a string that represents this object's name ; should be a key-entry to i18n files.
Since:
jpicedt 1.3.3

paint

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


hitTest

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


intersect

public boolean intersect(Rectangle2D r,
                         ArrayList<Element> list)

setCompoundMode

public void setCompoundMode(BranchElement.CompoundMode m)
Description copied from class: BranchElement
If s is true, the associated view will attempt to paint this BranchElement as a single path made up by piecing childrens' shapes (aka PSTricks' pscustom). The associated formatter is expected to do likewise if its hosting content-type supports it. If s is false, this is the legacy behaviour, that is, every child is painted independently.

Overrides:
setCompoundMode in class BranchElement

asArray

public Element[] asArray()
Return the selected elements wrapped in an array (may be a convenience call to asCollection)

Specified by:
asArray in interface SelectionHandler

selectAll

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

Specified by:
selectAll in interface SelectionHandler

replace

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

Specified by:
replace in interface SelectionHandler

replace

public void replace(Element oldE,
                    Element newE)
La méthode correspondante de PicGroup est surchargée pour ne pas affecter les vues.

Specified by:
replace in interface SelectionHandler
Overrides:
replace in class BranchElement
Parameters:
oldE - l'Element à remplacer.
newE - l'Element qui sert de remplacement.
See Also:
SelectionHandler.replace(Element oldE, Element newE)

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

add

public boolean add(Element child)
overriden so that the parent of the added element isn't set to this, and its view is left unchanged. Addition is successfull only if neither child nor one of its parents is selected yet (for instance, it's impossible to select the child of a PicGroup that is already selected, since in a sense this child is already selected through indirect lineage).

Specified by:
add in interface Collection<Element>
Specified by:
add in interface List<Element>
Overrides:
add in class BranchElement

add

public void add(int position,
                Element child)
Convenient call to add(child).

Specified by:
add in interface List<Element>
Overrides:
add in class BranchElement

addAll

public boolean addAll(Collection<? extends Element> c)
Appends all the elements in the given collection that are instance of Element as children of this BranchElement.

Specified by:
addAll in interface Collection<Element>
Specified by:
addAll in interface List<Element>
Overrides:
addAll in class BranchElement

addAll

public boolean addAll(int index,
                      Collection<? extends Element> c)
Commodité d'appel de addAll(c).

Specified by:
addAll in interface List<Element>
Overrides:
addAll in class BranchElement

remove

public boolean remove(Object child)
Overriden so as to leave child's parent and view unchanged.

Specified by:
remove in interface Collection<Element>
Specified by:
remove in interface List<Element>
Overrides:
remove in class BranchElement
Parameters:
child - if child is the selection-handler itself, call removeAllChildren().
Returns:
true si child faisait partie de la sélection.

remove

public Element remove(int index)
Remove the child with the given index from this BranchElement.

Specified by:
remove in interface List<Element>
Overrides:
remove in class BranchElement

clear

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

Specified by:
clear in interface Collection<Element>
Specified by:
clear in interface List<Element>
Overrides:
clear in class BranchElement

getParent

public BranchElement 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 setCtrlPt/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:
eventType - the event type

toString

public 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