Source Code Cross Referenced for SelectionTools.java in  » GIS » openjump » de » fho » jump » pirol » utilities » apiTools » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » openjump » de.fho.jump.pirol.utilities.apiTools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 11.02.2005 for PIROL
003:         *
004:         * SVN header information:
005:         *  $Author: javamap $
006:         *  $Rev: 856 $
007:         *  $Date: 2007-06-18 21:15:27 -0700 (Mon, 18 Jun 2007) $
008:         *  $Id: SelectionTools.java 856 2007-06-19 04:15:27Z javamap $
009:         */
010:        package de.fho.jump.pirol.utilities.apiTools;
011:
012:        import java.util.ArrayList;
013:        import java.util.Iterator;
014:        import java.util.List;
015:        import java.util.Map;
016:
017:        import com.vividsolutions.jts.geom.Geometry;
018:        import com.vividsolutions.jump.feature.Feature;
019:        import com.vividsolutions.jump.feature.FeatureCollection;
020:        import com.vividsolutions.jump.feature.FeatureCollectionWrapper;
021:        import com.vividsolutions.jump.workbench.model.FenceLayerFinder;
022:        import com.vividsolutions.jump.workbench.model.Layer;
023:        import com.vividsolutions.jump.workbench.plugin.PlugInContext;
024:        import com.vividsolutions.jump.workbench.ui.SelectionManager;
025:
026:        /**
027:         * Class to easily handle selections and selection tools. Also has methods to
028:         * find features by given geometries.
029:         * 
030:         * @author Ole Rahn
031:         * 
032:         * FH Osnabrück - University of Applied Sciences Osnabrück
033:         * Project PIROL 2005
034:         * Daten- und Wissensmanagement
035:         * 
036:         */
037:
038:        public class SelectionTools extends ToolToMakeYourLifeEasier {
039:            protected PlugInContext context = null;
040:
041:            public SelectionTools(PlugInContext context) {
042:                super ();
043:                this .context = context;
044:            }
045:
046:            /**
047:             * create a selection out of the given features that is visible in the Jump map
048:             *@param features features to be selected
049:             */
050:            public void selectFeatures(List features) {
051:                SelectionTools.selectFeatures(features, this .context);
052:            }
053:
054:            public static void selectLayer(PlugInContext context, Layer layer) {
055:                // TODO: how to select a layer???       
056:            }
057:
058:            public static void selectFeatures(List features,
059:                    PlugInContext context) {
060:                SelectionManager sm = context.getLayerViewPanel()
061:                        .getSelectionManager();
062:                sm.clear();
063:
064:                Map layer2FeatList = LayerTools.getLayer2FeatureMap(features,
065:                        context);
066:                Layer[] layersWithFeatures = (Layer[]) layer2FeatList.keySet()
067:                        .toArray(new Layer[0]);
068:
069:                for (int i = 0; i < layersWithFeatures.length; i++) {
070:                    sm.getFeatureSelection().selectItems(
071:                            layersWithFeatures[i],
072:                            (ArrayList) layer2FeatList
073:                                    .get(layersWithFeatures[i]));
074:                }
075:
076:            }
077:
078:            public static List<Feature> getSelectedFeaturesFromLayer(
079:                    PlugInContext context, Layer layer) {
080:                return new ArrayList<Feature>(context.getLayerViewPanel()
081:                        .getSelectionManager().getFeaturesWithSelectedItems(
082:                                layer));
083:            }
084:
085:            public static List<Feature> getSelectedFeatures(
086:                    PlugInContext context) {
087:                return new ArrayList<Feature>(context.getLayerViewPanel()
088:                        .getSelectionManager().getFeaturesWithSelectedItems());
089:            }
090:
091:            public List<Feature> getSelectedFeatures() {
092:                return SelectionTools.getSelectedFeatures(this .context);
093:            }
094:
095:            /**
096:             * 
097:             *@param context current PlugIn context
098:             *@return the geometry of the current fence, or null if there is currently no fence
099:             */
100:            public static Geometry getFenceGeometry(PlugInContext context) {
101:                Layer fence = new FenceLayerFinder(context.getLayerViewPanel())
102:                        .getLayer();
103:                if (fence == null)
104:                    return null;
105:                FeatureCollectionWrapper fenceCollWrap = fence
106:                        .getFeatureCollectionWrapper();
107:                Feature fencePolygon = (Feature) fenceCollWrap
108:                        .getUltimateWrappee().getFeatures().get(0);
109:                return fencePolygon.getGeometry();
110:            }
111:
112:            /**
113:             *@return the geometry of the current fence, or null if there is currently no fence
114:             */
115:            public Geometry getFenceGeometry() {
116:                return SelectionTools.getFenceGeometry(this .context);
117:            }
118:
119:            public List getFeaturesInFence() {
120:                Geometry fenceGeometry = this .getFenceGeometry();
121:                return this .getFeaturesInGeometry(fenceGeometry);
122:            }
123:
124:            public List getFeaturesInGeometry(Geometry fenceGeometry) {
125:                ArrayList featsInFence = new ArrayList();
126:                List layers = this .context.getLayerManager().getVisibleLayers(
127:                        false);
128:
129:                Iterator iter = layers.iterator();
130:                Layer tmp;
131:                while (iter.hasNext()) {
132:                    tmp = (Layer) iter.next();
133:                    featsInFence
134:                            .addAll(SelectionTools
135:                                    .getFeaturesInFenceInLayerAsList(tmp,
136:                                            fenceGeometry));
137:                }
138:
139:                return featsInFence;
140:            }
141:
142:            /**
143:             * Get a list of those features from the given layer that are included by the given fence geometry.
144:             * @param layer - Layer to search in
145:             * @param fenceGeometry - Geometry to search in
146:             */
147:            public static Feature[] getFeaturesInFenceInLayer(Layer layer,
148:                    Geometry fenceGeometry) {
149:                return SelectionTools.getFeaturesOnTheSameSpot(layer,
150:                        fenceGeometry, false);
151:            }
152:
153:            /**
154:             * Get a list of those features from the given layer that are included by the given fence geometry.
155:             * @param layer - Layer to search in
156:             * @param fenceGeometry - Geometry to search in
157:             */
158:            public static List getFeaturesInFenceInLayerAsList(Layer layer,
159:                    Geometry fenceGeometry) {
160:                Feature[] featureArray = SelectionTools
161:                        .getFeaturesOnTheSameSpot(layer, fenceGeometry, false);
162:                ArrayList result = new ArrayList();
163:
164:                for (int i = 0; i < featureArray.length; i++) {
165:                    result.add(featureArray[i]);
166:                }
167:
168:                return result;
169:            }
170:
171:            /**
172:             * Get a list of features (a sub list of the given array) that are included by the given fence geometry.
173:             * @param featArray - Array of features to search in
174:             * @param fenceGeometry - Geometry to search in
175:             */
176:            public static Feature[] getFeaturesInFenceInLayer(
177:                    Feature[] featArray, Geometry fenceGeometry) {
178:                return SelectionTools.getFeaturesOnTheSameSpot(featArray,
179:                        fenceGeometry, false);
180:            }
181:
182:            /**
183:             * Get a list of those features from the given layer that are included by the given fence geometry.
184:             * @param layer - Layer to search in
185:             * @param fenceGeometry - Geometry to search in
186:             * @param bothWays - sets if it's also a hit if the feature's geometry includes the fence geometry
187:             */
188:            public static Feature[] getFeaturesOnTheSameSpot(Layer layer,
189:                    Geometry fenceGeometry, boolean bothWays) {
190:                FeatureCollection featColl = layer
191:                        .getFeatureCollectionWrapper().getUltimateWrappee();
192:                return SelectionTools.getFeaturesOnTheSameSpot(
193:                        FeatureCollectionTools
194:                                .FeatureCollection2FeatureArray(featColl),
195:                        fenceGeometry, bothWays);
196:            }
197:
198:            /**
199:             * Get a list of features (a sub list of the given array) that are included by the given fence geometry.
200:             * @param featArray - Array of features to search in
201:             * @param fenceGeometry - Geometry to search in
202:             * @param bothWays - sets if it's also a hit if the feature's geometry includes the fence geometry
203:             */
204:            public static Feature[] getFeaturesOnTheSameSpot(
205:                    Feature[] featArray, Geometry fenceGeometry,
206:                    boolean bothWays) {
207:                ArrayList featuresInsideTheFence = new ArrayList();
208:
209:                //		Envelope fenceEnv = fenceGeometry.getEnvelopeInternal();
210:                //		Envelope featEnv;
211:                Geometry featGeom = null;
212:
213:                Feature feat;
214:
215:                int numFeats = featArray.length;
216:
217:                for (int i = 0; i < numFeats; i++) {
218:                    feat = featArray[i];
219:
220:                    featGeom = feat.getGeometry();
221:                    /*
222:                    featEnv = featGeom.getEnvelopeInternal();
223:                    
224:                    // quick test, first:
225:                    if (!fenceEnv.contains(featEnv) && !fenceEnv.intersects(featEnv) && !bothWays){
226:                        continue;
227:                    } else if (bothWays){
228:                        if (!fenceEnv.contains(featEnv) && !fenceEnv.intersects(featGeom.getEnvelopeInternal()) && !featEnv.contains(fenceEnv) )
229:                            continue;
230:                    }
231:                     */
232:                    if (!fenceGeometry.disjoint(featGeom)) {
233:                        featuresInsideTheFence.add(feat);
234:                    } else if (bothWays) {
235:                        if (!featGeom.disjoint(fenceGeometry)) {
236:                            featuresInsideTheFence.add(feat);
237:                        }
238:                    }
239:                }
240:                return (Feature[]) featuresInsideTheFence
241:                        .toArray(new Feature[0]);
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.