ChemWriter v1.3.0

com.metamolecular.chemwriter.applet
Class EditorApplet

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by com.metamolecular.chemwriter.applet.BaseApplet
                          extended by com.metamolecular.chemwriter.applet.EditorApplet
All Implemented Interfaces:
PaintStyler, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer

public class EditorApplet
extends BaseApplet

A 2D structure editor applet. When deployed, all public methods should be available through JavaScript.

Author:
Richard L. Apodaca
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
EditorApplet()
          Default constructor.
 
Method Summary
 boolean canRedo()
          Returns true if the last user action can be redone or false otherwise.
 boolean canUndo()
          Returns true if the last user action can be undone or false otherwise.
 void clear()
          Clears the molecule without changing any settings.
 double getBondLength()
          Returns the bond length for new bonds, in molecule units.
 int getDocumentHeight()
          Returns the height of the document in pixels.
 int getDocumentWidth()
          Returns the width of the document in pixels.
 double getHoverRadius()
          Returns the hover radius, or the radius around which atoms will be detected as being hovered over by the mouse cursor.
 java.lang.String getMolfile()
          Returns the molfile representation of the molecule contained in this applet.
 java.lang.String getTool()
          Returns the name of the active tool.
 double getZoomFactor()
          Returns the zoom factor to be applied by zoomIn and zoomOut.
 void init()
           
 boolean isBlank()
          Returns true if this applet's canvas contains no molecule, or false otherwise.
 boolean isPreventStrayHeteroatoms()
          Returns true if stray heteroatom protection is enabled, or false otherwise.
 void paint(java.awt.Graphics g)
           
 void redo()
          Redoes the last user action, or does nothing if there is nothing to redo.
 void resetView()
          Resets the editor view by scaling to the default scale and centering the molecule to the extent possible.
 void setBondLength(double length)
          Sets the bond length for new bonds, in molecule units.
 void setDocumentSize(int width, int height)
          Resizes the document.
 void setHoverRadius(double radius)
          Sets the hover radius, or the radius around which atoms will be detected as being hovered over by the mouse cursor.
 void setMolfile(java.lang.String molfile)
          Replaces the current molecule with one defined by molfile.
 void setPreventStrayHeteroatoms(boolean enabled)
          Determines whether stray heteroatom protection will be enabled or not.
 void setTool(java.lang.String name)
          Selects the drawing tool to be used.
 void setZoomFactor(double zoomFactor)
          Sets the zoom factor to be applied by zoomIn and zoomOut.
 void start()
           
 void stop()
           
 void undo()
          Performs an undo of the last user action, or does nothing if the undo limit has been reached.
 void zoomIn()
          Magnifies the molecule display by the value returned by getZoomFactor.
 void zoomOut()
          Reduces the molecule display by the value returned by getZoomFactor.
 
Methods inherited from class com.metamolecular.chemwriter.applet.BaseApplet
clearAtomColors, copyStyle, flash, getAppletInfo, getAtomColor, getAtomLabelFont, getAtomLabelFonts, getAtomLabelHeight, getBackgroundColor, getBondColor, getCapStyle, getColoredAtoms, getLineEndPadding, getLineOffset, getLineWidth, getParameterInfo, getStereoWidth, isAntialiasing, isAtomColoringEnabled, isCarbonVisible, isRenderVirtualHydrogens, isVirtualizeHydrogens, setAntialiasing, setAtomColor, setAtomColor, setAtomColoringEnabled, setAtomLabelFont, setAtomLabelHeight, setBackgroundColor, setBackgroundColor, setBondColor, setBondColor, setCapStyle, setCarbonVisible, setLineEndPadding, setLineOffset, setLineWidth, setRenderVirtualHydrogens, setStereoWidth, setVirtualizeHydrogens
 
Methods inherited from class javax.swing.JApplet
getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, remove, repaint, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, update
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EditorApplet

public EditorApplet()
             throws java.awt.HeadlessException
Default constructor.

Throws:
java.awt.HeadlessException
Method Detail

isBlank

public boolean isBlank()
Description copied from class: BaseApplet
Returns true if this applet's canvas contains no molecule, or false otherwise.

Specified by:
isBlank in class BaseApplet
Returns:
true if this applet's canvas contains no molecule, or false otherwise

getMolfile

public java.lang.String getMolfile()
Description copied from class: BaseApplet
Returns the molfile representation of the molecule contained in this applet.

Specified by:
getMolfile in class BaseApplet
Returns:
the molfile representation of the molecule contained in this applet
See Also:
MDL V2000 Molfile Specification

redo

public void redo()
Redoes the last user action, or does nothing if there is nothing to redo.


setTool

public void setTool(java.lang.String name)
Selects the drawing tool to be used. Automatically disables the current tool. Available names are:

Parameters:
name - the name of the tool to select

getTool

public java.lang.String getTool()
Returns the name of the active tool.

Returns:
the name of the active tool
Since:
1.1

