$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.List;
30import java.util.Map;
31
32import javax.swing.JButton;
33import javax.swing.JLabel;
34import javax.swing.JPanel;
35import javax.swing.table.DefaultTableModel;
36
37import org.openscience.cdk.interfaces.IAtom;
38import org.openscience.cdk.interfaces.IAtomContainer;
39
40import denoptim.exception.DENOPTIMException;
41import denoptim.graph.AttachmentPoint;
42import denoptim.graph.EmptyVertex;
43import denoptim.graph.Fragment;
44import denoptim.graph.Template;
45import denoptim.graph.Vertex;
46
47
55public class VertexViewPanel extends JPanel
56{
60 private static final long serialVersionUID = 1L;
61
65 private Vertex vertex;
66
70 public boolean alteredAPData = false;
71
72 private JPanel titlePanel;
73
74 private JLabel labTitle;
75 private JButton btnSwitchToNodeViewer;
76 private JButton btnSwitchToMolViewer;
77 private JButton btnSwitchTo2DViewer;
78
79 private JPanel centralPanel;
80
81 private JPanel emptyViewerCard;
86 protected final String EMPTYCARDNAME = "emptyCard";
87 protected final String GRAPHVIEWERCARDNAME = "emptyVertesCard";
88 protected final String MOLVIEWERCARDNAME = "fragViewerCard";
89 protected final String TWODVIEWERCARDNAME = "twoDimViewerCard";
90
91 private boolean editableAPTable = false;
92
97 private boolean switchbleByVertexType = true;
98
99//-----------------------------------------------------------------------------
100
106 public VertexViewPanel(boolean editableTable)
107 {
108 super(new BorderLayout());
109 this.editableAPTable = editableTable;
110 initialize();
111 }
112
113//-----------------------------------------------------------------------------
114
115 private void initialize()
116 {
117 centralPanel = new JPanel(new CardLayout());
118 this.add(centralPanel, BorderLayout.CENTER);
119
120 titlePanel = new JPanel();
121
122 labTitle = new JLabel("");
123 titlePanel.add(labTitle);
124
125 btnSwitchToNodeViewer = new JButton("Node View");
126 btnSwitchToNodeViewer.setToolTipText("Switch to graph node depiction "
127 + "of this vertex.");
128 btnSwitchToNodeViewer.addActionListener(new ActionListener() {
129 public void actionPerformed(ActionEvent e) {
131 }
132 });
133 btnSwitchToNodeViewer.setEnabled(false);
135
136 btnSwitchToMolViewer = new JButton("3D Molecule View");
137 btnSwitchToMolViewer.setToolTipText("Switch to 3D molecular depiction "
138 + "of this vertex.");
139 btnSwitchToMolViewer.addActionListener(new ActionListener() {
140 public void actionPerformed(ActionEvent e) {
142 }
143 });
144 btnSwitchToMolViewer.setEnabled(false);
146
147 btnSwitchTo2DViewer = new JButton("2D Molecular Structure");
148 btnSwitchTo2DViewer.setToolTipText("Switch to 2D molecular depiction "
149 + "of this vertex.");
150 btnSwitchTo2DViewer.addActionListener(new ActionListener() {
151 public void actionPerformed(ActionEvent e) {
153 }
154 });
155 btnSwitchTo2DViewer.setEnabled(false);
157
158 this.add(titlePanel, BorderLayout.NORTH);
159
160 emptyViewerCard = new JPanel();
161 emptyViewerCard.setToolTipText("Vertices are displayed here.");
163
165 graphNodeViewer.addPropertyChangeListener(
167 new PropertyChangeListener() {
168 @Override
169 public void propertyChange(PropertyChangeEvent evt) {
170 alteredAPData = true;
171 firePropertyChange(IVertexAPSelection.APDATACHANGEEVENT, false,
172 true);
173 }
174 });
176
178 fragViewer.addPropertyChangeListener(
180 new PropertyChangeListener() {
181 @Override
182 public void propertyChange(PropertyChangeEvent evt) {
183 alteredAPData = true;
184 firePropertyChange(IVertexAPSelection.APDATACHANGEEVENT, false,
185 true);
186 }
187 });
189
191 twoDimViewer.addPropertyChangeListener(
193 new PropertyChangeListener() {
194 @Override
195 public void propertyChange(PropertyChangeEvent evt) {
196 alteredAPData = true;
197 firePropertyChange(IVertexAPSelection.APDATACHANGEEVENT, false,
198 true);
199 }
200 });
202
203
205 }
206
207//-----------------------------------------------------------------------------
208
213 public boolean hasUnsavedAPEdits()
214 {
215 return alteredAPData;
216 }
217
218//-----------------------------------------------------------------------------
219
224 public void deprotectEdits()
225 {
228 alteredAPData = false;
229 }
230
231//-----------------------------------------------------------------------------
232
237 public void setSwitchable(boolean switchable)
238 {
240 {
241 if (switchable)
242 {
243 btnSwitchToMolViewer.setEnabled(true);
244 btnSwitchToNodeViewer.setEnabled(true);
245 btnSwitchTo2DViewer.setEnabled(true);
246 } else {
247 btnSwitchToMolViewer.setEnabled(false);
248 btnSwitchToNodeViewer.setEnabled(false);
249 btnSwitchTo2DViewer.setEnabled(false);
250 }
251 }
252 }
253
254//-----------------------------------------------------------------------------
255
256 private void switchToEmptyCard()
257 {
258 btnSwitchToMolViewer.setEnabled(false);
259 btnSwitchToNodeViewer.setEnabled(false);
260 btnSwitchTo2DViewer.setEnabled(false);
261 ((CardLayout) centralPanel.getLayout()).show(centralPanel,
263 activeViewer = null;
264 }
265
266//-----------------------------------------------------------------------------
267
269 {
270 ((CardLayout) centralPanel.getLayout()).show(centralPanel,
273 }
274
275//-----------------------------------------------------------------------------
276
278 {
279 ((CardLayout) centralPanel.getLayout()).show(centralPanel,
282 }
283
284//-----------------------------------------------------------------------------
285
286 private void switchTo2DViewer()
287 {
288 ((CardLayout) centralPanel.getLayout()).show(centralPanel,
291 }
292
293//-----------------------------------------------------------------------------
294
306 public boolean loadSMILES(String smiles)
307 {
309 return fragViewer.loadSMILES(smiles);
310 }
311
312//-----------------------------------------------------------------------------
313
324 {
325 Vertex v = null;
326 if (vertex == null || vertex instanceof Fragment)
327 {
330 } else {
331 v = vertex;
332 }
333 return v;
334 }
335
336//-----------------------------------------------------------------------------
337
342 public void loadPlainStructure(IAtomContainer mol)
343 {
346 }
347
348//-----------------------------------------------------------------------------
349
359 {
360 vertex = v;
361 if (v instanceof Fragment) {
362 labTitle.setText("Fragment");
363 Fragment frag = (Fragment) v;
365 } else if (v instanceof EmptyVertex) {
366 labTitle.setText("EmptyVertex");
367 EmptyVertex ev = (EmptyVertex) v;
369 } else if (v instanceof Template) {
370 labTitle.setText("Template");
371 Template tmpl = (Template) v;
373 } else {
374 System.err.println("Loading empty card as a result of vertex with "
375 + "type " + v.getClass().getName());
377 }
378 }
379
380//-----------------------------------------------------------------------------
381
389 {
390 btnSwitchToMolViewer.setEnabled(false);
391 btnSwitchToNodeViewer.setEnabled(false);
392 btnSwitchTo2DViewer.setEnabled(false);
395 switchbleByVertexType = false;
396 }
397
398//-----------------------------------------------------------------------------
399
409 {
410 btnSwitchToMolViewer.setEnabled(true);
411 btnSwitchToNodeViewer.setEnabled(true);
412 btnSwitchTo2DViewer.setEnabled(true);
417 if (frag.is3D())
418 {
420 } else {
422 }
423 }
424
425//-----------------------------------------------------------------------------
426
432 {
433 if (tmpl.containsAtoms())
434 {
435 Fragment frag;
436 try
437 {
438 frag = new Fragment(tmpl.getVertexId(),
440
442 btnSwitchToMolViewer.setEnabled(true);
443 btnSwitchToNodeViewer.setEnabled(true);
444 //TODO: maybe one day we'll enable looking at the 2D of the whole template
445 btnSwitchTo2DViewer.setEnabled(false);
447 } catch (DENOPTIMException e)
448 {
449 // We lease data in the viewer to increase speed of execution, but the
450 // leftover is outdated! This is the meaning of 'true'
451 fragViewer.clearAll(true);
452 switchbleByVertexType = false;
453 }
454 } else {
455 // We lease data in the viewer to increase speed of execution, but the
456 // leftover is outdated! This is the meaning of 'true'
457 fragViewer.clearAll(true);
458 switchbleByVertexType = false;
459 }
463 }
464
465//-----------------------------------------------------------------------------
466
471 public void highlightAtoms(List<IAtom> atoms)
472 {
473 fragViewer.setColorOfAtoms(atoms, "purple");
474 }
475
476//-----------------------------------------------------------------------------
477
481 public void clearCurrentSystem()
482 {
483 vertex = null;
484 graphNodeViewer.mapAPs = null;
486 fragViewer.mapAPs = null;
489 // NB: avoid it very slow! Mol viewer gets update upon loading a new mol
490 // clearMolecularViewer();
491 }
492
493//-----------------------------------------------------------------------------
494
503 public void clearMolecularViewer(boolean dataIsComing)
504 {
505 fragViewer.clearMolecularViewer(dataIsComing);
506 }
507
508//-----------------------------------------------------------------------------
509
514 public Map<Integer,AttachmentPoint> getActiveMapAPs()
515 {
517 }
518
519//-----------------------------------------------------------------------------
520
524 public DefaultTableModel getAPTableModel()
525 {
527 }
528
529//-----------------------------------------------------------------------------
530
536 public ArrayList<Integer> getSelectedAPIDs()
537 {
539 }
540
541//-----------------------------------------------------------------------------
542
547 protected ArrayList<IAtom> getAtomsSelectedFromJMol()
548 {
550 }
551
552//-----------------------------------------------------------------------------
553
558 protected void activateTabEditsListener(boolean var)
559 {
561 }
562
563//-----------------------------------------------------------------------------
564
565 /*
566 * This is needed to stop Jmol threads
567 */
568 protected void dispose()
569 {
571 }
572
573//-----------------------------------------------------------------------------
574
575}
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:318
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.
void setColorOfAtoms(List< IAtom > atoms, String color)
Highlights the given atoms in the Jmol viewer using colored halos (the same ring style as selection h...
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.
void highlightAtoms(List< IAtom > atoms)
Highlights the given atoms in the Jmol viewer.
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()