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


001:        /* uDig - User Friendly Desktop Internet GIS client
002:         * http://udig.refractions.net
003:         * (C) 2004, Refractions Research Inc.
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation;
008:         * version 2.1 of the License.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         */
015:        package net.refractions.udig.internal.ui;
016:
017:        import java.io.StringReader;
018:
019:        import javax.xml.transform.TransformerException;
020:
021:        import net.refractions.udig.ui.AbstractTextStrategizedTransfer;
022:        import net.refractions.udig.ui.internal.Messages;
023:
024:        import org.eclipse.swt.dnd.TextTransfer;
025:        import org.eclipse.swt.dnd.Transfer;
026:        import org.eclipse.swt.dnd.TransferData;
027:        import org.geotools.data.DataUtilities;
028:        import org.geotools.feature.Feature;
029:        import org.geotools.feature.FeatureCollection;
030:        import org.geotools.feature.FeatureCollections;
031:        import org.geotools.feature.FeatureType;
032:        import org.geotools.gml.GMLFilterDocument;
033:        import org.geotools.gml.GMLFilterFeature;
034:        import org.geotools.gml.GMLFilterGeometry;
035:        import org.geotools.gml.GMLReceiver;
036:        import org.geotools.gml.producer.FeatureTransformer;
037:        import org.xml.sax.InputSource;
038:        import org.xml.sax.XMLReader;
039:        import org.xml.sax.helpers.XMLReaderFactory;
040:
041:        import com.vividsolutions.jts.geom.Geometry;
042:        import com.vividsolutions.jts.io.WKTReader;
043:        import com.vividsolutions.jts.io.WKTWriter;
044:
045:        public class FeatureTextTransfer extends
046:                AbstractTextStrategizedTransfer implements  UDIGTransfer {
047:            private static FeatureTextTransfer _instance = new FeatureTextTransfer();
048:
049:            private FeatureTextTransfer() {
050:            }
051:
052:            /**
053:             * Returns the singleton instance of the TextTransfer class.
054:             * 
055:             * @return the singleton instance of the TextTransfer class
056:             */
057:            public static FeatureTextTransfer getInstance() {
058:                return _instance;
059:            }
060:
061:            private TransferStrategy[] transferStrategies;
062:
063:            @Override
064:            public synchronized TransferStrategy[] getAllStrategies() {
065:                if (transferStrategies == null) {
066:                    transferStrategies = new TransferStrategy[] {
067:                            new GMLStrategy(), new JtsWktStrategy() };
068:                }
069:                TransferStrategy[] copy = new TransferStrategy[transferStrategies.length];
070:                System.arraycopy(transferStrategies, 0, copy, 0,
071:                        transferStrategies.length);
072:                return copy;
073:            }
074:
075:            @Override
076:            public String[] getStrategyNames() {
077:                return new String[] {
078:                        Messages.FeatureTextTransfer_strategy_gml_name,
079:                        Messages.FeatureTextTransfer_strategy_wkt_name };
080:            }
081:
082:            @Override
083:            public String getTransferName() {
084:                return Messages.FeatureTextTransfer_transfer_name;
085:            }
086:
087:            @Override
088:            public TransferStrategy getDefaultStrategy() {
089:                return getAllStrategies()[0];
090:            }
091:
092:            @Override
093:            public TransferData[] getSupportedTypes() {
094:                return TextTransfer.getInstance().getSupportedTypes();
095:            }
096:
097:            @Override
098:            public boolean isSupportedType(TransferData transferData) {
099:                return TextTransfer.getInstance().isSupportedType(transferData);
100:            }
101:
102:            public boolean validate(Object object) {
103:                return object instanceof  Feature;
104:            }
105:
106:            /**
107:             * Encodes a Feature as a GML string.
108:             * 
109:             * @author jeichar
110:             */
111:            public static class GMLStrategy implements  TransferStrategy {
112:                @SuppressWarnings("unchecked")//$NON-NLS-1$
113:                public void javaToNative(Object object,
114:                        TransferData transferData) {
115:                    Feature feature = (Feature) object;
116:                    FeatureCollection collection = FeatureCollections
117:                            .newCollection();
118:                    collection.add(feature);
119:                    FeatureTransformer transformer = new FeatureTransformer();
120:                    transformer.setIndentation(4);
121:                    try {
122:                        TextTransfer.getInstance()
123:                                .javaToNative(
124:                                        transformer.transform(collection),
125:                                        transferData);
126:                    } catch (TransformerException e) {
127:                        throw (RuntimeException) new RuntimeException()
128:                                .initCause(e);
129:                    }
130:                }
131:
132:                @SuppressWarnings("deprecation")
133:                public Object nativeToJava(TransferData transferData) {
134:                    String string = (String) TextTransfer.getInstance()
135:                            .nativeToJava(transferData);
136:                    InputSource input = new InputSource(
137:                            new StringReader(string));
138:                    FeatureCollection collection = FeatureCollections
139:                            .newCollection();
140:                    GMLReceiver receiver = new GMLReceiver(collection);
141:                    GMLFilterFeature filterFeature = new GMLFilterFeature(
142:                            receiver);
143:                    GMLFilterGeometry filterGeometry = new GMLFilterGeometry(
144:                            filterFeature);
145:                    GMLFilterDocument filterDocument = new GMLFilterDocument(
146:                            filterGeometry);
147:                    try {
148:                        // parse xml
149:                        XMLReader reader = XMLReaderFactory.createXMLReader();
150:                        reader.setContentHandler(filterDocument);
151:                        reader.parse(input);
152:                    } catch (Exception e) {
153:                        throw new RuntimeException(e);
154:                    }
155:
156:                    return collection.features().next();
157:                }
158:            }
159:
160:            /**
161:             * This strategy exports a feature as Well Known Text as generated by JTS WKTWriter.
162:             * 
163:             * @author jeichar
164:             */
165:            public static class JtsWktStrategy implements  TransferStrategy {
166:
167:                /**
168:                 * @see Transfer#javaToNative
169:                 */
170:                public void javaToNative(Object object,
171:                        TransferData transferData) {
172:                    String stringToEncode;
173:
174:                    Feature feature = (Feature) object;
175:
176:                    WKTWriter writer = new WKTWriter();
177:                    String geometry = writer.writeFormatted(feature
178:                            .getDefaultGeometry());
179:
180:                    stringToEncode = geometry;
181:                    TextTransfer.getInstance().javaToNative(stringToEncode,
182:                            transferData);
183:                }
184:
185:                /**
186:                 * @see Transfer#nativeToJava
187:                 */
188:                @SuppressWarnings("deprecation")
189:                public Object nativeToJava(TransferData transferData) {
190:                    String string = (String) TextTransfer.getInstance()
191:                            .nativeToJava(transferData);
192:
193:                    WKTReader reader = new WKTReader();
194:                    try {
195:                        Geometry read = reader.read(string);
196:                        FeatureType ft = DataUtilities
197:                                .createType(
198:                                        "Temp Type", "*geom:" + read.getClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
199:                        return ft.create(new Object[] { read });
200:                    } catch (Exception e) {
201:                        UiPlugin.log("", e); //$NON-NLS-1$
202:                    }
203:                    return null;
204:                }
205:
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.