net.sf.latexdraw.glib.models.impl
Class LAbstractCtrlPointShape

java.lang.Object
  extended by net.sf.latexdraw.glib.models.impl.LShape
      extended by net.sf.latexdraw.glib.models.impl.LModifiablePointsShape
          extended by net.sf.latexdraw.glib.models.impl.LAbstractCtrlPointShape
All Implemented Interfaces:
IArrowable, IControlPointShape, IModifiablePointsShape, IShape, Modifiable
Direct Known Subclasses:
LBezierCurve

abstract class LAbstractCtrlPointShape
extends LModifiablePointsShape
implements IControlPointShape

Defines a model of a abstract shape that contains control points.

This file is part of LaTeXDraw.
Copyright (c) 2005-2012 Arnaud BLOUIN

LaTeXDraw is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
LaTeXDraw is distributed without any warranty; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

07/05/2009

Since:
3.0
Version:
3.0
Author:
Arnaud BLOUIN

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.sf.latexdraw.glib.models.interfaces.IShape
IShape.BorderPos, IShape.FillingStyle, IShape.LineStyle, IShape.Position
 
Field Summary
protected  int balanceGap
          Define the gap between a control point and its point in pixel when using balance() method.
protected  java.util.List<IPoint> firstCtrlPts
          This vector contains the points which allows to change the angles of the curves
protected  java.util.List<IPoint> secondCtrlPts
          Contains the second control points of each points; useful for closed curve.
 
Fields inherited from class net.sf.latexdraw.glib.models.impl.LShape
arrows, bordersPosition, dashSepBlack, dashSepWhite, dbleBordCol, dbleBordSep, dotSep, fillingCol, fillingStyle, gradAngle, gradColEnd, gradColStart, gradMidPt, hasDbleBord, hasShadow, hatchingsAngle, hatchingsCol, hatchingsSep, hatchingsWidth, id, lineColour, lineStyle, modified, opacity, points, rotationAngle, shadowAngle, shadowCol, shadowSize, showPts, thickness
 
Fields inherited from interface net.sf.latexdraw.glib.models.interfaces.IControlPointShape
DEFAULT_BALANCE_GAP, DEFAULT_POSITION_CTRL
 
Fields inherited from interface net.sf.latexdraw.glib.models.interfaces.IShape
GOLDEN_ANGLE, PPC
 
Constructor Summary
LAbstractCtrlPointShape(boolean uniqueID)
          Creates the shape.
 
Method Summary
 void addPoint(IPoint pt, int position)
          Adds the given point to the points list at the given position.
 void balance()
          Balances all the control points in order the create a rounded shape.
 void copy(IShape sh)
          Copies a shape using another.
protected  void copyPoints(IShape sh)
           
private  IPoint[] getBalancedPoints(IPoint pt, IPoint prevPt, IPoint nextPt)
          Method used by the balance method.
 int getBalanceGap()
           
 IPoint getFirstCtrlPtAt(int position)
           
 java.util.List<IPoint> getFirstCtrlPts()
           
 IPoint getSecondCtrlPtAt(int position)
           
 java.util.List<IPoint> getSecondCtrlPts()
           
 IPoint removePoint(int position)
          Removes the point at the given position.
 boolean removePoint(IPoint pt)
          Removes the given point of the shape.
 IPoint replacePoint(IPoint pt, int position)
          Replaces the point at the given position by the given point.
 void scale(double x, double y, IShape.Position pos, java.awt.geom.Rectangle2D bound)
          Scales the shape where the move reference point is the bottom right point, and the fixation point the top left point.
 void setBalanceGap(int balanceGap)
           
private  void setControlPoints(int position, IPoint[] ctrlPts)
          Method used by the balance method.
 boolean setPoint(double x, double y, int position)
          Sets the point at the given position to the given coordinate.
 void setXFirstCtrlPt(double x, int id)
          Sets the X-coordinate of one of the first control point.
 void setXSecondCtrlPt(double x, int id)
          Sets the X-coordinate of one of the second control point.
 void setYFirstCtrlPt(double y, int id)
          Sets the Y-coordinate of one of the first control point.
 void setYSecondCtrlPt(double y, int id)
          Sets the Y-coordinate of one of the second control point.
 void translate(double tx, double ty)
          Translates the shape.
 void updateSecondControlPoints()
          Updates the second control points by using the first control points.
 
