chemaxon.struc.graphics
Class MPolyline

java.lang.Object
  extended bychemaxon.struc.MObject
      extended bychemaxon.struc.graphics.MPolyline
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
MEFlow, MRectangle

public class MPolyline
extends MObject

Polyline object.

Since:
Marvin 3.3, 10/03/2003
Version:
3.5, 11/04/2004
Author:
Peter Csizmadia
See Also:
Serialized Form

Field Summary
static int ARROW_BACK_FLAG
          Arrow points back.
static int ARROW_HALF_LEFT
          Only the left half of the arrow head is drawn.
static int ARROW_HALF_MASK
          Unshifted mask of the half arrow option bits in flags.
static int ARROW_HALF_RIGHT
          Only the right half of the arrow head is drawn.
static int CLOSED_FLAG
          Closed flag.
static double DEFAULT_THICKNESS
          Default line thickness.
static int HEAD
          Arrow head.
static int TAIL
          Arrow tail (feather).
static int THICKNESS_SET_FLAG
          Thickness is set flag.
 
Fields inherited from class chemaxon.struc.MObject
PAINT_ANTIALIAS, PAINT_FOCUSED, TRANSFORM_DISTORT
 
Constructor Summary
  MPolyline()
          Contructs an empty line.
protected MPolyline(boolean closed, java.awt.Color c, java.awt.Color bg)
          Creates a closed polyline.
  MPolyline(MPoint p1, MPoint p2)
          Contructs a line with the specified endpoints.
  MPolyline(MPoint p1, MPoint p2, java.awt.Color c, java.awt.Color bg)
          Contructs a line with the specified endpoints.
protected MPolyline(MPolyline l)
          Copy constructor.
  MPolyline(MPolyline l, MPoint p)
          Contructs a polyline from the specified starting polyline and endpoint.
 
Method Summary
 void addAttributeKeys(java.util.Vector v)
          Adds the attribute names to the specified vector.
 void calcCenter(DPoint3 p)
          Calculates the geometrical center.
 boolean checkValidity(MDocument doc, java.util.Vector invec)
          Is it a valid object in the document?
 java.lang.Object clone()
          Creates a clone.
 boolean containsAtom(MolAtom a)
          Checks if the atom set contains the specified atom object.
 void copyProperties(MPolyline l)
          Copies line properties to another line object.
 double distanceFrom(double x, double y, CTransform3D t)
          Gets the 2D distance from the specified point.
 void finishCloning(MDocument olddoc, MDocument newdoc)
          Finish cloning a document.
 double getArcAngle()
          Gets the central angle of the arc.
static DPoint3 getArcCenter(DPoint3 p1, DPoint3 p2, double angle)
          Returns the arc center.
 double getArcRadius()
          Gets the arc radius.
 int getArrowFlags(int i)
          Gets the arrow flags.
 double getArrowLength(int i)
          Gets the arrow head length.
 double getArrowWidth(int i)
          Gets the arrow head width.
 java.lang.String getAttribute(java.lang.String s)
          Gets the value of an attribute.
 int getFlags()
          Gets the flags.
 MPoint getPoint(int i)
          Gets a point of the line.
 int getPointCount()
          Gets the number of points.
 MPoint getPointRef(int i)
          Gets a point of the line.
 int getPointRefCount()
          Gets the number of point references.
 double getSkip(int i)
          Gets the distance of the (visible) head or tail from the corresponding line end point.
 double getThickness()
          Gets the line thickness.
 boolean hasBackground()
          A polyline has a background only if it is closed.
 boolean hasColor()
          A polyline does not have a non-line, non-background color.
 boolean hasFace()
          Is it 2 dimensional?
 boolean hasLineColor()
          A polyline have a line color always.
 boolean hasOutline()
          Does it have an outline?
 boolean isArrow()
          Checks if it is an arrow.
 boolean isEmpty()
          A polyline becomes empty if it has less than 2 points.
 boolean isThicknessSet()
          Checks if the line thickness is set.
 void paint(java.awt.Graphics g, CTransform3D t, int f, java.awt.Color c, java.awt.Color selc, java.awt.Color focusc)
          Paints the object.
 void removeChild(MObject o)
          Removes a child object.
 void replaceAtom(MolAtom orig, MolAtom a)
          Replaces a contained atom with another one.
 void setArcAngle(double phi)
          Sets the central angle of the arc.
 void setArrow(boolean v)
          Sets or unsets arrow mode.
 void setArrowFlags(int i, int f)
          Sets the flags.
 void setArrowLength(int i, double l)
          Sets the arrow head length.
 void setArrowWidth(int i, double l)
          Sets the arrow head width.
 void setAttribute(java.lang.String s, java.lang.String v)
          Sets the value of an attribute.
 void setFlags(int f)
          Sets the flags.
 void setPoints(MPoint[] p)
          Sets the points.
 void setSkip(int i, double d)
          Sets the distance of the (visible) head or tail from the corresponding line end point.
 void setThickness(double w)
          Sets the line thickness.
 void transform(CTransform3D t, int opts)
          Transforms all points, scales the arrow head widths and lengths.
 void unselectContents()
          Unselects the points.
 
