View Javadoc

1   package org.molwind.chemical.model;
2   
3   /*
4    * This file is part of Molwind.
5    *
6    * Molwind is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * Molwind is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with Molwind. If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  import java.io.File;
21  import java.util.ArrayList;
22  import java.util.Iterator;
23  
24  import org.molwind.chemical.io.SDFileIterator;
25  import org.molwind.chemical.view.ChemicalTileGenerator;
26  import org.molwind.model.AbstractMolwindWorld;
27  import org.molwind.view.TileGenerator;
28  
29  /**
30   * ChemicalWorld represents a world of chemicals.
31   *
32   * @author <a href="mailto:oliver.karch@molwind.org">Oliver Karch</a>
33   * @version 1.0
34   */
35  public class ChemicalWorld extends AbstractMolwindWorld {
36  
37      private ArrayList files;
38      private ChemicalTileGenerator tileGenerator;
39  
40      /**
41       * Creates a new chemical world.
42       *
43       * @param worldName
44       *      the name of the world
45       * @param file
46       *      molecule data read from an SDFile
47       */
48      public ChemicalWorld(final String worldName, final File file) {
49          super(worldName);
50          files = new ArrayList();
51          addFile(file);
52          tileGenerator = null;
53      }
54  
55      /**
56       * Creates a new chemical world.
57       *
58       * @param worldName
59       *      the name of the world
60       */
61      public ChemicalWorld(final String worldName) {
62          this(worldName, null);
63      }
64  
65      /**
66       * Adds the file to this chemical world.
67       *
68       * @param file
69       *      molecule data read from an SDFile
70       */
71      public void addFile(final File file) {
72          files.add(file);
73      }
74  
75      /**
76       * Returns an iterator over the world's entities.
77       *
78       * @return
79       *      an entity reader for this world
80       */
81      public Iterator getEntityIterator() {
82          File[] theFiles = new File[files.size()];
83          theFiles = (File[]) files.toArray(theFiles);
84          return new SDFileIterator(theFiles, getRelationshipResolver());
85      }
86  
87      /**
88       * Returns an instance of a tile generator.
89       *
90       * @return
91       *      a tile generator which visualizes the entities of this world
92       */
93      public TileGenerator getTileGenerator(){
94          if (tileGenerator == null) {
95              tileGenerator = new ChemicalTileGenerator(this);
96          }
97          return (TileGenerator)tileGenerator;
98      }
99  
100 }