Documentation of 'org.jhotdraw.draw.DrawingView' Java class
DrawingView
org.jhotdraw.draw

Interface DrawingView

  • All Known Implementing Classes:
    DefaultDrawingView


    public interface DrawingView
    A drawing view paints a Drawing on a JComponent. A drawing view can hold only one drawing at a time, but a drawing can be in multiple drawing views at the same time.

    To support editing, a drawing view needs to be added to a DrawingEditor. The current Tool of the drawing editor receives mouse and key events from all drawing views of the drawing editor.

    DrawingView can paint the drawing with a scale factor. It supports conversion between view coordinates and drawing coordinates.

    DrawingView maintains a selection of the Figures contained in the drawing. The selected figures can be the target of the current tool of the drawing editor.

    The painting process of DrawingView view usually involves the following steps:

    1. Paint the background of the drawing view.
    2. Invoke Drawing.drawCanvas(java.awt.Graphics2D).
    3. Invoke Constrainer.draw(java.awt.Graphics2D, org.jhotdraw.draw.DrawingView) if a constrainer is set.
    4. Invoke Figure.draw(java.awt.Graphics2D).
    5. Invoke Handle.draw(java.awt.Graphics2D) on the handles of selected figures.
    6. Invoke Tool.draw(java.awt.Graphics2D) if the drawing view is the active view of the DrawingEditor.

    Design Patterns

    Framework
    The following interfaces define the contracts of a framework for structured drawing editors:
    Contract: Drawing, Figure, DrawingView, DrawingEditor, Handle and Tool.

    Chain of responsibility
    Mouse and keyboard events of the user occur on the drawing view, and are preprocessed by the DragTracker of a SelectionTool. In turn org.jhotdraw.draw.selectiontool.DragTracker invokes "track" methods on a Handle which in turn changes an aspect of a figure.
    Client: SelectionTool; Handler: DragTracker, Handle.

    Mediator
    DrawingEditor acts as a mediator for coordinating drawing tools and drawing views:
    Mediator: DrawingEditor; Colleagues: DrawingView, Tool.

    Model-View-Controller
    The following classes implement together the Model-View-Controller design pattern:
    Model: Drawing; View: DrawingView; Controller: DrawingEditor.

    Observer
    Selection changes of DrawingView are observed by user interface components which act on selected figures.
    Subject: DrawingView; Observer: FigureSelectionListener; Event: FigureSelectionEvent.

    Observer
    State changes of figures can be observed by other objects. Specifically CompositeFigure observes area invalidations and remove requests of its child figures. DrawingView also observes area invalidations of its drawing object. Subject: Figure; Observer: FigureListener; Event: FigureEvent; Concrete Observer: CompositeFigure, DrawingView.

    Observer
    State changes of handles can be observed by other objects. Specifically DrawingView observes area invalidations and remove requests of handles.
    Subject: Handle; Observer: HandleListener; Event: HandleEvent; Concrete Observer: DrawingView.

    Strategy
    Editing can be constrained by a constrainer which is associated to a drawing view.
    Context: DrawingView; Strategy: Constrainer.


    • Field Detail

      • DRAWING_PROPERTY

        static final java.lang.String DRAWING_PROPERTY
        This constant is used to identify the drawing property of the DrawingView.
        See Also:
        Constant Field Values
      • CURSOR_PROPERTY

        static final java.lang.String CURSOR_PROPERTY
        This constant is used to identify the cursor property of the DrawingView.
        See Also:
        Constant Field Values
      • CONSTRAINER_PROPERTY

        static final java.lang.String CONSTRAINER_PROPERTY
        This constant is used to identify the constrainer property of the DrawingView.
        See Also:
        Constant Field Values
      • VISIBLE_CONSTRAINER_PROPERTY

        static final java.lang.String VISIBLE_CONSTRAINER_PROPERTY
        This constant is used to identify the visible constrainer property of the DrawingView.
        See Also:
        Constant Field Values
      • INVISIBLE_CONSTRAINER_PROPERTY

        static final java.lang.String INVISIBLE_CONSTRAINER_PROPERTY
        This constant is used to identify the invisible constrainer property of the DrawingView.
        See Also:
        Constant Field Values
      • CONSTRAINER_VISIBLE_PROPERTY

        static final java.lang.String CONSTRAINER_VISIBLE_PROPERTY
        This constant is used to identify the constrainer visible property of the DrawingView.
        See Also:
        Constant Field Values
      • SCALE_FACTOR_PROPERTY

        static final java.lang.String SCALE_FACTOR_PROPERTY
        This constant is used to identify the scale factor property of the DrawingView.
        See Also:
        Constant Field Values
      • HANDLE_DETAIL_LEVEL_PROPERTY

        static final java.lang.String HANDLE_DETAIL_LEVEL_PROPERTY
        This constant is used to identify the handle detail level property of the DrawingView.
        See Also:
        Constant Field Values
      • ENABLED_PROPERTY

        static final java.lang.String ENABLED_PROPERTY
        This constant is used to identify the enabled property of the DrawingView.
        See Also:
        Constant Field Values
      • ACTIVE_HANDLE_PROPERTY

        static final java.lang.String ACTIVE_HANDLE_PROPERTY
        This constant is used to identify the activeHandle property of the DrawingView.
        See Also:
        Constant Field Values
    • Method Detail

      • getDrawing

        @Nullable
        Drawing getDrawing()
        Gets the drawing. This is a bound property.
      • setDrawing

        void setDrawing(@Nullable
                        Drawing d)
        Sets and installs another drawing in the view. This is a bound property.
      • setCursor

        void setCursor(@Nullable
                       java.awt.Cursor c)
        Sets the cursor of the DrawingView. This is a bound property.
      • isFigureSelected

        boolean isFigureSelected(Figure checkFigure)
        Test whether a given figure is selected.
      • addToSelection

        void addToSelection(Figure figure)
        Adds a figure to the current selection.
      • addToSelection

        void addToSelection(java.util.Collection<Figure> figures)
        Adds a collection of figures to the current selection.
      • removeFromSelection

        void removeFromSelection(Figure figure)
        Removes a figure from the selection.
      • toggleSelection

        void toggleSelection(Figure figure)
        If a figure isn't selected it is added to the selection. Otherwise it is removed from the selection.
      • clearSelection

        void clearSelection()
        Clears the current selection.
      • selectAll

        void selectAll()
        Selects all figures.
      • getSelectedFigures

        java.util.Set<Figure> getSelectedFigures()
        Gets the selected figures. Returns an empty set, if no figures are selected.
      • getSelectionCount

        int getSelectionCount()
        Gets the number of selected figures.
      • findHandle

        @Nullable
        Handle findHandle(java.awt.Point p)
        Finds a handle at the given coordinates.
        Returns:
        A handle, null if no handle is found.
      • getCompatibleHandles

        java.util.Collection<Handle> getCompatibleHandles(Handle handle)
        Gets compatible handles.
        Returns:
        A collection containing the handle and all compatible handles.
      • setActiveHandle

        void setActiveHandle(@Nullable
                             Handle newValue)
        Sets the active handle.
      • getActiveHandle

        @Nullable
        Handle getActiveHandle()
        Gets the active handle.
      • findFigure

        @Nullable
        Figure findFigure(java.awt.Point p)
        Finds a figure at the given point.
        Returns:
        A figure, null if no figure is found.
      • findFigures

        java.util.Collection<Figure> findFigures(java.awt.Rectangle r)
        Returns all figures that lie within or intersect the specified bounds. The figures are returned in Z-order from back to front.
      • findFiguresWithin

        java.util.Collection<Figure> findFiguresWithin(java.awt.Rectangle r)
        Returns all figures that lie within the specified bounds. The figures are returned in Z-order from back to front.
      • addNotify

        void addNotify(DrawingEditor editor)
        Informs the view that it has been added to the specified editor. The view must draw the tool of the editor, if getActiveView() of the editor returns the view.
      • removeNotify

        void removeNotify(DrawingEditor editor)
        Informs the view that it has been removed from the specified editor. The view must not draw the tool from the editor anymore.
      • getEditor

        @Nullable
        DrawingEditor getEditor()
        Gets the drawing editor associated to the DrawingView. This is a bound property.
      • addFigureSelectionListener

        void addFigureSelectionListener(FigureSelectionListener fsl)
        Add a listener for selection changes in this DrawingView.
        Parameters:
        fsl - jhotdraw.framework.FigureSelectionListener
      • removeFigureSelectionListener

        void removeFigureSelectionListener(FigureSelectionListener fsl)
        Remove a listener for selection changes in this DrawingView.
        Parameters:
        fsl - jhotdraw.framework.FigureSelectionListener
      • requestFocus

        void requestFocus()
        This is a convenience method for invoking getComponent().requestFocus().
      • drawingToView

        java.awt.Point drawingToView(java.awt.geom.Point2D.Double p)
        Converts drawing coordinates to view coordinates.
      • viewToDrawing

        java.awt.geom.Point2D.Double viewToDrawing(java.awt.Point p)
        Converts view coordinates to drawing coordinates.
      • drawingToView

        java.awt.Rectangle drawingToView(java.awt.geom.Rectangle2D.Double p)
        Converts drawing coordinates to view coordinates.
      • viewToDrawing

        java.awt.geom.Rectangle2D.Double viewToDrawing(java.awt.Rectangle p)
        Converts view coordinates to drawing coordinates.
      • getConstrainer

        @Nullable
        Constrainer getConstrainer()
        Gets the current constrainer of this view. If isConstrainerVisible is true, this method returns getVisibleConstrainer, otherwise it returns getInvisibleConstrainer. This is a bound property.
      • setVisibleConstrainer

        void setVisibleConstrainer(@Nullable
                                   Constrainer constrainer)
        Sets the editor's constrainer for this view, for use, when the visible constrainer is turned on. This is a bound property.
      • getVisibleConstrainer

        @Nullable
        Constrainer getVisibleConstrainer()
        Gets the editor's constrainer for this view, for use, when the visible constrainer is turned on. This is a bound property.
      • setInvisibleConstrainer

        void setInvisibleConstrainer(Constrainer constrainer)
        Sets the editor's constrainer for this view, for use, when the visible constrainer is turned off. This is a bound property.
      • getInvisibleConstrainer

        Constrainer getInvisibleConstrainer()
        Gets the editor's constrainer for this view, for use, when the visible constrainer is turned off. This is a bound property.
      • setConstrainerVisible

        void setConstrainerVisible(boolean newValue)
        Changes between a visible Constrainer and an invisible Constrainer. This is a bound property.
      • isConstrainerVisible

        boolean isConstrainerVisible()
        Returns true, if the visible Constrainer is in use, returns false, if the invisible Constrainer is in use. This is a bound property.
      • getComponent

        javax.swing.JComponent getComponent()
        Returns the JComponent of the drawing view.
      • getDrawingToViewTransform

        java.awt.geom.AffineTransform getDrawingToViewTransform()
        Gets an transform which can be used to convert drawing coordinates to view coordinates.
      • getScaleFactor

        double getScaleFactor()
        Gets the scale factor of the drawing view. This is a bound property.
      • setScaleFactor

        void setScaleFactor(double newValue)
        Sets the scale factor of the drawing view. This is a bound property.
      • setHandleDetailLevel

        void setHandleDetailLevel(int newValue)
        The detail level of the handles. This is a bound property.
      • getHandleDetailLevel

        int getHandleDetailLevel()
        Returns the detail level of the handles. This is a bound property.
      • setEnabled

        void setEnabled(boolean newValue)
        Sets the enabled state of the drawing view. This is a bound property.
      • isEnabled

        boolean isEnabled()
        Gets the enabled state of the drawing view. This is a bound property.
      • repaintHandles

        void repaintHandles()
        Repaints the handles of the view.
      • addPropertyChangeListener

        void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
        Adds a property change listener to the drawing view.
        Parameters:
        listener -
      • removePropertyChangeListener

        void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
        Removes a property change listener to the drawing view.
        Parameters:
        listener -
      • addMouseListener

        void addMouseListener(java.awt.event.MouseListener l)
        Adds a mouse listener to the drawing view.
        Parameters:
        l - the listener.
      • removeMouseListener

        void removeMouseListener(java.awt.event.MouseListener l)
        Removes a mouse listener to the drawing view.
        Parameters:
        l - the listener.
      • addKeyListener

        void addKeyListener(java.awt.event.KeyListener l)
        Adds a key listener to the drawing view.
        Parameters:
        l - the listener.
      • removeKeyListener

        void removeKeyListener(java.awt.event.KeyListener l)
        Removes a key listener to the drawing view.
        Parameters:
        l - the listener.
      • addMouseMotionListener

        void addMouseMotionListener(java.awt.event.MouseMotionListener l)
        Adds a mouse motion listener to the drawing view.
        Parameters:
        l - the listener.
      • removeMouseMotionListener

        void removeMouseMotionListener(java.awt.event.MouseMotionListener l)
        Removes a mouse motion listener to the drawing view.
        Parameters:
        l - the listener.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.