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

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/io/iterator/DefaultIteratingChemObjectReader.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:46:10 +0100 (Thu, 04 Jan 2007) $
 
4
 * $Revision: 7636 $
 
5
 *
 
6
 * Copyright (C) 2003-2007  The Jmol Development Team
 
7
 *
 
8
 * Contact: cdk-devel@lists.sourceforge.net
 
9
 *
 
10
 *  This library is free software; you can redistribute it and/or
 
11
 *  modify it under the terms of the GNU Lesser General Public
 
12
 *  License as published by the Free Software Foundation; either
 
13
 *  version 2.1 of the License, or (at your option) any later version.
 
14
 *
 
15
 *  This library 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 GNU
 
18
 *  Lesser General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU Lesser General Public
 
21
 *  License along with this library; if not, write to the Free Software
 
22
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
23
 */
 
24
package org.openscience.cdk.io.iterator;
 
25
 
 
26
import java.util.Vector;
 
27
 
 
28
import org.openscience.cdk.io.ReaderEvent;
 
29
import org.openscience.cdk.io.listener.IChemObjectIOListener;
 
30
import org.openscience.cdk.io.listener.IReaderListener;
 
31
import org.openscience.cdk.io.setting.IOSetting;
 
32
 
 
33
/**
 
34
 * Abstract class that IteratingChemObjectReader's can implement to have it
 
35
 * take care of basic stuff, like managing the ReaderListeners.
 
36
 *
 
37
 * @cdk.module io
 
38
 */
 
39
public abstract class DefaultIteratingChemObjectReader implements IIteratingChemObjectReader {
 
40
 
 
41
    /**
 
42
     * An event to be sent to listeners when a frame is read.
 
43
     */
 
44
    private ReaderEvent frameReadEvent = null;
 
45
 
 
46
    /**
 
47
     * Holder of reader event listeners.
 
48
     */
 
49
    private Vector listenerList = new Vector();
 
50
 
 
51
    public void addChemObjectIOListener(IChemObjectIOListener listener) {
 
52
        listenerList.addElement(listener);
 
53
    }
 
54
 
 
55
    public void removeChemObjectIOListener(IChemObjectIOListener listener) {
 
56
        listenerList.removeElement(listener);
 
57
    }
 
58
 
 
59
    public boolean accepts(Class objectClass) {
 
60
        return false; // it's an iterator, idiot.
 
61
    }
 
62
    
 
63
    /* Extra convenience methods */
 
64
    
 
65
    /**
 
66
     * File IO generally does not support removing of entries.
 
67
     */
 
68
    public void remove() {
 
69
        throw new UnsupportedOperationException();
 
70
    }
 
71
    
 
72
    /**
 
73
     * Sends a frame read event to the registered ReaderListeners.
 
74
     */
 
75
    protected void fireFrameRead() {
 
76
        for (int i = 0; i < listenerList.size(); ++i) {
 
77
            IReaderListener listener = (IReaderListener) listenerList.elementAt(i);
 
78
            
 
79
            // Lazily create the event:
 
80
            if (frameReadEvent == null) {
 
81
                frameReadEvent = new ReaderEvent(this);
 
82
            }
 
83
            listener.frameRead(frameReadEvent);
 
84
        }
 
85
    }
 
86
 
 
87
    protected void fireIOSettingQuestion(IOSetting setting) {
 
88
        for (int i = 0; i < listenerList.size(); ++i) {
 
89
            IChemObjectIOListener listener = (IChemObjectIOListener) listenerList.elementAt(i);
 
90
            listener.processIOSettingQuestion(setting);
 
91
        }
 
92
    }
 
93
 
 
94
    public IOSetting[] getIOSettings() {
 
95
        return new IOSetting[0];
 
96
    }
 
97
   
 
98
}