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 JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intDo not paint handles.protected static final intPaint handles.protected static final intOnly paint handles of selected objects.protected static final booleanFields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface JaxoDrawingArea
DEFAULT_HELP_COLOR, DEFAULT_HELP_STROKE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn this CanvasComponent as a Component.protected booleanCheck if the system clipboard contains a JaxoGraph.voidPuts the current clipboard to the system clipboard.voidCopies the current clipboard to the system clipboard and removes the corresponding objects from the drawing area.protected abstract voidDeletes 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 JaxoGraphReturns the current graph.Origin of the actual canvas within the component.Canvas size.Gets the current clipboard.protected DimensionThe effective maximum canvas size.protected final JaxoFBoxPopupMenuThe JaxoFBoxPopupMenu for this canvas.protected JaxoPaintableGridgetGrid()Grid to be used.protected JaxoHandleThe currently set handle.protected intHow 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 RectangleDetermines the bounds of the given object on the screen.intgetScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) Return the unit increment for block scrolling.booleanReturn true if a viewport should force the height of the scrollable.booleanReturn true if a viewport should force the width of the scrollable.intgetScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) Return the unit increment for scrolling.protected JaxoGraphGraph on the system clipboard.getZoom()Return a zoom on this drawing area.protected booleanDetermines if objects are painted with antialiasing turned on.protected voidMark background or grid invalid (but not the graph/objects).voidMark the whole image as invalid.voidmoveGraph(int dx, int dy) Displace the whole graph by a given offset.protected voidpaintBackgroundAndGrid(Graphics2D g, Rectangle rect) Paint background (unless covered by grid), and grid (if on).voidprotected voidMake 'g' the contents of the system clipboard.protected abstract voidBuild a new off-screen image.protected voidRepaint the given Rectangle in graph coordinates.protected abstract voidResets the preferred size of the canvas.voidsetAntialiasEnabled(boolean value) Sets the antialias property.voidsetCanvasBackground(Color color) Sets the color of the background.voidsetCanvasGraph(JaxoGraph value) Sets the graph to be painted.voidsetCanvasGraphAndGrid(JaxoGraph newGraph, JaxoPaintableGrid newGrid) Set both graph and grid.voidsetGrid(JaxoPaintableGrid value) Sets the grid to be painted on this drawing area.voidsetHandle(JaxoHandle newHandle) Sets a new handle.protected voidsetHandlePaintMode(int value) Sets how to paint handles.voidsetMaximumCanvasSize(Dimension value) Sets the maximum canvas size.voidsetMinimumCanvasSize(Dimension value) Sets the minimum canvas size.protected booleanBrings up a ColorChooser panel for the given object.protected booleanBring up an EditPanel to edit properties of the given JaxoObject.protected booleanshowSelectionPanel(Point location) Brings up the faint-box popup panel for the current selection.protected voidMoves the given JaxoObject so that its first point is snapped to the current grid.protected voidSnap the given point to the current grid.protected PointPoint 'p' in graph coordinates converted to component coordinates.protected RectangleA Rectangle in graph coordinates converted to component coordinates.protected PointPoint 'p' in component coordinates converted to graph coordinates.booleanSets all objects in the current graph as not marked.voidUpdates the language on any localized sub-components.protected abstract voidupdateMode(int mode) Resets canvas parameters for the given mode.Methods inherited from class 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, updateUIMethods inherited from class 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, validateTreeMethods inherited from class 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, transferFocusUpCycleMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface JaxoCanvasComponent
addMouseListener, addMouseMotionListener, addPropertyChangeListener, getGraphics, print, removeMouseListener, removeMouseMotionListener, repaintMethods inherited from interface 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:
propertyChangein interfacePropertyChangeListener
-
asComponent
Return this CanvasComponent as a Component.- Specified by:
asComponentin interfaceJaxoCanvasComponent- Returns:
- this CanvasComponent as a Component or null, if this is not a Component.
-
getHandle
-
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
-
setCanvasGraph
Sets the graph to be painted.- Specified by:
setCanvasGraphin 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:
moveGraphin 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:
copyMarkedObjectsin interfaceJaxoDrawingArea
-
cutMarkedObjects
public void cutMarkedObjects()Copies the current clipboard to the system clipboard and removes the corresponding objects from the drawing area.- Specified by:
cutMarkedObjectsin interfaceJaxoDrawingArea
-
unMarkGraph
public boolean unMarkGraph()Sets all objects in the current graph as not marked.- Specified by:
unMarkGraphin 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:
getCanvasBackgroundin interfaceJaxoCanvasComponent- Returns:
- The canvas background color.
-
setCanvasBackground
Sets the color of the background.- Specified by:
setCanvasBackgroundin interfaceJaxoCanvasComponent- Parameters:
color- The background color.
-
getCanvasOrigin
Origin of the actual canvas within the component. This is always the top-left corner.- Specified by:
getCanvasOriginin 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:
getCanvasBoundsin 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:
getCanvasSizein 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:
getMinimumCanvasSizein interfaceJaxoCanvasComponent- Returns:
- The minimum canvas size.
-
setMinimumCanvasSize
Sets the minimum canvas size.- Specified by:
setMinimumCanvasSizein 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:
getMaximumCanvasSizein interfaceJaxoCanvasComponent- Returns:
- The maximum canvas size.
-
setMaximumCanvasSize
Sets the maximum canvas size.- Specified by:
setMaximumCanvasSizein 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
-
toComponentCoordinates
-
toComponentCoordinates
-
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:
getZoomin 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:
setGridin 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:
getPreferredScrollableViewportSizein interfaceScrollable- Returns:
- The preferred size of the viewport.
-
getScrollableUnitIncrement
Return the unit increment for scrolling.- Specified by:
getScrollableUnitIncrementin 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:
getScrollableBlockIncrementin 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:
getScrollableTracksViewportWidthin 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:
getScrollableTracksViewportHeightin 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:
getClipboardin 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:
updateLanguagein 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.
-