~ubuntu-branches/ubuntu/trusty/cdk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/applications/jchempaint/dialogs/DictionaryDialog.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.sf.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.Color;
 
32
import java.awt.Dimension;
 
33
 
 
34
import javax.swing.BorderFactory;
 
35
import javax.swing.JEditorPane;
 
36
import javax.swing.JFrame;
 
37
import javax.swing.JScrollPane;
 
38
import javax.swing.JTextArea;
 
39
import javax.swing.border.Border;
 
40
 
 
41
import org.openscience.cdk.applications.jchempaint.JChemPaintEditorPanel;
 
42
import org.openscience.cdk.dict.DictionaryDatabase;
 
43
 
 
44
/**
 
45
  * Simple Dialog that shows the loaded dictionaries.
 
46
  *
 
47
  * @cdk.module jchempaint
 
48
  */
 
49
public class DictionaryDialog extends JFrame {
 
50
 
 
51
        private static final long serialVersionUID = -8933920987749316390L;
 
52
        
 
53
        private JEditorPane infoPane;
 
54
    
 
55
        /**
 
56
         * Displays the Info Dialog for JChemPaint. 
 
57
         */
 
58
    public DictionaryDialog() {
 
59
        super("Loaded Dictionaries");
 
60
        createDialog();
 
61
        displayContent();
 
62
        pack();
 
63
        setVisible(true);
 
64
    }
 
65
    
 
66
    
 
67
    
 
68
    private void createDialog(){
 
69
        
 
70
        getContentPane().setLayout(new BorderLayout());
 
71
        setBackground(Color.white);
 
72
 
 
73
        Border lb = BorderFactory.createLineBorder(Color.white, 5);
 
74
        JTextArea jtf1 = new JTextArea("Loaded Dictionaries");
 
75
        jtf1.setBorder(lb);
 
76
        jtf1.setEditable(false);
 
77
        infoPane = new JEditorPane();
 
78
        infoPane.setEditable(false);
 
79
        infoPane.setBorder(lb);
 
80
        infoPane.revalidate();
 
81
        JScrollPane scrollPane = new JScrollPane(infoPane);
 
82
        scrollPane.setPreferredSize(new Dimension(400, 350));
 
83
        
 
84
        setTitle("Information");
 
85
        getContentPane().add("Center",scrollPane);
 
86
        getContentPane().add("North",jtf1);
 
87
    }
 
88
    
 
89
    private void displayContent() {
 
90
        StringBuffer content = new StringBuffer();
 
91
        content.append("<html>\n");
 
92
        
 
93
        // convert Dictionary to HTML
 
94
        DictionaryDatabase dictdb = JChemPaintEditorPanel.getDictionaryDatabase();
 
95
        String[] dicts = dictdb.getDictionaryNames();
 
96
        if (dicts.length > 0) {
 
97
            content.append("<table>");
 
98
            for (int i=0; i<dicts.length; i++) {
 
99
                String[] entries = dictdb.getDictionaryEntries(dicts[i]);
 
100
                for (int j=0; j<entries.length; j++) {
 
101
                    content.append("<tr>");
 
102
                    content.append("<td>" + dicts[i]);
 
103
                    content.append("<td>" + entries[j]);
 
104
                    content.append("</tr>\n");
 
105
                }
 
106
            }
 
107
            content.append("</table>");
 
108
        } else {
 
109
            content.append("<p>No dictionaries are loaded.");
 
110
        }
 
111
        
 
112
        content.append("</html>\n");
 
113
        
 
114
        infoPane.setContentType("text/html");
 
115
        infoPane.setText(content.toString());
 
116
        infoPane.revalidate();
 
117
    }
 
118
 
 
119
}