3
* $Date: 2007-01-04 18:26:00 +0100 (Thu, 04 Jan 2007) $
6
* Copyright (C) 2001-2007 The Chemistry Development Kit (CDK) project
8
* Contact: cdk-devel@lists.sourceforge.net
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public License
12
* as published by the Free Software Foundation; either version 2.1
13
* of the License, or (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24
package org.openscience.cdk.applications.swing;
26
import java.awt.BorderLayout;
27
import java.awt.Dimension;
28
import java.util.EventObject;
30
import javax.swing.JFrame;
31
import javax.swing.JPanel;
32
import javax.swing.JScrollPane;
33
import javax.swing.JTable;
34
import javax.swing.table.AbstractTableModel;
36
import org.openscience.cdk.event.ICDKChangeListener;
39
* @cdk.module applications
42
public class AtomicTable extends JPanel implements ICDKChangeListener {
44
private static final long serialVersionUID = -7017202227040620173L;
47
private String title = "Molecule Viewer";
49
public AtomicTable(org.openscience.cdk.interfaces.IAtomContainer atomContainer) {
50
AtomContainerModel acm = new AtomContainerModel(atomContainer);
51
table = new JTable(acm);
52
table.setPreferredScrollableViewportSize(new Dimension(500,300));
53
JScrollPane scrollPane = new JScrollPane(table);
54
this.add(scrollPane, BorderLayout.CENTER);
58
* Contructs a JFrame into which this JPanel is
59
* put and displays the frame with the molecule
63
JFrame frame = new JFrame();
64
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
65
frame.getContentPane().add(this);
66
frame.setTitle(title);
68
frame.setVisible(true);
71
public void stateChanged(EventObject e) {
72
// not implemented yet
75
class AtomContainerModel extends AbstractTableModel {
77
private static final long serialVersionUID = -3331835007097257315L;
79
private org.openscience.cdk.interfaces.IAtomContainer atomContainer;
81
final String[] columnNames = {"atom", "x2", "y2", "x3",
82
"y3", "z3", "charge"};
84
public AtomContainerModel(org.openscience.cdk.interfaces.IAtomContainer ac) {
88
public int getColumnCount() {
89
return columnNames.length;
92
public int getRowCount() {
93
return atomContainer.getAtomCount();
96
public String getColumnName(int col) {
97
return columnNames[col];
100
public Class getColumnClass(int col) {
101
Object o = getValueAt(0,col);
103
return (new String()).getClass();
109
public Object getValueAt(int row, int col) {
110
if (getColumnName(col).equals("atom")) {
111
return (atomContainer.getAtom(row)).getSymbol();
112
} else if (getColumnName(col).equals("x2")) {
113
return new Double((atomContainer.getAtom(row)).getPoint2d().x);
114
} else if (getColumnName(col).equals("y2")) {
115
return new Double((atomContainer.getAtom(row)).getPoint2d().y);
116
} else if (getColumnName(col).equals("x3")) {
117
return new Double((atomContainer.getAtom(row)).getPoint3d().x);
118
} else if (getColumnName(col).equals("y3")) {
119
return new Double((atomContainer.getAtom(row)).getPoint3d().y);
120
} else if (getColumnName(col).equals("z3")) {
121
return new Double((atomContainer.getAtom(row)).getPoint3d().z);
122
} else if (getColumnName(col).equals("charge")) {
123
return new Double((atomContainer.getAtom(row)).getCharge());
129
public boolean isCellEditable(int row, int col) {