001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032: package com.vividsolutions.jump.workbench.datasource;
033:
034: import com.vividsolutions.jts.util.Assert;
035:
036: import com.vividsolutions.jump.I18N;
037: import com.vividsolutions.jump.io.*;
038: import com.vividsolutions.jump.io.datasource.StandardReaderWriterFileDataSource;
039: import com.vividsolutions.jump.workbench.WorkbenchContext;
040: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
041: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
042: import com.vividsolutions.jump.workbench.ui.GUIUtil;
043:
044: import javax.swing.JFileChooser;
045:
046: /**
047: * Adds to the JUMP Workbench the UIs for opening and saving files with the
048: * basic file formats.
049: */
050: public class InstallStandardDataSourceQueryChoosersPlugIn extends
051: AbstractPlugIn {
052:
053: private void addFileDataSourceQueryChoosers(JUMPReader reader,
054: JUMPWriter writer, final String description,
055: WorkbenchContext context, Class readerWriterDataSourceClass) {
056:
057: DataSourceQueryChooserManager chooserManager = DataSourceQueryChooserManager
058: .get(context.getBlackboard());
059:
060: chooserManager
061: .addLoadDataSourceQueryChooser(new LoadFileDataSourceQueryChooser(
062: readerWriterDataSourceClass, description,
063: extensions(readerWriterDataSourceClass),
064: context) {
065: protected void addFileFilters(JFileChooser chooser) {
066: super .addFileFilters(chooser);
067: InstallStandardDataSourceQueryChoosersPlugIn
068: .addCompressedFileFilter(description,
069: chooser);
070: }
071: });
072:
073: chooserManager
074: .addSaveDataSourceQueryChooser(new SaveFileDataSourceQueryChooser(
075: readerWriterDataSourceClass, description,
076: extensions(readerWriterDataSourceClass),
077: context));
078: }
079:
080: public static String[] extensions(Class readerWriterDataSourceClass) {
081: String[] exts = null;
082:
083: try {
084: exts = ((StandardReaderWriterFileDataSource) readerWriterDataSourceClass
085: .newInstance()).getExtensions();
086: } catch (Exception e) {
087: Assert.shouldNeverReachHere(e.toString());
088: }
089:
090: return exts;
091: }
092:
093: public void initialize(final PlugInContext context)
094: throws Exception {
095: addFileDataSourceQueryChoosers(new JMLReader(),
096: new JMLWriter(), "JUMP GML", context
097: .getWorkbenchContext(),
098: StandardReaderWriterFileDataSource.JML.class);
099:
100: new GMLDataSourceQueryChooserInstaller()
101: .addLoadGMLFileDataSourceQueryChooser(context);
102: new GMLDataSourceQueryChooserInstaller()
103: .addSaveGMLFileDataSourceQueryChooser(context);
104:
105: addFileDataSourceQueryChoosers(new FMEGMLReader(),
106: new FMEGMLWriter(), "FME GML", context
107: .getWorkbenchContext(),
108: StandardReaderWriterFileDataSource.FMEGML.class);
109:
110: addFileDataSourceQueryChoosers(new WKTReader(),
111: new WKTWriter(), "WKT", context.getWorkbenchContext(),
112: StandardReaderWriterFileDataSource.WKT.class);
113:
114: addFileDataSourceQueryChoosers(new ShapefileReader(),
115: new ShapefileWriter(), "ESRI Shapefile", context
116: .getWorkbenchContext(),
117: StandardReaderWriterFileDataSource.Shapefile.class);
118: }
119:
120: public static void addCompressedFileFilter(
121: final String description, JFileChooser chooser) {
122: chooser
123: .addChoosableFileFilter(GUIUtil
124: .createFileFilter(
125: I18N
126: .get("datasource.InstallStandardDataSourceQueryChoosersPlugIn.compressed")
127: + " " + description,
128: new String[] { "zip", "gz" }));
129: }
130: }
|