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 java.io.File;
035: import java.util.Collection;
036:
037: import javax.swing.JFileChooser;
038: import javax.swing.event.AncestorEvent;
039: import javax.swing.event.AncestorListener;
040:
041: import com.vividsolutions.jump.util.Blackboard;
042: import com.vividsolutions.jump.workbench.WorkbenchContext;
043: import com.vividsolutions.jump.workbench.ui.GUIUtil;
044: import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
045:
046: /**
047: * UI for picking a file-based dataset to save. Does not automatically append an
048: * extension if user does not specify one because, unlike Windows, on
049: * Unix it is common for files not to have extensions.
050: */
051: public class SaveFileDataSourceQueryChooser extends
052: FileDataSourceQueryChooser {
053: private static final String FILE_CHOOSER_DIRECTORY_KEY = SaveFileDataSourceQueryChooser.class
054: .getName()
055: + " - FILE CHOOSER DIRECTORY";
056: private WorkbenchContext context;
057:
058: /**
059: * @param extensions e.g. txt
060: */
061: public SaveFileDataSourceQueryChooser(Class dataSourceClass,
062: String description, String[] extensions,
063: WorkbenchContext context) {
064: super (dataSourceClass, description, extensions);
065: this .context = context;
066: }
067:
068: protected FileChooserPanel getFileChooserPanel() {
069: final String FILE_CHOOSER_PANEL_KEY = SaveFileDataSourceQueryChooser.class
070: .getName()
071: + " - SAVE FILE CHOOSER PANEL";
072:
073: //SaveFileDataSourceQueryChoosers share the same JFileChooser so that the user's
074: //work is not lost when he switches data-source types. The JFileChooser options
075: //are set once because setting them freezes the GUI for a few seconds. [Jon Aquino]
076: if (blackboard().get(FILE_CHOOSER_PANEL_KEY) == null) {
077: final JFileChooser fileChooser = GUIUtil
078: .createJFileChooserWithOverwritePrompting();
079: fileChooser.setMultiSelectionEnabled(false);
080: fileChooser.setControlButtonsAreShown(false);
081: blackboard().put(FILE_CHOOSER_PANEL_KEY,
082: new FileChooserPanel(fileChooser, blackboard()));
083:
084: if (PersistentBlackboardPlugIn.get(context).get(
085: FILE_CHOOSER_DIRECTORY_KEY) != null) {
086: fileChooser.setCurrentDirectory(new File(
087: (String) PersistentBlackboardPlugIn
088: .get(context).get(
089: FILE_CHOOSER_DIRECTORY_KEY)));
090: }
091: fileChooser.addAncestorListener(new AncestorListener() {
092: public void ancestorAdded(AncestorEvent event) {
093: if (event.getAncestor() instanceof DataSourceQueryChooserDialog) {
094: fileChooser.rescanCurrentDirectory();
095: }
096: }
097:
098: public void ancestorMoved(AncestorEvent event) {
099: }
100:
101: public void ancestorRemoved(AncestorEvent event) {
102: }
103: });
104: }
105:
106: return (FileChooserPanel) blackboard().get(
107: FILE_CHOOSER_PANEL_KEY);
108: }
109:
110: private Blackboard blackboard() {
111: return context.getBlackboard();
112: }
113:
114: public Collection getDataSourceQueries() {
115: //User has pressed OK, so persist the directory. [Jon Aquino]
116: PersistentBlackboardPlugIn.get(context).put(
117: FILE_CHOOSER_DIRECTORY_KEY,
118: getFileChooserPanel().getChooser()
119: .getCurrentDirectory().toString());
120:
121: return super.getDataSourceQueries();
122: }
123: }
|