Source Code Cross Referenced for LayerTools.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 08.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: LayerTools.java 856 2007-06-19 04:15:27Z javamap $
009:         */
010:        package de.fho.jump.pirol.utilities.apiTools;
011:
012:        import java.awt.Color;
013:        import java.util.ArrayList;
014:        import java.util.Collection;
015:        import java.util.HashMap;
016:        import java.util.Iterator;
017:        import java.util.List;
018:        import java.util.Map;
019:
020:        import com.vividsolutions.jts.geom.Geometry;
021:        import com.vividsolutions.jump.feature.AttributeType;
022:        import com.vividsolutions.jump.feature.BasicFeature;
023:        import com.vividsolutions.jump.feature.Feature;
024:        import com.vividsolutions.jump.feature.FeatureCollection;
025:        import com.vividsolutions.jump.feature.FeatureDataset;
026:        import com.vividsolutions.jump.feature.FeatureSchema;
027:        import com.vividsolutions.jump.workbench.model.Category;
028:        import com.vividsolutions.jump.workbench.model.Layer;
029:        import com.vividsolutions.jump.workbench.model.Layerable;
030:        import com.vividsolutions.jump.workbench.plugin.PlugInContext;
031:
032:        import de.fho.jump.pirol.utilities.FeatureCollection.PirolFeatureCollection;
033:        import de.fho.jump.pirol.utilities.FeatureCollection.PirolFeatureCollectionRole;
034:        import de.fho.jump.pirol.utilities.FeatureCollection.RoleTriangularIrregularNet;
035:        import de.fho.jump.pirol.utilities.i18n.PirolPlugInMessages;
036:        import de.fho.jump.pirol.utilities.settings.PirolPlugInSettings;
037:
038:        /**
039:         * Class for more convenient use of Layer objects. Offers methods e.g. to get features that reside within
040:         * a given geometry or to easily add a result layer to the map.
041:         * 
042:         * @author Ole Rahn
043:         * 
044:         * FH Osnabrück - University of Applied Sciences Osnabrück
045:         * Project PIROL 2005
046:         * Daten- und Wissensmanagement
047:         * 
048:         */
049:        public class LayerTools extends ToolToMakeYourLifeEasier {
050:            protected PlugInContext context = null;
051:
052:            public LayerTools(PlugInContext context) {
053:                super ();
054:                this .context = context;
055:            }
056:
057:            public Layer[] getSelectedLayers() {
058:                return this .context.getSelectedLayers();
059:            }
060:
061:            public List getSelectedFeatures() {
062:                return SelectionTools.getSelectedFeatures(this .context);
063:            }
064:
065:            public Geometry getFenceGeometry() {
066:                return SelectionTools.getFenceGeometry(this .context);
067:            }
068:
069:            public List getFeaturesInFence() {
070:                SelectionTools st = new SelectionTools(this .context);
071:                return st.getFeaturesInFence();
072:            }
073:
074:            public Feature[] getFeaturesInFenceInLayer(Layer layer,
075:                    Geometry fenceGeometry) {
076:                return SelectionTools.getFeaturesInFenceInLayer(layer,
077:                        fenceGeometry);
078:            }
079:
080:            public Feature[] getFeaturesInFenceInLayer(Feature[] featArray,
081:                    Geometry fenceGeometry) {
082:                return SelectionTools.getFeaturesInFenceInLayer(featArray,
083:                        fenceGeometry);
084:            }
085:
086:            public int getNumSelectedLayers() {
087:                return LayerTools.getNumSelectedLayers(this .context);
088:            }
089:
090:            public static int getNumSelectedLayers(PlugInContext context) {
091:                return context.getSelectedLayers().length;
092:            }
093:
094:            public static Layer addStandardResultLayer(String title,
095:                    FeatureCollection featCollection, PlugInContext context,
096:                    PirolFeatureCollectionRole role) {
097:                return LayerTools.addStandardResultLayer(title, featCollection,
098:                        Color.yellow, context, role);
099:            }
100:
101:            public static Layer addAndSelectStandardResultLayer(String title,
102:                    FeatureCollection featCollection, Color color,
103:                    PlugInContext context, PirolFeatureCollectionRole role) {
104:                return LayerTools.addStandardResultLayer(title, featCollection,
105:                        color, context, true, role);
106:            }
107:
108:            public static Layer addAndSelectStandardResultLayer(String title,
109:                    FeatureCollection featCollection, PlugInContext context,
110:                    PirolFeatureCollectionRole role) {
111:                return LayerTools.addStandardResultLayer(title, featCollection,
112:                        Color.YELLOW, context, true, role);
113:            }
114:
115:            public static Layer addStandardResultLayer(String title,
116:                    FeatureCollection featCollection, Color color,
117:                    PlugInContext context, PirolFeatureCollectionRole role) {
118:                return LayerTools.addStandardResultLayer(title, featCollection,
119:                        color, context, false, role);
120:            }
121:
122:            public static Layer addStandardResultLayer(String title,
123:                    FeatureCollection featCollection, Color color,
124:                    PlugInContext context, boolean select,
125:                    PirolFeatureCollectionRole role) {
126:                if (featCollection == null || context == null
127:                        || LayerTools.getResultCategory(context) == null)
128:                    return null;
129:
130:                Layer newLayer = null;
131:
132:                if (!PirolFeatureCollection.class.isInstance(featCollection)) {
133:                    newLayer = new Layer(title, color,
134:                            new PirolFeatureCollection(featCollection, role),
135:                            context.getLayerManager());
136:                } else {
137:                    if (role != null)
138:                        ((PirolFeatureCollection) featCollection).addRole(role);
139:                    newLayer = new Layer(title, color, featCollection, context
140:                            .getLayerManager());
141:                }
142:
143:                context.getLayerManager().addLayer(
144:                        PirolPlugInSettings.resultLayerCategory(), newLayer);
145:
146:                if (select) {
147:                    SelectionTools.selectLayer(context, newLayer);
148:                }
149:
150:                return newLayer;
151:            }
152:
153:            public Layer addStandardResultLayer(String title,
154:                    FeatureCollection featCollection,
155:                    PirolFeatureCollectionRole role) {
156:                return LayerTools.addStandardResultLayer(title, featCollection,
157:                        this .context, role);
158:            }
159:
160:            public Map getLayer2FeatureMap(List features) {
161:                return LayerTools.getLayer2FeatureMap(features, this .context);
162:            }
163:
164:            public final static Layer putGeometryArrayIntoMap(
165:                    Geometry[] geometryArray, PlugInContext context) {
166:                FeatureSchema fs = new FeatureSchema();
167:                fs.addAttribute(PirolPlugInMessages.getString("geometry"),
168:                        AttributeType.GEOMETRY);
169:                FeatureCollection fc = new FeatureDataset(fs);
170:
171:                Feature f;
172:                for (int i = 0; i < geometryArray.length; i++) {
173:                    f = new BasicFeature(fs);
174:                    f.setGeometry(geometryArray[i]);
175:                    fc.add(f);
176:                }
177:
178:                return LayerTools.addStandardResultLayer(PirolPlugInMessages
179:                        .getString("triangles"), fc, context,
180:                        new RoleTriangularIrregularNet());
181:            }
182:
183:            public static Map getLayer2FeatureMap(List features,
184:                    PlugInContext context) {
185:                Layer layer = null;
186:                List<Layer> layers = context.getLayerManager()
187:                        .getVisibleLayers(false);
188:
189:                Iterator iter = layers.iterator();
190:                Iterator featIter;
191:                Map layer2FeatList = new HashMap();
192:                List layerFeats;
193:                Feature feat;
194:
195:                while (iter.hasNext()) {
196:                    layer = (Layer) iter.next();
197:                    layerFeats = layer.getFeatureCollectionWrapper()
198:                            .getUltimateWrappee().getFeatures();
199:                    featIter = features.iterator();
200:                    while (featIter.hasNext()) {
201:                        feat = (Feature) featIter.next();
202:
203:                        if (layerFeats.contains(feat)) {
204:                            if (!layer2FeatList.containsKey(layer)) {
205:                                layer2FeatList.put(layer, new ArrayList());
206:                            }
207:                            ((ArrayList) layer2FeatList.get(layer)).add(feat);
208:                        }
209:                    }
210:                }
211:                return layer2FeatList;
212:            }
213:
214:            public Category getResultCategory() {
215:                return LayerTools.getResultCategory(this .context);
216:            }
217:
218:            public static Category getResultCategory(PlugInContext context) {
219:                Category category = context.getLayerManager().getCategory(
220:                        PirolPlugInSettings.resultLayerCategory());
221:
222:                if (category == null) {
223:                    context.getLayerManager().addCategory(
224:                            PirolPlugInSettings.resultLayerCategory(), 0);
225:                    category = context.getLayerManager().getCategory(
226:                            PirolPlugInSettings.resultLayerCategory());
227:                }
228:
229:                return category;
230:            }
231:
232:            /**
233:             * Get a given number of selected Layers.
234:             * @param context the current PlugInContext
235:             * @param num max. number of layers to return, -1 returns all selected layers
236:             * @return a given number of selected Layers, null if no Layers are selected
237:             */
238:            public static Layer[] getSelectedLayers(PlugInContext context,
239:                    int num) {
240:                Layer[] selLayers = context.getSelectedLayers();
241:
242:                if (selLayers.length == 0) {
243:                    return null;
244:                } else if (num <= 0) {
245:                    return selLayers;
246:                } else {
247:                    Layer[] result = new Layer[num];
248:
249:                    for (int i = 0; i < selLayers.length && i < result.length; i++) {
250:                        result[i] = selLayers[i];
251:                    }
252:
253:                    return result;
254:                }
255:            }
256:
257:            /**
258:             * get one Layer that is selected
259:             * @param context the current PlugInContext
260:             * @return one selected Layer, null if no Layers are selected
261:             */
262:            public static Layer getSelectedLayer(PlugInContext context) {
263:                Layer[] selLayers = LayerTools.getSelectedLayers(context, 1);
264:
265:                if (selLayers == null || selLayers.length == 0) {
266:                    return null;
267:                }
268:                return selLayers[0];
269:            }
270:
271:            /**
272:             * get one Layer that is selected
273:             * @param context the current PlugInContext
274:             * @return one selected Layer, null if no Layers are selected
275:             */
276:            public static Layerable getSelectedLayerable(PlugInContext context,
277:                    Class layerableClass) {
278:
279:                Collection selLayers = context.getLayerNamePanel()
280:                        .selectedNodes(layerableClass);
281:
282:                if (selLayers == null || selLayers.size() == 0) {
283:                    return null;
284:                }
285:
286:                return ((Layerable[]) selLayers.toArray(new Layerable[0]))[0];
287:            }
288:
289:            /**
290:             * returns a layername, that is not yet used in the layername panel
291:             */
292:            public static String getUniqueLayerName(PlugInContext context,
293:                    String name) {
294:
295:                return context.getLayerManager().uniqueLayerName(name);
296:            }
297:
298:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.