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.jump.coordsys.CoordinateSystem;
035: import com.vividsolutions.jump.coordsys.CoordinateSystemSupport;
036: import com.vividsolutions.jump.util.Blackboard;
037: import com.vividsolutions.jump.workbench.WorkbenchContext;
038: import com.vividsolutions.jump.workbench.ui.GUIUtil;
039: import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
040:
041: import java.awt.event.ComponentAdapter;
042: import java.awt.event.ComponentEvent;
043: import java.io.File;
044:
045: import java.util.Collection;
046:
047: import javax.swing.JFileChooser;
048: import javax.swing.SwingUtilities;
049: import javax.swing.event.AncestorEvent;
050: import javax.swing.event.AncestorListener;
051:
052: /**
053: * UI for picking a file-based dataset to load.
054: */
055: public class LoadFileDataSourceQueryChooser extends
056: FileDataSourceQueryChooser {
057: public static final String FILE_CHOOSER_DIRECTORY_KEY = LoadFileDataSourceQueryChooser.class
058: .getName()
059: + " - FILE CHOOSER DIRECTORY";
060: public static final String FILE_CHOOSER_COORDINATE_SYSTEM_KEY = LoadFileDataSourceQueryChooser.class
061: .getName()
062: + " - FILE CHOOSER COORDINATE SYSTEM";
063: public static final String FILE_CHOOSER_PANEL_KEY = LoadFileDataSourceQueryChooser.class
064: .getName()
065: + " - FILE CHOOSER PANEL";
066: public static final String FILE_CHOOSER_KEY = LoadFileDataSourceQueryChooser.class
067: .getName()
068: + " - FILE CHOOSER";
069:
070: private WorkbenchContext context;
071:
072: /**
073: * @param extensions e.g. txt
074: */
075: public LoadFileDataSourceQueryChooser(Class dataSourceClass,
076: String description, String[] extensions,
077: WorkbenchContext context) {
078: super (dataSourceClass, description, extensions);
079: this .context = context;
080: }
081:
082: private Blackboard blackboard() {
083: return context.getBlackboard();
084: }
085:
086: protected FileChooserPanel getFileChooserPanel() {
087: //LoadFileDataSourceQueryChoosers share the same JFileChooser so that the user's
088: //work is not lost when he switches data-source types. Also, the JFileChooser options
089: //are set once because setting them is slow (freezes the GUI for a few seconds).
090: //[Jon Aquino]
091: if (blackboard().get(FILE_CHOOSER_PANEL_KEY) == null) {
092: final JFileChooser fileChooser = GUIUtil
093: .createJFileChooserWithExistenceChecking();
094: fileChooser.setMultiSelectionEnabled(true);
095: fileChooser.setControlButtonsAreShown(false);
096:
097: blackboard().put(FILE_CHOOSER_KEY, fileChooser);
098: blackboard().put(FILE_CHOOSER_PANEL_KEY,
099: new FileChooserPanel(fileChooser, blackboard()));
100:
101: if (PersistentBlackboardPlugIn.get(context).get(
102: FILE_CHOOSER_DIRECTORY_KEY) != null) {
103: fileChooser.setCurrentDirectory(new File(
104: (String) PersistentBlackboardPlugIn
105: .get(context).get(
106: FILE_CHOOSER_DIRECTORY_KEY)));
107: ((FileChooserPanel) blackboard().get(
108: FILE_CHOOSER_PANEL_KEY))
109: .setSelectedCoordinateSystem((String) PersistentBlackboardPlugIn
110: .get(context)
111: .get(FILE_CHOOSER_COORDINATE_SYSTEM_KEY));
112: }
113:
114: if (CoordinateSystemSupport.isEnabled(blackboard())) {
115: ((FileChooserPanel) blackboard().get(
116: FILE_CHOOSER_PANEL_KEY))
117: .setCoordinateSystemComboBoxVisible(true);
118: }
119: }
120:
121: return (FileChooserPanel) blackboard().get(
122: FILE_CHOOSER_PANEL_KEY);
123: }
124:
125: public Collection getDataSourceQueries() {
126: //User has pressed OK, so persist the directory. [Jon Aquino]
127: PersistentBlackboardPlugIn.get(context).put(
128: FILE_CHOOSER_DIRECTORY_KEY,
129: getFileChooserPanel().getChooser()
130: .getCurrentDirectory().toString());
131: PersistentBlackboardPlugIn.get(context).put(
132: FILE_CHOOSER_COORDINATE_SYSTEM_KEY,
133: getFileChooserPanel().getSelectedCoordinateSystem()
134: .getName());
135:
136: return super.getDataSourceQueries();
137: }
138: }
|