Package net.sf.jaxodraw.gui
Class AbstractJaxoCanvas
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
net.sf.jaxodraw.gui.AbstractJaxoCanvas
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,PropertyChangeListener
,Serializable
,EventListener
,Scrollable
,JaxoCanvasComponent
,JaxoDrawingArea
,JaxoLocalized
- Direct Known Subclasses:
JaxoCanvas
Abstract base class for the canvas.
- Since:
- 2.1
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
Do not paint handles.protected static final int
Paint handles.protected static final int
Only paint handles of selected objects.protected static final boolean
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields inherited from interface net.sf.jaxodraw.gui.JaxoDrawingArea
DEFAULT_HELP_COLOR, DEFAULT_HELP_STROKE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn this CanvasComponent as a Component.protected boolean
Check if the system clipboard contains a JaxoGraph.void
Puts the current clipboard to the system clipboard.void
Copies the current clipboard to the system clipboard and removes the corresponding objects from the drawing area.protected abstract void
Deletes all 'marked' objects from the drawing area and the current canvas graph.Background color in the region that is actually covered by the canvasgetCanvasSize()
, which is the whole canvas, unless the effective maximum size is smaller than the component size.Part of the component that is covered by the actual canvas.protected JaxoGraph
Returns the current graph.Origin of the actual canvas within the component.Canvas size.Gets the current clipboard.protected Dimension
The effective maximum canvas size.protected final JaxoFBoxPopupMenu
The JaxoFBoxPopupMenu for this canvas.protected JaxoPaintableGrid
getGrid()
Grid to be used.protected JaxoHandle
The currently set handle.protected int
How to paint handles.Maximum size of the canvas (even if there are objects with a larger bounding box).Minimum size of the canvas (even if there are no objects or they have a smaller bounding box).Return the preferred size of the viewport.protected Rectangle
Determines the bounds of the given object on the screen.int
getScrollableBlockIncrement
(Rectangle visibleRect, int orientation, int direction) Return the unit increment for block scrolling.boolean
Return true if a viewport should force the height of the scrollable.boolean
Return true if a viewport should force the width of the scrollable.int
getScrollableUnitIncrement
(Rectangle visibleRect, int orientation, int direction) Return the unit increment for scrolling.protected JaxoGraph
Graph on the system clipboard.getZoom()
Return a zoom on this drawing area.protected boolean
Determines if objects are painted with antialiasing turned on.protected void
Mark background or grid invalid (but not the graph/objects).void
Mark the whole image as invalid.void
moveGraph
(int dx, int dy) Displace the whole graph by a given offset.protected void
paintBackgroundAndGrid
(Graphics2D g, Rectangle rect) Paint background (unless covered by grid), and grid (if on).void
protected void
Make 'g' the contents of the system clipboard.protected abstract void
Build a new off-screen image.protected void
Repaint the given Rectangle in graph coordinates.protected abstract void
Resets the preferred size of the canvas.void
setAntialiasEnabled
(boolean value) Sets the antialias property.void
setCanvasBackground
(Color color) Sets the color of the background.void
setCanvasGraph
(JaxoGraph value) Sets the graph to be painted.void
setCanvasGraphAndGrid
(JaxoGraph newGraph, JaxoPaintableGrid newGrid) Set both graph and grid.void
setGrid
(JaxoPaintableGrid value) Sets the grid to be painted on this drawing area.void
setHandle
(JaxoHandle newHandle) Sets a new handle.protected void
setHandlePaintMode
(int value) Sets how to paint handles.void
setMaximumCanvasSize
(Dimension value) Sets the maximum canvas size.void
setMinimumCanvasSize
(Dimension value) Sets the minimum canvas size.protected boolean
Brings up a ColorChooser panel for the given object.protected boolean
Bring up an EditPanel to edit properties of the given JaxoObject.protected boolean
showSelectionPanel
(Point location) Brings up the faint-box popup panel for the current selection.protected void
Moves the given JaxoObject so that its first point is snapped to the current grid.protected void
Snap the given point to the current grid.protected Point
Point 'p' in graph coordinates converted to component coordinates.protected Rectangle
A Rectangle in graph coordinates converted to component coordinates.protected Point
Point 'p' in component coordinates converted to graph coordinates.boolean
Sets all objects in the current graph as not marked.void
Updates the language on any localized sub-components.protected abstract void
updateMode
(int mode) Resets canvas parameters for the given mode.Methods inherited from class javax.swing.JComponent
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, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
Methods inherited from class java.awt.Container
add, 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, invalidate, 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, validateTree
Methods inherited from class java.awt.Component
action, 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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.sf.jaxodraw.gui.JaxoCanvasComponent
addMouseListener, addMouseMotionListener, addPropertyChangeListener, getGraphics, print, removeMouseListener, removeMouseMotionListener, repaint
Methods inherited from interface net.sf.jaxodraw.gui.JaxoDrawingArea
clear, continueEdit, continueSelect, editNearestObject, finalizeEdit, finalizeSelect, groupMarkedObjects, initiateEdit, initiateSelect, markImageInvalid, moveSelection, pasteFromClipboard, refresh, ungroupMarkedObjects, updatePointsAid
-
Field Details
-
HANDLE_PAINT_OFF
protected static final int HANDLE_PAINT_OFFDo not paint handles.- See Also:
-
HANDLE_PAINT_ON
protected static final int HANDLE_PAINT_ONPaint handles.- See Also:
-
HANDLE_PAINT_SELECTION
protected static final int HANDLE_PAINT_SELECTIONOnly paint handles of selected objects.- See Also:
-
HOVERING_EDITED_OBJECTS
protected static final boolean HOVERING_EDITED_OBJECTS- See Also:
-
-
Constructor Details
-
AbstractJaxoCanvas
protected AbstractJaxoCanvas()Constructor.
-
-
Method Details
-
getFboxPopup
The JaxoFBoxPopupMenu for this canvas.- Returns:
- a JaxoFBoxPopupMenu, not null.
-
propertyChange
- Specified by:
propertyChange
in interfacePropertyChangeListener
-
asComponent
Return this CanvasComponent as a Component.- Specified by:
asComponent
in interfaceJaxoCanvasComponent
- Returns:
- this CanvasComponent as a Component or null, if this is not a Component.
-
getHandle
The currently set handle.- Returns:
- The current handle.
-
setHandle
Sets a new handle.- Parameters:
newHandle
- The handle to set.
-
getHandlePaintMode
protected int getHandlePaintMode()How to paint handles.- Returns:
- the current handle paint mode.
-
setHandlePaintMode
protected void setHandlePaintMode(int value) Sets how to paint handles.- Parameters:
value
- One of the HANDLE_PAINT constants.
-
getCanvasGraph
Returns the current graph.- Returns:
- The current graph.
-
setCanvasGraph
Sets the graph to be painted.- Specified by:
setCanvasGraph
in interfaceJaxoDrawingArea
- Parameters:
value
- The graph to be set.
-
moveGraph
public void moveGraph(int dx, int dy) Displace the whole graph by a given offset.- Specified by:
moveGraph
in interfaceJaxoDrawingArea
- Parameters:
dx
- the offset in x direction.dy
- the offset in y direction.
-
copyMarkedObjects
public void copyMarkedObjects()Puts the current clipboard to the system clipboard.- Specified by:
copyMarkedObjects
in interfaceJaxoDrawingArea
-
cutMarkedObjects
public void cutMarkedObjects()Copies the current clipboard to the system clipboard and removes the corresponding objects from the drawing area.- Specified by:
cutMarkedObjects
in interfaceJaxoDrawingArea
-
unMarkGraph
public boolean unMarkGraph()Sets all objects in the current graph as not marked.- Specified by:
unMarkGraph
in interfaceJaxoDrawingArea
- Returns:
- true if the graph had actually contained marked objects. In this case the canvas was also repainted. False otherwise, in which case this method has no effect.
-
getCanvasBackground
Background color in the region that is actually covered by the canvasgetCanvasSize()
, which is the whole canvas, unless the effective maximum size is smaller than the component size. Note that this color may be overwritten by the grid.- Specified by:
getCanvasBackground
in interfaceJaxoCanvasComponent
- Returns:
- The canvas background color.
-
setCanvasBackground
Sets the color of the background.- Specified by:
setCanvasBackground
in interfaceJaxoCanvasComponent
- Parameters:
color
- The background color.
-
getCanvasOrigin
Origin of the actual canvas within the component. This is always the top-left corner.- Specified by:
getCanvasOrigin
in interfaceJaxoCanvasComponent
- Returns:
- a Point at the origin.
-
getCanvasBounds
Part of the component that is covered by the actual canvas. This includes canvas background and grid, -- i.e. a rectangle with size 'canvasSize' and origin 'canvasOrigin'.- Specified by:
getCanvasBounds
in interfaceJaxoCanvasComponent
- Returns:
- Rectangle the canvas bounds.
- See Also:
-
getCanvasSize
Canvas size. This is equal to the (inner) component size unless because of viewport size tracking, the component has become larger than the effective maximum canvas size.- Specified by:
getCanvasSize
in interfaceJaxoCanvasComponent
- Returns:
- The canvas size.
-
getMinimumCanvasSize
Minimum size of the canvas (even if there are no objects or they have a smaller bounding box). The default value is (0,0).- Specified by:
getMinimumCanvasSize
in interfaceJaxoCanvasComponent
- Returns:
- The minimum canvas size.
-
setMinimumCanvasSize
Sets the minimum canvas size.- Specified by:
setMinimumCanvasSize
in interfaceJaxoCanvasComponent
- Parameters:
value
- The minimum canvas size.
-
getMaximumCanvasSize
Maximum size of the canvas (even if there are objects with a larger bounding box). The default value is larger than (0,0). If the maximum canvas size is smaller (in either direction) than the minimum canvas size, the latter wins.- Specified by:
getMaximumCanvasSize
in interfaceJaxoCanvasComponent
- Returns:
- The maximum canvas size.
-
setMaximumCanvasSize
Sets the maximum canvas size.- Specified by:
setMaximumCanvasSize
in interfaceJaxoCanvasComponent
- Parameters:
value
- The maximum canvas size.
-
getEffectiveMaximumCanvasSize
The effective maximum canvas size. This is equal to the maximum canvas size, but with a lower bound of minimum canvas size for width and height.- Returns:
- the effective maximum canvas size.
-
toGraphCoordinates
Point 'p' in component coordinates converted to graph coordinates. At the moment, only translated by canvas origin.- Parameters:
p
- Point in component coordinates.- Returns:
- Point in graph coordinates.
-
toComponentCoordinates
Point 'p' in graph coordinates converted to component coordinates. At the moment, only translated by canvas origin.- Parameters:
p
- Point in graph coordinates.- Returns:
- Point in component coordinates.
-
toComponentCoordinates
A Rectangle in graph coordinates converted to component coordinates. At the moment, only translated by canvas origin.- Parameters:
r
- Rectangle in graph coordinates.- Returns:
- Rectangle in component coordinates.
-
getScreenBounds
Determines the bounds of the given object on the screen.- Parameters:
o
- the JaxoObject.- Returns:
- Rectangle
-
getZoom
Return a zoom on this drawing area.- Specified by:
getZoom
in interfaceJaxoDrawingArea
- Returns:
- a zoom on this drawing area.
-
getGrid
Grid to be used. A non-null grid is painted and potentially used for snapping points. If grid properties change, the canvas automatically updates and repaints itself.- Returns:
- The grid currently used by this canvas. May be null.
-
setGrid
Sets the grid to be painted on this drawing area.- Specified by:
setGrid
in interfaceJaxoDrawingArea
- Parameters:
value
- The new grid. May be null.
-
setCanvasGraphAndGrid
Set both graph and grid. This is an optimization to avoid painting to the background image twice (because that is done synchronously).- Parameters:
newGraph
- The new graph.newGrid
- The new grid.
-
isAntialiasEnabled
protected boolean isAntialiasEnabled()Determines if objects are painted with antialiasing turned on. This does not apply to handles.- Returns:
- True if antialising is enabled.
-
setAntialiasEnabled
public void setAntialiasEnabled(boolean value) Sets the antialias property.- Parameters:
value
- True if antialising should be enabled.
-
getPreferredScrollableViewportSize
Return the preferred size of the viewport.- Specified by:
getPreferredScrollableViewportSize
in interfaceScrollable
- Returns:
- The preferred size of the viewport.
-
getScrollableUnitIncrement
Return the unit increment for scrolling.- Specified by:
getScrollableUnitIncrement
in interfaceScrollable
- Parameters:
visibleRect
- the visible view area.orientation
- Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.direction
- less than zero to scroll up/left, greater than zero for down/right.- Returns:
- Returns 6.
-
getScrollableBlockIncrement
Return the unit increment for block scrolling.- Specified by:
getScrollableBlockIncrement
in interfaceScrollable
- Parameters:
visibleRect
- the visible view area.orientation
- Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.direction
- less than zero to scroll up/left, greater than zero for down/right.- Returns:
- Returns the width/height of visibleRect depending on orientation.
-
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()Return true if a viewport should force the width of the scrollable.- Specified by:
getScrollableTracksViewportWidth
in interfaceScrollable
- Returns:
- true if the parent's width is larger than the width of the preferred size.
-
getScrollableTracksViewportHeight
public boolean getScrollableTracksViewportHeight()Return true if a viewport should force the height of the scrollable.- Specified by:
getScrollableTracksViewportHeight
in interfaceScrollable
- Returns:
- true if the parent's height is larger than the height of the preferred size.
-
canPasteGraphFromSystemClipboard
protected boolean canPasteGraphFromSystemClipboard()Check if the system clipboard contains a JaxoGraph.- Returns:
- true if the system clipboard contains a JaxoGraph, false otherwise.
-
getSystemClipboardGraph
Graph on the system clipboard.- Returns:
- the current graph on the system clipboard, or null if none.
-
putToSystemClipboard
Make 'g' the contents of the system clipboard.- Parameters:
g
- the graph to put on the clipboard.
-
getClipboard
Gets the current clipboard. This never returns null.- Specified by:
getClipboard
in interfaceJaxoDrawingArea
- Returns:
- A JaxoGraph holding all the objects that are currently on the clipboard, or an empty graph, if the clipboard is empty.
-
markBackgroundInvalid
protected void markBackgroundInvalid()Mark background or grid invalid (but not the graph/objects). -
markImageInvalid
public void markImageInvalid()Mark the whole image as invalid. Currently this repaints everything at once, could be changed to defer until later. -
paintBackgroundAndGrid
Paint background (unless covered by grid), and grid (if on). This method may change the graphics clip and color.- Parameters:
g
- the graphics context to paint to.rect
- the rectangle to paint.
-
snapPoint
Snap the given point to the current grid. If the current grid is null, does nothing.- Parameters:
p
- the point to snap.
-
snapObject
Moves the given JaxoObject so that its first point is snapped to the current grid. If the current grid is null, does nothing.- Parameters:
o
- the JaxoObject to snap.
-
updateLanguage
public void updateLanguage()Updates the language on any localized sub-components.- Specified by:
updateLanguage
in interfaceJaxoLocalized
-
repaintBoundingBox
Repaint the given Rectangle in graph coordinates. Currently these are always the same as component coordinates.- Parameters:
r
- the Rectangle to repaint.
-
showColorPanel
Brings up a ColorChooser panel for the given object.- Parameters:
ob
- the object to edit.- Returns:
- true if the color of the object has been changed, false if it is unchanged.
-
showSelectionPanel
Brings up the faint-box popup panel for the current selection.- Parameters:
location
- the location of the popup panel.- Returns:
- true if the selection panel was actually shown. This is the case if either the graph contained marked objects (i.e. the selection is not empty) or there are currently objects on the clipboard to paste. Returns false if none of this is the case.
-
showEditPanel
Bring up an EditPanel to edit properties of the given JaxoObject.- Parameters:
o
- the object to edit.- Returns:
- true if the object has been modified, false if the object was unchanged.
-
revalidateCanvas
protected abstract void revalidateCanvas()Resets the preferred size of the canvas. -
rebuildImage
protected abstract void rebuildImage()Build a new off-screen image. This should only be needed for resizing the canvas. -
deleteMarkedObjects
protected abstract void deleteMarkedObjects()Deletes all 'marked' objects from the drawing area and the current canvas graph. -
updateMode
protected abstract void updateMode(int mode) Resets canvas parameters for the given mode. Sets the cursor, and determines whether to draw visualAid and handles.- Parameters:
mode
- The mode to adjust to.
-