Methods inherited from class net.sf.latexdraw.glib.models.impl.LModifiablePointsShape
addPoint, setPoint
 
Methods inherited from class net.sf.latexdraw.glib.models.impl.LShape
addToRotationAngle, copyArrows, duplicate, getArrowAt, getArrowInset, getArrowLength, getArrowLine, getArrows, getArrowSizeDim, getArrowSizeNum, getArrowStyle, getBorderGap, getBordersPosition, getBottomLeftPoint, getBottomRightPoint, getBracketNum, getDashSepBlack, getDashSepWhite, getDbleBordCol, getDbleBordSep, getDotSep, getDotSizeDim, getDotSizeNum, getFillingCol, getFillingStyle, getFullBottomRightPoint, getFullTopLeftPoint, getGradAngle, getGradColEnd, getGradColStart, getGradMidPt, getGravityCentre, getHatchingsAngle, getHatchingsCol, getHatchingsSep, getHatchingsWidth, getId, getLineColour, getLineStyle, getNbPoints, getOpacity, getPoints, getPtAt, getRBracketNum, getRotationAngle, getShadowAngle, getShadowCol, getShadowGap, getShadowSize, getTBarSizeDim, getTBarSizeNum, getThickness, getTopLeftPoint, getTopRightPoint, hasDbleBord, hasGradient, hasHatchings, hasShadow, isArrowable, isBordersMovable, isColourable, isDbleBorderable, isFillable, isFilled, isInteriorStylable, isLineStylable, isModified, isParametersEquals, isShadowable, isShowPts, isShowPtsable, isThicknessable, mirrorHorizontal, mirrorVertical, rotate, scaleSetPoints, setArrowInset, setArrowLength, setArrowSizeDim, setArrowSizeNum, setArrowStyle, setBordersPosition, setBracketNum, setDashSepBlack, setDashSepWhite, setDbleBordCol, setDbleBordSep, setDotSep, setDotSizeDim, setDotSizeNum, setFilled, setFillingCol, setFillingStyle, setGradAngle, setGradColEnd, setGradColStart, setGradMidPt, setHasDbleBord, setHasShadow, setHatchingsAngle, setHatchingsCol, setHatchingsSep, setHatchingsWidth, setId, setLineColour, setLineStyle, setModified, setNewId, setOpacity, setRBracketNum, setRotationAngle, setShadowAngle, setShadowCol, setShadowSize, setShowPts, setTBarSizeDim, setTBarSizeNum, setThickness, shadowFillsShape
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.latexdraw.glib.models.interfaces.IModifiablePointsShape
addPoint, setPoint
 
Methods inherited from interface net.sf.latexdraw.glib.models.interfaces.IShape
addToRotationAngle, duplicate, getArrowAt, getArrowLine, getArrows, getArrowStyle, getBorderGap, getBordersPosition, getBottomLeftPoint, getBottomRightPoint, getDashSepBlack, getDashSepWhite, getDbleBordCol, getDbleBordSep, getDotSep, getFillingCol, getFillingStyle, getFullBottomRightPoint, getFullTopLeftPoint, getGradAngle, getGradColEnd, getGradColStart, getGradMidPt, getGravityCentre, getHatchingsAngle, getHatchingsCol, getHatchingsSep, getHatchingsWidth, getId, getLineColour, getLineStyle, getNbPoints, getOpacity, getPoints, getPtAt, getRotationAngle, getShadowAngle, getShadowCol, getShadowGap, getShadowSize, getThickness, getTopLeftPoint, getTopRightPoint, hasDbleBord, hasGradient, hasHatchings, hasShadow, isArrowable, isBordersMovable, isColourable, isDbleBorderable, isFillable, isFilled, isInteriorStylable, isLineStylable, isParametersEquals, isShadowable, isShowPts, isShowPtsable, isThicknessable, mirrorHorizontal, mirrorVertical, rotate, setArrowStyle, setBordersPosition, setDashSepBlack, setDashSepWhite, setDbleBordCol, setDbleBordSep, setDotSep, setFilled, setFillingCol, setFillingStyle, setGradAngle, setGradColEnd, setGradColStart, setGradMidPt, setHasDbleBord, setHasShadow, setHatchingsAngle, setHatchingsCol, setHatchingsSep, setHatchingsWidth, setId, setLineColour, setLineStyle, setNewId, setOpacity, setRotationAngle, setShadowAngle, setShadowCol, setShadowSize, setShowPts, setThickness, shadowFillsShape
 
