01: /*
02: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI for
03: * visualizing and manipulating spatial features with geometry and attributes.
04: *
05: * Copyright (C) 2003 Vivid Solutions
06: *
07: * This program is free software; you can redistribute it and/or modify it under
08: * the terms of the GNU General Public License as published by the Free Software
09: * Foundation; either version 2 of the License, or (at your option) any later
10: * version.
11: *
12: * This program is distributed in the hope that it will be useful, but WITHOUT
13: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15: * details.
16: *
17: * You should have received a copy of the GNU General Public License along with
18: * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19: * Place - Suite 330, Boston, MA 02111-1307, USA.
20: *
21: * For more information, contact:
22: *
23: * Vivid Solutions Suite #1A 2328 Government Street Victoria BC V8T 5G5 Canada
24: *
25: * (250)385-6040 www.vividsolutions.com
26: */
27: package com.vividsolutions.jump.workbench.ui.plugin;
28:
29: import com.vividsolutions.jump.I18N;
30: import com.vividsolutions.jump.util.FileUtil;
31: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
32: import com.vividsolutions.jump.workbench.ui.GUIUtil;
33: import java.io.File;
34: import javax.swing.JFileChooser;
35: import javax.swing.filechooser.FileFilter;
36:
37: public class SaveProjectAsPlugIn extends AbstractSaveProjectPlugIn {
38: public static final FileFilter JUMP_PROJECT_FILE_FILTER = GUIUtil
39: .createFileFilter(
40: I18N
41: .get("ui.plugin.SaveProjectAsPlugIn.jump-project-files"),
42: new String[] { "jmp", "jcs" });
43: private JFileChooser fileChooser;
44:
45: public void initialize(PlugInContext context) throws Exception {
46: //Don't initialize fileChooser at field declaration; otherwise get
47: // intermittent
48: //exceptions:
49: //java.lang.NullPointerException
50: // at javax.swing.ImageIcon.<init>(ImageIcon.java:161)
51: // at javax.swing.ImageIcon.<init>(ImageIcon.java:147)
52: // at
53: // com.sun.java.swing.plaf.windows.WindowsFileChooserUI$ShortCutPanel.<init>(WindowsFileChooserUI.java:603)
54: // at
55: // com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponents(WindowsFileChooserUI.java:361)
56: // at
57: // javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:130)
58: // at
59: // com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(WindowsFileChooserUI.java:176)
60: // at javax.swing.JComponent.setUI(JComponent.java:449)
61: // at javax.swing.JFileChooser.updateUI(JFileChooser.java:1701)
62: // at javax.swing.JFileChooser.setup(JFileChooser.java:345)
63: // at javax.swing.JFileChooser.<init>(JFileChooser.java:320)
64: //[Jon Aquino 2004-01-12]
65: fileChooser = GUIUtil
66: .createJFileChooserWithOverwritePrompting("jmp");
67: fileChooser.setDialogTitle(I18N
68: .get("ui.plugin.SaveProjectAsPlugIn.save-project"));
69: GUIUtil.removeChoosableFileFilters(fileChooser);
70: fileChooser.addChoosableFileFilter(JUMP_PROJECT_FILE_FILTER);
71: fileChooser.addChoosableFileFilter(GUIUtil.ALL_FILES_FILTER);
72: fileChooser.setFileFilter(JUMP_PROJECT_FILE_FILTER);
73: }
74:
75: public String getName() {
76: return I18N
77: .get("ui.plugin.SaveProjectAsPlugIn.save-project-as");
78: }
79:
80: public boolean execute(PlugInContext context) throws Exception {
81: reportNothingToUndoYet(context);
82: if (context.getTask().getProjectFile() != null) {
83: fileChooser.setSelectedFile(context.getTask()
84: .getProjectFile());
85: }
86: if (JFileChooser.APPROVE_OPTION != fileChooser
87: .showSaveDialog(context.getWorkbenchFrame())) {
88: return false;
89: }
90: File file = fileChooser.getSelectedFile();
91: file = FileUtil.addExtensionIfNone(file, "jmp");
92: save(context.getTask(), file, context.getWorkbenchFrame());
93: return true;
94: }
95: }
|