org.jscience.chemistry.gui.extended.molecule
Class Renderer

java.lang.Object
  extended by org.jscience.chemistry.gui.extended.molecule.Renderer
All Implemented Interfaces:
IRenderer

public class Renderer
extends java.lang.Object
implements IRenderer

An implementation of a JViewer's renderer interface for drawing and manipulating a Molecule.

See Also:
IRenderer

Field Summary
protected  float AB_DEV
          Aromatic bond separation
static int ALL_ATOMS_ONE_COLOR
          DOCUMENT ME!
protected  java.awt.Color atombg
          Color of default atom background
protected  java.awt.Font atomFont
          Font to display atom labels
protected  java.awt.Color bondColor
          Default color to display bonds
static int COLOR_BY_ATOM_TYPE
          Coloring scheme constants
protected  int colorScheme
          draw atom color according to which coloring scheme
protected  float DB_DEV
          Double bond separation
protected  float findRadius
          Upper bound of the distance (in pixel) between an atom (or bond) and the pick-location if the atom (or bond) is considered picked
protected  java.awt.Color highlightColor
          Color to display highlighted atoms
protected  int hTreatment
          Flag indicating how to handle the display of hydrogens
protected  Molecule mol
          molecule to be drawn
static int PICK_ATOM_FIRST
          Indicate the atom is preferred picked object when an atom and a bond both lie close enough to a single-picking location
static int PICK_ATOM_ONLY
          Indicate only atoms are pickable, bond picking is not interested
static int PICK_BOND_FIRST
          Indicate the bond is preferred picked object when an atom and a bond both lie close enough to a single-picking location
static int PICK_BOND_ONLY
          Indicate only bonds are pickable, atom picking is not interested
protected  boolean pickHiddenAtom
          Indicate whether hidden atoms are pickable
protected  boolean pickHiddenBond
          Indicate whether hidden atoms are pickable
 int pickPreference
          Indicate the picking preference is on atom, bond or distance
protected  java.awt.Color selectColor
          Color to display selected atoms
static int SHORTEST_WIN
          Indicate distance is used to break the tie when an atom and a bond both lie close enough to a single-picking locaition
static int SHOW_ALL_H
          Display all hydrogens
static int SHOW_NO_H
          Don't display any hydrogens
static int SHOW_NON_C_H
          Display hydrogens not attached to carbons
protected  boolean showAtomLabels
          Indicates whether atom labels should be displayed
protected  float TB_DEV
          Triple bond separation
protected  float WB_DEV
          Wedge bond separation
 
Constructor Summary
Renderer()
          Default constructor
Renderer(Molecule mol)
          Constructor
Renderer(Renderer r)
          Copy constructor
 
Method Summary
 java.lang.Object copy()
          DOCUMENT ME!
 void draw(java.awt.Graphics g)
          Draw the Molecule.
protected  void drawAnyBond(java.awt.Graphics g, java.awt.Color c1, java.awt.Color c2, float x1, float y1, float x2, float y2)
          Draws an any bond
protected  void drawAromaticBond(java.awt.Graphics g, java.awt.Color c1, java.awt.Color c2, float x1, float y1, float x2, float y2)
          Draws an aromatic bond
 void drawAtom(java.awt.Graphics g, Atom a)
          Draws an atom.
 void drawBond(java.awt.Graphics g, Bond b)
          Draws a bond
protected  void drawDashBond(java.awt.Graphics g, float x1, float y1, float x2, float y2)
          Draws a dashed wedge bond (assumes black & white)
protected  void drawSingleBond(java.awt.Graphics g, java.awt.Color c1, java.awt.Color c2, float x1, float y1, float x2, float y2)
          Draws a single bond