Methods inherited from class chemaxon.struc.MObject
addCdataAttributeKeys, addNotify, distanceFrom, getBackground, getColor, getLineColor, isChildOf, isInternalSelectable, isSelectableNow, isSelected, isTransformable, makeColor, makeColorString, removeNotify, setBackground, setColor, setLineColor, setSelected
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_THICKNESS

public static double DEFAULT_THICKNESS
Default line thickness.

Since:
Marvin 3.4, 06/09/2004

TAIL

public static int TAIL
Arrow tail (feather).

Since:
Marvin 3.5, 06/30/2004
See Also:
getArrowLength(int), getArrowWidth(int)

HEAD

public static int HEAD
Arrow head.

Since:
Marvin 3.5, 06/30/2004
See Also:
getArrowLength(int), getArrowWidth(int)

CLOSED_FLAG

public static int CLOSED_FLAG
Closed flag.

Since:
Marvin 3.5, 06/30/2004

THICKNESS_SET_FLAG

public static int THICKNESS_SET_FLAG
Thickness is set flag.

Since:
Marvin 3.5, 06/30/2004

ARROW_BACK_FLAG

public static int ARROW_BACK_FLAG
Arrow points back.

Since:
Marvin 3.5, 07/02/2004

ARROW_HALF_MASK

public static int ARROW_HALF_MASK
Unshifted mask of the half arrow option bits in flags.

Since:
Marvin 3.5, 07/01/2004

ARROW_HALF_LEFT

public static int ARROW_HALF_LEFT
Only the left half of the arrow head is drawn.

Since:
Marvin 3.5, 07/01/2004

ARROW_HALF_RIGHT

public static int ARROW_HALF_RIGHT
Only the right half of the arrow head is drawn.

Since:
Marvin 3.5, 07/01/2004
Constructor Detail

MPolyline

public MPolyline()
Contructs an empty line.


MPolyline

public MPolyline(MPoint p1,
                 MPoint p2)
Contructs a line with the specified endpoints.

Parameters:
p1 - the starting point
p2 - the endpoint

MPolyline

public MPolyline(MPoint p1,
                 MPoint p2,
                 java.awt.Color c,
                 java.awt.Color bg)
Contructs a line with the specified endpoints.

Parameters:
p1 - the starting point
p2 - the endpoint
c - the color
bg - the background color

MPolyline

protected MPolyline(boolean closed,
                    java.awt.Color c,
                    java.awt.Color bg)
Creates a closed polyline.

Parameters:
closed - the polyline is closed if true, open otherwise
c - the color
bg - the background color

MPolyline

protected MPolyline(MPolyline l)
Copy constructor.

Parameters:
l - the original polyline

MPolyline

public MPolyline(MPolyline l,
                 MPoint p)
Contructs a polyline from the specified starting polyline and endpoint.

Parameters:
l - the starting polyline
p - the new endpoint
Method Detail

copyProperties

public void copyProperties(MPolyline l)
Copies line properties to another line object.

Parameters:
l - the other line
Since:
Marvin 3.5, 07/13/2004

isArrow

public boolean isArrow()
Checks if it is an arrow.

Returns:
true if the line has an arrow head or tail, false otherwise
Since:
Marvin 3.5, 06/30/2004

setArrow

public void setArrow(boolean v)
Sets or unsets arrow mode.

