$darkmode
DENOPTIM
GUIAtomSelectionDialog.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
21import java.awt.Component;
22import java.awt.event.ActionEvent;
23import java.awt.event.ActionListener;
24import java.util.ArrayList;
25import java.util.List;
26
27import javax.swing.JPanel;
28
29import org.openscience.cdk.interfaces.IAtom;
30import org.openscience.cdk.interfaces.IAtomContainer;
31
32import denoptim.graph.Vertex;
33import denoptim.utils.MoleculeUtils;
34
39{
40
44 private static final long serialVersionUID = -1416475901274128714L;
45
47
48 private List<List<IAtom>> selectedAtoms = new ArrayList<>();
49
50//------------------------------------------------------------------------------
51
56 @SuppressWarnings("serial")
57 public GUIAtomSelectionDialog(Component refForPlacement, Vertex vertex,
58 List<IAtom> highlightedAtoms,
59 int selectionGroupsCount, int selectionGroupIndex)
60 {
61 super(refForPlacement);
62
63 if (selectionGroupsCount > 1) {
64 setTitle("Select Atoms of group " + (selectionGroupIndex) + " (out of " + selectionGroupsCount + " groups)");
65 this.btnDone.setText("Done");
66 this.btnDone.setToolTipText("Save selection and move to next selection group.");
67 } else {
68 setTitle("Select Atoms");
69 this.btnDone.setText("Done");
70 this.btnDone.setToolTipText("Save selection.");
71 }
72
73 // The viewer with Jmol and non-editable APtable
74 vertexViewer = new VertexViewPanel(false);
77
78 // Highlight the atoms if provided
79 if (highlightedAtoms != null) {
80 vertexViewer.highlightAtoms(highlightedAtoms);
81 }
82
83 // Customize the buttons of the modal dialog
84 for (ActionListener listener : btnDone.getActionListeners())
85 {
86 btnDone.removeActionListener(listener);
87 }
88 this.btnDone.setText("Done");
89 this.btnDone.setToolTipText("Save selection and moves on.");
90 this.btnDone.addActionListener(new ActionListener() {
91
92 @Override
93 public void actionPerformed(ActionEvent e) {
94 // Store the current selection
95 IAtomContainer iac = vertex.getIAtomContainer();
96 List<IAtom> selectedAtms = vertexViewer.getAtomsSelectedFromJMol();
97 result = selectedAtms;
98
99 //TODO del
100 for (IAtom atm : selectedAtms) {
101 System.out.println(MoleculeUtils.getAtomRef(atm, iac));
102 }
103
104 close();
105 }
106 });
107
108 this.btnCanc.setEnabled(true);
109 this.btnCanc.setVisible(true);
110 }
111
112//-----------------------------------------------------------------------------
113
114 @Override
115 public void dispose()
116 {
117 if (vertexViewer != null)
118 {
119 remove(vertexViewer);
121 vertexViewer = null;
122 }
123 super.dispose();
124 }
125
126//-----------------------------------------------------------------------------
127
128}
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
A dialog window meant only to select atoms one or multiple times.
static final long serialVersionUID
Version UID.
JButton btnCanc
The button that is used to close the dialog without processing any input.
void addToCentralPane(JComponent comp)
Adds a component to the central part of this dialog frame.
JButton btnDone
The button that is used to launch the processing of the data given to the open dialog,...
Object result
The result to be returned once the dialog is closed.
void close()
Closes the dialog window.
A panel for visualizing vertices.
void loadVertexToViewer(Vertex v)
Loads the given vertex to this viewer.
void highlightAtoms(List< IAtom > atoms)
Highlights the given atoms in the Jmol viewer.
ArrayList< IAtom > getAtomsSelectedFromJMol()
Identifies the atoms that are selected in the Jmol viewer.
Utilities for molecule conversion.
static String getAtomRef(IAtom atm, IAtomContainer mol)