Source Code Cross Referenced for GeomPropertySource.java in  » GIS » udig-1.1 » net » refractions » udig » project » ui » internal » properties » 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 » udig 1.1 » net.refractions.udig.project.ui.internal.properties 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004, Refractions Research Inc. This
003:         * library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
004:         * License as published by the Free Software Foundation; version 2.1 of the License. This library is distributed in the
005:         * hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
006:         * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
007:         */
008:        package net.refractions.udig.project.ui.internal.properties;
009:
010:        import net.refractions.udig.core.internal.GeometryBuilder;
011:        import net.refractions.udig.project.ui.internal.Messages;
012:
013:        import org.eclipse.jface.viewers.ILabelProvider;
014:        import org.eclipse.jface.viewers.LabelProvider;
015:        import org.eclipse.ui.views.properties.IPropertyDescriptor;
016:        import org.eclipse.ui.views.properties.IPropertySource2;
017:        import org.eclipse.ui.views.properties.PropertyDescriptor;
018:
019:        import com.vividsolutions.jts.geom.Coordinate;
020:        import com.vividsolutions.jts.geom.Geometry;
021:        import com.vividsolutions.jts.geom.GeometryCollection;
022:        import com.vividsolutions.jts.geom.LinearRing;
023:        import com.vividsolutions.jts.geom.Polygon;
024:
025:        /**
026:         * TODO provide type description
027:         * 
028:         * @author jeichar
029:         * @since TODO provide version
030:         */
031:        public class GeomPropertySource implements  IPropertySource2 {
032:            private static final String TYPE = "TYPE"; //$NON-NLS-1$
033:            private static final String AREA = "AREA"; //$NON-NLS-1$
034:            private static final String COORDS = "COORDS"; //$NON-NLS-1$
035:
036:            private Geometry geom;
037:            GeometryCollection collection;
038:            IPropertyDescriptor[] propertyDescriptors;
039:            GeometryBuilder builder = GeometryBuilder.create();
040:            private static final String SHELL = "SHELL"; //$NON-NLS-1$
041:            private static final String HOLES = "HOLES"; //$NON-NLS-1$
042:            private static final String COLLECTION = "COLLECTION"; //$NON-NLS-1$
043:
044:            /**
045:             * Creates a new instance of GeomPropertySource
046:             * 
047:             * @param geometry the geometry that is the source for this PropertySource
048:             */
049:            public GeomPropertySource(Geometry geometry) {
050:                this .geom = geometry;
051:                if (geometry instanceof  GeometryCollection) {
052:                    collection = (GeometryCollection) geometry;
053:                    createGeometryCollectionDescriptors();
054:                } else if (geometry instanceof  Polygon) {
055:                    createPolygonDescriptors();
056:                } else {
057:                    createGeometryDescriptors();
058:                }
059:            }
060:
061:            /**
062:             * TODO summary sentence for createPolygonDescriptors ...
063:             */
064:            private void createPolygonDescriptors() {
065:                Polygon poly = (Polygon) geom;
066:                propertyDescriptors = new IPropertyDescriptor[poly
067:                        .getNumInteriorRing() + 2];
068:                propertyDescriptors[0] = new PropertyDescriptor(new ID(AREA),
069:                        Messages.GeomPropertySource_area);
070:                propertyDescriptors[1] = new GeometryPropertyDescriptor(new ID(
071:                        SHELL), Messages.GeomPropertySource_exteriorShell);
072:                for (int i = 0; i < propertyDescriptors.length - 2; i++) {
073:                    propertyDescriptors[i + 2] = new GeometryPropertyDescriptor(
074:                            new ID(HOLES, i),
075:                            Messages.GeomPropertySource_polygonHole);
076:                }
077:            }
078:
079:            private void createGeometryDescriptors() {
080:                IPropertyDescriptor coords = new PropertyDescriptor(new ID(
081:                        COORDS), Messages.GeomPropertySource_coordinates) {
082:                    /**
083:                     * @see org.eclipse.ui.views.properties.PropertyDescriptor#getLabelProvider()
084:                     */
085:                    public ILabelProvider getLabelProvider() {
086:                        return new LabelProvider() {
087:                            /**
088:                             * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
089:                             */
090:                            public String getText(Object element) {
091:                                return ""; //$NON-NLS-1$
092:                            }
093:                        };
094:                    }
095:                };
096:                propertyDescriptors = new IPropertyDescriptor[] {
097:                        new PropertyDescriptor(new ID(AREA),
098:                                Messages.GeomPropertySource_area), coords };
099:            }
100:
101:            void createGeometryCollectionDescriptors() {
102:                propertyDescriptors = new IPropertyDescriptor[collection
103:                        .getNumGeometries() + 1];
104:                propertyDescriptors[0] = new PropertyDescriptor(new ID(AREA),
105:                        Messages.GeomPropertySource_area);
106:                for (int i = 0; i < propertyDescriptors.length - 1; i++) {
107:                    Geometry geometry = collection.getGeometryN(i);
108:                    propertyDescriptors[i + 1] = new GeometryPropertyDescriptor(
109:                            new ID(COLLECTION, i, collection.getGeometryN(i)),
110:                            geometry.getGeometryType());
111:                }
112:            }
113:
114:            /**
115:             * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
116:             */
117:            public Object getEditableValue() {
118:                return geom;
119:            }
120:
121:            /**
122:             * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
123:             */
124:            public IPropertyDescriptor[] getPropertyDescriptors() {
125:
126:                IPropertyDescriptor[] c = new IPropertyDescriptor[propertyDescriptors.length];
127:                System.arraycopy(propertyDescriptors, 0, c, 0, c.length);
128:                return c;
129:            }
130:
131:            /**
132:             * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
133:             */
134:            public Object getPropertyValue(Object idObject) {
135:                ID id = (ID) idObject;
136:                if (id.id == COLLECTION) {
137:                    return new GeomPropertySource(collection
138:                            .getGeometryN(id.index));
139:                }
140:                if (id.id == TYPE)
141:                    return geom.getGeometryType();
142:                if (id.id == AREA)
143:                    return String.valueOf(geom.getArea());
144:                if (id.id == COORDS) {
145:                    return new CoordinateSetPropertySource(geom
146:                            .getCoordinates(), geom);
147:                }
148:                if (id.id == HOLES) {
149:                    Polygon poly = (Polygon) geom;
150:                    return new GeomPropertySource(poly
151:                            .getInteriorRingN(id.index));
152:                }
153:                if (id.id == SHELL) {
154:                    Polygon poly = (Polygon) geom;
155:                    return new GeomPropertySource(poly.getExteriorRing());
156:                }
157:                return null;
158:            }
159:
160:            /**
161:             * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
162:             */
163:            public boolean isPropertySet(Object id) {
164:                // TODO Auto-generated method stub
165:                return false;
166:            }
167:
168:            /**
169:             * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
170:             */
171:            public void resetPropertyValue(Object id) {
172:                // TODO Auto-generated method stub
173:            }
174:
175:            /**
176:             * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object,
177:             *      java.lang.Object)
178:             */
179:            public void setPropertyValue(Object idObject, Object value) {
180:                ID id = (ID) idObject;
181:                if (id.id == COORDS) {
182:                    geom = builder.safeCreateGeometry(geom.getClass(),
183:                            (Coordinate[]) value);
184:                }
185:                if (id.id == SHELL) {
186:                    Polygon polygon = (Polygon) geom;
187:                    LinearRing[] rings = new LinearRing[polygon
188:                            .getNumInteriorRing()];
189:                    for (int i = 0; i < rings.length; i++) {
190:                        rings[i] = (LinearRing) polygon.getInteriorRingN(i);
191:                    }
192:                    geom = builder.factory.createPolygon((LinearRing) value,
193:                            rings);
194:                }
195:                if (id.id == HOLES) {
196:                    Polygon polygon = (Polygon) geom;
197:                    LinearRing[] rings = new LinearRing[polygon
198:                            .getNumInteriorRing()];
199:                    for (int i = 0; i < rings.length; i++) {
200:                        rings[i] = (LinearRing) polygon.getInteriorRingN(i);
201:                    }
202:                    rings[id.index] = (LinearRing) value;
203:                    geom = builder.factory.createPolygon((LinearRing) polygon
204:                            .getExteriorRing(), rings);
205:                }
206:                if (id.id == COLLECTION) {
207:                    Geometry[] geoms = new Geometry[collection
208:                            .getNumGeometries()];
209:                    for (int i = 0; i < geoms.length; i++) {
210:                        geoms[i] = collection.getGeometryN(i);
211:                    }
212:                    geoms[id.index] = (Geometry) value;
213:                    geom = collection = builder.factory
214:                            .createGeometryCollection(geoms);
215:                }
216:            }
217:
218:            static class ID {
219:                int index;
220:                String id;
221:
222:                ID(String id, int index, Object data) {
223:                    this .index = index;
224:                    this .id = id;
225:                }
226:
227:                ID(String id, int index) {
228:                    this (id, index, null);
229:                }
230:
231:                ID(String id) {
232:                    this (id, 0, null);
233:                }
234:            }
235:
236:            /**
237:             * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertyResettable(java.lang.Object)
238:             */
239:            public boolean isPropertyResettable(Object id) {
240:                // TODO implement method body
241:                return true;
242:            }
243:        }
w__w__w___.___j__a_v___a___2__s.c__om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.