org.diamondspin
Class DSStroke

java.lang.Object
  extended by org.diamondspin.DSStroke
All Implemented Interfaces:
MouseListener, MouseMotionListener, Serializable, Cloneable, EventListener, DSElement

public class DSStroke
extends Object
implements MouseMotionListener, MouseListener, DSElement, Cloneable, Serializable

DSStroke is a digital ink marker the user can draw with. It may be on top of the table,of an other element or to initiate an action.

Copyright 2002-2009 DiamondSpin project. All Rights Reserved.

Permission to use, copy, modify and distribute this software and its documentation for educational, research and non-profit purposes, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and the following three paragraphs appear in all copies.

To request Permission to incorporate this software into commercial products contact one of the authors of the project.
  • Frederic Vernier (frederic.vernier@limsi.fr)
  • Chia Shen (chia_shen@harvard.edu)
  • Guillaume Besacier (guillaume.besacier@limsi.fr)
  • Daniel Wigdor (dwigdor@microsoft.com)

IN NO EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

THE AUTHORS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE AUTHORS HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

Creation date : 17 october 2001

Version:
: 1.0
Author:
: Frederic vernier, (frederic.vernier@gmail.com) under Chia Shen supervision (chia_shen@harvard.edu).
See Also:
Serialized Form

Field Summary
protected  boolean active
           
protected  double alpha
           
protected  DSElement AttachedElement1
           
protected  double beta
           
protected  Color color1
           
protected  double d
           
protected  DSTabletopPane dsTabletopPane
           
static int FINISHED
           
protected  int idOwner
           
static int INITED
          The state of the stroke under construction
protected  int maxX
           
protected  int maxY
           
static int MIN_DIST_POINTS
           
protected  int minX
           
protected  int minY
           
static int STARTED
           
protected  int state
           
protected  ArrayList<DSPoint> strokePoints
          all the points of the stroke
protected  ArrayList<Float> strokeSizes
           
protected  ArrayList<Long> strokeTimes
           
 
Fields inherited from interface org.diamondspin.DSElement
HIGH_QUALITY, LOW_QUALITY
 