protected  void drawWedgeBond(java.awt.Graphics g, float x1, float y1, float x2, float y2)
          Draws a wedge bond
 Atom findAtom(float tx, float ty)
           
 void findAtoms(java.awt.Polygon pickPolygon, java.util.Vector resultVector)
          Find a list of atoms within the given polygon
 Bond findBond(float tx, float ty)
           
 void findBonds(java.awt.Polygon pickPolygon, java.util.Vector resultVector)
          Find a list of bonds within the given polygon
 java.lang.Object findObject(float tx, float ty)
          Find an object given location
 java.util.Vector findObjects(java.awt.Polygon pickPolygon)
          Return a list of objects that are within the given polygon
 float getAB_DEV()
          Return aromatic bond separation
 java.awt.Color getAtombg()
          Return atom background color
 java.awt.Font getAtomFont()
          Return atom font
 float[] getBBox()
          Return the bounding box of the Molecule.
 java.awt.Color getBondColor()
          Return bond color
 boolean getColorByAtomType()
          Return flag that indicates whether to paint the atom according to its type
 int getColorScheme()
          Return color scheme
 float getDB_DEV()
          Return double bond separation
 java.awt.Color getHighlightColor()
          Return color to paint hightlighted atoms
 int getHTreatment()
          Return hydrogen treatment
 Molecule getMol()
          Return the molecule.
 boolean getPickHiddenAtom()
           
 boolean getPickHiddenBond()
           
 java.awt.Color getSelectColor()
          Return color to paint selected atoms
 boolean getShowAtomLabels()
          Return flag that indicates whether atom labels should display
 float getTB_DEV()
          Return triple bond separation
 float getWB_DEV()
          Return wedge bond separation
 boolean isHidden(Atom atom)
           
 void matMult(Matrix3D rhs)
          Multiply the Molecule's transformation matrix by the matrix specified.
 void matScale(float xf, float yf, float zf)
          Apply the specified scale to the Molecule's transformation matrix.
 void matTransform()
          Apply the Molecule's transformation matrix to its atoms.
 void matTranslate(float xt, float yt, float zt)
          Apply the specified translation to the Molecule's transformation matrix.
 void matUnit()
          Reset the Molecule's transformation matrix to the identity matrix.
 void setAB_DEV(float abDev)
          Set aromatic bond separation
 void setAtombg(java.awt.Color color)
          Set atom background color
 void setAtomFont(java.awt.Font font)
          Set atom font
 void setBondColor(java.awt.Color color)
          Set bond color
 void setColorByAtomType(boolean bool)
          Set flag to indicate whether to paint the atom according to its type As data member colorByAtomType, this method is redundent, but is kept to be compatible with pre-existing code
 void setColorScheme(int colorScheme)
          Set color scheme
 void setDB_DEV(float dbDev)
          Set double bond separation
 void setFindRadius(float findRadius)
          Set the findRadius
 void setHighlightColor(java.awt.Color color)
          Set color to paint hightlighted atoms
 void setHTreatment(int hTreatment)
          Set hydrogen treatment
 void setMol(Molecule mol)
          Set the molecule
 void setPickHiddenAtom(boolean pickHiddenAtom)
          Set the policy whether hidden atoms are pickable
 void setPickHiddenBond(boolean pickHiddenBond)
          Set the policy whether hidden bonds are pickable
 void setPickPreference(int pickPreference)
          Set the pickPreference policy
 void setSelectColor(java.awt.Color color)
          Set color to paint selected atoms
 void setShowAtomLabels(boolean bool)
          Set flag to indicate whether atom labels should display or not
 void setTB_DEV(float tbDev)
          Set triple bond separation
 void setWB_DEV(float wbDev)
          Set wedge bond separation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHOW_ALL_H

public static final int SHOW_ALL_H
Display all hydrogens

See Also:
Constant Field Values

SHOW_NO_H

public static final int SHOW_NO_H
Don't display any hydrogens

See Also:
Constant Field Values

SHOW_NON_C_H

public static final int SHOW_NON_C_H
Display hydrogens not attached to carbons

See Also:
Constant Field Values

COLOR_BY_ATOM_TYPE

public static final int COLOR_BY_ATOM_TYPE
Coloring scheme constants

See Also:
Constant Field Values

ALL_ATOMS_ONE_COLOR

public static final int ALL_ATOMS_ONE_COLOR
DOCUMENT ME!

See Also:
Constant Field Values

PICK_ATOM_FIRST

public static final int PICK_ATOM_FIRST
Indicate the atom is preferred picked object when an atom and a bond both lie close enough to a single-picking location

See Also:
Constant Field Values

PICK_BOND_FIRST

public static final int PICK_BOND_FIRST
Indicate the bond is preferred picked object when an atom and a bond both lie close enough to a single-picking location

See Also:
Constant Field Values

SHORTEST_WIN

