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

Last change on this file since 5040 was 4674, checked in by jmt12, 21 years ago

* empty log message *

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