Class MSketchPane

All Implemented Interfaces:
ComponentListener, ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible

@PublicAPI public class MSketchPane extends MarvinPane
The MarvinSketch Bean.

In order to use this class one needs to install a valid license:
     LicenseHandler lm = LicenseHandler.getInstance();
     lm.setLicenseFile(path_to_license_file);
 
See Also:
  • Field Details

    • SM_SELECT

      public static final int SM_SELECT
      Select mode.
      Since:
      4.0, 02/17/2004
      See Also:
    • SM_DELETE

      public static final int SM_DELETE
      Delete mode.
      Since:
      4.0, 02/17/2004
      See Also:
    • SM_ATOM

      public static final int SM_ATOM
      Atom mode. Additional flags must be used to specify the element type. Example:
       setSketchMode(MSketchPane.SM_Atom | (6 << MSketchPane.SM_FLAGS_OFF));
       
      Since:
      4.0, 02/17/2004
      See Also:
    • SM_BOND

      public static final int SM_BOND
      Bond mode. Additional flags must be used to specify the bond type. Example:
       setSketchMode(MSketchPane.SM_BOND | (1 << MSketchPane.SM_FLAGS_OFF));
       
      Since:
      4.0, 02/17/2004
      See Also:
    • SM_SELECT_LASSO

      public static final int SM_SELECT_LASSO
      Lasso select mode.
      See Also:
    • SM_MASK

      public static final int SM_MASK
      Sketch mode mask.
      Since:
      4.0, 02/17/2004
      See Also:
    • SM_FLAGS_OFF

      public static final int SM_FLAGS_OFF
      Offset of flags in sketch mode.
      Since:
      4.0, 02/17/2004
      See Also:
  • Constructor Details

    • MSketchPane

      public MSketchPane()
      Constructs the sketcher.
      Throws:
      LicenseException - if no valid license found
    • MSketchPane

      public MSketchPane(UserSettings settings)
      Constructs the sketcher with the specified user settings object.
      Parameters:
      settings - the user settings
      Throws:
      LicenseException - if no valid license found
      Since:
      Marvin 3.0
    • MSketchPane

      public MSketchPane(UserSettings settings, boolean loadtmpl)
      Constructs the sketcher with the specified user settings object.
      Parameters:
      settings - the user settings
      loadtmpl - load template structures and abbreviated groups immediately ( true) or not (false)
      Throws:
      LicenseException - if no valid license found
      Since:
      Marvin 3.4.2
    • MSketchPane

      public MSketchPane(UserSettings settings, boolean loadtmpl, JComponent parent)
      Constructs the sketcher with the specified user settings object.
      Parameters:
      settings - the user settings
      loadtmpl - load template structures and abbreviated groups immediately ( true) or not (false)
      parent - the parent Component of the MSketchPane
      Throws:
      LicenseException - if no valid license found
      Since:
      Marvin 5.12
  • Method Details

    • getCanvasComponent

      public JComponent getCanvasComponent()
      Determines canvas component of MarvinSketch. This method is required to add new eventlistener to MarvinSketch. (e.g.: getCanvasComponent().addMouseListener(actionListener); This method is required for creating a custom popup menu.)
      Returns:
      Canvas component of MarvinSketch.
      Since:
      Marvin 2.9.12
      See Also:
    • setAutoScale

      public void setAutoScale(boolean as)
      Sets the autoscale property. If autoscale is true the molecule is sized to fit on the molecule panel.
      Parameters:
      as - set to true to enable autoscale
    • getAutoScale

      public boolean getAutoScale()
      Returns autoscale property.
      Returns:
      true, if autoscale is enabled
    • propertyChange

      public void propertyChange(PropertyChangeEvent ev)
      Handles property change events.
      Specified by:
      propertyChange in interface PropertyChangeListener
      Overrides:
      propertyChange in class MarvinPane
      Parameters:
      ev - the event object
    • addPropertyChangeListener

      public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
      Adds a PropertyChangeListener for a specific property. The listener will be invoked only when a call on firePropertyChange names that specific property.

      If listener is null, no exception is thrown and no action is performed.

      MarvinSketch: parameters and events

      Overrides:
      addPropertyChangeListener in class Container
      Parameters:
      propertyName - the name of the property to listen on
      listener - the PropertyChangeListener to be added
    • getMol

      public Molecule getMol()
      Returns the clone of the current molecule being on the canvas. In case this molecule is changed, it will not affect the content of the canvas.
      Returns:
      the molecule
    • getMol

      public String getMol(String fmt)
      Gets the molecule in a text format. The format descriptor string can also contain export options. Format and options are separated by a colon, multiple options can be separated by commas. See the text formats and their options on the File Formats in Marvin page. Examples:
       s1 = msketch.getMol("mol");
       s2 = msketch.getMol("smiles:a-H"); // aromatize and remove Hydrogens
       
      Parameters:
      fmt - the format descriptor string
      Returns:
      the molecule in the specified format
    • setMol

      public void setMol(Molecule m)
      Sets the molecule. Initialization is always performed.
      Parameters:
      m - the molecule
    • setMol

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setMol(Molecule m, boolean init)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use setMol(Molecule) instead of this method.
      Sets the molecule.
      Parameters:
      m - the molecule
      init - parameter is not used
    • setMol

      public void setMol(String s)
      Starts loading a molecule into the sketcher. The argument can be a molecule in text format, or a reference/URL to a molecule file. The file format and/or import options can be specified if the argument is in one of the following forms: "file{options}", "file{format:}", or "file{format:options}". See the text formats and their options on the File Formats in Marvin page.
      Examples:
      setMol(dir+fileSeparator+"foo.xyz.gz{gzip:xyz:f1.4C4}");
      setMol("CCCC=O");
      Parameters:
      s - molfile contents, URL or (Unix) filename
    • setMol

      public void setMol(String s, String opts)
      Starts loading a molecule into the sketcher. The first argument can be a molecule in text format, or a reference/URL to a molecule file. The file format and/or import options can be specified if the second argument is in one of the following forms: "options", "format:", or "format:options". See the text formats and their options on the File Formats in Marvin page.
      Parameters:
      s - molfile contents, URL or (Unix) filename
      opts - options or null
      Since:
      Marvin 3.3
    • setMol

      public void setMol(File f, String opts)
      Sets the molecule. The file format and/or import options can be specified with the opts argument in one of the following forms: "options", "format:", or "format:options". See the text formats and their options on the File Formats in Marvin page.
      Example: setMol(new File(dir, "foo.xyz.gz"), "gzip:xyz:f1.4C4");
      Parameters:
      f - the molecule file
      opts - import options or null
    • getDocument

      public MDocument getDocument()
      Gets the document.
      Returns:
      the document
      Since:
      Marvin 3.4, 06/03/2004
    • setDocument

      public void setDocument(MDocument doc)
      Sets the document.
      Parameters:
      doc - the document
      Since:
      Marvin 3.4, 06/03/2004
    • getSelection

      public Molecule getSelection()
      Gets a clone of the selection.
      Returns:
      the selection
    • getObjectAtPointer

      public Object getObjectAtPointer()
      Get the object at the mouse pointer.
      Returns:
      a MolAtom or MolBond object.
    • getPiece

      public String getPiece(String fmt)
      Gets the current molecule piece in the specified format.
      Parameters:
      fmt - the format
      Returns:
      the piece in the specified molecule file format
      See Also:
    • setPiece

      public void setPiece(String s)
      Sets the molecule piece.
      Parameters:
      s - the piece in some molecule file format
    • getImage

      public Image getImage(double scale)
      Gets the canvas contents as an image using a scale factor.
      Examples:
      To get an image with a scale factor equivalent to 100% magnification: getImage(getDefaultScale());
      To get an image with the actual scale factor: getImage(getScale());
      Parameters:
      scale - the absolute scale factor, see getScale()
      Returns:
      the molecule image
      Since:
      Marvin 4.0, 07/09/2005
    • getImage

      public Image getImage(Dimension size)
      Gets the canvas contents as an image scaled to fit in the specified rectangle. The best width/height ratio can be determined using the getBoundRectSize() method.
      Parameters:
      size - the image size
      Returns:
      the molecule image
      Since:
      Marvin 4.0, 07/09/2005
    • getBoundRectSize

      public double[] getBoundRectSize()
      Gets the size of the bounding rectangle.
      Returns:
      two-element array containing the width and height in C-C bond length units
      Since:
      Marvin 4.0, 07/09/2005
      See Also:
    • getDefaultScale

      public static double getDefaultScale()
      Returns the default scale factor which is equivalent to 100% magnification.
      Returns:
      default displayed length of a C-C bond in pixels
    • getScale

      public double getScale()
      Returns the scale factor of the current magnification. The scale factor determines the displayed size of a Carbon-Carbon single bond measured in pixels. In case the magnification is 100%, the returned scale factor equals with the value of getDefaultScale().
      Returns:
      displayed length of a C-C bond in pixels
      See Also:
    • setScale

      public void setScale(double m)
      Sets the scale factor and changes magnification of the canvas. The scale factor determines the displayed size of a Carbon-Carbon single bond measured in pixels. In case the value of getDefaultScale() is set, the magnification of the canvas will be set to 100%.
      Parameters:
      m - displayed length of a C-C bond in pixels
      See Also:
    • getStickdst

      public double getStickdst()
      Gets the sticking distance.
      Returns:
      the stick distance in C-C bond length units
      See Also:
    • setStickdst

      public void setStickdst(double d)
      Sets the sticking distance.
      Parameters:
      d - the stick distance in C-C bond length units
      See Also:
    • getMergedst

      public double getMergedst()
      Gets the merge distance.
      Returns:
      the merge distance in C-C bond length units
      See Also:
    • setMergedst

      public void setMergedst(double d)
      Sets the merge distance.
      Parameters:
      d - the merge distance in C-C bond length units
      See Also:
    • getUndo

      public int getUndo()
      Gets the maximum undo depth.
      Returns:
      maximum history length
    • setUndo

      public void setUndo(int u)
      Sets the maximum undo depth.
      Parameters:
      u - maximum history length
    • getReactionSupport

      public boolean getReactionSupport()
      Is reaction drawing supported?
      Returns:
      true if supported, false otherwise
    • setReactionSupport

      public void setReactionSupport(boolean v)
      Allows or disallows reaction drawing.
      Parameters:
      v - true to allow, false to disallow
    • isReactionErrorVisible

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public boolean isReactionErrorVisible()
      Deprecated, for removal: This API element is subject to removal in a future version.
      As of Version 5.3.2, this method is deprecated and has no replacement. It will be removed in a future version of Marvin.

      Are reaction errors highlighted?

      Returns:
      false
      Since:
      Marvin 2.9.13
    • isValenceErrorVisible

      public boolean isValenceErrorVisible()
      Are valence errors highlighted?
      Returns:
      True, if valence errors are highlighted with underline.
      Since:
      Marvin 2.9.13
    • setValenceErrorVisible

      public void setValenceErrorVisible(boolean v)
      Shows or hides valence errors
      Parameters:
      v - True, underlines atom symbols in case valence errors.
      Since:
      Marvin 2.9.13
    • isBondDraggedAlong

      public boolean isBondDraggedAlong()
      Is the currently used bond shown at the mouse cursor?
      Returns:
      true if the bond is dragged along by the mouse cursor, false otherwise
      Since:
      Marvin 3.5, 09/30/2004
    • setBondDraggedAlong

      public void setBondDraggedAlong(boolean v)
      Sets the visibility of the currently used bond at the mouse cursor.
      Parameters:
      v - true to drag along the bond by the mouse cursor, false to hide it
      Since:
      Marvin 3.5, 09/30/2004
    • setSketchMode

      public void setSketchMode(int mode)
      Sets the sketching mode.
      Parameters:
      mode - the sketching mode
      Since:
      Marvin 4.0
      See Also:
    • getSketchMode

      public int getSketchMode()
      Gets the sketching mode.
      Returns:
      the sketching mode or -1 for special modes
      Since:
      Marvin 4.0
      See Also:
    • getSimpView

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public int getSimpView()
      Deprecated, for removal: This API element is subject to removal in a future version.
      as of Marvin 3.5, replaced by isBondDraggedAlong()
      Gets the visibility of the object in hand.
      Returns:
      0 normally, 1 if the objects in hand are invisible
    • setSimpView

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setSimpView(int v)
      Deprecated, for removal: This API element is subject to removal in a future version.
      as of Marvin 3.5, replaced by setBondDraggedAlong(boolean)
      Hides the object in hand.
      Parameters:
      v - 0 for normal behaviour, 1 to hide bond in hand
    • getMag

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public double getMag()
      Deprecated, for removal: This API element is subject to removal in a future version.
      As of Marvin 2.8.1, replaced by getScale()
      Returns:
      the magnification
    • setMag

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setMag(double m)
      Deprecated, for removal: This API element is subject to removal in a future version.
      As of Marvin 2.8.1, replaced by setScale()
      Parameters:
      m - the magnification
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Saves object state. For internal use only! This method does not implement the Externalizable interface. It is called by the writeExternal method of class MSketch, which does implement it.
      Overrides:
      writeExternal in class MarvinPane
      Parameters:
      out - the stream to write the object to
      Throws:
      IOException - Includes any I/O exceptions that may occur
      Since:
      Marvin 3.5, 2004/11/01
    • readExternal

      public void readExternal(ObjectInput in) throws IOException
      Restores object state. For internal use only! This method does not implement the Externalizable interface. It is called by the readExternal method of class MSketch, which does implement it.
      Overrides:
      readExternal in class MarvinPane
      Parameters:
      in - the stream to read data from in order to restore the object
      Throws:
      IOException - if I/O errors occur
      ClassNotFoundException - If the class for an object being restored cannot be found.
      Since:
      Marvin 3.5, 2004/11/01
    • getMrvWithSettings

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public String getMrvWithSettings()
      Deprecated, for removal: This API element is subject to removal in a future version.
      use getMol(String) instead
      Gets the molecule in the sketcher with its current settings in MRV format.
      Returns:
      the MRV source
      Since:
      4.0 07/01/2005
      See Also:
    • setMrvWithSettings

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setMrvWithSettings(String mrvsource)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sets the molecule and its display settings. Settings can be imported if the MRV source includes display infos.
      Parameters:
      mrvsource - the MRV source
      Since:
      4.0 07/01/2005
      See Also:
    • isCloseEnabled

      public boolean isCloseEnabled()
      Determines if the File->Close menu item is enabled or not.
      Returns:
      True, if Close is enabled in the menu, else false.
      Since:
      4.0 07/05/2005
      See Also:
    • setCloseEnabled

      public void setCloseEnabled(boolean b)
      Set the accessibility of the Close menu item in the File menu.
      Parameters:
      b - True to enable close operation from the file menu. False to set it to disabled.
      Since:
      4.0 07/05/2005
      See Also:
    • undo

      public void undo()
      Invokes an undo command.
    • redo

      public void redo()
      Invokes a redo command.
    • setConfirmExit

      public void setConfirmExit(boolean b)
      Sets to drop confirmation dialog about exit or not.
      Parameters:
      b - True, confirmation dialog will be appear by exit if modifications were not saved, else false.
    • isConfirmExit

      public boolean isConfirmExit()
      Gets whether the confirmation dialog will be appear or not by exit.
      Returns:
      True, confirmation dialog will be appear by exit if modifications were not saved, else false.
    • isLoadedMolModified

      public boolean isLoadedMolModified()
      Determines whether the original molecule that is loaded in is modified or not.
      Returns:
      If modified returns with true, else false.
      Since:
      5.0.2 02/29/2008
    • doPaste

      public void doPaste()
      Invokes Paste action.
      Specified by:
      doPaste in class MarvinPane
      Since:
      Marvin 5.0
    • clearHistory

      public void clearHistory()
      Reset undo queue.
      Since:
      Marvin 4.1.11 07/06/2007
    • getCommonActions

      @Deprecated public chemaxon.marvin.common.swing.action.CommonActions getCommonActions()
      Deprecated.
      at N/A (before 02/12/2015)
      Description copied from class: MarvinPane
      Gets the common actions.
      Overrides:
      getCommonActions in class MarvinPane
      Returns:
      the actions
    • centralizeMoleculeDisplay

      public void centralizeMoleculeDisplay()
      Puts the molecule into the center of the display.
    • setDisabledGroupTypes

      public void setDisabledGroupTypes(List<String> disabledGroupTypes)
    • getDisabledGroupTypes

      public List<String> getDisabledGroupTypes()
    • showStartupSelector

      public void showStartupSelector()
      This method is used in startup time to throw up a skin selector dialog.
    • getMolPanel

      public chemaxon.marvin.sketch.swing.SketchPanel getMolPanel()
      Description copied from class: MarvinPane
      Returns the underlying panel.
      Overrides:
      getMolPanel in class MarvinPane
      Returns:
      the underlying panel