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

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/io/cml/JMOLANIMATIONConvention.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
/* $Revision: 7981 $ $Author: egonw $ $Date: 2007-02-20 18:05:37 +0100 (Tue, 20 Feb 2007) $
 
2
 *
 
3
 * Copyright (C) 1997-2007  Egon Willighagen <egonw@users.sf.net>
 
4
 *
 
5
 * Contact: cdk-devel@lists.sourceforge.net
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public License
 
9
 * as published by the Free Software Foundation; either version 2.1
 
10
 * of the License, or (at your option) any later version.
 
11
 * All we ask is that proper credit is given for our work, which includes
 
12
 * - but is not limited to - adding the above copyright notice to the beginning
 
13
 * of your source code files, and to any copyright notice that you may distribute
 
14
 * with programs based on this work.
 
15
 *
 
16
 * This program is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 * GNU Lesser General Public License for more details.
 
20
 *
 
21
 * You should have received a copy of the GNU Lesser General Public License
 
22
 * along with this program; if not, write to the Free Software
 
23
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
24
 *
 
25
 */
 
26
package org.openscience.cdk.io.cml;
 
27
 
 
28
import org.openscience.cdk.interfaces.IChemFile;
 
29
import org.openscience.cdk.tools.LoggingTool;
 
30
import org.xml.sax.Attributes;
 
31
 
 
32
/**
 
33
 * @author Egon Willighagen <egonw@sci.kun.nl>
 
34
 *
 
35
 * @cdk.module io
 
36
 */
 
37
public class JMOLANIMATIONConvention extends CMLCoreModule {
 
38
 
 
39
    private final int UNKNOWN = -1;
 
40
    private final int ENERGY = 1;
 
41
 
 
42
    private int current;
 
43
    private String frame_energy;
 
44
    private LoggingTool logger;
 
45
 
 
46
    public JMOLANIMATIONConvention(IChemFile chemFile) {
 
47
        super(chemFile);
 
48
        logger = new LoggingTool(this);
 
49
        current = UNKNOWN;
 
50
    }
 
51
 
 
52
    public JMOLANIMATIONConvention(ICMLModule conv) {
 
53
        super(conv);
 
54
        logger = new LoggingTool(this);
 
55
    }
 
56
 
 
57
    public void startElement(CMLStack xpath, String uri, String local, String raw, Attributes atts) {
 
58
        String name = local;
 
59
        if (name.equals("list")) {
 
60
            logger.debug("Oke, JMOLANIMATION seems to be kicked in :)");
 
61
//            cdo.startObject("Animation");
 
62
            currentChemSequence = currentChemFile.getBuilder().newChemSequence();
 
63
            super.startElement(xpath, uri, local, raw, atts);
 
64
        } else if (name.equals("molecule")) {
 
65
//            cdo.startObject("Frame");
 
66
                currentChemModel = currentChemFile.getBuilder().newChemModel();
 
67
            logger.debug("New frame being parsed.");
 
68
            super.startElement(xpath, uri, local, raw, atts);
 
69
        } else if (name.equals("float")) {
 
70
            boolean isEnergy = false;
 
71
            logger.debug("FLOAT found!");
 
72
            for (int i = 0; i < atts.getLength(); i++) {
 
73
              logger.debug(" att: ", atts.getQName(i), " -> ", atts.getValue(i));
 
74
                if (atts.getQName(i).equals("title")
 
75
                        && atts.getValue(i).equals("FRAME_ENERGY")) {
 
76
                    isEnergy = true;
 
77
                }
 
78
            }
 
79
            if (isEnergy) {
 
80
                // oke, this is the frames energy!
 
81
                current = ENERGY;
 
82
            } else {
 
83
                super.startElement(xpath, uri, local, raw, atts);
 
84
            }
 
85
        } else {
 
86
            super.startElement(xpath, uri, local, raw, atts);
 
87
        }
 
88
    }
 
89
 
 
90
    public void endElement(CMLStack xpath, String uri, String local, String raw) {
 
91
        String name = local;
 
92
        if (current == ENERGY) {
 
93
//            cdo.setObjectProperty("Frame", "energy", frame_energy);
 
94
                // + " " + units);
 
95
                // FIXME: does not have a ChemFileCDO equivalent
 
96
            current = UNKNOWN;
 
97
            frame_energy = "";
 
98
        } else if (name.equals("list")) {
 
99
            super.endElement(xpath, uri, local, raw);
 
100
//            cdo.endObject("Animation");
 
101
            currentChemFile.addChemSequence(currentChemSequence);
 
102
        } else if (name.equals("molecule")) {
 
103
            super.endElement(xpath, uri, local, raw);
 
104
//            cdo.endObject("Frame");
 
105
            // nothing done in the CD upon this event
 
106
        } else {
 
107
            super.endElement(xpath, uri, local, raw);
 
108
        }
 
109
    }
 
110
 
 
111
    public void characterData(CMLStack xpath, char ch[], int start, int length) {
 
112
        if (current == ENERGY) {
 
113
            frame_energy = new String(ch, start, length);
 
114
        } else {
 
115
            super.characterData(xpath, ch, start, length);
 
116
        }
 
117
    }
 
118
}