Parameters:
v - true to make an arrow from the line, false to remove arrow properties
Since:
Marvin 3.5, 06/30/2004

setPoints

public void setPoints(MPoint[] p)
Sets the points.

Parameters:
p - the points

clone

public java.lang.Object clone()
Description copied from class: MObject
Creates a clone.

Specified by:
clone in class MObject
Returns:
the clone

getFlags

public int getFlags()
Gets the flags.

Since:
Marvin 3.5, 06/30/2004
See Also:
CLOSED_FLAG, THICKNESS_SET_FLAG

setFlags

public void setFlags(int f)
Sets the flags.

Since:
Marvin 3.5, 06/30/2004
See Also:
CLOSED_FLAG, THICKNESS_SET_FLAG

getArrowFlags

public int getArrowFlags(int i)
Gets the arrow flags.

Since:
Marvin 3.5, 07/01/2004

setArrowFlags

public void setArrowFlags(int i,
                          int f)
Sets the flags.

Since:
Marvin 3.5, 07/01/2004

getSkip

public double getSkip(int i)
Gets the distance of the (visible) head or tail from the corresponding line end point.

Parameters:
i - HEAD or TAIL
Returns:
the skip value
Since:
Marvin 3.5, 07/15/2004

setSkip

public void setSkip(int i,
                    double d)
Sets the distance of the (visible) head or tail from the corresponding line end point.

Parameters:
i - HEAD or TAIL
d - the skip value
Since:
Marvin 3.5, 07/15/2004

hasColor

public boolean hasColor()
A polyline does not have a non-line, non-background color.

Overrides:
hasColor in class MObject
Returns:
false

hasLineColor

public boolean hasLineColor()
A polyline have a line color always.

Overrides:
hasLineColor in class MObject
Returns:
true

hasBackground

public boolean hasBackground()
A polyline has a background only if it is closed.

Overrides:
hasBackground in class MObject
Returns:
true if closed

isThicknessSet

public boolean isThicknessSet()
Checks if the line thickness is set. If it is not set, then the default value is used.

Returns:
true if thickness is set, false otherwise
Since:
Marvin 3.4, 06/09/2004
See Also:
DEFAULT_THICKNESS

getThickness

public double getThickness()
Gets the line thickness.

Returns:
the line thickness
Since:
Marvin 3.4, 06/09/2004

setThickness

public void setThickness(double w)
Sets the line thickness.

Parameters:
w - thickness value or 0 to use default
Since:
Marvin 3.4, 06/09/2004

getArcAngle

public double getArcAngle()
Gets the central angle of the arc.

Returns:
the central angle of the arc or zero if the line is linear.
Since:
Marvin 3.5, 07/02/2004

setArcAngle

public void setArcAngle(double phi)
Sets the central angle of the arc.

Parameters:
phi - the central angle of the arc, zero makes the line linear
Since:
Marvin 3.5, 07/02/2004

getArcRadius

public double getArcRadius()
Gets the arc radius.

Returns:
the radius
Since:
Marvin 3.5, 07/16/2004

getArrowLength

public double getArrowLength(int i)
Gets the arrow head length.

Parameters:
i - HEAD or TAIL
Returns:
the arrow head length
Since:
Marvin 3.5, 06/30/2004

setArrowLength

public void setArrowLength(int i,
                           double l)
Sets the arrow head length.

Parameters:
i - HEAD or TAIL
l - the head length
Since:
Marvin 3.5, 06/30/2004

getArrowWidth

public double getArrowWidth(int i)
Gets the arrow head width.

Parameters:
i - HEAD or TAIL
Returns:
the arrow head width
Since:
Marvin 3.5, 06/30/2004

setArrowWidth

public void setArrowWidth(int i,
                          double l)
Sets the arrow head width.

Parameters:
i - HEAD or TAIL
l - the head width
Since:
Marvin 3.5, 06/30/2004

getPointCount

public int getPointCount()
Gets the number of points.

Specified by:
getPointCount in class MObject
Returns:
the number of points (at least 2)

getPoint

public MPoint getPoint(int i)
Gets a point of the line.

Specified by:
getPoint in class MObject
Parameters:
i - the point index
Returns:
the point's clone

getPointRefCount

public int getPointRefCount()
Gets the number of point references.