public static final int SHORTEST_WIN
Indicate distance is used to break the tie when an atom and a bond both lie close enough to a single-picking locaition

See Also:
Constant Field Values

PICK_ATOM_ONLY

public static final int PICK_ATOM_ONLY
Indicate only atoms are pickable, bond picking is not interested

See Also:
Constant Field Values

PICK_BOND_ONLY

public static final int PICK_BOND_ONLY
Indicate only bonds are pickable, atom picking is not interested

See Also:
Constant Field Values

mol

protected Molecule mol
molecule to be drawn


hTreatment

protected int hTreatment
Flag indicating how to handle the display of hydrogens


DB_DEV

protected float DB_DEV
Double bond separation


TB_DEV

protected float TB_DEV
Triple bond separation


AB_DEV

protected float AB_DEV
Aromatic bond separation


WB_DEV

protected float WB_DEV
Wedge bond separation


atomFont

protected java.awt.Font atomFont
Font to display atom labels


bondColor

protected java.awt.Color bondColor
Default color to display bonds


showAtomLabels

protected boolean showAtomLabels
Indicates whether atom labels should be displayed


colorScheme

protected int colorScheme
draw atom color according to which coloring scheme


selectColor

protected java.awt.Color selectColor
Color to display selected atoms


highlightColor

protected java.awt.Color highlightColor
Color to display highlighted atoms


atombg

protected java.awt.Color atombg
Color of default atom background


findRadius

protected float findRadius
Upper bound of the distance (in pixel) between an atom (or bond) and the pick-location if the atom (or bond) is considered picked


pickHiddenAtom

protected boolean pickHiddenAtom
Indicate whether hidden atoms are pickable


pickHiddenBond

protected boolean pickHiddenBond
Indicate whether hidden atoms are pickable


pickPreference

public int pickPreference
Indicate the picking preference is on atom, bond or distance

Constructor Detail

Renderer

public Renderer()
Default constructor


Renderer

public Renderer(Molecule mol)
Constructor

Parameters:
mol - the Molecule drawn and manipulated by this renderer.

Renderer

public Renderer(Renderer r)
Copy constructor

Parameters:
r - Renderer
Method Detail

getMol

public Molecule getMol()
Return the molecule.


setMol

public void setMol(Molecule mol)
Set the molecule

Parameters:
mol - Molecule

getBBox

public float[] getBBox()
Return the bounding box of the Molecule.

Specified by:
getBBox in interface IRenderer
Returns:
Array of 6 floats in order of xmin, xmax, ymin, ymax, zmin, zmax

matUnit

public void matUnit()
Reset the Molecule's transformation matrix to the identity matrix.

Specified by:
matUnit in interface IRenderer

matTranslate

public void matTranslate(float xt,
                         float yt,
                         float zt)
Apply the specified translation to the Molecule's transformation matrix.

Specified by:
matTranslate in interface IRenderer
Parameters:
xt - x component of translation
yt - y component of translation
zt - z component of translation

matScale

public void matScale(float xf,
                     float yf,
                     float zf)
Apply the specified scale to the Molecule's transformation matrix.

Specified by:
matScale in interface IRenderer
Parameters:
xf - x scale factor
yf - y scale factor
zf - z scale factor

matMult

public void matMult(Matrix3D rhs)
Multiply the Molecule's transformation matrix by the matrix specified.

Specified by:
matMult in interface IRenderer
Parameters:
rhs - matrix to be multiplied to Molecule's matrix: M = M * rhs

matTransform

public void matTransform()
Apply the Molecule's transformation matrix to its atoms.

Specified by:
matTransform in interface IRenderer

drawAtom

public void drawAtom(java.awt.Graphics g,
                     Atom a)
Draws an atom. Draws a filled circle, the atom name, then atom charge.

Parameters:
a - atom
g - graphics context
See Also:
draw(java.awt.Graphics)

drawBond

public void drawBond(java.awt.Graphics g,
                     Bond b)
Draws a bond

Parameters:
b - bond
g - graphics context
See Also:
draw(java.awt.Graphics), drawSingleBond(java.awt.Graphics, java.awt.Color, java.awt.Color, float, float, float, float), drawAromaticBond(java.awt.Graphics, java.awt.Color, java.awt.Color, float, float, float, float), drawWedgeBond(java.awt.Graphics, float, float, float, float), drawDashBond(java.awt.Graphics, float, float, float, float), drawAnyBond(java.awt.Graphics, java.awt.Color, java.awt.Color, float, float, float, float)

