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.JLabel;
043: import javax.swing.JPanel;
044:
045: public class JMLFileDriverPanel extends AbstractDriverPanel {
046: //<<TODO:REFACTOR>> Eliminate this class; its code is very similar to
047: //BasicFileDriverPanel. [Jon Aquino]
048: //<<TODO>> This variable isn't used. Eliminate it. [Jon Aquino]
049: private final static String TEMPLATE_FILE_CACHE_KEY = "TEMPLATE_FILE";
050: BorderLayout borderLayout1 = new BorderLayout();
051: OKCancelPanel okCancelPanel = new OKCancelPanel();
052: JPanel centrePanel = new JPanel();
053: JPanel innerCentrePanel = new JPanel();
054: FileNamePanel templateFileNamePanel;
055: FileNamePanel jmlFileNamePanel;
056: JLabel whitespaceLabel = new JLabel();
057: GridBagLayout gridBagLayout1 = new GridBagLayout();
058: GridBagLayout gridBagLayout2 = new GridBagLayout();
059:
060: public JMLFileDriverPanel(ErrorHandler errorHandler) {
061: templateFileNamePanel = new FileNamePanel(errorHandler);
062: jmlFileNamePanel = new FileNamePanel(errorHandler);
063:
064: try {
065: jbInit();
066: jmlFileNamePanel.setFileMustExist(true);
067:
068: /*jmlFileNamePanel.addBrowseListener(
069: new ActionListener() {
070: public void actionPerformed(ActionEvent e) {
071: setTemplateFile();
072: }
073: });*/
074: } catch (Exception ex) {
075: ex.printStackTrace();
076: }
077: }
078:
079: public void setGMLFileMustExist(boolean gmlFileMustExist) {
080: jmlFileNamePanel.setFileMustExist(gmlFileMustExist);
081: }
082:
083: public void setCache(DriverPanelCache cache) {
084: super .setCache(cache);
085:
086: if (cache.get(DriverPanelCache.FILE_CACHE_KEY) != null) {
087: jmlFileNamePanel.setSelectedFile((File) cache
088: .get(DriverPanelCache.FILE_CACHE_KEY));
089: }
090:
091: if (cache.get(TEMPLATE_FILE_CACHE_KEY) != null) {
092: templateFileNamePanel.setSelectedFile((File) cache
093: .get(TEMPLATE_FILE_CACHE_KEY));
094: }
095: }
096:
097: public String getValidationError() {
098: if (!jmlFileNamePanel.isInputValid()) {
099: return jmlFileNamePanel.getValidationError();
100: }
101:
102: return null;
103: }
104:
105: public File getJMLFile() {
106: return jmlFileNamePanel.getSelectedFile();
107: }
108:
109: public File getTemplateFile() {
110: return templateFileNamePanel.getSelectedFile();
111: }
112:
113: public DriverPanelCache getCache() {
114: DriverPanelCache cache = super .getCache();
115: cache.put(DriverPanelCache.FILE_CACHE_KEY, jmlFileNamePanel
116: .getSelectedFile());
117:
118: //cache.put(TEMPLATE_FILE_CACHE_KEY, templateFileNamePanel.getSelectedFile());
119: return cache;
120: }
121:
122: public void addActionListener(ActionListener l) {
123: okCancelPanel.addActionListener(l);
124: }
125:
126: public void removeActionListener(ActionListener l) {
127: okCancelPanel.removeActionListener(l);
128: }
129:
130: public boolean wasOKPressed() {
131: return okCancelPanel.wasOKPressed();
132: }
133:
134: void jbInit() throws Exception {
135: this .setLayout(borderLayout1);
136: innerCentrePanel.setLayout(gridBagLayout1);
137: whitespaceLabel.setText(" ");
138: jmlFileNamePanel.setUpperDescription("JML File");
139: centrePanel.setLayout(gridBagLayout2);
140: this .add(okCancelPanel, BorderLayout.SOUTH);
141: this .add(centrePanel, BorderLayout.CENTER);
142: centrePanel.add(innerCentrePanel, new GridBagConstraints(0, 0,
143: 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
144: GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0,
145: 0));
146: innerCentrePanel.add(jmlFileNamePanel, new GridBagConstraints(
147: 0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
148: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
149: innerCentrePanel.add(whitespaceLabel, new GridBagConstraints(1,
150: 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
151: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
152: }
153: }
|