Class AbstractJaxoCanvas

All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Scrollable, JaxoCanvasComponent, JaxoDrawingArea, JaxoLocalized
Direct Known Subclasses:
JaxoCanvas

public abstract class AbstractJaxoCanvas extends JComponent implements JaxoDrawingArea
Abstract base class for the canvas.
Since:
2.1
See Also:
  • Field Details

    • HANDLE_PAINT_OFF

      protected static final int HANDLE_PAINT_OFF
      Do not paint handles.
      See Also:
    • HANDLE_PAINT_ON

      protected static final int HANDLE_PAINT_ON
      Paint handles.
      See Also:
    • HANDLE_PAINT_SELECTION

      protected static final int HANDLE_PAINT_SELECTION
      Only 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

      protected final JaxoFBoxPopupMenu getFboxPopup()
      The JaxoFBoxPopupMenu for this canvas.
      Returns:
      a JaxoFBoxPopupMenu, not null.
    • propertyChange

      public void propertyChange(PropertyChangeEvent evt)
      Specified by:
      propertyChange in interface PropertyChangeListener
    • asComponent

      public Component asComponent()
      Return this CanvasComponent as a Component.
      Specified by:
      asComponent in interface JaxoCanvasComponent
      Returns:
      this CanvasComponent as a Component or null, if this is not a Component.
    • getHandle

      protected JaxoHandle getHandle()
      The currently set handle.
      Returns:
      The current handle.
    • setHandle

      public void setHandle(JaxoHandle newHandle)
      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

      protected JaxoGraph getCanvasGraph()
      Returns the current graph.
      Returns:
      The current graph.
    • setCanvasGraph

      public void setCanvasGraph(JaxoGraph value)
      Sets the graph to be painted.
      Specified by:
      setCanvasGraph in interface JaxoDrawingArea
      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 interface JaxoDrawingArea
      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 interface JaxoDrawingArea
    • 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 interface JaxoDrawingArea
    • unMarkGraph

      public boolean unMarkGraph()
      Sets all objects in the current graph as not marked.
      Specified by:
      unMarkGraph in interface JaxoDrawingArea
      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

      public Color getCanvasBackground()
      Background color in the region that is actually covered by the canvas getCanvasSize(), 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 interface JaxoCanvasComponent
      Returns:
      The canvas background color.
    • setCanvasBackground

      public void setCanvasBackground(Color color)
      Sets the color of the background.
      Specified by:
      setCanvasBackground in interface JaxoCanvasComponent
      Parameters:
      color - The background color.
    • getCanvasOrigin

      public Point getCanvasOrigin()
      Origin of the actual canvas within the component. This is always the top-left corner.
      Specified by:
      getCanvasOrigin in interface JaxoCanvasComponent
      Returns:
      a Point at the origin.
    • getCanvasBounds

      public Rectangle 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 interface JaxoCanvasComponent
      Returns:
      Rectangle the canvas bounds.
      See Also:
    • getCanvasSize

      public Dimension 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 interface JaxoCanvasComponent
      Returns:
      The canvas size.
    • getMinimumCanvasSize

      public Dimension 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 interface JaxoCanvasComponent
      Returns:
      The minimum canvas size.
    • setMinimumCanvasSize

      public void setMinimumCanvasSize(Dimension value)
      Sets the minimum canvas size.
      Specified by:
      setMinimumCanvasSize in interface JaxoCanvasComponent
      Parameters:
      value - The minimum canvas size.
    • getMaximumCanvasSize

      public Dimension 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 interface JaxoCanvasComponent
      Returns:
      The maximum canvas size.
    • setMaximumCanvasSize

      public void setMaximumCanvasSize(Dimension value)
      Sets the maximum canvas size.
      Specified by:
      setMaximumCanvasSize in interface JaxoCanvasComponent
      Parameters:
      value - The maximum canvas size.
    • getEffectiveMaximumCanvasSize

      protected Dimension 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

      protected Point toGraphCoordinates(Point p)
      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

      protected Point toComponentCoordinates(Point p)
      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

      protected Rectangle toComponentCoordinates(Rectangle r)
      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

      protected Rectangle getScreenBounds(JaxoObject o)
      Determines the bounds of the given object on the screen.
      Parameters:
      o - the JaxoObject.
      Returns:
      Rectangle
    • getZoom

      public JaxoZoom getZoom()
      Return a zoom on this drawing area.
      Specified by:
      getZoom in interface JaxoDrawingArea
      Returns:
      a zoom on this drawing area.
    • getGrid

      protected JaxoPaintableGrid 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

      public void setGrid(JaxoPaintableGrid value)
      Sets the grid to be painted on this drawing area.
      Specified by:
      setGrid in interface JaxoDrawingArea
      Parameters:
      value - The new grid. May be null.
    • setCanvasGraphAndGrid

      public void setCanvasGraphAndGrid(JaxoGraph newGraph, JaxoPaintableGrid newGrid)
      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

      public Dimension getPreferredScrollableViewportSize()
      Return the preferred size of the viewport.
      Specified by:
      getPreferredScrollableViewportSize in interface Scrollable
      Returns:
      The preferred size of the viewport.
    • getScrollableUnitIncrement

      public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
      Return the unit increment for scrolling.
      Specified by:
      getScrollableUnitIncrement in interface Scrollable
      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

      public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
      Return the unit increment for block scrolling.
      Specified by:
      getScrollableBlockIncrement in interface Scrollable
      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 interface Scrollable
      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 interface Scrollable
      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

      protected JaxoGraph getSystemClipboardGraph()
      Graph on the system clipboard.
      Returns:
      the current graph on the system clipboard, or null if none.
    • putToSystemClipboard

      protected void putToSystemClipboard(JaxoGraph g)
      Make 'g' the contents of the system clipboard.
      Parameters:
      g - the graph to put on the clipboard.
    • getClipboard

      public JaxoGraph getClipboard()
      Gets the current clipboard. This never returns null.
      Specified by:
      getClipboard in interface JaxoDrawingArea
      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

      protected void paintBackgroundAndGrid(Graphics2D g, Rectangle rect)
      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

      protected void snapPoint(Point p)
      Snap the given point to the current grid. If the current grid is null, does nothing.
      Parameters:
      p - the point to snap.
    • snapObject

      protected void snapObject(JaxoObject o)
      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 interface JaxoLocalized
    • repaintBoundingBox

      protected void repaintBoundingBox(Rectangle2D r)
      Repaint the given Rectangle in graph coordinates. Currently these are always the same as component coordinates.
      Parameters:
      r - the Rectangle to repaint.
    • showColorPanel

      protected boolean showColorPanel(JaxoObject ob)
      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

      protected boolean showSelectionPanel(Point location)
      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

      protected boolean showEditPanel(JaxoObject o)
      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.