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.ui;
034:
035: import java.awt.BorderLayout;
036: import java.awt.GridBagConstraints;
037: import java.awt.GridBagLayout;
038: import java.awt.Insets;
039: import java.awt.event.ActionListener;
040: import java.io.File;
041:
042: import javax.swing.JPanel;
043: import javax.swing.filechooser.FileFilter;
044:
045: import com.vividsolutions.jump.I18N;
046:
047: //JBuilder displays this component as a "Red Bean". There's a trick to
048: //displaying it -- see jcstest.AbstractDriverPanelProxy and
049: //http://www.visi.com/~gyles19/fom-serve/cache/97.html. [Jon Aquino]
050: //<<TODO:REFACTORING>> This class duplicates code in GMLFileDriverPanel. I wonder
051: //how we can refactor them. [Jon Aquino]
052:
053: /**
054: * Base for UI supporting File-based Driver.
055: */
056:
057: public class BasicFileDriverPanel extends AbstractDriverPanel {
058: BorderLayout borderLayout1 = new BorderLayout();
059: OKCancelPanel okCancelPanel = new OKCancelPanel();
060: JPanel centrePanel = new JPanel();
061: JPanel innerCentrePanel = new JPanel();
062: protected FileNamePanel fileNamePanel;
063: GridBagLayout gridBagLayout1 = new GridBagLayout();
064: GridBagLayout gridBagLayout2 = new GridBagLayout();
065:
066: public BasicFileDriverPanel(ErrorHandler errorHandler) {
067: fileNamePanel = new FileNamePanel(errorHandler);
068:
069: try {
070: jbInit();
071: } catch (Exception ex) {
072: ex.printStackTrace();
073: }
074: }
075:
076: void jbInit() throws Exception {
077: this .setLayout(borderLayout1);
078: innerCentrePanel.setLayout(gridBagLayout1);
079: fileNamePanel
080: .setUpperDescription(I18N
081: .get("ui.BasicFileDriverPanel.file-description-goes-here"));
082: centrePanel.setLayout(gridBagLayout2);
083: this .add(okCancelPanel, BorderLayout.SOUTH);
084: this .add(centrePanel, BorderLayout.CENTER);
085: centrePanel.add(innerCentrePanel, new GridBagConstraints(0, 0,
086: 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
087: GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0,
088: 0));
089: innerCentrePanel.add(fileNamePanel, new GridBagConstraints(1,
090: 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
091: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
092: }
093:
094: public void setFileMustExist(boolean fileMustExist) {
095: fileNamePanel.setFileMustExist(fileMustExist);
096: }
097:
098: public String getValidationError() {
099: if (!fileNamePanel.isInputValid()) {
100: return fileNamePanel.getValidationError();
101: }
102:
103: return null;
104: }
105:
106: public File getSelectedFile() {
107: return fileNamePanel.getSelectedFile();
108: }
109:
110: public void addActionListener(ActionListener l) {
111: okCancelPanel.addActionListener(l);
112: }
113:
114: public void removeActionListener(ActionListener l) {
115: okCancelPanel.removeActionListener(l);
116: }
117:
118: public boolean wasOKPressed() {
119: return okCancelPanel.wasOKPressed();
120: }
121:
122: public void setFileDescription(String description) {
123: fileNamePanel.setUpperDescription(description);
124: }
125:
126: public void setCache(DriverPanelCache cache) {
127: super .setCache(cache);
128:
129: if (cache.get(DriverPanelCache.FILE_CACHE_KEY) != null) {
130: fileNamePanel.setSelectedFile((File) cache
131: .get(DriverPanelCache.FILE_CACHE_KEY));
132: }
133: }
134:
135: public DriverPanelCache getCache() {
136: DriverPanelCache cache = super .getCache();
137: cache.put(DriverPanelCache.FILE_CACHE_KEY, fileNamePanel
138: .getSelectedFile());
139:
140: return cache;
141: }
142:
143: public void setFileFilter(FileFilter filter) {
144: fileNamePanel.setFileFilter(filter);
145: }
146: }
|