public class DefaultDrawingView extends javax.swing.JComponent implements DrawingView, EditableComponent
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.javax.swing.JComponent.AccessibleJComponent| Modifier and Type | Field and Description |
|---|---|
protected java.awt.image.BufferedImage |
backgroundTile |
static java.lang.String |
DRAWING_DOUBLE_BUFFERED_PROPERTY |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTACTIVE_HANDLE_PROPERTY, CONSTRAINER_PROPERTY, CONSTRAINER_VISIBLE_PROPERTY, CURSOR_PROPERTY, DRAWING_PROPERTY, ENABLED_PROPERTY, HANDLE_DETAIL_LEVEL_PROPERTY, INVISIBLE_CONSTRAINER_PROPERTY, SCALE_FACTOR_PROPERTY, VISIBLE_CONSTRAINER_PROPERTYSELECTION_EMPTY_PROPERTY| Constructor and Description |
|---|
DefaultDrawingView()
Creates new instance.
|
| 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.
|
protected org.jhotdraw.draw.DefaultDrawingView.EventHandler |
createEventHandler() |
void |
delete()
Deletes the selected components or the component at (or after) the
caret position.
|
protected void |
drawBackground(java.awt.Graphics2D g)
Draws the background of the drawing view.
|
protected void |
drawCanvas(java.awt.Graphics2D gr)
Draws the canvas.
|
protected void |
drawConstrainer(java.awt.Graphics2D g) |
protected void |
drawDrawing(java.awt.Graphics2D gr) |
protected void |
drawDrawingNonvolatileBuffered(java.awt.Graphics2D g)
Draws the drawing double buffered using a buffered image.
|
protected void |
drawDrawingVolatileBuffered(java.awt.Graphics2D g)
Draws the drawing double buffered using a volatile image.
|
protected void |
drawHandles(java.awt.Graphics2D g) |
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.
|
protected void |
drawTool(java.awt.Graphics2D g) |
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.
|
protected void |
fireSelectionChanged(java.util.Set<Figure> oldValue,
java.util.Set<Figure> newValue)
Notify all listenerList that have registered interest for
notification on this event type.
|
protected void |
fireViewTransformChanged() |
Handle |
getActiveHandle()
Gets the active handle.
|
protected java.awt.Paint |
getBackgroundPaint(int x,
int y)
Returns a paint for drawing the background of the drawing area.
|
protected java.awt.Rectangle |
getCanvasViewBounds()
Returns the bounds of the canvas on the drawing view.
|
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.
|
protected java.awt.geom.Rectangle2D.Double |
getDrawingArea() |
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() |
protected void |
invalidateDimension() |
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.
|
protected void |
repaintDrawingArea(java.awt.geom.Rectangle2D.Double r) |
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.
|
protected void |
setViewRenderingHints(java.awt.Graphics2D g) |
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.
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUIadd, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, 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, transferFocusUpCycleclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, isEnabled, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, requestFocus, setCursoraddPropertyChangeListener, removePropertyChangeListenerprotected java.awt.image.BufferedImage backgroundTile
public static final java.lang.String DRAWING_DOUBLE_BUFFERED_PROPERTY
public void repaintHandles()
DrawingViewrepaintHandles in interface DrawingViewprotected void drawBackground(java.awt.Graphics2D g)
public boolean isSelectionEmpty()
EditableComponentisSelectionEmpty in interface EditableComponentprotected org.jhotdraw.draw.DefaultDrawingView.EventHandler createEventHandler()
public Drawing getDrawing()
DrawingViewgetDrawing in interface DrawingViewpublic java.lang.String getToolTipText(java.awt.event.MouseEvent evt)
getToolTipText in class javax.swing.JComponentpublic void setEmptyDrawingMessage(java.lang.String newValue)
public java.lang.String getEmptyDrawingMessage()
public void paintComponent(java.awt.Graphics gr)
paintComponent in class javax.swing.JComponentprotected void drawDrawingVolatileBuffered(java.awt.Graphics2D g)
protected void drawDrawingNonvolatileBuffered(java.awt.Graphics2D g)
public void printComponent(java.awt.Graphics gr)
printComponent in class javax.swing.JComponentprotected void setViewRenderingHints(java.awt.Graphics2D g)
protected java.awt.Rectangle getCanvasViewBounds()
protected void drawCanvas(java.awt.Graphics2D gr)
AttributeKeys.CANVAS_FILL_OPACITY is
not fully opaque, the canvas area is filled with the background paint
before the AttributeKeys.CANVAS_FILL_COLOR is drawn.protected void drawConstrainer(java.awt.Graphics2D g)
protected void drawDrawing(java.awt.Graphics2D gr)
protected void drawHandles(java.awt.Graphics2D g)
protected void drawTool(java.awt.Graphics2D g)
public void setDrawing(Drawing newValue)
DrawingViewsetDrawing in interface DrawingViewpublic void paint(java.awt.Graphics g)
paint in class javax.swing.JComponentprotected void repaintDrawingArea(java.awt.geom.Rectangle2D.Double r)
public void invalidate()
invalidate in class java.awt.Containerpublic void removeNotify()
removeNotify in class javax.swing.JComponentpublic void addToSelection(Figure figure)
addToSelection in interface DrawingViewpublic void addToSelection(java.util.Collection<Figure> figures)
addToSelection in interface DrawingViewpublic void removeFromSelection(Figure figure)
removeFromSelection in interface DrawingViewpublic void toggleSelection(Figure figure)
toggleSelection in interface DrawingViewpublic void setEnabled(boolean b)
DrawingViewsetEnabled in interface DrawingViewsetEnabled in class javax.swing.JComponentpublic void selectAll()
selectAll in interface DrawingViewselectAll in interface EditableComponentpublic void clearSelection()
clearSelection in interface DrawingViewclearSelection in interface EditableComponentpublic boolean isFigureSelected(Figure checkFigure)
isFigureSelected in interface DrawingViewpublic java.util.Set<Figure> getSelectedFigures()
getSelectedFigures in interface DrawingViewpublic int getSelectionCount()
getSelectionCount in interface DrawingViewpublic Handle findHandle(java.awt.Point p)
findHandle in interface DrawingViewpublic java.util.Collection<Handle> getCompatibleHandles(Handle master)
getCompatibleHandles in interface DrawingViewpublic Figure findFigure(java.awt.Point p)
findFigure in interface DrawingViewpublic java.util.Collection<Figure> findFigures(java.awt.Rectangle r)
DrawingViewfindFigures in interface DrawingViewpublic java.util.Collection<Figure> findFiguresWithin(java.awt.Rectangle r)
DrawingViewfindFiguresWithin in interface DrawingViewpublic void addFigureSelectionListener(FigureSelectionListener fsl)
DrawingViewaddFigureSelectionListener in interface DrawingViewfsl - jhotdraw.framework.FigureSelectionListenerpublic void removeFigureSelectionListener(FigureSelectionListener fsl)
DrawingViewremoveFigureSelectionListener in interface DrawingViewfsl - jhotdraw.framework.FigureSelectionListenerprotected void fireSelectionChanged(java.util.Set<Figure> oldValue, java.util.Set<Figure> newValue)
EditableComponent.SELECTION_EMPTY_PROPERTY.protected void invalidateDimension()
public Constrainer getConstrainer()
DrawingViewgetConstrainer in interface DrawingViewpublic java.awt.Dimension getPreferredSize()
getPreferredSize in class javax.swing.JComponentprotected java.awt.geom.Rectangle2D.Double getDrawingArea()
public void setBounds(int x,
int y,
int width,
int height)
setBounds in class java.awt.Componentpublic java.awt.Point drawingToView(java.awt.geom.Point2D.Double p)
drawingToView in interface DrawingViewpublic java.awt.Rectangle drawingToView(java.awt.geom.Rectangle2D.Double r)
DrawingViewdrawingToView in interface DrawingViewpublic java.awt.geom.Point2D.Double viewToDrawing(java.awt.Point p)
viewToDrawing in interface DrawingViewpublic java.awt.geom.Rectangle2D.Double viewToDrawing(java.awt.Rectangle r)
DrawingViewviewToDrawing in interface DrawingViewpublic javax.swing.JComponent getComponent()
DrawingViewgetComponent in interface DrawingViewpublic double getScaleFactor()
DrawingViewgetScaleFactor in interface DrawingViewpublic void setScaleFactor(double newValue)
DrawingViewsetScaleFactor in interface DrawingViewprotected void fireViewTransformChanged()
public void setHandleDetailLevel(int newValue)
DrawingViewsetHandleDetailLevel in interface DrawingViewpublic int getHandleDetailLevel()
DrawingViewgetHandleDetailLevel in interface DrawingViewpublic java.awt.geom.AffineTransform getDrawingToViewTransform()
DrawingViewgetDrawingToViewTransform in interface DrawingViewpublic void delete()
EditableComponentdelete in interface EditableComponentpublic void duplicate()
EditableComponentduplicate in interface EditableComponentpublic void removeNotify(DrawingEditor editor)
DrawingViewremoveNotify in interface DrawingViewpublic void addNotify(DrawingEditor editor)
DrawingViewaddNotify in interface DrawingViewpublic void setVisibleConstrainer(Constrainer newValue)
DrawingViewsetVisibleConstrainer in interface DrawingViewpublic Constrainer getVisibleConstrainer()
DrawingViewgetVisibleConstrainer in interface DrawingViewpublic void setInvisibleConstrainer(Constrainer newValue)
DrawingViewsetInvisibleConstrainer in interface DrawingViewpublic Constrainer getInvisibleConstrainer()
DrawingViewgetInvisibleConstrainer in interface DrawingViewpublic void setConstrainerVisible(boolean newValue)
DrawingViewsetConstrainerVisible in interface DrawingViewpublic boolean isConstrainerVisible()
DrawingViewisConstrainerVisible in interface DrawingViewpublic void setDrawingDoubleBuffered(boolean newValue)
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.
public boolean isDrawingDoubleBuffered()
protected java.awt.Paint getBackgroundPaint(int x,
int y)
public DrawingEditor getEditor()
DrawingViewgetEditor in interface DrawingViewpublic void setActiveHandle(Handle newValue)
DrawingViewsetActiveHandle in interface DrawingViewpublic Handle getActiveHandle()
DrawingViewgetActiveHandle in interface DrawingView