Class 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
    • 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
      • unSelectAll

        public void unSelectAll()
        Unselect all Element's in the given drawing.
        Specified by:
        unSelectAll 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