chemaxon.marvin.beans
Class MViewEditor

java.lang.Object
  extended by javax.swing.AbstractCellEditor
      extended by chemaxon.marvin.beans.MViewEditor
All Implemented Interfaces:
java.io.Serializable, javax.swing.CellEditor, javax.swing.table.TableCellEditor

public class MViewEditor
extends javax.swing.AbstractCellEditor
implements javax.swing.table.TableCellEditor

MViewEditor is an implementation of AbstractCellEditor and TableCellEditor that can be used to assign a cell editor to Molecule objects in JTables.

Using MViewPane as a cell editor provides two major advantages.

  1. It offers many functionalities that modify the visualization but not the structure itself, for example rotation, zoom, display and color schemas, or the dimension in which the structure is shown.
  2. It can also be used as an indirect cell editor. Double clicking on the MViewPane cell editor brings up MarvinSketch, in which the structure can be modified. After MarvinSketch is closed, the molecule is updated.
Example of usage: http://www.chemaxon.com/marvin/examples/beans/view-jtable/index.html

Since:
Marvin 5.1.2
Version:
5.2.2 05/18/2009
Author:
Judit Vasko-Szedlar, Peter Csizmadia
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
MViewEditor()
          Creates the cell editor.
 
Method Summary
 java.lang.Object getCellEditorValue()
          Returns the edited molecule that is a Molecule instance.
 int getEditable()
          Returns the mode that determines if the structure is editable.
 MViewPane getEditorComponent()
          Returns the editor component.
 java.awt.Component getTableCellEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int column)
          Sets up the editor component.
protected  void setBackgroundColor(javax.swing.JTable table, MViewPane mviewPane, boolean isSelected, int row, int column)
          Sets the background color for the current cell based on selection.
protected  void setBorder(javax.swing.JTable table, MViewPane mviewPane, boolean isSelected, int row, int column)
          Sets the border for the current cell based on selection.
 void setEditable(int e)
          Sets the mode that determines if the structure is editable.
 
Methods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, cancelCellEditing, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.CellEditor
addCellEditorListener, cancelCellEditing, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditing
 

Constructor Detail

MViewEditor

public MViewEditor()
Creates the cell editor. It can be assigned to JTables for example with table.setDefaultEditor(Molecule.class, new MViewEditor());

Method Detail

getEditorComponent

public MViewPane getEditorComponent()
Returns the editor component.

Returns:
the MViewPane editor component

getEditable

public int getEditable()
Returns the mode that determines if the structure is editable.

Returns:
MViewPane.VIEW_ONLY if molecules can be viewed only, MViewPane.EDITABLE if they are editable with MarvinView, MViewPane.SKETCHABLE if they are editable with MarvinSketch.

setEditable

public void setEditable(int e)
Sets the mode that determines if the structure is editable. If the structure is allowed to be edited, the Edit > Structure menu or the double mouse click performs the editing.

MViewPane.VIEW_ONLY: editing is disabled, MViewPane.EDITABLE: editing is enabled and launches MarvinView in a new window, MViewPane.SKETCHABLE: editing is enabled and launches MarvinSketch in a new window.

Parameters:
e - identifier of the mode

getCellEditorValue

public java.lang.Object getCellEditorValue()
Returns the edited molecule that is a Molecule instance.

Specified by:
getCellEditorValue in interface javax.swing.CellEditor

getTableCellEditorComponent

public java.awt.Component getTableCellEditorComponent(javax.swing.JTable table,
                                                      java.lang.Object value,
                                                      boolean isSelected,
                                                      int row,
                                                      int column)
Sets up the editor component.

Specified by:
getTableCellEditorComponent in interface javax.swing.table.TableCellEditor
Parameters:
table - the JTable that is asking the editor to edit; can be null
value - the value of the cell to be edited; it is considered to be a Molecule instance; null is a valid value
isSelected - true if the cell is to be rendered with highlighting
row - the row of the cell being edited
column - the column of the cell being edited
Returns:
the component for editing

setBackgroundColor

protected void setBackgroundColor(javax.swing.JTable table,
                                  MViewPane mviewPane,
                                  boolean isSelected,
                                  int row,
                                  int column)
Sets the background color for the current cell based on selection. The default implementation sets the table selection color on the editor component. The method is called by getTableCellEditorComponent( javax.swing.JTable, Object, boolean, int, int), overwrite to change the default behavior.

Parameters:
table - the JTable that is asking the editor to edit; can be null
mviewPane - the editor component
isSelected - true if the cell is to be rendered with the selection highlighted; otherwise false
row - the row of the cell being edited
column - the column of the cell being edited

setBorder

protected void setBorder(javax.swing.JTable table,
                         MViewPane mviewPane,
                         boolean isSelected,
                         int row,
                         int column)
Sets the border for the current cell based on selection. The default implementation sets the table selection color on the editor component. The method is called by getTableCellEditorComponent( javax.swing.JTable, Object, boolean, int, int), overwrite to change the default behavior.

Parameters:
table - the JTable that is asking the editor to edit; can be null
mviewPane - the editor component
isSelected - true if the cell is to be rendered with the selection highlighted; otherwise false
row - the row of the cell being edited
column - the column of the cell being edited