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 | */
|
---|
37 | package org.greenstone.gatherer.msm;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 | import java.awt.event.*;
|
---|
41 | import java.io.*;
|
---|
42 | import javax.swing.*;
|
---|
43 | import javax.swing.filechooser.*;
|
---|
44 | import org.greenstone.gatherer.Dictionary;
|
---|
45 | import org.greenstone.gatherer.Gatherer;
|
---|
46 | import org.greenstone.gatherer.msm.MetadataSet;
|
---|
47 | import org.greenstone.gatherer.msm.MetadataSetManager;
|
---|
48 | import org.greenstone.gatherer.util.Utility;
|
---|
49 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
50 | import org.greenstone.gatherer.gui.SimpleMenuBar;
|
---|
51 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
52 |
|
---|
53 | /** 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).
|
---|
54 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
55 | * @version 2.3
|
---|
56 | */
|
---|
57 | final public class ExportMDSPrompt
|
---|
58 | extends ModalDialog
|
---|
59 | implements ActionListener, KeyListener {
|
---|
60 | /** Is this an export prompt or an import one? */
|
---|
61 | private boolean export;
|
---|
62 | /** The file we wish to export the metadata set to. */
|
---|
63 | private File file = null;
|
---|
64 | /** The action the user has chosen from the dialog (either -1, if cancelled, or EXPORT). */
|
---|
65 | private int action = -1;
|
---|
66 | /** The button used to browse the local file system. */
|
---|
67 | private JButton browse_button = null;
|
---|
68 | /** Used to cancel the dialog. */
|
---|
69 | private JButton cancel_button = null;
|
---|
70 | /** Used to initiate the export, then dispose of the dialog. */
|
---|
71 | private JButton export_button = null;
|
---|
72 | /** The metadata sets available for export. */
|
---|
73 | private JComboBox sets = null;
|
---|
74 | /** The destination file name as a string. */
|
---|
75 | private JTextField file_name = null;
|
---|
76 | /** Ths button that, if selected, signifies you wish to export the metadata set with all values. */
|
---|
77 | private JRadioButton all_values = null;
|
---|
78 | /** The button that, if selected, signifies you wish to export the metadata set without any values (ie no mdv files). */
|
---|
79 | private JRadioButton no_values = null;
|
---|
80 | /** The button that, if selected, signifies you wish to export the metadata set with only those values that are subject nodes in the hierarchy. */
|
---|
81 | private JRadioButton structure_only = null;
|
---|
82 | /** A reference to the metadata set manager. */
|
---|
83 | private MetadataSetManager manager;
|
---|
84 | /** The default size for this dialog window. */
|
---|
85 | final static public Dimension EXPORT_SIZE = new Dimension(500,245);
|
---|
86 | /** The default size for this dialog window. */
|
---|
87 | final static public Dimension IMPORT_SIZE = new Dimension(500,145);
|
---|
88 | /** The default export action (there are several depending on how much information you wish to export). */
|
---|
89 | final static public int EXPORT = 0;
|
---|
90 |
|
---|
91 | /** Constructor.
|
---|
92 | * @param manager A reference to the <strong>MetadataSetManager</strong>.
|
---|
93 | * @see org.greenstone.gatherer.Configuration
|
---|
94 | * @see org.greenstone.gatherer.util.Utility
|
---|
95 | */
|
---|
96 | public ExportMDSPrompt(MetadataSetManager manager, boolean export) {
|
---|
97 | super(Gatherer.g_man);
|
---|
98 | this.export = export;
|
---|
99 |
|
---|
100 | // Creation
|
---|
101 | setModal(true);
|
---|
102 | if(export) {
|
---|
103 | setSize(EXPORT_SIZE);
|
---|
104 | setJMenuBar(new SimpleMenuBar("selectingmetadatasets"));
|
---|
105 | Dictionary.setText(this, "MSMPrompt.Export_Title");
|
---|
106 | }
|
---|
107 | else {
|
---|
108 | setSize(IMPORT_SIZE);
|
---|
109 | setJMenuBar(new SimpleMenuBar("selectingmetadatasets"));
|
---|
110 | Dictionary.setText(this, "MSMPrompt.Import_Title");
|
---|
111 | }
|
---|
112 | JPanel content_pane = (JPanel) getContentPane();
|
---|
113 | JPanel control_pane = new JPanel();
|
---|
114 | JLabel set_label = new JLabel();
|
---|
115 | Dictionary.setText(set_label, "MSMPrompt.Export_Set");
|
---|
116 | sets = new JComboBox(manager.getSets());
|
---|
117 | Dictionary.setTooltip(sets, "MSMPrompt.Export_Set_Tooltip");
|
---|
118 | JLabel condition_label = new JLabel();
|
---|
119 | Dictionary.setText(condition_label, "MSMPrompt.Export_Conditions");
|
---|
120 | JPanel condition_pane = new JPanel();
|
---|
121 | ButtonGroup condition_group = new ButtonGroup();
|
---|
122 | all_values = new JRadioButton();
|
---|
123 | all_values.setOpaque(false);
|
---|
124 | Dictionary.setText(all_values, "MSMPrompt.Export_All_Values");
|
---|
125 | condition_group.add(all_values);
|
---|
126 | no_values = new JRadioButton();
|
---|
127 | no_values.setOpaque(false);
|
---|
128 | Dictionary.setText(no_values, "MSMPrompt.Export_No_Values");
|
---|
129 | condition_group.add(no_values);
|
---|
130 | structure_only = new JRadioButton();
|
---|
131 | structure_only.setOpaque(false);
|
---|
132 | Dictionary.setText(structure_only, "MSMPrompt.Export_Subjects_Only");
|
---|
133 | condition_group.add(structure_only);
|
---|
134 | all_values.setSelected(true);
|
---|
135 | JLabel file_label = new JLabel();
|
---|
136 | Dictionary.setText(file_label, "MSMPrompt.Export_File");
|
---|
137 | JPanel file_pane = new JPanel();
|
---|
138 | file_name = new JTextField(Utility.METADATA_DIR);
|
---|
139 | Dictionary.setTooltip(file_name, "MSMPrompt.Export_File_Tooltip");
|
---|
140 | browse_button = new GLIButton();
|
---|
141 | browse_button.setMnemonic(KeyEvent.VK_B);
|
---|
142 | Dictionary.setBoth(browse_button, "General.Browse", "General.Browse_Tooltip");
|
---|
143 |
|
---|
144 | JPanel button_pane = new JPanel();
|
---|
145 | if(export) {
|
---|
146 | export_button = new GLIButton();
|
---|
147 | export_button.setEnabled(false);
|
---|
148 | export_button.setMnemonic(KeyEvent.VK_E);
|
---|
149 | Dictionary.setBoth(export_button, "MSMPrompt.File_Export", "MSMPrompt.File_Export_Tooltip");
|
---|
150 | }
|
---|
151 | else {
|
---|
152 | export_button = new GLIButton();
|
---|
153 | export_button.setEnabled(true);
|
---|
154 | export_button.setMnemonic(KeyEvent.VK_I);
|
---|
155 | Dictionary.setBoth(export_button, "MSMPrompt.File_Import", "MSMPrompt.File_Import_Tooltip");
|
---|
156 | }
|
---|
157 |
|
---|
158 | cancel_button = new GLIButton();
|
---|
159 | cancel_button.setMnemonic(KeyEvent.VK_C);
|
---|
160 | Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
|
---|
161 |
|
---|
162 | // Listeners
|
---|
163 | browse_button.addActionListener(this);
|
---|
164 | cancel_button.addActionListener(this);
|
---|
165 | export_button.addActionListener(this);
|
---|
166 | file_name.addKeyListener(this);
|
---|
167 |
|
---|
168 | // Layout
|
---|
169 | condition_pane.setLayout(new GridLayout(1,3));
|
---|
170 | condition_pane.add(all_values);
|
---|
171 | condition_pane.add(structure_only);
|
---|
172 | condition_pane.add(no_values);
|
---|
173 |
|
---|
174 | file_pane.setLayout(new BorderLayout());
|
---|
175 | file_pane.add(file_name, BorderLayout.CENTER);
|
---|
176 | file_pane.add(browse_button, BorderLayout.EAST);
|
---|
177 |
|
---|
178 | if(export) {
|
---|
179 | control_pane.setLayout(new GridLayout(6, 1));
|
---|
180 | control_pane.add(set_label);
|
---|
181 | control_pane.add(sets);
|
---|
182 | control_pane.add(condition_label);
|
---|
183 | control_pane.add(condition_pane);
|
---|
184 | control_pane.add(file_label);
|
---|
185 | control_pane.add(file_pane);
|
---|
186 | }
|
---|
187 | else {
|
---|
188 | control_pane.setLayout(new GridLayout(2,1));
|
---|
189 | control_pane.add(condition_label);
|
---|
190 | control_pane.add(condition_pane);
|
---|
191 | }
|
---|
192 |
|
---|
193 | button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
|
---|
194 | button_pane.setLayout(new GridLayout(1,2));
|
---|
195 | button_pane.add(export_button);
|
---|
196 | button_pane.add(cancel_button);
|
---|
197 |
|
---|
198 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
199 | content_pane.setLayout(new BorderLayout());
|
---|
200 | content_pane.add(control_pane, BorderLayout.CENTER);
|
---|
201 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
202 | // Display
|
---|
203 | Dimension screen_size = Gatherer.config.screen_size;
|
---|
204 | setLocation((screen_size.width - getSize().width) / 2, (screen_size.height - getSize().height) / 2);
|
---|
205 | }
|
---|
206 |
|
---|
207 | /** Whenever one of the buttons in the dialog is actioned this method is called to trigger the appropriate effects.
|
---|
208 | * @param event An <strong>ActionEvent</strong> containing information about the action performed.
|
---|
209 | * @see org.greenstone.gatherer.Gatherer
|
---|
210 | * @see org.greenstone.gatherer.msm.MDSFileFilter
|
---|
211 | * @see org.greenstone.gatherer.util.Utility
|
---|
212 | */
|
---|
213 | public void actionPerformed(ActionEvent event) {
|
---|
214 | if(event.getSource() == export_button) {
|
---|
215 | action = EXPORT;
|
---|
216 | dispose();
|
---|
217 | }
|
---|
218 | else if(event.getSource() == cancel_button) {
|
---|
219 | action = -1;
|
---|
220 | dispose();
|
---|
221 | }
|
---|
222 | else {
|
---|
223 | JFileChooser chooser = new JFileChooser(new File(Utility.METADATA_DIR));
|
---|
224 | javax.swing.filechooser.FileFilter filter = new MDSFileFilter();
|
---|
225 | chooser.setApproveButtonText(Dictionary.get("General.OK"));
|
---|
226 | chooser.setFileFilter(filter);
|
---|
227 | int returnVal = chooser.showSaveDialog(Gatherer.g_man);
|
---|
228 | if(returnVal == JFileChooser.APPROVE_OPTION) {
|
---|
229 | file = chooser.getSelectedFile();
|
---|
230 | if(file.getName().indexOf(".") == -1) {
|
---|
231 | file = new File(file.getName() + ".mds");
|
---|
232 | }
|
---|
233 | file_name.setText(file.getAbsolutePath());
|
---|
234 | export_button.setEnabled(true);
|
---|
235 | }
|
---|
236 | }
|
---|
237 | }
|
---|
238 | /** Show the prompt and get the user input.
|
---|
239 | * @return An <i>int</i> specifying what action the user has choosen.
|
---|
240 | */
|
---|
241 | public int display() {
|
---|
242 | setVisible(true);
|
---|
243 | return action;
|
---|
244 | }
|
---|
245 | /** Get the current value of condition.
|
---|
246 | * @return The value as an <i>int</i>.
|
---|
247 | * @see org.greenstone.gatherer.msm.MetadataSet
|
---|
248 | */
|
---|
249 | public int getSelectedCondition() {
|
---|
250 | if(all_values.isSelected()) {
|
---|
251 | return MetadataSet.ALL_VALUES;
|
---|
252 | }
|
---|
253 | else if(no_values.isSelected()) {
|
---|
254 | return MetadataSet.NO_VALUES;
|
---|
255 | }
|
---|
256 | else {
|
---|
257 | return MetadataSet.SUBJECTS_ONLY;
|
---|
258 | }
|
---|
259 | }
|
---|
260 | /** Get the current value of file.
|
---|
261 | * @return The value as a <strong>File</strong>.
|
---|
262 | */
|
---|
263 | public File getSelectedFile() {
|
---|
264 | return file;
|
---|
265 | }
|
---|
266 | /** Get the current value of set.
|
---|
267 | * @return The value as a <strong>MetadataSet</strong>.
|
---|
268 | */
|
---|
269 | public MetadataSet getSelectedSet() {
|
---|
270 | return (MetadataSet) sets.getSelectedItem();
|
---|
271 | }
|
---|
272 | /** 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.
|
---|
273 | * @param event A <strong>KeyEvent</strong> containing information about the key pressed.
|
---|
274 | */
|
---|
275 | public void keyPressed(KeyEvent event) {
|
---|
276 | }
|
---|
277 | /** 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.
|
---|
278 | * @param event A <strong>KeyEvent</strong> containing information about the key typed.
|
---|
279 | */
|
---|
280 | public void keyReleased(KeyEvent event) {
|
---|
281 | String pos_file = file_name.getText();
|
---|
282 | if(pos_file.indexOf(".") != -1) {
|
---|
283 | file = new File(file_name.getText());
|
---|
284 | if(file.canWrite() || !file.exists()) {
|
---|
285 | export_button.setEnabled(true);
|
---|
286 | }
|
---|
287 | else if(export) {
|
---|
288 | export_button.setEnabled(false);
|
---|
289 | }
|
---|
290 | }
|
---|
291 | }
|
---|
292 | /** 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.
|
---|
293 | * @param event A <strong>KeyEvent</strong> containing information about the key typed.
|
---|
294 | */
|
---|
295 | public void keyTyped(KeyEvent event) {
|
---|
296 | }
|
---|
297 | }
|
---|