drawSingleBond

protected void drawSingleBond(java.awt.Graphics g,
                              java.awt.Color c1,
                              java.awt.Color c2,
                              float x1,
                              float y1,
                              float x2,
                              float y2)
Draws a single bond

Parameters:
g - graphics context
c1 - color of the first half of the bond
c2 - color of the second half of the bond
x1 - x coord of from atom
y1 - y coord of from atom
x2 - x coord of to atom
y2 - y coord of to atom
See Also:
drawBond(java.awt.Graphics, org.jscience.chemistry.gui.extended.molecule.Bond)

drawAromaticBond

protected void drawAromaticBond(java.awt.Graphics g,
                                java.awt.Color c1,
                                java.awt.Color c2,
                                float x1,
                                float y1,
                                float x2,
                                float y2)
Draws an aromatic bond

Parameters:
g - graphics context
c1 - color of the first half of the bond
c2 - color of the second half of the bond
x1 - x coord of from atom
y1 - y coord of from atom
x2 - x coord of to atom
y2 - y coord of to atom
See Also:
drawBond(java.awt.Graphics, org.jscience.chemistry.gui.extended.molecule.Bond)

drawWedgeBond

protected void drawWedgeBond(java.awt.Graphics g,
                             float x1,
                             float y1,
                             float x2,
                             float y2)
Draws a wedge bond

See Also:
drawBond(java.awt.Graphics, org.jscience.chemistry.gui.extended.molecule.Bond)

drawDashBond

protected void drawDashBond(java.awt.Graphics g,
                            float x1,
                            float y1,
                            float x2,
                            float y2)
Draws a dashed wedge bond (assumes black & white)

See Also:
drawBond(java.awt.Graphics, org.jscience.chemistry.gui.extended.molecule.Bond)

drawAnyBond

protected void drawAnyBond(java.awt.Graphics g,
                           java.awt.Color c1,
                           java.awt.Color c2,
                           float x1,
                           float y1,
                           float x2,
                           float y2)
Draws an any bond

Parameters:
g - graphics context
c1 - color of the first half of the bond
c2 - color of the second half of the bond
x1 - x coord of from atom
y1 - y coord of from atom
x2 - x coord of to atom
y2 - y coord of to atom
See Also:
drawBond(java.awt.Graphics, org.jscience.chemistry.gui.extended.molecule.Bond)

draw

public void draw(java.awt.Graphics g)
Draw the Molecule.

Specified by:
draw in interface IRenderer
Parameters:
g - the graphics context.

findObject

public java.lang.Object findObject(float tx,
                                   float ty)
Description copied from interface: IRenderer
Find an object given location

Specified by:
findObject in interface IRenderer
Parameters:
tx - transformed x coordinate
ty - transformed y coordinate
Returns:
an rendered object closest to the input transformed (tx, ty) coordinate within this renderer, with consideration to pickPreference.
See Also:
pickPreference

findAtom

public Atom findAtom(float tx,
                     float ty)
Parameters:
tx - transformed x coordinate
ty - transformed y coordinate
Returns:
a rendered atom closest to the input transformed (tx, ty) coordinate

findBond

public Bond findBond(float tx,
                     float ty)
Parameters:
tx - transformed x coordinate
ty - transformed y coordinate
Returns:
a rendered bond closest to the input transformed (tx, ty) coordinate

findObjects

public java.util.Vector findObjects(java.awt.Polygon pickPolygon)
Return a list of objects that are within the given polygon

Specified by:
findObjects in interface IRenderer
Parameters:
pickPolygon - the polygon within which objects are considered picked
Returns:
DOCUMENT ME!

findAtoms

public void findAtoms(java.awt.Polygon pickPolygon,
                      java.util.Vector resultVector)
Find a list of atoms within the given polygon

Parameters:
pickPolygon - the polygon with which atoms are considerred picked
resultVector - vector into which the found atoms are put

findBonds

public void findBonds(java.awt.Polygon pickPolygon,
                      java.util.Vector resultVector)
Find a list of bonds within the given polygon

Parameters:
pickPolygon - the polygon with which bonds are considerred picked
resultVector - vector into which the found bonds are put

isHidden

