$darkmode
DENOPTIM
VertexViewPanel.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2020 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.gui;
20
21
22import java.awt.BorderLayout;
23import java.awt.CardLayout;
24import java.awt.event.ActionEvent;
25import java.awt.event.ActionListener;
26import java.beans.PropertyChangeEvent;
27import java.beans.PropertyChangeListener;
28import java.util.ArrayList;
29import java.util.Map;
30
31import javax.swing.JButton;
32import javax.swing.JLabel;
33import javax.swing.JPanel;
34import javax.swing.table.DefaultTableModel;
35
36import org.openscience.cdk.interfaces.IAtom;
37import org.openscience.cdk.interfaces.IAtomContainer;
38
39import denoptim.exception.DENOPTIMException;
40import denoptim.graph.AttachmentPoint;
41import denoptim.graph.EmptyVertex;
42import denoptim.graph.Fragment;
43import denoptim.graph.Template;
44import denoptim.graph.Vertex;
45
46
54public class VertexViewPanel extends JPanel
55{
59 private static final long serialVersionUID = 1L;
60
64 private Vertex vertex;
65
69 public boolean alteredAPData = false;
70
71 private JPanel titlePanel;
72
73 private JLabel labTitle;
74 private JButton btnSwitchToNodeViewer;
75 private JButton btnSwitchToMolViewer;
76 private JButton btnSwitchTo2DViewer;
77
78 private JPanel centralPanel;
79
80 private JPanel emptyViewerCard;
85 protected final String EMPTYCARDNAME = "emptyCard";
86 protected final String GRAPHVIEWERCARDNAME = "emptyVertesCard";
87 protected final String MOLVIEWERCARDNAME = "fragViewerCard";
88 protected final String TWODVIEWERCARDNAME = "twoDimViewerCard";
89
90 private boolean editableAPTable = false;
91
96 private boolean switchbleByVertexType = true;
97
98//-----------------------------------------------------------------------------
99
105 public VertexViewPanel(boolean editableTable)
106 {
107 super(new BorderLayout());
108 this.editableAPTable = editableTable;
109 initialize();
110 }
111
112//-----------------------------------------------------------------------------
113
114 private void initialize()
115 {
116 centralPanel = new JPanel(new CardLayout());
117 this.add(centralPanel, BorderLayout.CENTER);
118
119 titlePanel = new JPanel();
120
121 labTitle = new JLabel("");
122 titlePanel.add(labTitle);
123
124 btnSwitchToNodeViewer = new JButton("Node View");
125 btnSwitchToNodeViewer.setToolTipText("Switch to graph node depiction "
126 + "of this vertex.");
127 btnSwitchToNodeViewer.addActionListener(new ActionListener() {
128 public void actionPerformed(ActionEvent e) {
130 }
131 });
132 btnSwitchToNodeViewer.setEnabled(false);
134
135 btnSwitchToMolViewer = new JButton("3D Molecule View");
136 btnSwitchToMolViewer.setToolTipText("Switch to 3D molecular depiction "
137 + "of this vertex.");
138 btnSwitchToMolViewer.addActionListener(new ActionListener() {
139 public void actionPerformed(ActionEvent e) {
141 }
142 });
143 btnSwitchToMolViewer.setEnabled(false);
145
146 btnSwitchTo2DViewer = new JButton("2D Molecular Structure");
147 btnSwitchTo2DViewer.setToolTipText("Switch to 2D molecular depiction "
148 + "of this vertex.");
149 btnSwitchTo2DViewer.addActionListener(new ActionListener() {
150 public void actionPerformed(ActionEvent e) {
152 }
153 });
154 btnSwitchTo2DViewer.setEnabled(false);
156
157 this.add(titlePanel, BorderLayout.NORTH);
158
159 emptyViewerCard = new JPanel();
160 emptyViewerCard.setToolTipText("Vertices are displayed here.");
162
164 graphNodeViewer.addPropertyChangeListener(
166 new PropertyChangeListener() {
167 @Override
168 public void propertyChange(PropertyChangeEvent evt) {
169 alteredAPData = true;
170 firePropertyChange(IVertexAPSelection.APDATACHANGEEVENT, false,
171 true);
172 }
173 });
175
177 fragViewer.addPropertyChangeListener(
179 new PropertyChangeListener() {
180 @Override
181 public void propertyChange(PropertyChangeEvent evt) {
182 alteredAPData = true;
183 firePropertyChange(IVertexAPSelection.APDATACHANGEEVENT, false,
184 true);
185 }
186 });
188
190 twoDimViewer.addPropertyChangeListener(
192 new PropertyChangeListener() {
193 @Override
194 public void propertyChange(PropertyChangeEvent evt) {
195 alteredAPData = true;
196 firePropertyChange(IVertexAPSelection.APDATACHANGEEVENT, false,
197 true);
198 }
199 });
201
202
204 }
205
206//-----------------------------------------------------------------------------
207
212 public boolean hasUnsavedAPEdits()
213 {
214 return alteredAPData;
215 }
216
217//-----------------------------------------------------------------------------
218
223 public void deprotectEdits()
224 {
227 alteredAPData = false;
228 }
229
230//-----------------------------------------------------------------------------
231
236 public void setSwitchable(boolean switchable)
237 {
239 {
240 if (switchable)
241 {
242 btnSwitchToMolViewer.setEnabled(true);
243 btnSwitchToNodeViewer.setEnabled(true);
244 btnSwitchTo2DViewer.setEnabled(true);
245 } else {
246 btnSwitchToMolViewer.setEnabled(false);
247 btnSwitchToNodeViewer.setEnabled(false);
248 btnSwitchTo2DViewer.setEnabled(false);
249 }
250 }
251 }
252
253//-----------------------------------------------------------------------------
254
255 private void switchToEmptyCard()
256 {
257 btnSwitchToMolViewer.setEnabled(false);
258 btnSwitchToNodeViewer.setEnabled(false);
259 btnSwitchTo2DViewer.setEnabled(false);
260 ((CardLayout) centralPanel.getLayout()).show(centralPanel,
262 activeViewer = null;
263 }
264
265//-----------------------------------------------------------------------------
266
268 {
269 ((CardLayout) centralPanel.getLayout()).show(centralPanel,
272 }
273
274//-----------------------------------------------------------------------------
275
277 {
278 ((CardLayout) centralPanel.getLayout()).show(centralPanel,
281 }
282
283//-----------------------------------------------------------------------------
284
285 private void switchTo2DViewer()
286 {
287 ((CardLayout) centralPanel.getLayout()).show(centralPanel,
290 }
291
292//-----------------------------------------------------------------------------
293
305 public boolean loadSMILES(String smiles)
306 {
308 return fragViewer.loadSMILES(smiles);
309 }
310
311//-----------------------------------------------------------------------------
312
323 {
324 Vertex v = null;
325 if (vertex == null || vertex instanceof Fragment)
326 {
329 } else {
330 v = vertex;
331 }
332 return v;
333 }
334
335//-----------------------------------------------------------------------------
336
341 public void loadPlainStructure(IAtomContainer mol)
342 {
345 }
346
347//-----------------------------------------------------------------------------
348
358 {
359 vertex = v;
360 if (v instanceof Fragment) {
361 labTitle.setText("Fragment");
362 Fragment frag = (Fragment) v;
364 } else if (v instanceof EmptyVertex) {
365 labTitle.setText("EmptyVertex");
366 EmptyVertex ev = (EmptyVertex) v;
368 } else if (v instanceof Template) {
369 labTitle.setText("Template");
370 Template tmpl = (Template) v;
372 } else {
373 System.err.println("Loading empty card as a result of vertex with "
374 + "type " + v.getClass().getName());
376 }
377 }
378
379//-----------------------------------------------------------------------------
380
388 {
389 btnSwitchToMolViewer.setEnabled(false);
390 btnSwitchToNodeViewer.setEnabled(false);
391 btnSwitchTo2DViewer.setEnabled(false);
394 switchbleByVertexType = false;
395 }
396
397//-----------------------------------------------------------------------------
398
408 {
409 btnSwitchToMolViewer.setEnabled(true);
410 btnSwitchToNodeViewer.setEnabled(true);
411 btnSwitchTo2DViewer.setEnabled(true);
416 if (frag.is3D())
417 {
419 } else {
421 }
422 }
423
424//-----------------------------------------------------------------------------
425
431 {
432 if (tmpl.containsAtoms())
433 {
434 Fragment frag;
435 try
436 {
437 frag = new Fragment(tmpl.getVertexId(),
439
441 btnSwitchToMolViewer.setEnabled(true);
442 btnSwitchToNodeViewer.setEnabled(true);
443 //TODO: maybe one day we'll enable looking at the 2D of the whole template
444 btnSwitchTo2DViewer.setEnabled(false);
446 } catch (DENOPTIMException e)
447 {
448 // We lease data in the viewer to increase speed of execution, but the
449 // leftover is outdated! This is the meaning of 'true'
450 fragViewer.clearAll(true);
451 switchbleByVertexType = false;
452 }
453 } else {
454 // We lease data in the viewer to increase speed of execution, but the
455 // leftover is outdated! This is the meaning of 'true'
456 fragViewer.clearAll(true);
457 switchbleByVertexType = false;
458 }
462 }
463
464//-----------------------------------------------------------------------------
465
469 public void clearCurrentSystem()
470 {
471 vertex = null;
472 graphNodeViewer.mapAPs = null;
474 fragViewer.mapAPs = null;
477 // NB: avoid it very slow! Mol viewer gets update upon loading a new mol
478 // clearMolecularViewer();
479 }
480
481//-----------------------------------------------------------------------------
482
491 public void clearMolecularViewer(boolean dataIsComing)
492 {
493 fragViewer.clearMolecularViewer(dataIsComing);
494 }
495
496//-----------------------------------------------------------------------------
497
502 public Map<Integer,AttachmentPoint> getActiveMapAPs()
503 {
505 }
506
507//-----------------------------------------------------------------------------
508
512 public DefaultTableModel getAPTableModel()
513 {
515 }
516
517//-----------------------------------------------------------------------------
518
524 public ArrayList<Integer> getSelectedAPIDs()
525 {
527 }
528
529//-----------------------------------------------------------------------------
530
535 protected ArrayList<IAtom> getAtomsSelectedFromJMol()
536 {
538 }
539
540//-----------------------------------------------------------------------------
541
546 protected void activateTabEditsListener(boolean var)
547 {
549 }
550
551//-----------------------------------------------------------------------------
552
553 /*
554 * This is needed to stop Jmol threads
555 */
556 protected void dispose()
557 {
559 }
560
561//-----------------------------------------------------------------------------
562
563}
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.
Definition: Fragment.java:61
boolean is3D()
Checks if atoms and APs contained in this fragment have non-zero 3D coordinates.
Definition: Fragment.java:195
IAtomContainer getIAtomContainer()
The molecular representation, if any, is generated by this method and stored until further changes in...
Definition: Template.java:715
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
Vertex.BBType getBuildingBlockType()
Definition: Vertex.java:298
A panel with a molecular viewer and attachment point table.
boolean loadSMILES(String smiles)
Loads a molecule build from a smiles string.
void clearAll(boolean dataIsComing)
Removes the currently visualized molecule and AP table.
ArrayList< IAtom > getAtomsSelectedFromJMol()
Identifies the atoms that are selected in the Jmol viewer.
void clearAPTable()
Clears the table of attachment points.
void loadPlainStructure(IAtomContainer mol)
Loads a structure in the Jmol viewer.
void deprotectEdits()
Overrides the flag signaling unsaved edits to saying that there are no altered data.
void loadFragmentToViewer(Fragment frag)
Loads the given fragments to this viewer.
void activateTabEditsListener(boolean var)
Allows to activate and deactivate the listener.
void clearMolecularViewer(boolean dataIsComing)
Clears the molecular viewer.
Fragment getLoadedStructure()
Returns the chemical representation of the currently loaded chemical object.
A panel to visualize a vertex as a graph component with attachment point table.
void setVertexSpecificEditableAPTable(boolean editable)
void deprotectEdits()
Overrides the flag signaling unsaved edits to saying that there are no altered data.
void clearAPTable()
Clears the table of attachment points.
A panel to visualize a vertex as two-dimensional chemical structure with attachment point table.
A panel for visualizing vertices.
void clearCurrentSystem()
Removes the currently visualized molecule and AP table.
ArrayList< Integer > getSelectedAPIDs()
Identifies which attachment points are selected in the currently active viewer.
void loadTemplateToViewer(Template tmpl)
Loads the given template to this viewer.
boolean hasUnsavedAPEdits()
Check for unsaved edits to the AP data.
DefaultTableModel getAPTableModel()
VertexViewPanel(boolean editableTable)
Constructor that allows to specify whether the AP table is editable or not.
void activateTabEditsListener(boolean var)
Allows to activate and deactivate the listener.
Map< Integer, AttachmentPoint > getActiveMapAPs()
Returns the map of attachment points in the currently active viewer.
Vertex vertex
The currently loaded vertex.
void deprotectEdits()
Overrides the flag signaling unsaved edits to saying that there are no altered data.
void loadFragmentToViewer(Fragment frag)
Loads the given fragments to this viewer.
void loadVertexToViewer(Vertex v)
Loads the given vertex to this viewer.
boolean switchbleByVertexType
Flag enabling/disabling the capability to switch between mol- and graph-based viewer.
Vertex getLoadedStructure()
Returns the currently loaded vertex.
void loadPlainStructure(IAtomContainer mol)
Loads a structure in the Jmol viewer.
VertexAsGraphViewPanel graphNodeViewer
static final long serialVersionUID
Version UID.
boolean alteredAPData
Flag signalling that data about APs has been changed in the GUI.
boolean loadSMILES(String smiles)
Loads a molecule build from a smiles string.
void setSwitchable(boolean switchable)
Enable/disable switch-able view.
ArrayList< IAtom > getAtomsSelectedFromJMol()
Identifies the atoms that are selected in the Jmol viewer.
void clearMolecularViewer(boolean dataIsComing)
Clears the molecular viewer.
VertexAsTwoDimStructureViewPanel twoDimViewer
IVertexAPSelection activeViewer
void loadEmptyVertexToViewer(EmptyVertex ev)
Loads the given empty vertex to this viewer.
Interface for all vertex viewers that intend to allow selection of attachment points.
ArrayList< Integer > getSelectedAPIDs()
Map< Integer, AttachmentPoint > getMapOfAPsInTable()
DefaultTableModel getAPTableModel()