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

Class DefaultDrawingView

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, DrawingView, EditableComponent


    public class DefaultDrawingView
    extends javax.swing.JComponent
    implements DrawingView, EditableComponent
    A default implementation of DrawingView suited for viewing drawings with a small number of figures. FIXME - Implement clone Method. FIXME - Use double buffering for the drawing to improve performance.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.BaselineResizeBehavior
    • Constructor Summary

      Constructors 
      Constructor and Description
      DefaultDrawingView()
      Creates new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void addFigureSelectionListener(FigureSelectionListener fsl)
      Add a listener for selection changes in this DrawingView.
      void addNotify(DrawingEditor editor)
      Informs the view that it has been added to the specified editor.
      void addToSelection(java.util.Collection<Figure> figures)
      Adds a collection of figures to the current selection.
      void addToSelection(Figure figure)
      Adds a figure to the current selection.
      void clearSelection()
      Clears the current selection.
      void delete()
      Deletes the selected components or the component at (or after) the caret position.
      java.awt.Point drawingToView(java.awt.geom.Point2D.Double p)
      Converts drawing coordinates to view coordinates.
      java.awt.Rectangle drawingToView(java.awt.geom.Rectangle2D.Double r)
      Converts drawing coordinates to view coordinates.
      void duplicate()
      Duplicates the selected region.
      Figure findFigure(java.awt.Point p)
      Finds a figure at a given coordinates.
      java.util.Collection<Figure> findFigures(java.awt.Rectangle r)
      Returns all figures that lie within or intersect the specified bounds.
      java.util.Collection<Figure> findFiguresWithin(java.awt.Rectangle r)
      Returns all figures that lie within the specified bounds.
      Handle findHandle(java.awt.Point p)
      Finds a handle at a given coordinates.
      Handle getActiveHandle()
      Gets the active handle.
      java.util.Collection<Handle> getCompatibleHandles(Handle master)
      Gets compatible handles.
      javax.swing.JComponent getComponent()
      Returns the JComponent of the drawing view.
      Constrainer getConstrainer()
      Gets the current constrainer of this view.
      Drawing getDrawing()
      Gets the drawing.
      java.awt.geom.AffineTransform getDrawingToViewTransform()
      Gets an transform which can be used to convert drawing coordinates to view coordinates.
      DrawingEditor getEditor()
      Gets the drawing editor associated to the DrawingView.
      java.lang.String getEmptyDrawingMessage() 
      int getHandleDetailLevel()
      Returns the detail level of the handles.
      Constrainer getInvisibleConstrainer()
      Gets the editor's constrainer for this view, for use, when the visible constrainer is turned off.
      java.awt.Dimension getPreferredSize() 
      double getScaleFactor()
      Gets the scale factor of the drawing view.
      java.util.Set<Figure> getSelectedFigures()
      Gets the current selection as a FigureSelection.
      int getSelectionCount()
      Gets the number of selected figures.
      java.lang.String getToolTipText(java.awt.event.MouseEvent evt) 
      Constrainer getVisibleConstrainer()
      Gets the editor's constrainer for this view, for use, when the visible constrainer is turned on.
      void invalidate() 
      boolean isConstrainerVisible()
      Returns true, if the visible Constrainer is in use, returns false, if the invisible Constrainer is in use.
      boolean isDrawingDoubleBuffered()
      Returns true, if the the drawing is double buffered.
      boolean isFigureSelected(Figure checkFigure)
      Test whether a given figure is selected.
      boolean isSelectionEmpty()
      Returns true if the selection is empty.
      void paint(java.awt.Graphics g) 
      void paintComponent(java.awt.Graphics gr)
      Paints the drawing view.
      void printComponent(java.awt.Graphics gr)
      Prints the drawing view.
      void removeFigureSelectionListener(FigureSelectionListener fsl)
      Remove a listener for selection changes in this DrawingView.
      void removeFromSelection(Figure figure)
      Removes a figure from the selection.
      void removeNotify() 
      void removeNotify(DrawingEditor editor)
      Informs the view that it has been removed from the specified editor.
      void repaintHandles()
      Repaints the handles of the view.
      void selectAll()
      Selects all selectable figures.
      void setActiveHandle(Handle newValue)
      Sets the active handle.
      void setBounds(int x, int y, int width, int height)
      Side effect: Changes view Translation.
      void setConstrainerVisible(boolean newValue)
      Changes between a visible Constrainer and an invisible Constrainer.
      void setDrawing(Drawing newValue)
      Sets and installs another drawing in the view.
      void setDrawingDoubleBuffered(boolean newValue)
      Sets whether the drawing is double buffered.
      void setEmptyDrawingMessage(java.lang.String newValue) 
      void setEnabled(boolean b)
      Sets the enabled state of the drawing view.
      void setHandleDetailLevel(int newValue)
      The detail level of the handles.
      void setInvisibleConstrainer(Constrainer newValue)
      Sets the editor's constrainer for this view, for use, when the visible constrainer is turned off.
      void setScaleFactor(double newValue)
      Sets the scale factor of the drawing view.
      void setVisibleConstrainer(Constrainer newValue)
      Sets the editor's constrainer for this view, for use, when the visible constrainer is turned on.
      void toggleSelection(Figure figure)
      If a figure isn't selected it is added to the selection.
      java.awt.geom.Point2D.Double viewToDrawing(java.awt.Point p)
      Converts view coordinates to drawing coordinates.
      java.awt.geom.Rectangle2D.Double viewToDrawing(java.awt.Rectangle r)
      Converts view coordinates to drawing coordinates.
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DRAWING_DOUBLE_BUFFERED_PROPERTY

        public static final java.lang.String DRAWING_DOUBLE_BUFFERED_PROPERTY
        See Also:
        Constant Field Values
    • Constructor Detail

      • DefaultDrawingView

        public DefaultDrawingView()
        Creates new instance.
    • Method Detail

      • repaintHandles

        public void repaintHandles()
        Description copied from interface: DrawingView
        Repaints the handles of the view.
        Specified by:
        repaintHandles in interface DrawingView
      • getToolTipText

        public java.lang.String getToolTipText(java.awt.event.MouseEvent evt)
        Overrides:
        getToolTipText in class javax.swing.JComponent
      • setEmptyDrawingMessage

        public void setEmptyDrawingMessage(java.lang.String newValue)
      • getEmptyDrawingMessage

        public java.lang.String getEmptyDrawingMessage()
      • paintComponent

        public void paintComponent(java.awt.Graphics gr)
        Paints the drawing view. Uses rendering hints for fast painting. Paints the canvasColor, the grid, the drawing, the handles and the current tool.
        Overrides:
        paintComponent in class javax.swing.JComponent
      • printComponent

        public void printComponent(java.awt.Graphics gr)
        Prints the drawing view. Uses high quality rendering hints for printing. Only prints the drawing. Doesn't print the canvasColor, the grid, the handles and the tool.
        Overrides:
        printComponent in class javax.swing.JComponent
      • paint

        public void paint(java.awt.Graphics g)
        Overrides:
        paint in class javax.swing.JComponent
      • invalidate

        public void invalidate()
        Overrides:
        invalidate in class java.awt.Container
      • removeNotify

        public void removeNotify()
        Overrides:
        removeNotify in class javax.swing.JComponent
      • addToSelection

        public void addToSelection(Figure figure)
        Adds a figure to the current selection.
        Specified by:
        addToSelection in interface DrawingView
      • addToSelection

        public void addToSelection(java.util.Collection<Figure> figures)
        Adds a collection of figures to the current selection.
        Specified by:
        addToSelection in interface DrawingView
      • toggleSelection

        public void toggleSelection(Figure figure)
        If a figure isn't selected it is added to the selection. Otherwise it is removed from the selection.
        Specified by:
        toggleSelection in interface DrawingView
      • setEnabled

        public void setEnabled(boolean b)
        Description copied from interface: DrawingView
        Sets the enabled state of the drawing view. This is a bound property.
        Specified by:
        setEnabled in interface DrawingView
        Overrides:
        setEnabled in class javax.swing.JComponent
      • isFigureSelected

        public boolean isFigureSelected(Figure checkFigure)
        Test whether a given figure is selected.
        Specified by:
        isFigureSelected in interface DrawingView
      • getSelectedFigures

        public java.util.Set<Figure> getSelectedFigures()
        Gets the current selection as a FigureSelection. A FigureSelection can be cut, copied, pasted.
        Specified by:
        getSelectedFigures in interface DrawingView
      • getSelectionCount

        public int getSelectionCount()
        Gets the number of selected figures.
        Specified by:
        getSelectionCount in interface DrawingView
      • findHandle

        public Handle findHandle(java.awt.Point p)
        Finds a handle at a given coordinates.
        Specified by:
        findHandle in interface DrawingView
        Returns:
        A handle, null if no handle is found.
      • getCompatibleHandles

        public java.util.Collection<Handle> getCompatibleHandles(Handle master)
        Gets compatible handles.
        Specified by:
        getCompatibleHandles in interface DrawingView
        Returns:
        A collection containing the handle and all compatible handles.
      • findFigure

        public Figure findFigure(java.awt.Point p)
        Finds a figure at a given coordinates.
        Specified by:
        findFigure in interface DrawingView
        Returns:
        A figure, null if no figure is found.
      • findFigures

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

        public java.util.Collection<Figure> findFiguresWithin(java.awt.Rectangle r)
        Description copied from interface: DrawingView
        Returns all figures that lie within the specified bounds. The figures are returned in Z-order from back to front.
        Specified by:
        findFiguresWithin in interface DrawingView
      • getConstrainer

        public Constrainer getConstrainer()
        Description copied from interface: DrawingView
        Gets the current constrainer of this view. If isConstrainerVisible is true, this method returns getVisibleConstrainer, otherwise it returns getInvisibleConstrainer. This is a bound property.
        Specified by:
        getConstrainer in interface DrawingView
      • getPreferredSize

        public java.awt.Dimension getPreferredSize()
        Overrides:
        getPreferredSize in class javax.swing.JComponent
      • setBounds

        public void setBounds(int x,
                              int y,
                              int width,
                              int height)
        Side effect: Changes view Translation.
        Overrides:
        setBounds in class java.awt.Component
      • drawingToView

        public java.awt.Point drawingToView(java.awt.geom.Point2D.Double p)
        Converts drawing coordinates to view coordinates.
        Specified by:
        drawingToView in interface DrawingView
      • drawingToView

        public java.awt.Rectangle drawingToView(java.awt.geom.Rectangle2D.Double r)
        Description copied from interface: DrawingView
        Converts drawing coordinates to view coordinates.
        Specified by:
        drawingToView in interface DrawingView
      • viewToDrawing

        public java.awt.geom.Point2D.Double viewToDrawing(java.awt.Point p)
        Converts view coordinates to drawing coordinates.
        Specified by:
        viewToDrawing in interface DrawingView
      • viewToDrawing

        public java.awt.geom.Rectangle2D.Double viewToDrawing(java.awt.Rectangle r)
        Description copied from interface: DrawingView
        Converts view coordinates to drawing coordinates.
        Specified by:
        viewToDrawing in interface DrawingView
      • getComponent

        public javax.swing.JComponent getComponent()
        Description copied from interface: DrawingView
        Returns the JComponent of the drawing view.
        Specified by:
        getComponent in interface DrawingView
      • getScaleFactor

        public double getScaleFactor()
        Description copied from interface: DrawingView
        Gets the scale factor of the drawing view. This is a bound property.
        Specified by:
        getScaleFactor in interface DrawingView
      • setScaleFactor

        public void setScaleFactor(double newValue)
        Description copied from interface: DrawingView
        Sets the scale factor of the drawing view. This is a bound property.
        Specified by:
        setScaleFactor in interface DrawingView
      • setHandleDetailLevel

        public void setHandleDetailLevel(int newValue)
        Description copied from interface: DrawingView
        The detail level of the handles. This is a bound property.
        Specified by:
        setHandleDetailLevel in interface DrawingView
      • getHandleDetailLevel

        public int getHandleDetailLevel()
        Description copied from interface: DrawingView
        Returns the detail level of the handles. This is a bound property.
        Specified by:
        getHandleDetailLevel in interface DrawingView
      • getDrawingToViewTransform

        public java.awt.geom.AffineTransform getDrawingToViewTransform()
        Description copied from interface: DrawingView
        Gets an transform which can be used to convert drawing coordinates to view coordinates.
        Specified by:
        getDrawingToViewTransform in interface DrawingView
      • delete

        public void delete()
        Description copied from interface: EditableComponent
        Deletes the selected components or the component at (or after) the caret position.
        Specified by:
        delete in interface EditableComponent
      • removeNotify

        public void removeNotify(DrawingEditor editor)
        Description copied from interface: DrawingView
        Informs the view that it has been removed from the specified editor. The view must not draw the tool from the editor anymore.
        Specified by:
        removeNotify in interface DrawingView
      • addNotify

        public void addNotify(DrawingEditor editor)
        Description copied from interface: DrawingView
        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.
        Specified by:
        addNotify in interface DrawingView
      • setVisibleConstrainer

        public void setVisibleConstrainer(Constrainer newValue)
        Description copied from interface: DrawingView
        Sets the editor's constrainer for this view, for use, when the visible constrainer is turned on. This is a bound property.
        Specified by:
        setVisibleConstrainer in interface DrawingView
      • getVisibleConstrainer

        public Constrainer getVisibleConstrainer()
        Description copied from interface: DrawingView
        Gets the editor's constrainer for this view, for use, when the visible constrainer is turned on. This is a bound property.
        Specified by:
        getVisibleConstrainer in interface DrawingView
      • setInvisibleConstrainer

        public void setInvisibleConstrainer(Constrainer newValue)
        Description copied from interface: DrawingView
        Sets the editor's constrainer for this view, for use, when the visible constrainer is turned off. This is a bound property.
        Specified by:
        setInvisibleConstrainer in interface DrawingView
      • getInvisibleConstrainer

        public Constrainer getInvisibleConstrainer()
        Description copied from interface: DrawingView
        Gets the editor's constrainer for this view, for use, when the visible constrainer is turned off. This is a bound property.
        Specified by:
        getInvisibleConstrainer in interface DrawingView
      • setConstrainerVisible

        public void setConstrainerVisible(boolean newValue)
        Description copied from interface: DrawingView
        Changes between a visible Constrainer and an invisible Constrainer. This is a bound property.
        Specified by:
        setConstrainerVisible in interface DrawingView
      • isConstrainerVisible

        public boolean isConstrainerVisible()
        Description copied from interface: DrawingView
        Returns true, if the visible Constrainer is in use, returns false, if the invisible Constrainer is in use. This is a bound property.
        Specified by:
        isConstrainerVisible in interface DrawingView
      • setDrawingDoubleBuffered

        public void setDrawingDoubleBuffered(boolean newValue)
        Sets whether the drawing is double buffered.

        The default value is true.

        This is a bound property.

        If the drawing view is used for editing, you should leave this to true. If the drawing view is used for viewing only, you should set this to false.

      • isDrawingDoubleBuffered

        public boolean isDrawingDoubleBuffered()
        Returns true, if the the drawing is double buffered.
      • getEditor

        public DrawingEditor getEditor()
        Description copied from interface: DrawingView
        Gets the drawing editor associated to the DrawingView. This is a bound property.
        Specified by:
        getEditor in interface DrawingView

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.