001: /*
002: ** $Id: ExportView.java,v 1.5 2000/10/21 14:56:29 mrw Exp $
003: **
004: ** Dialog to accept export options.
005: **
006: ** Mike Wilson, July 2000, mrw@whisperingwind.co.uk
007: **
008: ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
009: **
010: ** This program is free software; you can redistribute it and/or modify
011: ** it under the terms of the GNU General Public License as published by
012: ** the Free Software Foundation; either version 2 of the License, or
013: ** (at your option) any later version.
014: **
015: ** This program is distributed in the hope that it will be useful,
016: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
017: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: ** GNU General Public License for more details.
019: **
020: ** You should have received a copy of the GNU Library General
021: ** Public License along with this library; if not, write to the
022: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: ** Boston, MA 02111-1307 USA.
024: */
025:
026: package uk.co.whisperingwind.vienna;
027:
028: import java.awt.BorderLayout;
029: import java.awt.GridBagConstraints;
030: import java.awt.GridBagLayout;
031: import java.awt.Insets;
032: import javax.swing.JButton;
033: import javax.swing.JCheckBox;
034: import javax.swing.JFrame;
035: import javax.swing.JLabel;
036: import javax.swing.JPanel;
037: import javax.swing.JTextField;
038: import uk.co.whisperingwind.framework.ActionFactory;
039: import uk.co.whisperingwind.framework.ModelEvent;
040: import uk.co.whisperingwind.framework.PanelDialogView;
041:
042: class ExportView extends PanelDialogView {
043: private ActionFactory.DefaultAction okAction = null;
044: private ActionFactory.DefaultAction cancelAction = null;
045:
046: private FileNameEntry textFileName = new FileNameEntry();
047: private JTextField textDelimiter = new JTextField(",", 4);
048: private JCheckBox checkTitles = new JCheckBox(
049: "Include column titles");
050: private JCheckBox checkQuote = new JCheckBox(
051: "Quote character fields");
052: private JTextField textQuote = new JTextField("\"", 4);
053:
054: public ExportView(JFrame parent, boolean modal) {
055: super (parent, modal);
056:
057: content.setTitle("Export query results");
058: createActions();
059:
060: panel.add(new ExportPanel(), BorderLayout.CENTER);
061:
062: JButton okButton = okAction.toolButtonFactory(buttonPanel);
063: cancelAction.toolButtonFactory(buttonPanel);
064:
065: content.getRootPane().setDefaultButton(okButton);
066: content.pack();
067:
068: textFileName.requestFocus();
069: checkQuote.setSelected(true);
070: checkTitles.setSelected(false);
071: textFileName.setText("export.csv");
072: }
073:
074: public void setFileName(String fileName) {
075: textFileName.setText(fileName);
076: }
077:
078: public String getFileName() {
079: return textFileName.getText();
080: }
081:
082: public String getDelimiter() {
083: return textDelimiter.getText();
084: }
085:
086: public boolean getWantTitles() {
087: return checkTitles.isSelected();
088: }
089:
090: public boolean getWantQuotes() {
091: return checkQuote.isSelected();
092: }
093:
094: public String getQuote() {
095: return textQuote.getText();
096: }
097:
098: protected void modelEvent(ModelEvent event) {
099: }
100:
101: protected void cleanUp() {
102: }
103:
104: /*
105: ** Create the Action instances used by this dialog.
106: */
107:
108: private void createActions() {
109: ConfigActionFactory factory = new ConfigActionFactory(
110: "/uk/co/whisperingwind/images");
111:
112: okAction = factory.createAction("ok");
113: cancelAction = factory.createAction("cancel");
114:
115: okAction.addActionListener(actionListener);
116: cancelAction.addActionListener(actionListener);
117: }
118:
119: private class ExportPanel extends JPanel {
120: public ExportPanel() {
121: setLayout(new GridBagLayout());
122: GridBagConstraints constraints = new GridBagConstraints();
123:
124: constraints.anchor = GridBagConstraints.WEST;
125: constraints.insets = new Insets(4, 4, 4, 4);
126: constraints.fill = GridBagConstraints.NONE;
127: constraints.gridwidth = GridBagConstraints.RELATIVE;
128: add(new JLabel("Output file name"), constraints);
129:
130: constraints.fill = GridBagConstraints.HORIZONTAL;
131: constraints.gridwidth = GridBagConstraints.REMAINDER;
132: constraints.weightx = 1.0;
133: add(textFileName, constraints);
134:
135: constraints.fill = GridBagConstraints.NONE;
136: constraints.weightx = 0.0;
137: constraints.gridwidth = GridBagConstraints.RELATIVE;
138: add(new JLabel("Delimiter"), constraints);
139:
140: constraints.gridwidth = GridBagConstraints.REMAINDER;
141: add(textDelimiter, constraints);
142:
143: add(checkTitles, constraints);
144: add(checkQuote, constraints);
145:
146: constraints.gridwidth = GridBagConstraints.RELATIVE;
147: add(new JLabel("Quote"), constraints);
148:
149: constraints.gridwidth = GridBagConstraints.REMAINDER;
150: add(textQuote, constraints);
151: }
152: }
153:
154: private class FileNameEntry extends JPanel {
155: private JTextField textFileName = new JTextField(20);
156:
157: public FileNameEntry() {
158: setLayout(new GridBagLayout());
159:
160: GridBagConstraints constraints = new GridBagConstraints();
161: constraints.anchor = GridBagConstraints.WEST;
162: constraints.insets = new Insets(0, 0, 0, 4);
163: constraints.fill = GridBagConstraints.HORIZONTAL;
164: constraints.weightx = 1.0;
165: add(textFileName, constraints);
166:
167: JButton lookupButton = new JButton("...");
168: lookupButton.setActionCommand("lookup");
169: lookupButton.addActionListener(actionListener);
170: lookupButton.setMargin(new Insets(0, 0, 0, 0));
171: constraints.insets = new Insets(0, 0, 0, 0);
172: constraints.gridwidth = GridBagConstraints.REMAINDER;
173: constraints.fill = GridBagConstraints.NONE;
174: constraints.weightx = 0.0;
175: add(lookupButton, constraints);
176: }
177:
178: public void requestFocus() {
179: textFileName.requestFocus();
180: }
181:
182: public void setText(String value) {
183: textFileName.setText(value);
184: }
185:
186: public String getText() {
187: return textFileName.getText();
188: }
189: }
190: }
|