diva.sketch
Class SketchLayer

java.lang.Object
  extended by diva.canvas.CanvasLayer
      extended by diva.sketch.SketchLayer
All Implemented Interfaces:
CanvasComponent

public class SketchLayer
extends CanvasLayer

A layer class that is specialized to make sketching strokes fast. This layer only paints the last segment of a hand-drawn stroke, so it doesn't have to redraw any of the layers behind it.

Version:
$Revision: 1.4 $
Author:
Michael Shilman (michaels@eecs.berkeley.edu)

Constructor Summary
SketchLayer()
          Create a new layer that is not in a pane.
SketchLayer(CanvasPane pane)
          Create a new layer within the given pane.
 
Method Summary
 void appendStroke(double x, double y)
          This completes a line segement with start point (_prevX,prevY) and (x,y) and asks the shape to paint itself.
 void finishStroke()
          Finish the current stroke and clear the layer.
 void setLineWidth(float width)
          Set the pen width used to paint the shape.
 void setPenColor(Color c)
          Set the pen color used to paint the shape.
 void startStroke(double x, double y)
          This sets the start point (_prevX, _prevY) of the line segment to be drawn.
 
Methods inherited from class diva.canvas.CanvasLayer
getCanvasPane, getLayerBounds, getParent, getToolTipText, getTransformContext, repaint, repaint, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SketchLayer

public SketchLayer()
Create a new layer that is not in a pane. The layer will not be displayed, and its coordinate tranformation will be as though it were a one-to-one mapping. Use of this constructor is strongly discouraged, as many of the geometry-related methods expect to see a pane. Create a SketchLayer with a PaintedShape object that contains a line. The shape is initialized to be drawn with black ink and 1 unit line width.


SketchLayer

public SketchLayer(CanvasPane pane)
Create a new layer within the given pane. Create a SketchLayer with a PaintedShape object that contains a line. The shape is initialized to be drawn with black ink and 1 unit line width.

Method Detail

appendStroke

public void appendStroke(double x,
                         double y)
This completes a line segement with start point (_prevX,prevY) and (x,y) and asks the shape to paint itself. Normally this would be called from within mouseDragged.


finishStroke

public void finishStroke()
Finish the current stroke and clear the layer. Normally this would be called from within mouseReleasd. This method is empty right now, because there's nothing that needs to be cleared up. The line segment is reset upon every appendStroke call, and is painted only when appendStroke is called. When a stroke has been completed (finishStroke in BasicInterpreter will be called), a figure will be created for it and be added to the canvas which will repaint, therefore the last segment is accounted for in the figure and need not be drawn here because it'll be cleared anyway when the canvas repaints.


setLineWidth

public void setLineWidth(float width)
Set the pen width used to paint the shape.


setPenColor

public void setPenColor(Color c)
Set the pen color used to paint the shape.


startStroke

public void startStroke(double x,
                        double y)
This sets the start point (_prevX, _prevY) of the line segment to be drawn. Normally this would be called from within mousePressed.



Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.