Source Code Cross Referenced for ImageFeatureCreator.java in  » GIS » openjump » com » vividsolutions » jump » workbench » ui » plugin » imagery » 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 » com.vividsolutions.jump.workbench.ui.plugin.imagery 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.vividsolutions.jump.workbench.ui.plugin.imagery;
002:
003:        import java.io.File;
004:        import java.util.*;
005:
006:        import javax.swing.JFileChooser;
007:        import javax.swing.JOptionPane;
008:        import javax.swing.filechooser.FileFilter;
009:
010:        import com.vividsolutions.jts.geom.Coordinate;
011:        import com.vividsolutions.jts.geom.GeometryFactory;
012:        import com.vividsolutions.jts.util.Assert;
013:        import com.vividsolutions.jump.I18N;
014:        import com.vividsolutions.jump.feature.BasicFeature;
015:        import com.vividsolutions.jump.feature.Feature;
016:        import com.vividsolutions.jump.util.Block;
017:        import com.vividsolutions.jump.util.CollectionUtil;
018:        import com.vividsolutions.jump.util.FileUtil;
019:        import com.vividsolutions.jump.util.OrderedMap;
020:        import com.vividsolutions.jump.workbench.imagery.ImageryLayerDataset;
021:        import com.vividsolutions.jump.workbench.imagery.ReferencedImage;
022:        import com.vividsolutions.jump.workbench.imagery.ReferencedImageFactory;
023:        import com.vividsolutions.jump.workbench.imagery.ReferencedImageStyle;
024:        import com.vividsolutions.jump.workbench.model.Layer;
025:        import com.vividsolutions.jump.workbench.plugin.PlugInContext;
026:        import com.vividsolutions.jump.workbench.ui.GUIUtil;
027:        import com.vividsolutions.jump.workbench.ui.GenericNames;
028:        import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
029:        import com.vividsolutions.jump.util.Blackboard;
030:
031:        public class ImageFeatureCreator {
032:
033:            public Collection getImages(PlugInContext context, Layer layer) {
034:                final String LAST_DIRECTORY_KEY = getClass().getName()
035:                        + " - LAST DIRECTORY";
036:                final String LAST_FILE_FILTER_DESCRIPTION_KEY = getClass()
037:                        .getName()
038:                        + " - LAST FILE FILTER DESCRIPTION";
039:
040:                Blackboard blackboard = PersistentBlackboardPlugIn.get(context
041:                        .getWorkbenchContext());
042:                JFileChooser fileChooser = GUIUtil
043:                        .createJFileChooserWithExistenceChecking();
044:
045:                fileChooser.setCurrentDirectory(new File((String) blackboard
046:                        .get(LAST_DIRECTORY_KEY, fileChooser
047:                                .getCurrentDirectory().getPath())));
048:                GUIUtil.removeChoosableFileFilters(fileChooser);
049:
050:                OrderedMap fileFilterToReferencedImageFactoryMap = getFileFilterToReferencedImageFactoryMap(insertCompositeReferencedImageFactory(context
051:                        .getWorkbenchContext().getRegistry().getEntries(
052:                                ReferencedImageFactory.REGISTRY_CLASSIFICATION)));
053:
054:                for (Iterator i = fileFilterToReferencedImageFactoryMap
055:                        .keyList().iterator(); i.hasNext();) {
056:                    FileFilter fileFilter = (FileFilter) i.next();
057:                    fileChooser.addChoosableFileFilter(fileFilter);
058:                }
059:                fileChooser
060:                        .setFileFilter((FileFilter) fileFilterToReferencedImageFactoryMap
061:                                .keyList().get(0));
062:
063:                for (Iterator i = Arrays.asList(
064:                        fileChooser.getChoosableFileFilters()).iterator(); i
065:                        .hasNext();) {
066:                    FileFilter fileFilter = (FileFilter) i.next();
067:                    if (fileFilter.getDescription().equals(
068:                            blackboard
069:                                    .get(LAST_FILE_FILTER_DESCRIPTION_KEY, ""))) {
070:                        fileChooser.setFileFilter(fileFilter);
071:                        break;
072:                    }
073:                }
074:                fileChooser.setMultiSelectionEnabled(true);
075:
076:                Collection selectedFeatures = null;
077:
078:                // Show modal here
079:                if (JFileChooser.APPROVE_OPTION == fileChooser
080:                        .showOpenDialog(context.getWorkbenchFrame())) {
081:                    blackboard.put(LAST_DIRECTORY_KEY, fileChooser
082:                            .getCurrentDirectory().getPath());
083:                    blackboard.put(LAST_FILE_FILTER_DESCRIPTION_KEY,
084:                            fileChooser.getFileFilter().getDescription());
085:
086:                    File[] selectedFiles = fileChooser.getSelectedFiles();
087:
088:                    if (selectedFiles != null && selectedFiles.length > 0) {
089:                        ReferencedImageFactory rif = (ReferencedImageFactory) fileFilterToReferencedImageFactoryMap
090:                                .get(fileChooser.getFileFilter());
091:
092:                        if (rif.isAvailable()) {
093:                            selectedFeatures = createFeatures(rif,
094:                                    selectedFiles,
095:                                    getImageryLayerDataset(layer));
096:                        } else {
097:                            Object[] options = { "OK" };
098:                            JOptionPane
099:                                    .showOptionDialog(
100:                                            null,
101:                                            I18N
102:                                                    .get("ui.plugin.imagery.ImageFeatureCreator.The-driver-for")
103:                                                    + " "
104:                                                    + rif.getTypeName()
105:                                                    + " "
106:                                                    + I18N
107:                                                            .get("ui.plugin.imagery.ImageFeatureCreator.is-not-available-Please-check-your-configuration"),
108:                                            I18N
109:                                                    .get("ui.plugin.imagery.ImageFeatureCreator.Warning"),
110:                                            JOptionPane.DEFAULT_OPTION,
111:                                            JOptionPane.WARNING_MESSAGE, null,
112:                                            options, options[0]);
113:                        }
114:                    }
115:                }
116:
117:                return selectedFeatures;
118:            }
119:
120:            /**
121:             * Sets whether an imagery layer is selectable, editable, and read-only.
122:             * The policy used is that a imagery layer is selectable/editable iff:
123:             * <ul>
124:             * <li>There is a single image in the layer
125:             * <li>The image type is editable
126:             * </ul>
127:             *
128:             * @param layer the layer to update
129:             */
130:            public void setLayerSelectability(Layer layer) {
131:                boolean selectable = false;
132:                Collection features = layer.getFeatureCollectionWrapper()
133:                        .getFeatures();
134:
135:                if (features.size() == 1) {
136:                    Feature f = (Feature) features.iterator().next();
137:                    String imageFilePath = (String) f
138:                            .getAttribute(ImageryLayerDataset.ATTR_FILE);
139:                    String factoryClassPath = (String) f
140:                            .getAttribute(ImageryLayerDataset.ATTR_FACTORY);
141:
142:                    if (imageFilePath != null && factoryClassPath != null) {
143:                        try {
144:                            ReferencedImageFactory imageFactory = (ReferencedImageFactory) Class
145:                                    .forName(factoryClassPath).newInstance();
146:                            selectable = imageFactory
147:                                    .isEditableImage(imageFilePath);
148:                        } catch (Exception ex) {
149:                            // do nothing
150:                        }
151:                    }
152:                }
153:
154:                layer.setSelectable(selectable);
155:                layer.setEditable(selectable);
156:                layer.setReadonly(!selectable);
157:            }
158:
159:            private ReferencedImageFactory getReferencedImageFactoryProper(
160:                    ReferencedImageFactory factory, File file) {
161:                return factory instanceof  CompositeReferencedImageFactory ? ((CompositeReferencedImageFactory) factory)
162:                        .referencedImageFactory(FileUtil.getExtension(file))
163:                        : factory;
164:            }
165:
166:            private ImageryLayerDataset getImageryLayerDataset(Layer layer) {
167:                ReferencedImageStyle irs = (ReferencedImageStyle) layer
168:                        .getStyle(ReferencedImageStyle.class);
169:                return irs.getImageryLayerDataset();
170:            }
171:
172:            private Collection createFeatures(
173:                    final ReferencedImageFactory referencedImageFactory,
174:                    File[] files, final ImageryLayerDataset imageryLayerDataset) {
175:                return CollectionUtil.collect(Arrays.asList(files),
176:                        new Block() {
177:                            public Object yield(Object file) {
178:                                return createFeature(referencedImageFactory,
179:                                        (File) file, imageryLayerDataset);
180:                            }
181:                        });
182:            }
183:
184:            private Feature createFeature(
185:                    ReferencedImageFactory referencedImageFactory, File file,
186:                    ImageryLayerDataset imageryLayerDataset) {
187:
188:                Feature feature = new BasicFeature(ImageryLayerDataset
189:                        .getSchema());
190:                feature.setAttribute(ImageryLayerDataset.ATTR_FILE, file
191:                        .getPath());
192:                feature.setAttribute(ImageryLayerDataset.ATTR_FORMAT,
193:                        getReferencedImageFactoryProper(referencedImageFactory,
194:                                file).getTypeName());
195:                feature.setAttribute(ImageryLayerDataset.ATTR_FACTORY,
196:                        getReferencedImageFactoryProper(referencedImageFactory,
197:                                file).getClass().getName());
198:                // Set Geometry to an empty Geometry, in case an exception occurs before
199:                // the Geometry is actually set. [Jon Aquino 2005-04-12]
200:                feature.setGeometry(new GeometryFactory()
201:                        .createPoint((Coordinate) null));
202:                // Set the Geometry. [Jon Aquino 2005-04-12]
203:                imageryLayerDataset.createImage(feature);
204:                return feature;
205:            }
206:
207:            private OrderedMap getFileFilterToReferencedImageFactoryMap(
208:                    Collection referencedImageFactories) {
209:                OrderedMap fileFilterToReferencedImageFactoryMap = new OrderedMap();
210:                for (Iterator i = referencedImageFactories.iterator(); i
211:                        .hasNext();) {
212:                    ReferencedImageFactory referencedImageFactory = (ReferencedImageFactory) i
213:                            .next();
214:                    //            if(referencedImageFactory.isAvailable()){
215:                    fileFilterToReferencedImageFactoryMap.put(
216:                            createFileFilter(referencedImageFactory),
217:                            referencedImageFactory);
218:                    //            }
219:                }
220:                return fileFilterToReferencedImageFactoryMap;
221:            }
222:
223:            private FileFilter createFileFilter(
224:                    ReferencedImageFactory referencedImageFactory) {
225:                return GUIUtil.createFileFilter((referencedImageFactory
226:                        .getTypeName().equals(
227:                                referencedImageFactory.getDescription()) ? ""
228:                        : referencedImageFactory.getTypeName() + " - ")
229:                        + referencedImageFactory.getDescription(),
230:                        referencedImageFactory.getExtensions());
231:            }
232:
233:            private Collection insertCompositeReferencedImageFactory(
234:                    List referencedImageFactories) {
235:                return CollectionUtil
236:                        .concatenate(Arrays
237:                                .asList(new Collection[] {
238:                                        Collections
239:                                                .singleton(new CompositeReferencedImageFactory(
240:                                                        referencedImageFactories)),
241:                                        referencedImageFactories }));
242:            }
243:
244:            private static class CompositeReferencedImageFactory implements 
245:                    ReferencedImageFactory {
246:
247:                private List referencedImageFactories;
248:
249:                public CompositeReferencedImageFactory(
250:                        List referencedImageFactories) {
251:                    this .referencedImageFactories = new ArrayList();
252:                    for (Iterator i = referencedImageFactories.iterator(); i
253:                            .hasNext();) {
254:                        ReferencedImageFactory referencedImageFactory = (ReferencedImageFactory) i
255:                                .next();
256:                        if (referencedImageFactory.isAvailable()) {
257:                            this .referencedImageFactories
258:                                    .add(referencedImageFactory);
259:                        }
260:                    }
261:                }
262:
263:                public String getTypeName() {
264:                    return I18N
265:                            .get("ui.plugin.imagery.ImageFeatureCreator.All-Formats");
266:                }
267:
268:                public boolean isEditableImage(String location) {
269:                    return false;
270:                }
271:
272:                public String getDescription() {
273:                    return getTypeName();
274:                }
275:
276:                public String[] getExtensions() {
277:                    return (String[]) CollectionUtil.concatenate(
278:                            CollectionUtil.collect(referencedImageFactories,
279:                                    new Block() {
280:                                        public Object yield(
281:                                                Object referencedImageFactory) {
282:                                            return Arrays
283:                                                    .asList(((ReferencedImageFactory) referencedImageFactory)
284:                                                            .getExtensions());
285:                                        }
286:                                    })).toArray(new String[] {});
287:                }
288:
289:                public ReferencedImageFactory referencedImageFactory(
290:                        String extension) {
291:                    for (Iterator i = referencedImageFactories.iterator(); i
292:                            .hasNext();) {
293:                        ReferencedImageFactory referencedImageFactory = (ReferencedImageFactory) i
294:                                .next();
295:                        if (Arrays.asList(
296:                                referencedImageFactory.getExtensions())
297:                                .contains(extension.toLowerCase())) {
298:                            return referencedImageFactory;
299:                        }
300:                    }
301:                    Assert.shouldNeverReachHere();
302:                    return null;
303:                }
304:
305:                public ReferencedImage createImage(String location) {
306:                    throw new UnsupportedOperationException();
307:                }
308:
309:                public boolean isAvailable() {
310:                    return true;
311:                }
312:            }
313:        }
w__w_w___.___j_a___v__a2_s___._c_om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.