Class PEAction

    • Field Summary

      • Fields inherited from class javax.swing.AbstractAction

        changeSupport, enabled
      • Fields inherited from interface javax.swing.Action

        ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
    • Constructor Summary

      Constructors 
      Constructor Description
      PEAction​(ActionDispatcher actionDispatcher, java.lang.String actionName, ActionLocalizer localizer)
      Constructor to be used either : when the target board is not known in advance (e.g.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void actionPerformed​(java.awt.event.ActionEvent e)
      This is a default implementation of the "actionPerformed" method suited for undoable actions : we first call "beginUndoableUpdate" with "actionName" as the presentation name, then delegate to "undoableActionPerformed", finally mark the undoable-update as ended.
      protected PECanvas getCanvas()
      Returns the PECanvas this Action acts upon, as specified by the ActionDispatcher provided in the constructor.
      protected Drawing getDrawing()
      Returns the Drawing that serves as a model for the target PECanvas (this is a convenience call to getCanvas().
      protected EditorKit getEditorKit()
      Returns the EditorKit associated with the target PECanvas (this is a convenience call to getCanvas().
      protected Element getSelectedObject()
      Returns the selected graphic element in the target board ;
      protected void setAttribute​(PicAttributeName name, java.lang.Object value)
      Applies the given attribute to the drawing content.
      protected void undoableActionPerformed​(java.awt.event.ActionEvent e)
      called by "actionPerformed" ; default implementation does nothing.
      • Methods inherited from class javax.swing.AbstractAction

        addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface javax.swing.Action

        accept
    • Constructor Detail

      • PEAction

        public PEAction​(ActionDispatcher actionDispatcher,
                        java.lang.String actionName,
                        ActionLocalizer localizer)
        Constructor to be used either :
        • when the target board is not known in advance (e.g. MDI), and one wants to provide an own ActionDispatcher implementation
        • or when the target board is known : in this case use a DefaultActionDispatcher constructed with the given target board.
        Parameters:
        actionDispatcher - the ActionDispatcher that provides a target when this Action gets invoked. If set to null, then subclasses may want to simply override actionPerformed().
        actionName - the actionName of this Action that serve to build this Action's properties using the given ActionLocalizer (if non-null) ; in any case, actionName is used to fill the ACTION_COMMAND_KEY property.
        actionLocalizer - the ActionLocalizer that feeds this Action with localized properties ; if null, the Action's NAME property is simply initialized to actionName, but other properties are not set (this allow a subclass to set these properties manually).
    • Method Detail

      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent e)
        This is a default implementation of the "actionPerformed" method suited for undoable actions : we first call "beginUndoableUpdate" with "actionName" as the presentation name, then delegate to "undoableActionPerformed", finally mark the undoable-update as ended.

        Action that don't want to be undoable should simply override this method as usual.

      • undoableActionPerformed

        protected void undoableActionPerformed​(java.awt.event.ActionEvent e)
        called by "actionPerformed" ; default implementation does nothing. Action that want to be undoable override this method instead of "actionPerformed".

        Note : this is not an abstract method, since this would force all PEAction's, including those we don't want to be undoable, to implement this method.

      • getCanvas

        protected PECanvas getCanvas()
        Returns the PECanvas this Action acts upon, as specified by the ActionDispatcher provided in the constructor.
        Returns:
        a null reference if no suitable canvas is found by the ActionDispatcher.
      • getDrawing

        protected Drawing getDrawing()
        Returns the Drawing that serves as a model for the target PECanvas (this is a convenience call to getCanvas().
      • getEditorKit

        protected EditorKit getEditorKit()
        Returns the EditorKit associated with the target PECanvas (this is a convenience call to getCanvas().
      • getSelectedObject

        protected Element getSelectedObject()
        Returns the selected graphic element in the target board ;
        Returns:
        null if there's no selected graphic element, OR more than one.
      • setAttribute

        protected final void setAttribute​(PicAttributeName name,
                                          java.lang.Object value)
        Applies the given attribute to the drawing content. If there is a selection, the attribute is applied to each element in the selection. If there is no selection, the attribute is applied to the input attribute set of the EditorKit (this specifies the attributes to be used for any new Element that gets added to the underlying Drawing).

        If there's a selected element, we add an UndoableEdit (hence PEAction that explicitly call setAttribute() must not override undoableActionPerformed, but simply actionPerformed).