public boolean isHidden(Atom atom)
Parameters:
atom - the atom to be check whether it is hidden
Returns:
true iff an atom is hidden

getHTreatment

public int getHTreatment()
Return hydrogen treatment


getDB_DEV

public float getDB_DEV()
Return double bond separation


getTB_DEV

public float getTB_DEV()
Return triple bond separation


getAB_DEV

public float getAB_DEV()
Return aromatic bond separation


getWB_DEV

public float getWB_DEV()
Return wedge bond separation


getAtomFont

public java.awt.Font getAtomFont()
Return atom font


getBondColor

public java.awt.Color getBondColor()
Return bond color


getShowAtomLabels

public boolean getShowAtomLabels()
Return flag that indicates whether atom labels should display


getColorByAtomType

public boolean getColorByAtomType()
Return flag that indicates whether to paint the atom according to its type


getColorScheme

public int getColorScheme()
Return color scheme


getSelectColor

public java.awt.Color getSelectColor()
Return color to paint selected atoms


getHighlightColor

public java.awt.Color getHighlightColor()
Return color to paint hightlighted atoms


getAtombg

public java.awt.Color getAtombg()
Return atom background color


getPickHiddenAtom

public boolean getPickHiddenAtom()
Returns:
the policy (in boolean) whether hidden atoms are pickable

getPickHiddenBond

public boolean getPickHiddenBond()
Returns:
the policy (in boolean) whether hidden bonds are pickable

setHTreatment

public void setHTreatment(int hTreatment)
Set hydrogen treatment

Parameters:
hTreatment - int one of ( SHOW_ALL_H, SHOW_NO_H, SHOW_NON_C_H )

setDB_DEV

public void setDB_DEV(float dbDev)
Set double bond separation

Parameters:
dbDev - float

setTB_DEV

public void setTB_DEV(float tbDev)
Set triple bond separation

Parameters:
tbDev - float

setAB_DEV

public void setAB_DEV(float abDev)
Set aromatic bond separation

Parameters:
abDev - float

setWB_DEV

public void setWB_DEV(float wbDev)
Set wedge bond separation

Parameters:
wbDev - float

setAtomFont

public void setAtomFont(java.awt.Font font)
Set atom font

Parameters:
font - Font to paint atom label

setBondColor

public void setBondColor(java.awt.Color color)
Set bond color

Parameters:
color - Color to draw bond

setShowAtomLabels

public void setShowAtomLabels(boolean bool)
Set flag to indicate whether atom labels should display or not

Parameters:
bool - boolean

setColorByAtomType

public void setColorByAtomType(boolean bool)
Set flag to indicate whether to paint the atom according to its type As data member colorByAtomType, this method is redundent, but is kept to be compatible with pre-existing code

Parameters:
bool - boolean

setColorScheme

public void setColorScheme(int colorScheme)
Set color scheme

Parameters:
colorScheme - int

setSelectColor

public void setSelectColor(java.awt.Color color)
Set color to paint selected atoms

Parameters:
color - Color

setHighlightColor

public void setHighlightColor(java.awt.Color color)
Set color to paint hightlighted atoms

Parameters:
color - Color

setAtombg

public void setAtombg(java.awt.Color color)
Set atom background color

Parameters:
color - Color

setPickHiddenAtom

public void setPickHiddenAtom(boolean pickHiddenAtom)
Set the policy whether hidden atoms are pickable

Parameters:
pickHiddenAtom - the policy whether hidden atoms are pickable

setPickHiddenBond

public void setPickHiddenBond(boolean pickHiddenBond)
Set the policy whether hidden bonds are pickable

Parameters:
pickHiddenBond - the policy whether hidden bonds are pickable

setFindRadius

public void setFindRadius(float findRadius)
Set the findRadius

Parameters:
findRadius - the upper bound of distance between a mouse click location and the atom (or bond) when the atom (or bond) is a candidate of the picked object.

setPickPreference

public void setPickPreference(int pickPreference)
Set the pickPreference policy

Parameters:
pickPreference - one of the picking policies among ATOM_FIRST, BOND_FIRST, SHORTEST_WIN, ATOM_ONLY and BOND_ONLY

copy

public java.lang.Object copy()
DOCUMENT ME!

Specified by:
copy in interface IRenderer
Returns:
DOCUMENT ME!