Methods inherited from interface org.malai.properties.Modifiable
isModified, setModified
 
Methods inherited from interface net.sf.latexdraw.glib.models.interfaces.IArrowable
getArrowInset, getArrowLength, getArrowSizeDim, getArrowSizeNum, getBracketNum, getDotSizeDim, getDotSizeNum, getRBracketNum, getTBarSizeDim, getTBarSizeNum, setArrowInset, setArrowLength, setArrowSizeDim, setArrowSizeNum, setBracketNum, setDotSizeDim, setDotSizeNum, setRBracketNum, setTBarSizeDim, setTBarSizeNum
 

Field Detail

firstCtrlPts

protected java.util.List<IPoint> firstCtrlPts
This vector contains the points which allows to change the angles of the curves


secondCtrlPts

protected java.util.List<IPoint> secondCtrlPts
Contains the second control points of each points; useful for closed curve.


balanceGap

protected int balanceGap
Define the gap between a control point and its point in pixel when using balance() method.

Constructor Detail

LAbstractCtrlPointShape

public LAbstractCtrlPointShape(boolean uniqueID)
Creates the shape.

Parameters:
uniqueID - True: the model will have a unique ID.
Method Detail

scale

public void scale(double x,
                  double y,
                  IShape.Position pos,
                  java.awt.geom.Rectangle2D bound)
Description copied from interface: IShape
Scales the shape where the move reference point is the bottom right point, and the fixation point the top left point.

Specified by:
scale in interface IShape
Overrides:
scale in class LShape
Parameters:
x - The X scale factor, in ]0,double].
y - The Y scale factor, in ]0,double].
pos - The position of the reference point: if the reference point is top-left point, then the scale will extend or reduce the shape at the bottom-right point. If the reference position is NORTH or SOUTH the sx parameter will not be used. If it is EAST or WEST the sy parameter will not be used.
bound - The bound (e.g. the border of the selected shapes) used to compute the scaling.

getBalanceGap

public int getBalanceGap()
Specified by:
getBalanceGap in interface IControlPointShape
Returns:
the balanceGap.

setBalanceGap

public void setBalanceGap(int balanceGap)
Specified by:
setBalanceGap in interface IControlPointShape
Parameters:
balanceGap - the balanceGap to set.

getBalancedPoints

private IPoint[] getBalancedPoints(IPoint pt,
                                   IPoint prevPt,
                                   IPoint nextPt)
Method used by the balance method. Just returns the balanced control points of the given points.


setControlPoints

private void setControlPoints(int position,
                              IPoint[] ctrlPts)
Method used by the balance method. Just sets the given control points at the given position.


balance

public void balance()
Description copied from interface: IControlPointShape
Balances all the control points in order the create a rounded shape.

Specified by:
balance in interface IControlPointShape

getFirstCtrlPtAt

public IPoint getFirstCtrlPtAt(int position)
Specified by:
getFirstCtrlPtAt in interface IControlPointShape
Parameters:
position - The position of the wanted points (-1 for the last point).
Returns:
The first control point at the given position or null if the position is not valid.

getFirstCtrlPts

public java.util.List<IPoint> getFirstCtrlPts()
Specified by:
getFirstCtrlPts in interface IControlPointShape
Returns:
the firstCtrlPts.

getSecondCtrlPtAt

public IPoint getSecondCtrlPtAt(int position)
Specified by:
getSecondCtrlPtAt in interface IControlPointShape
Parameters:
position - The position of the wanted points (-1 for the last point).
Returns:
The second control point at the given position or null if the position is not valid.

getSecondCtrlPts