setMolfile

public void setMolfile(java.lang.String molfile)
Description copied from class: BaseApplet
Replaces the current molecule with one defined by molfile.

Specified by:
setMolfile in class BaseApplet
Parameters:
molfile - the molfile representation that will replace the current molecule
See Also:
MDL V2000 Molfile Specification

undo

public void undo()
Performs an undo of the last user action, or does nothing if the undo limit has been reached.


canUndo

public boolean canUndo()
Returns true if the last user action can be undone or false otherwise.

Returns:
true if the last user action can be undone or false otherwise

canRedo

public boolean canRedo()
Returns true if the last user action can be redone or false otherwise.

Returns:
true if the last user action can be redone or false otherwise

zoomIn

public void zoomIn()
Magnifies the molecule display by the value returned by getZoomFactor.

Since:
1.1

zoomOut

public void zoomOut()
Reduces the molecule display by the value returned by getZoomFactor.

Since:
1.1

getZoomFactor

public double getZoomFactor()
Returns the zoom factor to be applied by zoomIn and zoomOut.

Returns:
the zoom factor to be applied by zoomIn and zoomOut
Since:
1.1

setZoomFactor

public void setZoomFactor(double zoomFactor)
Sets the zoom factor to be applied by zoomIn and zoomOut. zoomFactor is larger than zero.

Parameters:
zoomFactor - the new zoom factor
Since:
1.1

setBondLength

public void setBondLength(double length)
Sets the bond length for new bonds, in molecule units. Does not affect existing bond lengths.

Parameters:
length - the new bond length in molecule units - greater than zero
Since:
1.1

getBondLength

public double getBondLength()
Returns the bond length for new bonds, in molecule units.

Returns:
the bond length for new bonds in molecule units - greater than zero
Since:
1.1

setHoverRadius

public void setHoverRadius(double radius)
Sets the hover radius, or the radius around which atoms will be detected as being hovered over by the mouse cursor. This is also the radius around which the circle indicating a highlighted atom or bond will be drawn. This radius extends from the exact center of both atoms and bonds in all directions. Note that this radius may or may not intersect a line in certain kinds of bonds, depending on settings. Increasing this setting will make it easier for a user to hover the mouse curosor over a structure's atoms. A value of 0.5 or larger will make it impossible to detect bond hover events.

Parameters:
radius - the hover radius - greater than zero and preferably less than 0.5 relative to median bond length
Since:
1.3

getHoverRadius

public double getHoverRadius()
Returns the hover radius, or the radius around which atoms will be detected as being hovered over by the mouse cursor. This is also the radius around which the circle indicating a highlighted atom or bond will be drawn. This radius extends from the exact center of both atoms and bonds in all directions. Note that this radius may or may not intersect a line in certain kinds of bonds, depending on settings.

Returns:
the hover radius in terms of the median bond length
Since:
1.3

setPreventStrayHeteroatoms

public void setPreventStrayHeteroatoms(boolean enabled)
Determines whether stray heteroatom protection will be enabled or not. Stray heteroatom protection will disable keyboard shortcuts for heteroatoms placed into empty space, i.e., not connected to a neighboring atom. Enabling this feature makes it more difficult for a user to draw a structure in which disconnected heteroatoms appear. Disconnected heteroatoms can still be drawn by choosing the atom label tool.

Parameters:
enabled - enables protection if true
Since:
1.3

isPreventStrayHeteroatoms

public boolean isPreventStrayHeteroatoms()
Returns true if stray heteroatom protection is enabled, or false otherwise. Stray heteroatom protection will disable keyboard shortcuts for heteroatoms placed into empty space, i.e., not connected to a neighboring atom.

Returns:
true if stray heteroatom protection is enabled, or false otherwise
Since:
1.3

setDocumentSize

public void setDocumentSize(int width,
                            int height)
Resizes the document. Use this method to change the dimensions that the scroll pane encloses.

Parameters:
width - the new document width in pixels
height - the new document height in pixels
Since:
1.1

getDocumentWidth

public int getDocumentWidth()
Returns the width of the document in pixels. This represents the width that the horizontal scrollbar pans across.

Returns:
the width of the document in pixels
Since:
1.1

getDocumentHeight

public int getDocumentHeight()
Returns the height of the document in pixels. This represents the height that the vertical scrollbar pans across.

Returns:
the height of the document in pixels
Since:
1.1

clear

public void clear()
Clears the molecule without changing any settings.

Since:
1.1

resetView

public void resetView()
Resets the editor view by scaling to the default scale and centering the molecule to the extent possible.

Since:
1.1

start

public void start()
Overrides:
start in class java.applet.Applet

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Container

init

public void init()
Overrides:
init in class BaseApplet

stop

public void stop()
Overrides:
stop in class java.applet.Applet

ChemWriter v1.3.0

Copyright © 2007, 2008 Metamolecular, LLC. All Rights Reserved.