001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.cleverphl.gui;
025:
026: import jacareto.cleverphl.CleverPHL;
027: import jacareto.system.Customization;
028: import jacareto.system.Language;
029:
030: import java.awt.BorderLayout;
031: import java.awt.GridBagConstraints;
032: import java.awt.GridBagLayout;
033: import java.awt.Insets;
034: import java.awt.Point;
035: import java.awt.event.ActionEvent;
036: import java.awt.event.ActionListener;
037:
038: import javax.swing.JButton;
039: import javax.swing.JCheckBox;
040: import javax.swing.JDialog;
041: import javax.swing.JPanel;
042: import javax.swing.border.EmptyBorder;
043:
044: /**
045: * Dialog for saving the data set in XLS format.
046: *
047: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
048: * @version 1.01
049: */
050: public class SaveDataSetXLSDialog extends JDialog implements
051: ActionListener {
052: /** The checkbox for converting non-numeric values. */
053: private JCheckBox convertCheckBox;
054:
055: /** The checkbox for the header line. */
056: private JCheckBox headerCheckBox;
057:
058: /** The ok button. */
059: private JButton okButton;
060:
061: /** The cancel button. */
062: private JButton cancelButton;
063:
064: /** Whether or not ok has been pressed. */
065: private boolean okPressed;
066:
067: /**
068: * Creates a new dialog (visible).
069: *
070: * @param cleverPHL the CleverPHL instance
071: */
072: public SaveDataSetXLSDialog(CleverPHL cleverPHL) {
073: super (cleverPHL.getDataSetFrame(), true);
074: setName(cleverPHL.getCustomization().getString(
075: "Components.JacaretoComponent", "JACARETO_COMPONENT"));
076:
077: Language language = cleverPHL.getLanguage();
078: Customization customization = cleverPHL.getCustomization();
079:
080: setTitle(language
081: .getString("CleverPHL.SaveDataSetXLSDialog.Title"));
082:
083: // The file name text field
084: /*filenameField = new JTextField(20);
085: filenameField.setEditable (false);
086:
087: try {
088: File[] containedFiles=files.getDir("CLEVERPHL_DATASETS_DIR").listFiles ();
089: Vector datasetFiles = new Vector (containedFiles.length);
090: for (int j=0;j<containedFiles.length;j++) {
091: datasetFiles.add (containedFiles[j].getName());
092: }
093: int i = 0;
094: String prefix = session.getName()+"_";
095: while (datasetFiles.contains (prefix+i+".csv")) {
096: i++;
097: }
098: filenameField.setText (files.getDir(""CLEVERPHL_DATASETS_DIR"").getCanonicalPath()+File.separator+prefix+i+".csv");
099: } catch (IOException i) {
100: }
101:
102:
103: JLabel filenameLabel = new JLabel (language.getString ("General.Filename")+":");
104: JButton chooseButton = new JButton (language.getString ("General.Choose") + "...");
105: chooseButton.addActionListener (new ChooseButtonListener (cleverPHL));
106:
107: JPanel filePanel = new JPanel();
108: filePanel.setLayout (new FlowLayout (FlowLayout.LEFT));
109: filePanel.add (filenameLabel);
110: filePanel.add (filenameField);
111: filePanel.add (chooseButton); */
112: // The checkbox for the header line
113: headerCheckBox = new JCheckBox(language
114: .getString("CleverPHL.SaveDataSetXLSDialog.HeaderLine"));
115: headerCheckBox.setSelected(customization.getBoolean(
116: "DataSet.CSV.StoreHeaderLine", false));
117:
118: // The checkbox for converting non-numeric values
119: convertCheckBox = new JCheckBox(
120: language
121: .getString("CleverPHL.SaveDataSetXLSDialog.ConvertNonNumeric"));
122: convertCheckBox.setSelected(customization.getBoolean(
123: "DataSet.XLS.ConvertNonNumeric", false));
124:
125: // The panel with all components
126: JPanel leftPanelWrapper = new JPanel();
127: leftPanelWrapper.setLayout(new GridBagLayout());
128:
129: GridBagConstraints c = new GridBagConstraints();
130: c.gridx = 0;
131: c.gridy = 0;
132: c.weighty = 55;
133: c.insets = new Insets(5, 5, 5, 5);
134: c.anchor = GridBagConstraints.WEST;
135: c.gridy = 0;
136: c.weighty = 15;
137: leftPanelWrapper.add(headerCheckBox, c);
138: c.gridy = 1;
139: c.weighty = 15;
140: leftPanelWrapper.add(convertCheckBox, c);
141:
142: // The panel with the two buttons
143: JPanel buttonPanel = new JPanel();
144: okButton = new JButton(language.getString("General.Ok"));
145: okButton.addActionListener(this );
146: cancelButton = new JButton(language.getString("General.Cancel"));
147: cancelButton.addActionListener(this );
148: buttonPanel.add(okButton);
149: buttonPanel.add(cancelButton);
150: buttonPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
151:
152: // Add all to the content pane
153: getContentPane().setLayout(new BorderLayout());
154: getContentPane().add(leftPanelWrapper, BorderLayout.CENTER);
155: getContentPane().add(buttonPanel, BorderLayout.SOUTH);
156:
157: Point ownerLoc = cleverPHL.getDataSetFrame().getLocation();
158: setLocation(((int) ownerLoc.getX()) + 30, ((int) ownerLoc
159: .getY()) + 30);
160: pack();
161: setResizable(false);
162: setVisible(true);
163: }
164:
165: /**
166: * Called when one of the two buttons has been pressed.
167: *
168: * @param e the action event
169: */
170: public void actionPerformed(ActionEvent e) {
171: Object source = e.getSource();
172:
173: if (source == okButton) {
174: okPressed = true;
175: dispose();
176: } else {
177: okPressed = false;
178: dispose();
179: }
180: }
181:
182: /**
183: * Returns whether or not ok has been pressed.
184: *
185: * @return DOCUMENT ME!
186: */
187: public boolean okPressed() {
188: return okPressed;
189: }
190:
191: /**
192: * Whether or not the header line should be stored.
193: *
194: * @return DOCUMENT ME!
195: */
196: public boolean hasHeaderLine() {
197: return headerCheckBox.isSelected();
198: }
199:
200: /**
201: * Whether or not the non-numeric values should be converted.
202: *
203: * @return DOCUMENT ME!
204: */
205: public boolean convertNonNumeric() {
206: return convertCheckBox.isSelected();
207: }
208: }
|