Overrides:
getPointRefCount in class MObject
Returns:
the number of points (same value as the getPointCount() function)

getPointRef

public MPoint getPointRef(int i)
Gets a point of the line.

Overrides:
getPointRef in class MObject
Parameters:
i - the point index
Returns:
the point's reference

transform

public void transform(CTransform3D t,
                      int opts)
Transforms all points, scales the arrow head widths and lengths.

Specified by:
transform in class MObject
Parameters:
t - the transformation matrix
opts - transform options or 0
See Also:
MObject.TRANSFORM_DISTORT

unselectContents

public void unselectContents()
Unselects the points.

Overrides:
unselectContents in class MObject

calcCenter

public void calcCenter(DPoint3 p)
Calculates the geometrical center.

Specified by:
calcCenter in class MObject
Parameters:
p - store the coordinates here

distanceFrom

public double distanceFrom(double x,
                           double y,
                           CTransform3D t)
Gets the 2D distance from the specified point.

Specified by:
distanceFrom in class MObject
Parameters:
x - the x coordinate
y - the y coordinate
t - transformation or null
Since:
3.5, 11/04/2004

paint

public void paint(java.awt.Graphics g,
                  CTransform3D t,
                  int f,
                  java.awt.Color c,
                  java.awt.Color selc,
                  java.awt.Color focusc)
Paints the object.

Overrides:
paint in class MObject
Parameters:
g - the graphics context
t - the transformation matrix
f - flags
c - the color to use or null
selc - the selection color
focusc - the focus color

getArcCenter

public static DPoint3 getArcCenter(DPoint3 p1,
                                   DPoint3 p2,
                                   double angle)
Returns the arc center. For internal use only.

Parameters:
p1 - the first arc endpoint
p2 - the second arc endpoint
angle - the arc angle (degrees)
Returns:
the arc center
Since:
Marvin 3.5.1

isEmpty

public boolean isEmpty()
A polyline becomes empty if it has less than 2 points.

Overrides:
isEmpty in class MObject
Returns:
true if empty, false otherwise

hasOutline

public boolean hasOutline()
Does it have an outline?

Returns:
true if the color is not null or the object does not have a face

hasFace

public boolean hasFace()
Is it 2 dimensional?

Returns:
true if closed and it has a background color, false otherwise

removeChild

public void removeChild(MObject o)
Description copied from class: MObject
Removes a child object.

Overrides:
removeChild in class MObject
Parameters:
o - the child

addAttributeKeys

public void addAttributeKeys(java.util.Vector v)
Adds the attribute names to the specified vector.

Overrides:
addAttributeKeys in class MObject
Parameters:
v - the vector
Since:
Marvin 3.4, 06/09/2004

getAttribute

public java.lang.String getAttribute(java.lang.String s)
Gets the value of an attribute.

Overrides:
getAttribute in class MObject
Parameters:
s - the attribute name
Returns:
the value or null
Since:
Marvin 3.4, 06/09/2004

setAttribute

public void setAttribute(java.lang.String s,
                         java.lang.String v)
Sets the value of an attribute.

Overrides:
setAttribute in class MObject
Parameters:
s - the attribute name
v - the attribute value
Since:
Marvin 3.4, 07/01/2004

containsAtom

public boolean containsAtom(MolAtom a)
Checks if the atom set contains the specified atom object.

Overrides:
containsAtom in class MObject
Returns:
true if the atom set contains the specified object, false otherwise
Since:
Marvin 3.5, 07/04/2004

replaceAtom

public void replaceAtom(MolAtom orig,
                        MolAtom a)
Replaces a contained atom with another one.

Overrides:
replaceAtom in class MObject
Parameters:
orig - the original atom
a - the new atom
Since:
Marvin 3.5, 07/04/2004

checkValidity

public boolean checkValidity(MDocument doc,
                             java.util.Vector invec)
Is it a valid object in the document?

Overrides:
checkValidity in class MObject
Parameters:
doc - the document
invec - vector for invalid atoms or null
Returns:
true if the object is valid, false if it contains an invalid point
Since:
Marvin 3.5, 07/06/2004

finishCloning

public void finishCloning(MDocument olddoc,
                          MDocument newdoc)
Finish cloning a document.

Overrides:
finishCloning in class MObject
Since:
Marvin 3.5, 07/02/2004