source: gli/branches/rtl-gli/src/org/greenstone/gatherer/gui/WriteCDImagePrompt.java@ 18297

Last change on this file since 18297 was 18297, checked in by kjdon, 15 years ago

interface updated to display right to left for rtl languages. This code is thanks to Amin Hejazi. It seems to be only partially complete. Amin was working with Greenstone 3 so might have missed some panels

  • Property svn:keywords set to Author Date Id Revision
File size: 26.6 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.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import java.util.ArrayList;
43import javax.swing.*;
44import javax.swing.event.*;
45import org.greenstone.gatherer.Configuration;
46import org.greenstone.gatherer.DebugStream;
47import org.greenstone.gatherer.Dictionary;
48import org.greenstone.gatherer.Gatherer;
49import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
50import org.greenstone.gatherer.collection.CollectionManager;
51import org.greenstone.gatherer.greenstone.LocalGreenstone;
52import org.greenstone.gatherer.shell.GShell;
53import org.greenstone.gatherer.shell.GShellEvent;
54import org.greenstone.gatherer.shell.GShellListener;
55import org.greenstone.gatherer.util.ArrayTools;
56import org.greenstone.gatherer.util.CheckList;
57import org.greenstone.gatherer.util.CheckListEntry;
58import org.greenstone.gatherer.util.StaticStrings;
59import org.greenstone.gatherer.util.Utility;
60
61/** This class provides the functionality to write a CD-ROM/DVD image of current collections from the GSDLHOME/collect/ directory to CDROM. The user chooses the collection from a list, where each entry also displays details about itself, confirms the delete of a collection by checking a checkbox then presses the ok button to actually delete the collection.
62 Copied from DeleteCollectionPrompt
63 * @author John Thompson, Greenstone Digital Library, University of Waikato
64 * @version 2.3
65 */
66public class WriteCDImagePrompt
67 extends ModalDialog
68 implements GShellListener {
69
70 private OKButtonListener ok_button_listener;
71 private ArrayList all_collections = null;
72 private ArrayList selected_collections = null;
73 /** The list of collections to include in exported cd-rom/dvd image */
74 private CheckList list = null;
75 /** The currently selected collection for deletion. */
76 private BasicCollectionConfiguration collection = null;
77 /** A reference to ourself so any inner-classes can dispose of us. */
78 private WriteCDImagePrompt prompt = null;
79 /** The close button, which exits the prompt without deleting anything. */
80 private JButton cancel_button = null;
81 /** The ok button which causes the selected collection to be deleted. */
82 private JButton ok_button = null;
83 /** The label above details. */
84 private JLabel details_label = null;
85 /** The label above the list. */
86 private JLabel list_label = null;
87 /** The text area used to display details about the collection selected. */
88 private JTextArea details_textarea = null;
89 /** The text area used to display instructions for the cd-rom/dvd export */
90 private JTextArea instructions_textarea;
91
92 /** The radio button for switching on the noinstall option */
93 private JRadioButton noinstall_button = null;
94 private JRadioButton install_button = null;
95 private JTextField title_field = null;
96 private JTextField estimated_size_field = null;
97 private JLabel title_label = null;
98 private JLabel estimated_size_label = null;
99 /** A string array used to pass arguments to the exportcol.pl script */
100 private String args[] = null;
101 private String cd_title = null;
102 /** whether the exporting was successful or not */
103 private boolean successful = false;
104 /** whether we are trying to export or not */
105 private boolean exporting = false;
106 /** the error message if any */
107 private StringBuffer error_message = null;
108 /** This is the size of the exported stuff on its own without collections. */
109 private long total_exported_size = 14000000;
110 /** The size of the export prompt screen. */
111 public static final Dimension SIZE = new Dimension(500, 500);
112
113 /** Constructor.
114 * @see org.greenstone.gatherer.collection.WriteCDImagePrompt.CancelButtonListener
115 * @see org.greenstone.gatherer.collection.WriteCDImagePrompt.CollectionListListener
116 * @see org.greenstone.gatherer.collection.WriteCDImagePrompt.OKButtonListener
117 */
118 public WriteCDImagePrompt() {
119 super(Gatherer.g_man, true);
120 this.setComponentOrientation(Dictionary.getOrientation());
121 cancel_button = new GLIButton(Dictionary.get("General.Close"), Dictionary.get("General.Close_Tooltip"));
122
123 details_textarea = new JTextArea(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
124 details_textarea.setComponentOrientation(Dictionary.getOrientation());
125 details_textarea.setEditable(false);
126
127 details_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_Details"));
128 details_label.setComponentOrientation(Dictionary.getOrientation());
129
130 instructions_textarea = new JTextArea(Dictionary.get("WriteCDImagePrompt.Instructions"));
131 instructions_textarea.setComponentOrientation(Dictionary.getOrientation());
132 instructions_textarea.setCaretPosition(0);
133 instructions_textarea.setEditable(false);
134 instructions_textarea.setLineWrap(true);
135 instructions_textarea.setRows(4);
136 instructions_textarea.setWrapStyleWord(true);
137
138 all_collections = new ArrayList();
139 list = new CheckList(true);
140 list_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_List"));
141 list_label.setComponentOrientation(Dictionary.getOrientation());
142
143 ok_button = new GLIButton(Dictionary.get("WriteCDImagePrompt.Export"), Dictionary.get("WriteCDImagePrompt.Export_Tooltip"));
144
145 title_field = new JTextField();
146 title_field.setComponentOrientation(Dictionary.getOrientation());
147 // Dictionary.setTooltip(title_field, "WriteCDImagePrompt.CD_Name_Tooltip");
148 title_label = new JLabel(Dictionary.get("WriteCDImagePrompt.CD_Name"));
149 title_label.setComponentOrientation(Dictionary.getOrientation());
150
151 estimated_size_field = new JTextField();
152 estimated_size_field.setComponentOrientation(Dictionary.getOrientation());
153 estimated_size_field.setEditable(false);
154
155 // work out the size of the images directory - could be large if they
156 // have the classic interface pack installed
157 total_exported_size += getFileSize(new File(LocalGreenstone.getDirectoryPath()+File.separator+"images"));
158 estimated_size_field.setText(Utility.formatFileLength(total_exported_size));
159 estimated_size_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
160 estimated_size_label = new JLabel(Dictionary.get("WriteCDImagePrompt.Size_Label"));
161 estimated_size_label.setComponentOrientation(Dictionary.getOrientation());
162
163 scanForCollections();
164 list.setListData(all_collections);
165
166 prompt = this;
167 setSize(SIZE);
168 setTitle(Dictionary.get("WriteCDImagePrompt.Export"));
169
170 setJMenuBar(new SimpleMenuBar("exportingcollections"));
171 cancel_button.addActionListener(new CancelButtonListener());
172 list.addListSelectionListener(new CollectionListListener());
173 list.clearSelection();
174 list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
175 ok_button_listener = new OKButtonListener();
176 ok_button.addActionListener(ok_button_listener);
177 ok_button.setEnabled(false);
178 //title.getDocument().addDocumentListener(new DocumentListener());
179
180 noinstall_button = new JRadioButton(Dictionary.get("WriteCDImagePrompt.NoInstall"));
181 noinstall_button.setToolTipText(Dictionary.get("WriteCDImagePrompt.NoInstall_Tooltip"));
182 noinstall_button.setComponentOrientation(Dictionary.getOrientation());
183
184 install_button = new JRadioButton(Dictionary.get("WriteCDImagePrompt.Install"));
185 install_button.setToolTipText(Dictionary.get("WriteCDImagePrompt.Install_Tooltip"));
186 install_button.setComponentOrientation(Dictionary.getOrientation());
187
188 }
189
190 /** Destructor. */
191 public void destroy() {
192 all_collections.clear();
193 all_collections = null;
194 cancel_button = null;
195 details_textarea = null;
196 details_label = null;
197 list = null;
198 ok_button = null;
199 prompt = null;
200 if (selected_collections!=null) {
201 selected_collections.clear();
202 selected_collections = null;
203 }
204 title_field = null;
205 title_label = null;
206 }
207
208 /** This method causes the modal prompt to be displayed.
209 * returns true if it has exported the collections that are currently selected */
210 public boolean display() {
211
212 JScrollPane scrol_tmp;
213 // Radio buttons
214 ButtonGroup radio_group = new ButtonGroup();
215 radio_group.add(install_button);
216 install_button.setSelected(true);
217 radio_group.add(noinstall_button);
218
219 // Top pane
220 JPanel instructions_pane = new JPanel(new BorderLayout());
221 instructions_pane.setComponentOrientation(Dictionary.getOrientation());
222 instructions_pane.setBorder(BorderFactory.createEmptyBorder(5,5,0,5));
223 scrol_tmp = new JScrollPane(instructions_textarea);
224 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
225 instructions_pane.add(scrol_tmp, BorderLayout.CENTER);
226
227 title_label.setBorder(BorderFactory.createEmptyBorder(0,5,0,15));
228
229 JPanel title_pane = new JPanel(new BorderLayout());
230 title_pane.setComponentOrientation(Dictionary.getOrientation());
231 title_pane.add(title_label, BorderLayout.LINE_START);
232 title_pane.add(title_field, BorderLayout.CENTER);
233 title_pane.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
234
235 JPanel radio_pane = new JPanel(new GridLayout(2,1));
236 radio_pane.setComponentOrientation(Dictionary.getOrientation());
237 install_button.setBackground(Configuration.getColor("coloring.collection_heading_background", true));
238 noinstall_button.setBackground(Configuration.getColor("coloring.collection_heading_background", true));
239 radio_pane.add(install_button);
240 radio_pane.add(noinstall_button);
241
242 JPanel options_pane = new JPanel(new BorderLayout());
243 options_pane.setComponentOrientation(Dictionary.getOrientation());
244 options_pane.add(title_pane, BorderLayout.NORTH);
245 options_pane.add(radio_pane, BorderLayout.CENTER);
246 instructions_pane.add(options_pane, BorderLayout.SOUTH);
247
248 // Central pane
249 JPanel list_pane = new JPanel(new BorderLayout());
250 list_pane.setComponentOrientation(Dictionary.getOrientation());
251 list_pane.add(list_label, BorderLayout.NORTH);
252 scrol_tmp =new JScrollPane(list);
253 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
254 list_pane.add(scrol_tmp, BorderLayout.CENTER);
255 list_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
256
257 JPanel details_pane = new JPanel(new BorderLayout());
258 details_pane.add(details_label, BorderLayout.NORTH);
259 scrol_tmp =new JScrollPane(details_textarea);
260 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
261 details_pane.add(scrol_tmp, BorderLayout.CENTER);
262 details_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
263
264 JPanel central_pane = new JPanel(new GridLayout(2, 1));
265 central_pane.setComponentOrientation(Dictionary.getOrientation());
266 central_pane.add(list_pane);
267 central_pane.add(details_pane);
268 central_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
269
270 // Lower pane
271 JPanel estimated_size_pane = new JPanel(new BorderLayout());
272 estimated_size_pane.setComponentOrientation(Dictionary.getOrientation());
273 estimated_size_pane.add(estimated_size_label, BorderLayout.LINE_START);
274 estimated_size_pane.add(estimated_size_field, BorderLayout.CENTER);
275 estimated_size_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
276
277 JPanel button_pane = new JPanel(new GridLayout(1, 2));
278 button_pane.setComponentOrientation(Dictionary.getOrientation());
279 button_pane.add(ok_button);
280 button_pane.add(cancel_button);
281 button_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
282
283 JPanel lower_pane = new JPanel(new BorderLayout());
284 lower_pane.setComponentOrientation(Dictionary.getOrientation());
285 lower_pane.add(estimated_size_pane, BorderLayout.NORTH);
286 lower_pane.add(button_pane, BorderLayout.SOUTH);
287 lower_pane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
288
289 // Final.
290 JPanel content_pane = (JPanel)this.getContentPane();
291 content_pane.setComponentOrientation(Dictionary.getOrientation());
292 content_pane.setLayout(new BorderLayout());
293 content_pane.add(instructions_pane, BorderLayout.NORTH);
294 content_pane.add(central_pane, BorderLayout.CENTER);
295 content_pane.add(lower_pane, BorderLayout.SOUTH);
296
297 // Center and display.
298 Dimension screen_size = Configuration.screen_size;
299 this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
300 this.setVisible(true); // blocks until the dialog is killed
301 return true;
302
303 }
304
305
306 private long getFileSize(File file)
307 {
308 long file_size = 0;
309
310 // Directory case
311 if (file.isDirectory()) {
312 File files[] = file.listFiles();
313 for (int i = 0; i < files.length; i++) {
314 file_size += getFileSize(files[i]);
315 }
316 }
317 // File case
318 else {
319 file_size = file.length();
320 }
321
322 return file_size;
323 }
324
325 /** This method calls the builcol.pl scripts via a GShell so as to not lock up the processor.
326 * @see org.greenstone.gatherer.Configuration
327 * @see org.greenstone.gatherer.Gatherer
328 * @see org.greenstone.gatherer.collection.Collection
329 * @see org.greenstone.gatherer.gui.BuildOptions
330 * @see org.greenstone.gatherer.shell.GShell
331 * @see org.greenstone.gatherer.shell.GShellListener
332 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
333 * @see org.greenstone.gatherer.util.Utility
334 */
335 public void writeCDImageCollections()
336 {
337 DebugStream.println("WriteCDImagePrompt.writeCDImageCollections()");
338
339 int num_collections = selected_collections.size();
340 if (num_collections == 0) return;
341 cd_title = title_field.getText();
342 cd_title = cd_title.trim();
343 cd_title = cd_title.replaceAll("\"","");
344
345 // Generate the exportcol.pl command
346 ArrayList command_parts_list = new ArrayList();
347 if (Utility.isWindows() && (!Gatherer.isGsdlRemote)) {
348 command_parts_list.add(Configuration.perl_path);
349 command_parts_list.add("-S");
350 }
351 command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "exportcol.pl");
352
353 command_parts_list.add("-gli");
354 command_parts_list.add("-language");
355 command_parts_list.add(Configuration.getLanguage());
356
357 if (cd_title.equals("")) {
358 command_parts_list.add("-cdname");
359 command_parts_list.add("Greenstone Collections");
360
361 command_parts_list.add("-cddir");
362 command_parts_list.add("exported_collections");
363 }
364 else {
365 command_parts_list.add("-cdname");
366 command_parts_list.add(cd_title);
367
368 String cd_dir = "exported_"+cd_title.replaceAll("\\s","");
369 command_parts_list.add("-cddir");
370 command_parts_list.add(cd_dir);
371 }
372
373 if (noinstall_button.isSelected()) {
374 command_parts_list.add("-noinstall");
375 }
376
377 for (int i = 0; i < num_collections; i++) {
378 command_parts_list.add(((BasicCollectionConfiguration) selected_collections.get(i)).getShortName());
379 }
380
381 DebugStream.print("export command = ");
382 for (int i = 0; i < command_parts_list.size(); i++) {
383 DebugStream.print(command_parts_list.get(i) + " ");
384 }
385 DebugStream.println("");
386 // Run the exportcol.pl command
387 String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
388 GShell process = new GShell(command_parts, GShell.CDIMAGE, 3, this, null, GShell.GSHELL_CDIMAGE);
389 process.start();
390 //process.run();
391 DebugStream.println("WriteCDImagePrompt.writeCDImageCollections().return");
392
393 }
394
395 /** Shows an export complete prompt.
396 * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
397 * @see org.greenstone.gatherer.collection.Collection
398 */
399 public void resultPrompt(boolean success, String extra) {
400 args = new String[2];
401 StringBuffer coll_names = new StringBuffer();
402 for (int i=0; i<selected_collections.size();i++) {
403 if (i>0) {
404 coll_names.append(", ");
405 }
406 BasicCollectionConfiguration complete_collection = (BasicCollectionConfiguration)selected_collections.get(i);
407 coll_names.append(complete_collection.getName() + StaticStrings.SPACE_CHARACTER + StaticStrings.OPEN_PARENTHESIS_CHARACTER + complete_collection.getShortName() + StaticStrings.CLOSE_PARENTHESIS_CHARACTER);
408 complete_collection = null;
409 }
410
411 args[0] = coll_names.toString();
412 args[1] = LocalGreenstone.getTmpDirectoryPath();
413 if(cd_title.equals("")) {
414 args[1] += "exported_collections";
415 } else {
416 args[1] += "exported_"+cd_title.replaceAll("\\s","");
417 }
418 String title;
419 String label;
420 if (success) {
421 title = Dictionary.get("WriteCDImagePrompt.Successful_Title");
422 label = Dictionary.get("WriteCDImagePrompt.Successful_Export", args);
423 } else {
424 title = Dictionary.get("WriteCDImagePrompt.Failed_Title");
425 label = Dictionary.get("WriteCDImagePrompt.Failed_Export", args);
426 }
427 SimpleResultDialog result_dialog = new SimpleResultDialog(title, label, extra);
428 result_dialog.setVisible(true); // Blocks
429 result_dialog.dispose();
430 result_dialog = null;
431 }
432
433 /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
434 * @see org.greenstone.gatherer.Configuration
435 * @see org.greenstone.gatherer.Gatherer
436 * @see org.greenstone.gatherer.util.ArrayTools
437 * @see org.greenstone.gatherer.util.Utility
438 */
439 private void scanForCollections() {
440 // Start at the collect dir.
441 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
442 String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
443 if (collect_directory.exists()) {
444 // Now for each child directory see if it contains a .col file and
445 // if so try to load it..
446 File collections[] = collect_directory.listFiles();
447 ArrayTools.sort(collections);
448 for(int i = 0; collections != null && i < collections.length; i++) {
449 if(collections[i].isDirectory() && !collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
450 File config_file = new File(collections[i], file_name);
451 if (config_file.exists()) {
452 BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
453 all_collections.add(config);
454 config = null;
455 }
456 }
457 }
458 }
459 // Otherwise the collect directory doesn't actually exist, so there ain't much we can do.
460 }
461
462
463 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
464 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
465 */
466 public synchronized void message(GShellEvent event) {
467 // Ignore the messages from RecPlug with 'show_progress' set (used for progress bars)
468 String message = event.getMessage();
469 if (message.startsWith("exportcol.pl>")) {
470 message = message.substring(13);
471 //DebugStream.println("message = "+event.getMessage());
472 error_message.append(message);
473 error_message.append("\n");
474 }
475 }
476
477 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell begins its task. Implementation side-effect, not actually used.
478 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
479 */
480 public synchronized void processBegun(GShellEvent event) {
481 // We don't care.
482 }
483 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
484 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
485 */
486 public synchronized void processComplete(GShellEvent event) {
487 successful = false;
488 if(event.getStatus() == GShell.OK) {
489 if(event.getType() == GShell.CDIMAGE) {
490 successful = true;
491 }
492 }
493 ok_button_listener.processComplete();
494 }
495
496 /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
497 private class CancelButtonListener
498 implements ActionListener {
499 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
500 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
501 */
502 public void actionPerformed(ActionEvent event) {
503 prompt.dispose();
504 }
505 }
506
507 /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
508 */
509 private class CollectionListListener
510 implements ListSelectionListener
511 {
512 /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
513 * @param event a <strong>ListSelectionEvent</strong> containing all the relevant information garnered from the event itself
514 */
515 public void valueChanged(ListSelectionEvent event)
516 {
517 // Wait for things to settle down a bit
518 if (event.getValueIsAdjusting()) {
519 return;
520 }
521
522 // Can only export when something is ticked
523 ok_button.setEnabled(!list.isNothingTicked());
524
525 if (list.isSelectionEmpty()) {
526 // This only happens when the dialog is first entered
527 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
528 return;
529 }
530
531 collection = (BasicCollectionConfiguration) ((CheckListEntry) list.getSelectedValue()).getObject();
532 args = new String[3];
533 args[0] = collection.getCreator();
534 args[1] = collection.getMaintainer();
535 args[2] = collection.getDescription();
536 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.Details", args));
537 details_textarea.setCaretPosition(0);
538
539 // Find the size of the "etc", "images" and "index" directories of the collection
540 String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection.getShortName());
541 File etc_directory = new File(collection_directory_path + "etc");
542 File images_directory = new File(collection_directory_path + "images");
543 File index_directory = new File(collection_directory_path + "index");
544 long collection_size_built = getFileSize(etc_directory) + getFileSize(images_directory) + getFileSize(index_directory);
545
546 // Add/subtract it from the total, depending on whether the collection has just been ticked/unticked
547 if (((CheckListEntry) list.getSelectedValue()).isSelected()) {
548 total_exported_size += collection_size_built;
549 }
550 else {
551 total_exported_size -= collection_size_built;
552 }
553
554 // Update the size field
555 estimated_size_field.setText(Utility.formatFileLength(total_exported_size));
556 }
557 }
558
559
560 /** The OK button listener implementation. */
561 private class OKButtonListener
562 implements ActionListener {
563 private Component glass_pane;
564 private MouseListener mouse_blocker_listener;
565 private ProgressDialog progress_dialog;
566
567 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
568 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
569 * @see org.greenstone.gatherer.Configuration
570 * @see org.greenstone.gatherer.Gatherer
571 * @see org.greenstone.gatherer.util.Utility
572 */
573 public void actionPerformed(ActionEvent event) {
574 ///ystem.err.println("OK Clicked");
575 // Make sure there are some colls specified
576 selected_collections = list.getTicked();
577 error_message = new StringBuffer();
578
579 // Set the cursor to hourglass
580 glass_pane = getGlassPane();
581 mouse_blocker_listener = new MouseAdapter() {};
582 glass_pane.addMouseListener(mouse_blocker_listener);
583 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
584 glass_pane.setVisible(true);
585
586 // Export the selected collection.
587 ///ystem.err.println("Write CD-ROM/DVD image for named collections");
588 writeCDImageCollections();
589
590 // Show progress dialog
591 ///ystem.err.println("Showing progress dialog");
592 progress_dialog = new ProgressDialog();
593 progress_dialog.setVisible(true);
594 }
595
596 public void processComplete() {
597 ///ystem.err.println("Process complete");
598 // Dispose of progress dialog
599 progress_dialog.setVisible(false);
600 progress_dialog.dispose();
601 progress_dialog = null;
602
603 // unset the cursor
604 glass_pane.setVisible(false);
605 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
606 glass_pane.removeMouseListener(mouse_blocker_listener);
607 glass_pane = null;
608 mouse_blocker_listener= null;
609
610 if (successful) {
611 resultPrompt(true, error_message.toString());
612 } else {
613 resultPrompt(false, error_message.toString());
614 }
615 error_message = null;
616 }
617
618 private class ProgressDialog
619 extends ModalDialog {
620
621 private Dimension size = new Dimension(400,65);
622
623 public ProgressDialog() {
624 super(Gatherer.g_man, Dictionary.get("WriteCDImagePrompt.Title"), true);
625 this.setComponentOrientation(Dictionary.getOrientation());
626 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
627 setSize(size);
628 JPanel content_pane = (JPanel) getContentPane();
629 content_pane.setComponentOrientation(Dictionary.getOrientation());
630 JLabel progress_label = new JLabel(Dictionary.get("WriteCDImagePrompt.Progress_Label"));
631 progress_label.setComponentOrientation(Dictionary.getOrientation());
632
633 JProgressBar progress_bar = new JProgressBar();
634 progress_bar.setComponentOrientation(Dictionary.getOrientation());
635 progress_bar.setIndeterminate(true);
636 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
637 content_pane.setLayout(new BorderLayout());
638 content_pane.add(progress_label, BorderLayout.NORTH);
639 content_pane.add(progress_bar, BorderLayout.CENTER);
640 // Position
641 Rectangle frame_bounds = Gatherer.g_man.getBounds();
642 setLocation(frame_bounds.x + (frame_bounds.width - size.width) / 2, frame_bounds.y + (frame_bounds.height - size.height) / 2);
643 }
644 }
645 }
646}
Note: See TracBrowser for help on using the repository browser.