Constructor Summary
DSStroke(DSTabletopPane dsTabletopPane_Arg)
          Constructor without color (User's Color by default)
DSStroke(DSTabletopPane dsTabletopPane_Arg, Color Color_Arg)
          Constructor with color
DSStroke(DSTabletopPane dsTabletopPane_Arg, Color Color_Arg, DSElement AttachedElement_Arg)
          Constructor with color
DSStroke(DSTabletopPane dsTabletopPane_Arg, DSElement AttachedElement_Arg)
          Constructor without color but with attached element (User's Color by default)
DSStroke(DSTabletopPane dsTabletopPane_Arg, Polygon Polygon_Arg, Color Color_Arg, DSElement AttachedElement_Arg)
          Constructor with color and polygon
 
Method Summary
 boolean acceptSlavery(DSElement dsElement)
          obviously strokes can belong to other things
 boolean acceptSlaveryRelease()
          tells if I accept to be released
 void addDSElementListener(DSElementListener DSElementListener_Arg)
          we do not use this yet
 void addPoint(DSPoint pos, Float size, long timestamp)
          Add a point in the stroke
 DSStroke clone()
          duplicate this element
 boolean doesContain(double x_Arg, double y_Arg)
          Description of the Method.
 void erasePointsAround(Point pos, double radius)
          erase all the point close enough to the given position
 void finish()
           
 double getAbsoluteScale()
          Strokes ar not subject to scale and inner rotation
 double getAlpha()
          The degrees of freedom of the DSElements are their distance to the center, their angle comparing to the right direction (from center to the ful right), a scale (for zooming features) and
 DSElement getAttachedElement()
           
 double getBeta()
          The angle around its center
 Color getColor()
          Gets the color attribute of the DSStroke object
 double getD()
          The degrees of freedom of the DSElements are their distance to the center, their angle comparing to the right direction (from center to the ful right), a scale (for zooming features) and
 DSPoint getFirstPoint()
           
 int getHeight()
          Elements are displayed around their center (not around their top left corner) Width and Height are the amount of space used by the repaint.
 int getIDOwner()
          Gets the iDOwner attribute of the DSWindow object -1 means no owner
 DSPoint getIntervalX()
          return the maxi and mini point on the x axis
 DSPoint getIntervalY()
          return the maxi and mini point on the y axis (which is rotated !)
 int getNbPoints()
          return the number of points
 DSPoint getPoint(int index_arg)
           
 Polygon getPolygon()
           
 double getScale()
          The degrees of freedom of the DSElements are their distance to the center, their angle comparing to the right direction (from center to the ful right), a scale (for zooming features) and
 double getSize(int index_arg)
           
 int getState()
          Gets the state attribute of the DSStroke object
 DSTabletopPane getTabletopPane()
           
protected  ArrayList<DSPoint> getThePoints()
          Gets the thePoints attribute of the DSStroke object
 long getTime(int index_arg)
           
 AffineTransform getTransform()
          The matrix decribing how this element is transformed before rendering
 Polygon getUndeformedPolygon()
           
 int getWidth()
          Elements are displayed around their center (not around their top left corner) Width and Height are the amount of space used by the repaint.
 boolean grabElement(int dx_Arg, int dy_Arg)
          The stroke cannot be dragged
 boolean isActive()
          in the centralized architecture we have some elements are in the views and one or few element are handled directly by the DSTabletopPane as drag&dropped elements.
 boolean isBetaAbs()
          indicate how to use beta.
 boolean isMouseTarget(MouseEvent mouseEvent_Arg)
          the stroke can draw everywhere !
 boolean isVisible()
           
 void mirrorX(double xAxis)
          mirror all the point of the stroke around a vertical line
 void mirrorY(double yAxis)
          mirror all the point of the stroke around a horizontal line
 void mouseClicked(MouseEvent mouseEvent_Arg)
          unused mouse callbacks
 void mouseDragged(MouseEvent mouseEvent_Arg)
          drag = one more point
 void mouseEntered(MouseEvent mouseEvent_Arg)
          unused mouse callbacks
 void mouseExited(MouseEvent mouseEvent_Arg)
          unused mouse callbacks
 void mouseMoved(MouseEvent mouseEvent_Arg)
          unused mouse callbacks
 void mousePressed(MouseEvent mouseEvent_Arg)
          Handle a mouse event
 void mouseReleased(MouseEvent event)
          a last point for the road, close the polygon and notify dsTabletopPane
 void moveElementCenterTo(Point2D.Double touchPoint)
          can be used to make the element change its position to be centered under the given point
 void paint(Graphics graphics_arg)
          Call the other paint().
 void paint(Graphics2D graphics_Arg, int quality_Arg)
          Paint the stroke at a given quality level
 void paintCurve(Graphics2D g, Color color)
          draw a nice curve along the points given in parameter as a vector.
 void paintTransformed(Graphics2D Graphics_Arg, AffineTransform AffineTransform_Arg)
          Paint the stroke with a given transformation (not the one using the internal d,alpha of the stroke)
 void removeDSElementListener(DSElementListener DSElementListener_Arg)
          remove a listener
 void removeLastPoint()
          remove the last point in the stroke
 void reset()
          Reset the stroke
 void revealPoints(double size)
          reveal the hidden points of the stroke (the ones with size 0)
 void setActive(boolean active_Arg)
          change if the component is active or not (with shadow = is selected)
 void setAlpha(double alpha)
          Sets the alpha attribute of the DSStroke object
 void setAttachedElement(DSElement DSElement_Arg)
          set the attached element to this stroke.
 void setBeta(double beta)
          The angle around its center
 void setBetaAbs(boolean betaAbs)
          change how to use beta.
 void setColor(Color Color_Arg)
          Sets the color attribute of the DSStroke object
 void setD(double d)
          change the distance to the center of the circular layout
 void setIDOwner(int id)
          set the user id of the owner of this object (-1 is no owner)
 void setScale(double scale)
          The degrees of freedom of the DSElements are their distance to the center, their angle comparing to the right direction (from center to the ful right), a scale (for zooming features) and
 void setSize(int width_Arg, int height_Arg)
          do nothing because a stroke cannot be resized
 void setTabletopPane(DSTabletopPane dsTabletopPane_Arg)
           
 void setVisible(boolean visible_Arg)
          say if the component is visible
 String toString()
           
 void translate(int dx, int dy)
          translate all the point of the stroke
 DSPoint untransformPoint(double x_Arg, double y_Arg)
          transform a point into local-cartesian coordinate system
 void unTransformStroke(AffineTransform AffineTransform_Arg)
          transform the points of the stroke so they become relative to the global frame then retransform with the given matrix.
 void zoomTransformStroke(double ZoomFactor_Arg)
          transform the points by changing the size and applying a zoom factor to all of them without modifying the point locations
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

strokePoints

protected ArrayList<DSPoint> strokePoints
all the points of the stroke


strokeSizes

protected ArrayList<Float> strokeSizes

strokeTimes

protected ArrayList<Long> strokeTimes

MIN_DIST_POINTS

public static final int MIN_DIST_POINTS
See Also:
Constant Field Values

INITED

public static final int INITED
The state of the stroke under construction

See Also:
Constant Field Values

STARTED

public static final int STARTED
See Also:
Constant Field Values

FINISHED

public static final int FINISHED
See Also:
Constant Field Values

state

protected int state

idOwner

protected int idOwner

AttachedElement1

protected DSElement AttachedElement1

dsTabletopPane

protected transient DSTabletopPane dsTabletopPane

d

protected double d

alpha

protected double alpha

beta

protected double beta

minX

protected int minX

minY

protected int minY

maxX

protected int maxX

maxY

protected int maxY

color1

protected Color color1

active

protected boolean active
Constructor Detail

DSStroke

public DSStroke(DSTabletopPane dsTabletopPane_Arg)
Constructor without color (User's Color by default)

Parameters:
dsTabletopPane_Arg - the container in which the frame exists

DSStroke

public DSStroke(DSTabletopPane dsTabletopPane_Arg,
                DSElement AttachedElement_Arg)
Constructor without color but with attached element (User's Color by default)

Parameters:
dsTabletopPane_Arg - the container in which the frame exists

DSStroke

public DSStroke(DSTabletopPane dsTabletopPane_Arg,
                Color Color_Arg)
Constructor with color

Parameters:
Color_Arg - the color of the stroke

DSStroke

public DSStroke(DSTabletopPane dsTabletopPane_Arg,
                Color Color_Arg,
                DSElement AttachedElement_Arg)
Constructor with color

Parameters:
Color_Arg - the color of the stroke

DSStroke

public DSStroke(DSTabletopPane dsTabletopPane_Arg,
                Polygon Polygon_Arg,
                Color Color_Arg,
                DSElement AttachedElement_Arg)
Constructor with color and polygon

Parameters:
Polygon_Arg - the points of the stroke
Color_Arg - the color of the stroke
Method Detail

getTabletopPane

public DSTabletopPane getTabletopPane()

setTabletopPane

public void setTabletopPane(DSTabletopPane dsTabletopPane_Arg)

getD

public double getD()
Description copied from interface: DSElement
The degrees of freedom of the DSElements are their distance to the center, their angle comparing to the right direction (from center to the ful right), a scale (for zooming features) and

Specified by:
getD in interface DSElement
Returns:
the distance to the center of the circular layout

setD

public void setD(double d)
change the distance to the center of the circular layout

Specified by:
setD in interface DSElement
Parameters:
d - The new d value

getState

public int getState()
Gets the state attribute of the DSStroke object

Returns:
The state value

setAlpha

public void setAlpha(double alpha)
Sets the alpha attribute of the DSStroke object

Specified by:
setAlpha in interface DSElement
Parameters:
alpha - The new alpha value

setVisible

public void setVisible(boolean visible_Arg)
say if the component is visible

Specified by:
setVisible in interface DSElement
Parameters:
visible_Arg - The new visibility value

isVisible

public boolean isVisible()
Specified by:
isVisible in interface DSElement
Returns:
if this element is visible. Always true

getThePoints

protected ArrayList<DSPoint> getThePoints()
Gets the thePoints attribute of the DSStroke object

Returns:
The thePoints value

getAlpha

public double getAlpha()
Description copied from interface: DSElement
The degrees of freedom of the DSElements are their distance to the center, their angle comparing to the right direction (from center to the ful right), a scale (for zooming features) and

Specified by:
getAlpha in interface DSElement
Returns:
the angle from the right horitontal direction. Like the trigonometric circle ! 0-2PI

setColor

public void setColor(Color Color_Arg)
Sets the color attribute of the DSStroke object

Parameters:
Color_Arg - The new color value

getColor

public Color getColor()
Gets the color attribute of the DSStroke object

Returns:
The color value

getAttachedElement

public DSElement getAttachedElement()
Returns:
the attached element if this stroke is effectively attached to something solid

setAttachedElement

public void setAttachedElement(DSElement DSElement_Arg)
set the attached element to this stroke. Will be displayed by the stroke under itself


getIntervalX

public DSPoint getIntervalX()
return the maxi and mini point on the x axis

Returns:
The intervalX value

getIntervalY

public DSPoint getIntervalY()
return the maxi and mini point on the y axis (which is rotated !)

Returns:
The intervalY value

getPolygon

public Polygon getPolygon()
Returns:
the polygon of points on the stroke

getUndeformedPolygon

public Polygon getUndeformedPolygon()
Returns:
the polygon as it appears on the screen (no rotation, etc.)

unTransformStroke

public void unTransformStroke(AffineTransform AffineTransform_Arg)
transform the points of the stroke so they become relative to the global frame then retransform with the given matrix. When in the new coordinate frame (for instance a DSFrame holding the stroke afterward) This function has to be used with paintTransformed after !


zoomTransformStroke

public void zoomTransformStroke(double ZoomFactor_Arg)
transform the points by changing the size and applying a zoom factor to all of them without modifying the point locations


translate

public void translate(int dx,
                      int dy)
translate all the point of the stroke


mirrorX

public void mirrorX(double xAxis)
mirror all the point of the stroke around a vertical line


mirrorY

public void mirrorY(double yAxis)
mirror all the point of the stroke around a horizontal line


paint

public void paint(Graphics graphics_arg)
Call the other paint(). The one by default. There are no 2 qualities of repaint for this element

Specified by:
paint in interface DSElement
Parameters:
graphics_arg - Description of the Parameter

getTransform

public AffineTransform getTransform()
Description copied from interface: DSElement
The matrix decribing how this element is transformed before rendering

Specified by:
getTransform in interface DSElement

paint

public void paint(Graphics2D graphics_Arg,
                  int quality_Arg)
Paint the stroke at a given quality level

Specified by:
paint in interface DSElement
Parameters:
graphics_Arg - a graphic context on the general component
quality_Arg - quality of the drawing

paintTransformed

public void paintTransformed(Graphics2D Graphics_Arg,
                             AffineTransform AffineTransform_Arg)
Paint the stroke with a given transformation (not the one using the internal d,alpha of the stroke)

Parameters:
Graphics_Arg - a graphic context on the general component

getFirstPoint

public DSPoint getFirstPoint()
Returns:
the first point of the Stroke

getPoint

public DSPoint getPoint(int index_arg)
Returns:
the index_arg th point of the Stroke

getSize

public double getSize(int index_arg)
Returns:
the index_arg th point'size of the Stroke

getTime

public long getTime(int index_arg)
Returns:
the index_arg th point'time of the Stroke

paintCurve

public void paintCurve(Graphics2D g,
                       Color color)
draw a nice curve along the points given in parameter as a vector.

Parameters:
g - the graphics to draw with.
color - the color of the curve

reset

public void reset()
Reset the stroke


erasePointsAround

public void erasePointsAround(Point pos,
                              double radius)
erase all the point close enough to the given position

Parameters:
pos - around what position we are going o erase points
radius - how far from the given position erasing will be effective

revealPoints

public void revealPoints(double size)
reveal the hidden points of the stroke (the ones with size 0)

Parameters:
size - the new size of the revealed portions

getNbPoints

public int getNbPoints()
return the number of points

Returns:
The nbPoints value

addPoint

public final void addPoint(DSPoint pos,
                           Float size,
                           long timestamp)
Add a point in the stroke

Parameters:
pos - The point to add to the list of points in the stroke

removeLastPoint

public void removeLastPoint()
remove the last point in the stroke


mousePressed

public void mousePressed(MouseEvent mouseEvent_Arg)
Handle a mouse event

Specified by:
mousePressed in interface MouseListener
Specified by:
mousePressed in interface DSElement
Parameters:
mouseEvent_Arg - Description of the Parameter

mouseDragged

public void mouseDragged(MouseEvent mouseEvent_Arg)
drag = one more point

Specified by:
mouseDragged in interface MouseMotionListener
Specified by:
mouseDragged in interface DSElement
Parameters:
mouseEvent_Arg - Description of the Parameter

mouseReleased

public void mouseReleased(MouseEvent event)
a last point for the road, close the polygon and notify dsTabletopPane

Specified by:
mouseReleased in interface MouseListener
Specified by:
mouseReleased in interface DSElement
Parameters:
event - Description of the Parameter

mouseMoved

public void mouseMoved(MouseEvent mouseEvent_Arg)
unused mouse callbacks

Specified by:
mouseMoved in interface MouseMotionListener
Specified by:
mouseMoved in interface DSElement
Parameters:
mouseEvent_Arg - Description of the Parameter

mouseClicked

public void mouseClicked(MouseEvent mouseEvent_Arg)
unused mouse callbacks

Specified by:
mouseClicked in interface MouseListener
Specified by:
mouseClicked in interface DSElement
Parameters:
mouseEvent_Arg - Description of the Parameter

mouseEntered

public void mouseEntered(MouseEvent mouseEvent_Arg)
unused mouse callbacks

Specified by:
mouseEntered in interface MouseListener
Parameters:
mouseEvent_Arg - Description of the Parameter

mouseExited

public void mouseExited(MouseEvent mouseEvent_Arg)
unused mouse callbacks

Specified by:
mouseExited in interface MouseListener
Parameters:
mouseEvent_Arg - Description of the Parameter

untransformPoint

public DSPoint untransformPoint(double x_Arg,
                                double y_Arg)
transform a point into local-cartesian coordinate system


doesContain

public boolean doesContain(double x_Arg,
                           double y_Arg)
Description of the Method.

Specified by:
doesContain in interface DSElement
Parameters:
x_Arg - the x axis coordinate of the point to test.
y_Arg - the y axis coordinate of the point to test.
Returns:
return true if the point is INSIDE the stroke.

moveElementCenterTo

public void moveElementCenterTo(Point2D.Double touchPoint)
can be used to make the element change its position to be centered under the given point

Specified by:
moveElementCenterTo in interface DSElement
Parameters:
touchPoint - (the cartesian point under which to center the element)

getAbsoluteScale

public double getAbsoluteScale()
Strokes ar not subject to scale and inner rotation

Specified by:
getAbsoluteScale in interface DSElement
Returns:
The absScale value

getScale

public double getScale()
Description copied from interface: DSElement
The degrees of freedom of the DSElements are their distance to the center, their angle comparing to the right direction (from center to the ful right), a scale (for zooming features) and

Specified by:
getScale in interface DSElement
Returns:
The scale value

setScale

public void setScale(double scale)
Description copied from interface: DSElement
The degrees of freedom of the DSElements are their distance to the center, their angle comparing to the right direction (from center to the ful right), a scale (for zooming features) and

Specified by:
setScale in interface DSElement
Parameters:
scale - The new scale value

getBeta

public double getBeta()
Description copied from interface: DSElement
The angle around its center

Specified by:
getBeta in interface DSElement
Returns:
The beta value

setBeta

public void setBeta(double beta)
Description copied from interface: DSElement
The angle around its center

Specified by:
setBeta in interface DSElement
Parameters:
beta - The new beta value

isBetaAbs

public boolean isBetaAbs()
Description copied from interface: DSElement
indicate how to use beta. if false beta is used as an extra angle around the element center. if true, beta is used to achieve such absolute angle for the top of the document

Specified by:
isBetaAbs in interface DSElement

setBetaAbs

public void setBetaAbs(boolean betaAbs)
Description copied from interface: DSElement
change how to use beta. if false beta is used as an extra angle around the element center. if true, beta is used to achieve such absolute angle for the top of the document

Specified by:
setBetaAbs in interface DSElement

setIDOwner

public void setIDOwner(int id)
set the user id of the owner of this object (-1 is no owner)

Specified by:
setIDOwner in interface DSElement
Parameters:
id - The new iDOwner value

getIDOwner

public int getIDOwner()
Gets the iDOwner attribute of the DSWindow object -1 means no owner

Specified by:
getIDOwner in interface DSElement
Returns:
The iDOwner value

isMouseTarget

public boolean isMouseTarget(MouseEvent mouseEvent_Arg)
the stroke can draw everywhere !

Specified by:
isMouseTarget in interface DSElement
Parameters:
mouseEvent_Arg - Description of the Parameter
Returns:
The mouseTarget value

grabElement

public boolean grabElement(int dx_Arg,
                           int dy_Arg)
The stroke cannot be dragged

Specified by:
grabElement in interface DSElement
Parameters:
dx_Arg - Description of the Parameter
dy_Arg - Description of the Parameter

addDSElementListener

public void addDSElementListener(DSElementListener DSElementListener_Arg)
we do not use this yet

Specified by:
addDSElementListener in interface DSElement
Parameters:
DSElementListener_Arg - The feature to be added to the DSElementListener attribute

removeDSElementListener

public void removeDSElementListener(DSElementListener DSElementListener_Arg)
Description copied from interface: DSElement
remove a listener

Specified by:
removeDSElementListener in interface DSElement
Parameters:
DSElementListener_Arg - Description of the Parameter

getWidth

public int getWidth()
Elements are displayed around their center (not around their top left corner) Width and Height are the amount of space used by the repaint. some pixels can be transparent anyway

Specified by:
getWidth in interface DSElement
Returns:
The height value

getHeight

public int getHeight()
Elements are displayed around their center (not around their top left corner) Width and Height are the amount of space used by the repaint. some pixels can be transparent anyway

Specified by:
getHeight in interface DSElement
Returns:
The height value

isActive

public boolean isActive()
Description copied from interface: DSElement
in the centralized architecture we have some elements are in the views and one or few element are handled directly by the DSTabletopPane as drag&dropped elements. the element have to know if they are selected (or active) to repaint differently. We didn't choose the word selected which can also be implemented independently in a view to select elements.

Specified by:
isActive in interface DSElement
Returns:
if the component is active or not (with shadow = is selected)

setActive

public void setActive(boolean active_Arg)
change if the component is active or not (with shadow = is selected)

Specified by:
setActive in interface DSElement
Parameters:
active_Arg - The new active value

setSize

public void setSize(int width_Arg,
                    int height_Arg)
do nothing because a stroke cannot be resized

Specified by:
setSize in interface DSElement
Parameters:
width_Arg - The new size value
height_Arg - The new size value

clone

public DSStroke clone()
duplicate this element

Overrides:
clone in class Object

acceptSlavery

public boolean acceptSlavery(DSElement dsElement)
obviously strokes can belong to other things

Specified by:
acceptSlavery in interface DSElement
Parameters:
dsElement - the possible master
Returns:
always true to tell it accept slavery

acceptSlaveryRelease

public boolean acceptSlaveryRelease()
tells if I accept to be released

Specified by:
acceptSlaveryRelease in interface DSElement
Returns:
always true

finish

public void finish()

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2006 Frederic Vernier(LIMSI) Chia Shen(MERL) Guillaume Besacier(LIMSI). All Rights Reserved.