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

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/applications/jchempaint/action/ShowChemObjectDumpAction.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
/*
 
2
 *  $RCSfile$
 
3
 *  $Author: egonw $
 
4
 *  $Date: 2007-04-16 10:40:19 +0200 (Mon, 16 Apr 2007) $
 
5
 *  $Revision: 8201 $
 
6
 *
 
7
 *  Copyright (C) 2003-2007  The JChemPaint project
 
8
 *
 
9
 *  Contact: jchempaint-devel@lists.sourceforge.net
 
10
 *
 
11
 *  This program is free software; you can redistribute it and/or
 
12
 *  modify it under the terms of the GNU Lesser General Public License
 
13
 *  as published by the Free Software Foundation; either version 2.1
 
14
 *  of the License, or (at your option) any later version.
 
15
 *  All we ask is that proper credit is given for our work, which includes
 
16
 *  - but is not limited to - adding the above copyright notice to the beginning
 
17
 *  of your source code files, and to any copyright notice that you may distribute
 
18
 *  with programs based on this work.
 
19
 *
 
20
 *  This program is distributed in the hope that it will be useful,
 
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
 *  GNU Lesser General Public License for more details.
 
24
 *
 
25
 *  You should have received a copy of the GNU Lesser General Public License
 
26
 *  along with this program; if not, write to the Free Software
 
27
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
28
 */
 
29
package org.openscience.cdk.applications.jchempaint.action;
 
30
 
 
31
import nu.xom.Element;
 
32
import org.openscience.cdk.applications.jchempaint.dialogs.TextViewDialog;
 
33
import org.openscience.cdk.interfaces.IAtom;
 
34
import org.openscience.cdk.interfaces.IBond;
 
35
import org.openscience.cdk.interfaces.IChemObject;
 
36
import org.openscience.cdk.interfaces.IMolecule;
 
37
import org.openscience.cdk.libio.cml.Convertor;
 
38
import org.xmlcml.cml.element.CMLCml;
 
39
 
 
40
import javax.swing.*;
 
41
import java.awt.*;
 
42
import java.awt.event.ActionEvent;
 
43
 
 
44
 
 
45
/**
 
46
 * Allow to dump a IChemObject to a newly opened screen
 
47
 *
 
48
 * @cdk.module       jchempaint
 
49
 * @author           steinbeck
 
50
 * @cdk.require      java1.5+
 
51
 * @cdk.builddepends xom-1.0.jar
 
52
 */
 
53
public class ShowChemObjectDumpAction extends JCPAction
 
54
{
 
55
 
 
56
    private static final long serialVersionUID = 3112715648384115740L;
 
57
    
 
58
    TextViewDialog dialog = null;
 
59
 
 
60
        public void actionPerformed(ActionEvent event)
 
61
        {
 
62
                IChemObject object = getSource(event);
 
63
                // XXX needs fixing
 
64
                // JFrame frame = (JFrame) jcpPanel.getFrame();
 
65
                JFrame frame = new JFrame();
 
66
                if (dialog == null)
 
67
                {
 
68
                        dialog = new TextViewDialog(frame, "IChemObject Dump", new Dimension(500, 300));
 
69
                }
 
70
 
 
71
                Convertor convertor = new Convertor(false, null);
 
72
                try {
 
73
                        Element cmlDOM = new CMLCml();
 
74
                        if (object instanceof IMolecule) {
 
75
                                cmlDOM = convertor.cdkMoleculeToCMLMolecule((IMolecule)object);
 
76
                        } else if (object instanceof IAtom) {
 
77
                                cmlDOM = convertor.cdkAtomToCMLAtom(null, (IAtom)object);
 
78
                        } else if (object instanceof IBond) {
 
79
                                cmlDOM = convertor.cdkBondToCMLBond((IBond)object);
 
80
                        }
 
81
                        dialog.setText(cmlDOM.toXML());
 
82
                } catch (Exception exception)
 
83
                {
 
84
                        String message = "CML Writer cannot write ChemOject: " + object.getClass().getName();
 
85
                        logger.error(message);
 
86
                        logger.debug(exception);
 
87
                        dialog.setText(message);
 
88
                }
 
89
 
 
90
                dialog.setVisible(true);
 
91
        }
 
92
 
 
93
}
 
94