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:
033: package com.vividsolutions.jump.workbench.driver;
034:
035: import java.util.ArrayList;
036: import java.util.Arrays;
037: import java.util.Iterator;
038: import java.util.List;
039:
040: import com.vividsolutions.jts.util.Assert;
041: import com.vividsolutions.jump.I18N;
042: import com.vividsolutions.jump.workbench.WorkbenchProperties;
043: import com.vividsolutions.jump.workbench.ui.BasicFileDriverPanel;
044: import com.vividsolutions.jump.workbench.ui.ErrorHandler;
045:
046: public class DriverManager {
047: private ArrayList inputDrivers = new ArrayList();
048: private ArrayList outputDrivers = new ArrayList();
049: private List builtInInputDriverClasses = Arrays.asList(new Class[] {
050: FMEFileInputDriver.class, GMLFileInputDriver.class,
051: JMLFileInputDriver.class, ShapeFileInputDriver.class,
052: WKTFileInputDriver.class });
053: private List builtInOutputDriverClasses = Arrays
054: .asList(new Class[] { FMEFileOutputDriver.class,
055: GMLFileOutputDriver.class,
056: JMLFileOutputDriver.class,
057: ShapefileOutputDriver.class,
058: WKTFileOutputDriver.class });
059: private BasicFileDriverPanel sharedOpenBasicFileDriverPanel;
060: private BasicFileDriverPanel sharedSaveBasicFileDriverPanel;
061: private ErrorHandler errorHandler;
062:
063: public DriverManager(ErrorHandler errorHandler) {
064: this .errorHandler = errorHandler;
065: sharedOpenBasicFileDriverPanel = new SharedFileDriverPanel(I18N
066: .get("driver.DriverManager.file-to-open"), errorHandler);
067: sharedSaveBasicFileDriverPanel = new SharedFileDriverPanel(I18N
068: .get("driver.DriverManager.file-to-save"), errorHandler);
069: sharedOpenBasicFileDriverPanel.setFileMustExist(true);
070: sharedSaveBasicFileDriverPanel.setFileMustExist(false);
071: }
072:
073: public List getInputDrivers() {
074: return inputDrivers;
075: }
076:
077: public List getOutputDrivers() {
078: return outputDrivers;
079: }
080:
081: /**
082: * Need to share the file chooser; otherwise, whenever the user switched
083: * drivers, he would lose the filename he typed in.
084: */
085: public BasicFileDriverPanel getSharedOpenBasicFileDriverPanel() {
086: return sharedOpenBasicFileDriverPanel;
087: }
088:
089: public BasicFileDriverPanel getSharedSaveBasicFileDriverPanel() {
090: return sharedSaveBasicFileDriverPanel;
091: }
092:
093: public void loadDrivers(WorkbenchProperties properties)
094: throws ClassNotFoundException, IllegalAccessException,
095: InstantiationException {
096: ArrayList newInputDriverClasses = new ArrayList();
097: newInputDriverClasses.addAll(builtInInputDriverClasses);
098: newInputDriverClasses
099: .addAll(properties.getInputDriverClasses());
100: loadDrivers(newInputDriverClasses, inputDrivers);
101:
102: ArrayList newOutputDriverClasses = new ArrayList();
103: newOutputDriverClasses.addAll(builtInOutputDriverClasses);
104: newOutputDriverClasses.addAll(properties
105: .getOutputDriverClasses());
106: loadDrivers(newOutputDriverClasses, outputDrivers);
107: }
108:
109: /**
110: * Loads an instantiated, but not yet initialized, InputDriver, and adds it to the list.
111: * @param driver an instantiated but not yet initialed, InputDriver
112: */
113: public void loadInputDriver(AbstractInputDriver driver) {
114: driver.initialize(this , errorHandler);
115: inputDrivers.add(driver);
116: }
117:
118: /**
119: * Loads an instantiated, but not yet initialized OutputDriver, and adds it to the list.
120: * @param driver an instantiated but not yet initialized OutputDriver
121: */
122: public void loadOutputDriver(AbstractOutputDriver driver) {
123: driver.initialize(this , errorHandler);
124: outputDrivers.add(driver);
125: }
126:
127: private void loadDrivers(List driverClasses, List drivers)
128: throws ClassNotFoundException, IllegalAccessException,
129: InstantiationException {
130: for (Iterator i = driverClasses.iterator(); i.hasNext();) {
131: Class driverClass = (Class) i.next();
132: AbstractDriver driver = (AbstractDriver) driverClass
133: .newInstance();
134: driver.initialize(this , errorHandler);
135: drivers.add(driver);
136: }
137: }
138:
139: private static class SharedFileDriverPanel extends
140: BasicFileDriverPanel {
141: public SharedFileDriverPanel(String description,
142: ErrorHandler errorHandler) {
143: super (errorHandler);
144: fileNamePanel.setUpperDescription(description);
145: }
146:
147: public void setFileDescription(String description) {
148: Assert
149: .shouldNeverReachHere("Panel is shared; thus description cannot be changed");
150: }
151: }
152: }
|