/[schmitzm]/trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
ViewVC logotype

Annotation of /trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 52 - (hide annotations)
Fri Apr 17 13:57:14 2009 UTC (15 years, 10 months ago) by mojays
File size: 4845 byte(s)


1 mojays 47 /** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
2    
3     This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
4     This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
5     You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
6    
7     Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
8     Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
9     Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
10     **/
11 mojays 46 package skrueger.geotools;
12    
13 mojays 52 import java.util.Iterator;
14     import java.util.Map;
15     import java.util.TreeMap;
16     import java.util.Vector;
17    
18     import org.geotools.data.DefaultQuery;
19     import org.geotools.data.FeatureSource;
20     import org.geotools.data.Query;
21     import org.geotools.data.memory.MemoryDataStore;
22     import org.geotools.feature.FeatureCollection;
23     import org.opengis.filter.Filter;
24    
25 mojays 46 import schmitzm.geotools.gui.FeatureCollectionTableModel;
26 mojays 52 import skrueger.AttributeMetaData;
27 mojays 46
28 mojays 52
29     /**
30     * This class extends the
31     * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)
32     *
33     */
34 mojays 46 public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel {
35    
36 mojays 52 protected Map<Integer,AttributeMetaData> visibleAMD = null;
37    
38 mojays 46 public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {
39 mojays 52 super();
40     setFeatureCollection(map);
41 mojays 46 }
42    
43     public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
44 mojays 52 super();
45     setFeatureCollection(map);
46 mojays 46 }
47 mojays 52
48     protected void setFeatureSource(FeatureSource fs, Map<Integer,AttributeMetaData> amd) throws Exception {
49     FeatureCollection fc = null;
50     this.visibleAMD = new TreeMap<Integer, AttributeMetaData>();
51     if ( fs != null ) {
52     Query query = new DefaultQuery();
53     if ( amd != null ) {
54     // determine the names of the visible Attributes
55     this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true);
56     Vector<String> visibleAttrNames = new Vector<String>();
57     for ( int attrIdx : visibleAMD.keySet() )
58     visibleAttrNames.add( fs.getSchema().getAttributeType(attrIdx).getLocalName() );
59     // create a query for the visible attributes
60     query = new DefaultQuery(
61     fs.getSchema().getTypeName(),
62     Filter.INCLUDE,
63     visibleAttrNames.toArray(new String[0])
64     );
65     }
66     fc = fs.getFeatures(query);
67     }
68     setFeatureCollection( fc );
69 mojays 46 }
70    
71 mojays 52 public void setFeatureCollection(StyledFeatureCollectionInterface map) {
72     try {
73     if ( map == null )
74     setFeatureSource(null,null);
75     else {
76     FeatureCollection fc = map.getGeoObject();
77     String fcName = fc.getFeatureType().getTypeName();
78     FeatureSource fs = new MemoryDataStore(fc).getFeatureSource(fcName);
79     setFeatureSource(fs, map.getAttributeMetaDataMap());
80     }
81     } catch (Exception err) {
82     throw new RuntimeException(err);
83     }
84 mojays 46 }
85    
86 mojays 52 public void setFeatureCollection(StyledFeatureSourceInterface map) {
87     try {
88     if ( map == null )
89     setFeatureSource(null,null);
90     else
91     setFeatureSource(map.getGeoObject(), map.getAttributeMetaDataMap());
92     } catch (Exception err) {
93     throw new RuntimeException(err);
94     }
95 mojays 46 }
96 mojays 52
97     @Override
98     public void reorganize() {
99     super.reorganize();
100     // translate the column names
101     Iterator<Integer> keys = visibleAMD.keySet().iterator();
102     for (int i=0; keys.hasNext(); i++)
103     colNames[i] = visibleAMD.get( keys.next() ).getTitle().toString();
104     }
105    
106 mojays 46 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26