~ubuntu-branches/ubuntu/maverick/cdk/maverick

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/applications/jchempaint/dialogs/EditDictRefs.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $RCSfile$
 
2
 * $Author: egonw $
 
3
 * $Date: 2007-01-04 18:26:00 +0100 (Thu, 04 Jan 2007) $
 
4
 * $Revision: 7634 $
 
5
 *
 
6
 * Copyright (C) 1997-2007  The JChemPaint project
 
7
 *
 
8
 * Contact: jchempaint-devel@lists.sourceforge.net
 
9
 *
 
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.
 
14
 * All we ask is that proper credit is given for our work, which includes
 
15
 * - but is not limited to - adding the above copyright notice to the beginning
 
16
 * of your source code files, and to any copyright notice that you may distribute
 
17
 * with programs based on this work.
 
18
 * 
 
19
 * This program is distributed in the hope that it will be useful,
 
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
 * GNU Lesser General Public License for more details.
 
23
 * 
 
24
 * You should have received a copy of the GNU Lesser General Public License
 
25
 * along with this program; if not, write to the Free Software
 
26
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
27
 */
 
28
package org.openscience.cdk.applications.jchempaint.dialogs;
 
29
 
 
30
import java.awt.BorderLayout;
 
31
import java.awt.Dimension;
 
32
import java.awt.event.ActionEvent;
 
33
 
 
34
import javax.swing.AbstractAction;
 
35
import javax.swing.DefaultCellEditor;
 
36
import javax.swing.JButton;
 
37
import javax.swing.JComboBox;
 
38
import javax.swing.JFrame;
 
39
import javax.swing.JPanel;
 
40
import javax.swing.JScrollPane;
 
41
import javax.swing.JTable;
 
42
import javax.swing.table.TableColumn;
 
43
 
 
44
import org.openscience.cdk.ChemObject;
 
45
import org.openscience.cdk.applications.jchempaint.JChemPaintEditorPanel;
 
46
import org.openscience.cdk.applications.swing.DictRefEditorTableModel;
 
47
 
 
48
/**
 
49
 * Frame to allows editing of dictionary references of 
 
50
 * ChemObjects.
 
51
 *
 
52
 * @cdk.module jchempaint
 
53
 */
 
54
public class EditDictRefs extends JFrame  {
 
55
    
 
56
        private static final long serialVersionUID = 1835058218886715502L;
 
57
        
 
58
        DictRefEditorTableModel tableModel;
 
59
    
 
60
    public EditDictRefs() {
 
61
        super("Edit Dictionary References");
 
62
        getContentPane().setLayout(new BorderLayout());
 
63
        JPanel southPanel = new JPanel();
 
64
        JButton cancelButton = new JButton("Cancel");
 
65
        JButton applyButton = new JButton("Apply");
 
66
        applyButton.addActionListener(new ApplyAction());
 
67
        cancelButton.addActionListener(new CancelAction());
 
68
        southPanel.add(applyButton);
 
69
        southPanel.add(cancelButton);
 
70
        
 
71
        tableModel = new DictRefEditorTableModel();
 
72
        JTable table = new JTable(tableModel);
 
73
        table.setPreferredSize(new Dimension(500, 300));
 
74
        
 
75
        // setup dictionary list
 
76
        TableColumn dictColumn = table.getColumnModel().getColumn(1);
 
77
        JComboBox comboBox = new JComboBox();
 
78
        String[] dicts = JChemPaintEditorPanel.getDictionaryDatabase().getDictionaryNames();
 
79
        for (int i=0; i<dicts.length; i++) {
 
80
            comboBox.addItem(dicts[i]);
 
81
        }
 
82
        dictColumn.setCellEditor(new DefaultCellEditor(comboBox));
 
83
        
 
84
        JScrollPane scrollPane = new JScrollPane(table);
 
85
        scrollPane.setPreferredSize(new Dimension(500, 100));
 
86
        
 
87
        getContentPane().setLayout(new BorderLayout());
 
88
        getContentPane().add("Center", scrollPane);
 
89
        getContentPane().add("South", southPanel);
 
90
    }
 
91
    
 
92
    /**
 
93
     * Sets the IChemObject that is being edited.
 
94
     */
 
95
    public void setChemObject(ChemObject object) {
 
96
        tableModel.setChemObject(object);
 
97
    }
 
98
    
 
99
    public void closeFrame() {
 
100
        dispose();
 
101
    }
 
102
    
 
103
    class ApplyAction extends AbstractAction {
 
104
        
 
105
                private static final long serialVersionUID = -5199060935605242223L;
 
106
 
 
107
                ApplyAction() {
 
108
            super("Apply");
 
109
        }
 
110
        
 
111
        public void actionPerformed(ActionEvent e) {
 
112
        }
 
113
        
 
114
    }
 
115
    
 
116
    class CancelAction extends AbstractAction {
 
117
        
 
118
                private static final long serialVersionUID = -3203480495994212236L;
 
119
 
 
120
                CancelAction() {
 
121
            super("Cancel");
 
122
        }
 
123
        
 
124
        public void actionPerformed(ActionEvent e) {
 
125
            closeFrame();
 
126
        }
 
127
    }
 
128
}