21import java.awt.BorderLayout;
23import java.awt.Dimension;
24import java.awt.Graphics;
25import java.awt.Graphics2D;
26import java.awt.Rectangle;
27import java.awt.event.MouseEvent;
28import java.awt.event.MouseListener;
29import java.awt.event.MouseMotionListener;
30import java.awt.event.MouseWheelEvent;
31import java.awt.event.MouseWheelListener;
32import java.awt.geom.AffineTransform;
33import java.awt.geom.Point2D;
34import java.util.ArrayList;
35import java.util.HashMap;
39import javax.swing.JLabel;
40import javax.swing.JPanel;
41import javax.swing.JScrollPane;
42import javax.swing.JSplitPane;
43import javax.swing.JTable;
44import javax.swing.event.TableModelEvent;
45import javax.swing.event.TableModelListener;
46import javax.swing.table.DefaultTableModel;
47import javax.swing.table.JTableHeader;
49import org.openscience.cdk.AtomRef;
50import org.openscience.cdk.PseudoAtom;
51import org.openscience.cdk.interfaces.IAtom;
52import org.openscience.cdk.interfaces.IAtomContainer;
53import org.openscience.cdk.interfaces.IBond;
54import org.openscience.cdk.layout.StructureDiagramGenerator;
55import org.openscience.cdk.renderer.AtomContainerRenderer;
56import org.openscience.cdk.renderer.RendererModel;
57import org.openscience.cdk.renderer.color.IAtomColorer;
58import org.openscience.cdk.renderer.font.AWTFontManager;
59import org.openscience.cdk.renderer.generators.BasicAtomGenerator;
60import org.openscience.cdk.renderer.generators.BasicBondGenerator;
61import org.openscience.cdk.renderer.generators.BasicSceneGenerator;
62import org.openscience.cdk.renderer.generators.IGenerator;
63import org.openscience.cdk.renderer.visitor.AWTDrawVisitor;
65import denoptim.graph.AttachmentPoint;
66import denoptim.graph.EmptyVertex;
67import denoptim.graph.Fragment;
68import denoptim.graph.Vertex;
69import denoptim.utils.MoleculeUtils;
95 protected Map<Integer, AttachmentPoint>
mapAPs =
null;
121 MouseListener, MouseMotionListener
143 StructureDiagramGenerator sdg =
new StructureDiagramGenerator();
149 int numAtoms = extendedMol.getAtomCount();
152 extendedMol.addAtom(
new PseudoAtom(
""+(apId+1)));
153 extendedMol.addBond(ap.getAtomPositionNumber(),
154 apId+numAtoms, IBond.Order.SINGLE);
158 sdg.setMolecule(extendedMol);
159 sdg.generateCoordinates();
160 }
catch (Exception e)
166 this.mol = sdg.getMolecule();
169 List<IGenerator<IAtomContainer>> generators =
170 new ArrayList<IGenerator<IAtomContainer>>();
171 generators.add(
new BasicSceneGenerator());
172 generators.add(
new BasicBondGenerator());
174 renderer =
new AtomContainerRenderer(generators,
new AWTFontManager());
176 addMouseWheelListener(
this);
177 addMouseListener(
this);
178 addMouseMotionListener(
this);
181 public void paint(Graphics graphics)
186 renderer.setup(
mol,
new Rectangle(getWidth(), getHeight()));
189 graphics.setColor(Color.WHITE);
190 graphics.fillRect(0, 0, getWidth(), getHeight());
192 Graphics2D g2d = (Graphics2D) graphics;
194 AffineTransform saveTransform = g2d.getTransform();
195 at =
new AffineTransform(saveTransform);
198 at.translate(getWidth()/2, getHeight()/2);
200 at.translate(-getWidth()/2, -getHeight()/2);
203 g2d.setTransform(
at);
211 g2d.setTransform(saveTransform);
219 if (e.getWheelRotation() < 0) {
222 if (e.getWheelRotation() > 0) {
237 catch (Exception te) {
238 te.printStackTrace();
255 catch (Exception te) {
256 te.printStackTrace();
295 Color atomColor = model.get(AtomColor.class);
296 if ((Boolean) model.get(ColorByType.class))
298 boolean changeColor =
false;
300 if (atom instanceof AtomRef)
302 a = ((AtomRef) atom).deref();
303 if (a instanceof PseudoAtom)
305 }
else if (atom instanceof PseudoAtom)
311 atomColor =
new Color(0xFF00FF);
313 atomColor = ((IAtomColorer) model.get(AtomColorer.class))
330 this(editableTable, 340);
351 @SuppressWarnings(
"serial")
354 this.setOrientation(JSplitPane.VERTICAL_SPLIT);
355 this.setOneTouchExpandable(
true);
356 this.setDividerLocation(dividerPosition);
357 this.setResizeWeight(0.5);
365 public boolean isCellEditable(
int row,
int column) {
377 String column_names[]= {
"<html><b>AP#</b></html>",
378 "<html><b>APClass</b></html>"};
379 apTabModel.setColumnIdentifiers(column_names);
381 apTable.putClientProperty(
"terminateEditOnFocusLost",
true);
382 apTable.getColumnModel().getColumn(0).setMaxWidth(75);
383 apTable.setGridColor(Color.LIGHT_GRAY);
384 apTable.setPreferredScrollableViewportSize(
apTable.getPreferredSize());
385 JTableHeader apTabHeader =
apTable.getTableHeader();
386 apTabHeader.setPreferredSize(
new Dimension(100, 20));
471 mapAPs =
new HashMap<Integer,AttachmentPoint>();
474 if (lstAPs.size() == 0)
484 apTabModel.addRow(
new Object[]{arrId, ap.getAPClass()});
503 String[] parts =prop.split(PRESELPROPSEP);
506 for (
int i=0; i<parts.length; i++)
508 int apId = Integer.parseInt(parts[i]);
509 apTable.getSelectionModel().addSelectionInterval(apId, apId);
533 for (
int i=0; i<initRowCount; i++)
549 ArrayList<AttachmentPoint> selected =
550 new ArrayList<AttachmentPoint>();
552 for (
int rowId :
apTable.getSelectedRows())
567 ArrayList<Integer> selected =
new ArrayList<Integer>();
568 for (
int rowId :
apTable.getSelectedRows())
588 && e.getType() == TableModelEvent.UPDATE)
615 }
catch (Throwable t) {
616 System.out.println(
"Bad attempt to contro listener: "
618 System.out.println(t.getCause());
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
An empty vertex has the behaviors of a vertex, but has no molecular structure.
Class representing a continuously connected portion of chemical object holding attachment points.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
abstract List< AttachmentPoint > getAttachmentPoints()
Object getProperty(Object property)
abstract IAtomContainer getIAtomContainer()
A modal dialog with a viewer that understands the different types of DENOPTIM vertex and allows to se...
static final String PRESELECTEDAPSFIELD
Property used to pre-select APs.
static final String PRESELECTEDAPSFIELDSEP
Separator in property used to pre-select APs.
Color getAtomColor(IAtom atom, RendererModel model)
Chooses default colors from CDK2DAtomColor for all but PseudoAtoms which we expect to be placeholder ...
void setActive(boolean var)
PausableTableModelListener()
void tableChanged(TableModelEvent e)
Panel dealing with the painting of 2D chemical representation.
void mouseExited(MouseEvent e)
void mouseMoved(MouseEvent e)
void mouseEntered(MouseEvent e)
void mouseReleased(MouseEvent e)
AtomContainerRenderer renderer
void paint(Graphics graphics)
AffineTransform initialTransform
TwoDimStructurePanel(Vertex vertex)
static final long serialVersionUID
Version ID.
void mouseDragged(MouseEvent e)
void mousePressed(MouseEvent e)
void mouseClicked(MouseEvent e)
void mouseWheelMoved(MouseWheelEvent e)
A panel to visualize a vertex as two-dimensional chemical structure with attachment point table.
boolean hasUnsavedAPEdits()
Check for unsaved edits to the AP data.
VertexAsTwoDimStructureViewPanel(boolean editableTable)
Constructor that allows to specify whether the AP table is editable or not.
void setVertexSpecificEditableAPTable(boolean editable)
void clearPanel()
trashed the current panel displaying any 2D structure and replaces it with a new empty panel.
VertexAsTwoDimStructureViewPanel(boolean editableTable, int dividerPosition)
Constructor that allows to specify whether the AP table is editable or not.
void initialize(int dividerPosition)
void clearAll()
Removes the currently visualized molecule and AP table.
boolean vertexSpecificAPTabEditable
ArrayList< Integer > getSelectedAPIDs()
Identifies which attachment points are selected in the visualized table.
void deprotectEdits()
Overrides the flag signaling unsaved edits to saying that there are no altered data.
ArrayList< AttachmentPoint > getSelectedAPs()
Identifies which attachment points are selected in the visualized table.
void activateTabEditsListener(boolean var)
Allows to activate and deactivate the listener.
Map< Integer, AttachmentPoint > getMapOfAPsInTable()
Vertex vertex
The currently loaded fragment.
DefaultTableModel apTabModel
void clearAPTable()
Clears the table of attachment points.
DefaultTableModel getAPTableModel()
Map< Integer, AttachmentPoint > mapAPs
Temporary list of attachment points of the current fragment.
void loadVertexToViewer(Vertex v)
boolean alteredAPData
Flag signaling that data about APs has been changed in the GUI.
void loadVertexStructure()
static final long serialVersionUID
Version UID.
void updateAPsMapAndTable()
Uses the AP of the Fragment to create a new map and table of APs.
Utilities for molecule conversion.
static IAtomContainer makeSameAs(IAtomContainer mol)
Constructs a copy of an atom container, i.e., a molecule that reflects the one given in the input arg...
Interface for all vertex viewers that intend to allow selection of attachment points.
final String APDATACHANGEEVENT