Package diva.canvas

Class OverlayLayer

  • All Implemented Interfaces:
    CanvasComponent, VisibleComponent

    public class OverlayLayer
    extends CanvasLayer
    implements VisibleComponent
    OutlineLayer is a layer that is used to display the grey figures commonly used for drag-selection, reshaping items, and so on. It can have shapes added to it, which are all drawn in outline in grey (by default -- the color can be changed). There is no concept of a display list or z-depth in this layer, as all shapes are drawn in exactly the same color.

    Although currently it does not do so, this class will become optimized so that repaints of this layer do not require a repaint of backing layers.

    Version:
    $Id$
    Author:
    Michael Shilman, John Reekie
    Pt.AcceptedRating:
    Red
    • Constructor Summary

      Constructors 
      Constructor Description
      OverlayLayer()
      Create a new OverlayLayer with a default one-pixel stroke and a light grey stroke color.
      OverlayLayer​(java.awt.Stroke s, java.awt.Paint p)
      Create a new OverlayLayer with the given stroke and paint.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.awt.Shape s)
      Add a new shape to the list of shapes in this layer.
      void clear()
      Clear the layer.
      java.awt.Paint getPaint()
      Get the current paint.
      java.awt.Stroke getStroke()
      Get the current paint stroke.
      boolean isVisible()
      Test the visibility flag of this layer.
      void paint​(java.awt.Graphics2D g)
      Paint this layer onto a 2D graphics object.
      void paint​(java.awt.Graphics2D g, java.awt.geom.Rectangle2D region)
      Paint this layer onto a 2D graphics object, within the given region.
      void remove​(java.awt.Shape s)
      Remove a shape from the list of shapes in this layer.
      void repaint​(java.awt.geom.Rectangle2D region)
      Schedule a repaint of this layer over the given shape.
      void repaint​(java.awt.Shape shape)
      Schedule a repaint of this layer over the given shape.
      void setPaint​(java.awt.Paint p)
      Set the paint.
      void setStroke​(java.awt.Stroke s)
      Set the stroke.
      void setVisible​(boolean flag)
      Set the visibility flag of this layer.
      java.util.Iterator shapes()
      Return an iterator over the shapes currently in this layer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OverlayLayer

        public OverlayLayer()
        Create a new OverlayLayer with a default one-pixel stroke and a light grey stroke color.
      • OverlayLayer

        public OverlayLayer​(java.awt.Stroke s,
                            java.awt.Paint p)
        Create a new OverlayLayer with the given stroke and paint.
        Parameters:
        s - The given stroke
        p - The given paint
    • Method Detail

      • add

        public void add​(java.awt.Shape s)
        Add a new shape to the list of shapes in this layer.
        Parameters:
        s - The shape to be added
      • clear

        public void clear()
        Clear the layer.
      • getStroke

        public java.awt.Stroke getStroke()
        Get the current paint stroke.
        Returns:
        The stroke
        See Also:
        setStroke(Stroke)
      • getPaint

        public java.awt.Paint getPaint()
        Get the current paint.
        Returns:
        the Paint
        See Also:
        setPaint(Paint)
      • isVisible

        public boolean isVisible()
        Test the visibility flag of this layer. Note that this flag does not indicate whether the layer is actually visible on the screen, as its pane or one if its ancestors may not be visible.
        Specified by:
        isVisible in interface VisibleComponent
        Returns:
        true if the object is visible.
        See Also:
        setVisible(boolean)
      • paint

        public void paint​(java.awt.Graphics2D g)
        Paint this layer onto a 2D graphics object. If the layer is not visible, return immediately. Otherwise draw all shapes with the current stroke and paint.
        Specified by:
        paint in interface VisibleComponent
        Parameters:
        g - The 2D graphics object that this object it to be painted upon.
      • paint

        public void paint​(java.awt.Graphics2D g,
                          java.awt.geom.Rectangle2D region)
        Paint this layer onto a 2D graphics object, within the given region. If the layer is not visible, return immediately. Otherwise draw all figures that overlap the given region.
        Specified by:
        paint in interface VisibleComponent
        Parameters:
        g - The 2D graphics object that this object it to be painted upon.
        region - The region.
      • remove

        public void remove​(java.awt.Shape s)
        Remove a shape from the list of shapes in this layer.
        Parameters:
        s - The Shape to be removed
      • repaint

        public void repaint​(java.awt.geom.Rectangle2D region)
        Schedule a repaint of this layer over the given shape. The shape is assumed to be a shape that is on this layer. It is made larger by the line width of the outlines, to ensure that enough of the canvas is repainted. This particular version of this method is optimized for rectangles.
        Parameters:
        region - The region
      • repaint

        public void repaint​(java.awt.Shape shape)
        Schedule a repaint of this layer over the given shape. The shape is assumed to be a shape that is on this layer. The width of the outline is taken into account when repainting the canvas.
        Parameters:
        shape - The given shape
      • shapes

        public java.util.Iterator shapes()
        Return an iterator over the shapes currently in this layer.
        Returns:
        an iterator
      • setStroke

        public void setStroke​(java.awt.Stroke s)
        Set the stroke. All shapes will be stroked with the same stroke.
        Parameters:
        s - The stroke
        See Also:
        getStroke()
      • setPaint

        public void setPaint​(java.awt.Paint p)
        Set the paint. All shapes will be drawn with the same paint.
        Parameters:
        p - The paint
        See Also:
        getPaint()
      • setVisible

        public void setVisible​(boolean flag)
        Set the visibility flag of this layer. If the flag is false, then the layer will not be drawn on the screen.
        Specified by:
        setVisible in interface VisibleComponent
        Parameters:
        flag - the visibility flag
        See Also:
        isVisible()