source: trunk/gli/src/org/greenstone/gatherer/msm/ExportMDSPrompt.java@ 6213

Last change on this file since 6213 was 5593, checked in by mdewsnip, 21 years ago

Changed calls to the Dictionary.

  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.msm;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import javax.swing.*;
43import javax.swing.filechooser.*;
44import org.greenstone.gatherer.Dictionary;
45import org.greenstone.gatherer.Gatherer;
46import org.greenstone.gatherer.msm.MetadataSet;
47import org.greenstone.gatherer.msm.MetadataSetManager;
48import org.greenstone.gatherer.util.Utility;
49import org.greenstone.gatherer.gui.SimpleMenuBar;
50import org.greenstone.gatherer.gui.ModalDialog;
51
52/** A GUI component for allowing the user to export a metadata set, based on certain conditions, and to a certain file (not necessarily a .mds file).
53 * @author John Thompson, Greenstone Digital Library, University of Waikato
54 * @version 2.3
55 */
56final public class ExportMDSPrompt
57 extends ModalDialog
58 implements ActionListener, KeyListener {
59 /** Is this an export prompt or an import one? */
60 private boolean export;
61 /** The file we wish to export the metadata set to. */
62 private File file = null;
63 /** The action the user has chosen from the dialog (either -1, if cancelled, or EXPORT). */
64 private int action = -1;
65 /** The button used to browse the local file system. */
66 private JButton browse_button = null;
67 /** Used to cancel the dialog. */
68 private JButton cancel_button = null;
69 /** Used to initiate the export, then dispose of the dialog. */
70 private JButton export_button = null;
71 /** The metadata sets available for export. */
72 private JComboBox sets = null;
73 /** The destination file name as a string. */
74 private JTextField file_name = null;
75 /** Ths button that, if selected, signifies you wish to export the metadata set with all values. */
76 private JRadioButton all_values = null;
77 /** The button that, if selected, signifies you wish to export the metadata set without any values (ie no mdv files). */
78 private JRadioButton no_values = null;
79 /** The button that, if selected, signifies you wish to export the metadata set with only those values that are subject nodes in the hierarchy. */
80 private JRadioButton structure_only = null;
81 /** A reference to the metadata set manager. */
82 private MetadataSetManager manager;
83 /** The default size for this dialog window. */
84 final static public Dimension EXPORT_SIZE = new Dimension(500,245);
85 /** The default size for this dialog window. */
86 final static public Dimension IMPORT_SIZE = new Dimension(500,145);
87 /** The default export action (there are several depending on how much information you wish to export). */
88 final static public int EXPORT = 0;
89
90 /** Constructor.
91 * @param manager A reference to the <strong>MetadataSetManager</strong>.
92 * @see org.greenstone.gatherer.Configuration
93 * @see org.greenstone.gatherer.util.Utility
94 */
95 public ExportMDSPrompt(MetadataSetManager manager, boolean export) {
96 super(Gatherer.g_man);
97 this.export = export;
98
99 // Creation
100 setModal(true);
101 if(export) {
102 setSize(EXPORT_SIZE);
103 setJMenuBar(new SimpleMenuBar("selectingmetadatasets"));
104 Dictionary.setText(this, "MSMPrompt.Export_Title");
105 }
106 else {
107 setSize(IMPORT_SIZE);
108 setJMenuBar(new SimpleMenuBar("selectingmetadatasets"));
109 Dictionary.setText(this, "MSMPrompt.Import_Title");
110 }
111 JPanel content_pane = (JPanel) getContentPane();
112 JPanel control_pane = new JPanel();
113 JLabel set_label = new JLabel();
114 Dictionary.setText(set_label, "MSMPrompt.Export_Set");
115 sets = new JComboBox(manager.getSets());
116 Dictionary.setTooltip(sets, "MSMPrompt.Export_Set_Tooltip");
117 JLabel condition_label = new JLabel();
118 Dictionary.setText(condition_label, "MSMPrompt.Export_Conditions");
119 JPanel condition_pane = new JPanel();
120 ButtonGroup condition_group = new ButtonGroup();
121 all_values = new JRadioButton();
122 all_values.setOpaque(false);
123 Dictionary.setText(all_values, "MSMPrompt.Export_All_Values");
124 condition_group.add(all_values);
125 no_values = new JRadioButton();
126 no_values.setOpaque(false);
127 Dictionary.setText(no_values, "MSMPrompt.Export_No_Values");
128 condition_group.add(no_values);
129 structure_only = new JRadioButton();
130 structure_only.setOpaque(false);
131 Dictionary.setText(structure_only, "MSMPrompt.Export_Subjects_Only");
132 condition_group.add(structure_only);
133 all_values.setSelected(true);
134 JLabel file_label = new JLabel();
135 Dictionary.setText(file_label, "MSMPrompt.Export_File");
136 JPanel file_pane = new JPanel();
137 file_name = new JTextField(Utility.METADATA_DIR);
138 Dictionary.setTooltip(file_name, "MSMPrompt.Export_File_Tooltip");
139 browse_button = new JButton();
140 Dictionary.setBoth(browse_button, "General.Browse", "General.Browse_Tooltip");
141
142 JPanel button_pane = new JPanel();
143 if(export) {
144 export_button = new JButton();
145 export_button.setEnabled(false);
146 export_button.setMnemonic(KeyEvent.VK_E);
147 Dictionary.setBoth(export_button, "MSMPrompt.File_Export", "MSMPrompt.File_Export_Tooltip");
148 }
149 else {
150 export_button = new JButton();
151 export_button.setEnabled(true);
152 export_button.setMnemonic(KeyEvent.VK_I);
153 Dictionary.setBoth(export_button, "MSMPrompt.File_Import", "MSMPrompt.File_Import_Tooltip");
154 }
155
156 cancel_button = new JButton();
157 cancel_button.setMnemonic(KeyEvent.VK_C);
158 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
159
160 // Listeners
161 browse_button.addActionListener(this);
162 cancel_button.addActionListener(this);
163 export_button.addActionListener(this);
164 file_name.addKeyListener(this);
165
166 // Layout
167 condition_pane.setLayout(new GridLayout(1,3));
168 condition_pane.add(all_values);
169 condition_pane.add(structure_only);
170 condition_pane.add(no_values);
171
172 file_pane.setLayout(new BorderLayout());
173 file_pane.add(file_name, BorderLayout.CENTER);
174 file_pane.add(browse_button, BorderLayout.EAST);
175
176 if(export) {
177 control_pane.setLayout(new GridLayout(6, 1));
178 control_pane.add(set_label);
179 control_pane.add(sets);
180 control_pane.add(condition_label);
181 control_pane.add(condition_pane);
182 control_pane.add(file_label);
183 control_pane.add(file_pane);
184 }
185 else {
186 control_pane.setLayout(new GridLayout(2,1));
187 control_pane.add(condition_label);
188 control_pane.add(condition_pane);
189 }
190
191 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
192 button_pane.setLayout(new GridLayout(1,2));
193 button_pane.add(export_button);
194 button_pane.add(cancel_button);
195
196 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
197 content_pane.setLayout(new BorderLayout());
198 content_pane.add(control_pane, BorderLayout.CENTER);
199 content_pane.add(button_pane, BorderLayout.SOUTH);
200 // Display
201 Dimension screen_size = Gatherer.config.screen_size;
202 setLocation((screen_size.width - getSize().width) / 2, (screen_size.height - getSize().height) / 2);
203 }
204
205 /** Whenever one of the buttons in the dialog is actioned this method is called to trigger the appropriate effects.
206 * @param event An <strong>ActionEvent</strong> containing information about the action performed.
207 * @see org.greenstone.gatherer.Gatherer
208 * @see org.greenstone.gatherer.msm.MDSFileFilter
209 * @see org.greenstone.gatherer.util.Utility
210 */
211 public void actionPerformed(ActionEvent event) {
212 if(event.getSource() == export_button) {
213 action = EXPORT;
214 dispose();
215 }
216 else if(event.getSource() == cancel_button) {
217 action = -1;
218 dispose();
219 }
220 else {
221 JFileChooser chooser = new JFileChooser(new File(Utility.METADATA_DIR));
222 javax.swing.filechooser.FileFilter filter = new MDSFileFilter();
223 chooser.setApproveButtonText(Dictionary.get("General.OK"));
224 chooser.setFileFilter(filter);
225 int returnVal = chooser.showSaveDialog(Gatherer.g_man);
226 if(returnVal == JFileChooser.APPROVE_OPTION) {
227 file = chooser.getSelectedFile();
228 if(file.getName().indexOf(".") == -1) {
229 file = new File(file.getName() + ".mds");
230 }
231 file_name.setText(file.getAbsolutePath());
232 export_button.setEnabled(true);
233 }
234 }
235 }
236 /** Show the prompt and get the user input.
237 * @return An <i>int</i> specifying what action the user has choosen.
238 */
239 public int display() {
240 setVisible(true);
241 return action;
242 }
243 /** Get the current value of condition.
244 * @return The value as an <i>int</i>.
245 * @see org.greenstone.gatherer.msm.MetadataSet
246 */
247 public int getSelectedCondition() {
248 if(all_values.isSelected()) {
249 return MetadataSet.ALL_VALUES;
250 }
251 else if(no_values.isSelected()) {
252 return MetadataSet.NO_VALUES;
253 }
254 else {
255 return MetadataSet.SUBJECTS_ONLY;
256 }
257 }
258 /** Get the current value of file.
259 * @return The value as a <strong>File</strong>.
260 */
261 public File getSelectedFile() {
262 return file;
263 }
264 /** Get the current value of set.
265 * @return The value as a <strong>MetadataSet</strong>.
266 */
267 public MetadataSet getSelectedSet() {
268 return (MetadataSet) sets.getSelectedItem();
269 }
270 /** Any implementation of KeyListener must include this method so that we can be informed when a key has been pressed. In this case we ignore it.
271 * @param event A <strong>KeyEvent</strong> containing information about the key pressed.
272 */
273 public void keyPressed(KeyEvent event) {
274 }
275 /** Any implementation of KeyListener must include this method so that we can be informed once a key has been released. This is the earliest the VK code becomes stable and usable, so we will check if the file named in file_name can be written to and if so enable the export button.
276 * @param event A <strong>KeyEvent</strong> containing information about the key typed.
277 */
278 public void keyReleased(KeyEvent event) {
279 String pos_file = file_name.getText();
280 if(pos_file.indexOf(".") != -1) {
281 file = new File(file_name.getText());
282 if(file.canWrite() || !file.exists()) {
283 export_button.setEnabled(true);
284 }
285 else if(export) {
286 export_button.setEnabled(false);
287 }
288 }
289 }
290 /** Any implementation of KeyListener must include this method so that we can be informed when a key has been typed. In this case we ignore it.
291 * @param event A <strong>KeyEvent</strong> containing information about the key typed.
292 */
293 public void keyTyped(KeyEvent event) {
294 }
295}
Note: See TracBrowser for help on using the repository browser.