public java.util.List<IPoint> getSecondCtrlPts()
Specified by:
getSecondCtrlPts in interface IControlPointShape
Returns:
the secondCtrlPts.

setXFirstCtrlPt

public void setXFirstCtrlPt(double x,
                            int id)
Description copied from interface: IControlPointShape
Sets the X-coordinate of one of the first control point.

Specified by:
setXFirstCtrlPt in interface IControlPointShape
Parameters:
x - The new X-coordinate.
id - The position of the point to set.

setXSecondCtrlPt

public void setXSecondCtrlPt(double x,
                             int id)
Description copied from interface: IControlPointShape
Sets the X-coordinate of one of the second control point.

Specified by:
setXSecondCtrlPt in interface IControlPointShape
Parameters:
x - The new X-coordinate.
id - The position of the point to set.

setYFirstCtrlPt

public void setYFirstCtrlPt(double y,
                            int id)
Description copied from interface: IControlPointShape
Sets the Y-coordinate of one of the first control point.

Specified by:
setYFirstCtrlPt in interface IControlPointShape
Parameters:
y - The new Y-coordinate.
id - The position of the point to set.

setYSecondCtrlPt

public void setYSecondCtrlPt(double y,
                             int id)
Description copied from interface: IControlPointShape
Sets the Y-coordinate of one of the second control point.

Specified by:
setYSecondCtrlPt in interface IControlPointShape
Parameters:
y - The new Y-coordinate.
id - The position of the point to set.

updateSecondControlPoints

public void updateSecondControlPoints()
Description copied from interface: IControlPointShape
Updates the second control points by using the first control points.

Specified by:
updateSecondControlPoints in interface IControlPointShape

setPoint

public boolean setPoint(double x,
                        double y,
                        int position)
Description copied from interface: IModifiablePointsShape
Sets the point at the given position to the given coordinate.

Specified by:
setPoint in interface IModifiablePointsShape
Overrides:
setPoint in class LModifiablePointsShape
Parameters:
x - The new X-coordinate. The model is not updated!
y - The new Y-coordinate.
position - The position of the point to move in the points list (-1 corresponds to the last point).
Returns:
true if the operation is successful.

removePoint

public boolean removePoint(IPoint pt)
Description copied from interface: IModifiablePointsShape
Removes the given point of the shape.

Specified by:
removePoint in interface IModifiablePointsShape
Overrides:
removePoint in class LModifiablePointsShape
Parameters:
pt - The point to remove.
Returns:
True if the point is removed. False otherwise.

removePoint

public IPoint removePoint(int position)
Description copied from interface: IModifiablePointsShape
Removes the point at the given position.

Specified by:
removePoint in interface IModifiablePointsShape
Overrides:
removePoint in class LModifiablePointsShape
Parameters:
position - The position of the point to remove (-1 corresponds to the last point).
Returns:
The removed point or null.

replacePoint

public IPoint replacePoint(IPoint pt,
                           int position)
Description copied from interface: IModifiablePointsShape
Replaces the point at the given position by the given point.

Specified by:
replacePoint in interface IModifiablePointsShape
Overrides:
replacePoint in class LModifiablePointsShape
Parameters:
pt - The new point. Must not be a point of the shape.
position - The position of the point to remove (-1 corresponds to the last point).
Returns:
The removed point or null.

addPoint

public void addPoint(IPoint pt,
                     int position)
Description copied from interface: IModifiablePointsShape
Adds the given point to the points list at the given position. The model is not updated!

Specified by:
addPoint in interface IModifiablePointsShape
Overrides:
addPoint in class LModifiablePointsShape
Parameters:
pt - The point to add.
position - The position of insertion (-1 corresponds to the last point).

copyPoints

protected void copyPoints(IShape sh)
Overrides:
copyPoints in class LShape

translate

public void translate(double tx,
                      double ty)
Description copied from interface: IShape
Translates the shape.

Specified by:
translate in interface IShape
Overrides:
translate in class LShape
Parameters:
tx - The X translation.
ty - The Y translation.

copy

public void copy(IShape sh)
Description copied from interface: IShape
Copies a shape using another.

Specified by:
copy in interface IShape
Overrides:
copy in class LShape
Parameters:
sh - The shape to copy.