source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/gui/WriteCDImagePrompt.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 27.0 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 (!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 // we want to be able to export collections in other collect directories too
378 String collectDir = Gatherer.getCollectDirectoryPath();
379 if(collectDir != Gatherer.getDefaultGSCollectDirectoryPath(true)) {
380 command_parts_list.add("-collectdir");
381 command_parts_list.add(collectDir);
382 }
383
384 for (int i = 0; i < num_collections; i++) {
385 command_parts_list.add(((BasicCollectionConfiguration) selected_collections.get(i)).getShortName());
386 }
387
388 DebugStream.print("export command = ");
389 for (int i = 0; i < command_parts_list.size(); i++) {
390 DebugStream.print(command_parts_list.get(i) + " ");
391 }
392 DebugStream.println("");
393 // Run the exportcol.pl command
394 String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
395 GShell process = new GShell(command_parts, GShell.CDIMAGE, 3, this, null, GShell.GSHELL_CDIMAGE);
396 process.start();
397 //process.run();
398 DebugStream.println("WriteCDImagePrompt.writeCDImageCollections().return");
399
400 }
401
402 /** Shows an export complete prompt.
403 * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
404 * @see org.greenstone.gatherer.collection.Collection
405 */
406 public void resultPrompt(boolean success, String extra) {
407 args = new String[2];
408 StringBuffer coll_names = new StringBuffer();
409 for (int i=0; i<selected_collections.size();i++) {
410 if (i>0) {
411 coll_names.append(", ");
412 }
413 BasicCollectionConfiguration complete_collection = (BasicCollectionConfiguration)selected_collections.get(i);
414 coll_names.append(complete_collection.getName() + StaticStrings.SPACE_CHARACTER + StaticStrings.OPEN_PARENTHESIS_CHARACTER + complete_collection.getShortName() + StaticStrings.CLOSE_PARENTHESIS_CHARACTER);
415 complete_collection = null;
416 }
417
418 args[0] = coll_names.toString();
419 args[1] = LocalGreenstone.getTmpDirectoryPath();
420 if(cd_title.equals("")) {
421 args[1] += "exported_collections";
422 } else {
423 args[1] += "exported_"+cd_title.replaceAll("\\s","");
424 }
425 String title;
426 String label;
427 if (success) {
428 title = Dictionary.get("WriteCDImagePrompt.Successful_Title");
429 label = Dictionary.get("WriteCDImagePrompt.Successful_Export", args);
430 } else {
431 title = Dictionary.get("WriteCDImagePrompt.Failed_Title");
432 label = Dictionary.get("WriteCDImagePrompt.Failed_Export", args);
433 }
434 SimpleResultDialog result_dialog = new SimpleResultDialog(title, label, extra);
435 result_dialog.setVisible(true); // Blocks
436 result_dialog.dispose();
437 result_dialog = null;
438 }
439
440 /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
441 * @see org.greenstone.gatherer.Configuration
442 * @see org.greenstone.gatherer.Gatherer
443 * @see org.greenstone.gatherer.util.ArrayTools
444 * @see org.greenstone.gatherer.util.Utility
445 */
446 private void scanForCollections() {
447 // Start at the collect dir.
448 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
449 if (collect_directory.exists()) {
450 scanForCollectionsInternal(collect_directory);
451 }
452 }
453
454 private void scanForCollectionsInternal(File collect_directory) {
455
456 String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
457 // For each child directory see if it contains a .cfg file and
458 // if so try to load it..
459 File collections[] = collect_directory.listFiles();
460 ArrayTools.sort(collections);
461 for(int i = 0; collections != null && i < collections.length; i++) {
462 if(collections[i].isDirectory() && !collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
463 File config_file = new File(collections[i], file_name);
464 if (config_file.exists()) {
465 BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
466 if (config.getCollectGroup().equals("true")) {
467 scanForCollectionsInternal(collections[i]);
468 } else {
469 all_collections.add(config);
470 config = null;
471 }
472 }
473 }
474 }
475 }
476
477
478 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
479 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
480 */
481 public synchronized void message(GShellEvent event) {
482 // Ignore the messages from RecPlug with 'show_progress' set (used for progress bars)
483 String message = event.getMessage();
484 if (message.startsWith("exportcol.pl>")) {
485 message = message.substring(13);
486 //DebugStream.println("message = "+event.getMessage());
487 error_message.append(message);
488 error_message.append("\n");
489 }
490 }
491
492 /** 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.
493 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
494 */
495 public synchronized void processBegun(GShellEvent event) {
496 // We don't care.
497 }
498 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
499 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
500 */
501 public synchronized void processComplete(GShellEvent event) {
502 successful = false;
503 if(event.getStatus() == GShell.OK) {
504 if(event.getType() == GShell.CDIMAGE) {
505 successful = true;
506 }
507 }
508 ok_button_listener.processComplete();
509 }
510
511 /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
512 private class CancelButtonListener
513 implements ActionListener {
514 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
515 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
516 */
517 public void actionPerformed(ActionEvent event) {
518 prompt.dispose();
519 }
520 }
521
522 /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
523 */
524 private class CollectionListListener
525 implements ListSelectionListener
526 {
527 /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
528 * @param event a <strong>ListSelectionEvent</strong> containing all the relevant information garnered from the event itself
529 */
530 public void valueChanged(ListSelectionEvent event)
531 {
532 // Wait for things to settle down a bit
533 if (event.getValueIsAdjusting()) {
534 return;
535 }
536
537 // Can only export when something is ticked
538 ok_button.setEnabled(!list.isNothingTicked());
539
540 if (list.isSelectionEmpty()) {
541 // This only happens when the dialog is first entered
542 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
543 return;
544 }
545
546 collection = (BasicCollectionConfiguration) ((CheckListEntry) list.getSelectedValue()).getObject();
547 args = new String[3];
548 args[0] = collection.getCreator();
549 args[1] = collection.getMaintainer();
550 args[2] = collection.getDescription();
551 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.Details", args));
552 details_textarea.setCaretPosition(0);
553
554 // Find the size of the "etc", "images" and "index" directories of the collection
555 String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection.getShortName()); // (colgroup/)subcol
556 File etc_directory = new File(collection_directory_path + "etc");
557 File images_directory = new File(collection_directory_path + "images");
558 File index_directory = new File(collection_directory_path + "index");
559 long collection_size_built = getFileSize(etc_directory) + getFileSize(images_directory) + getFileSize(index_directory);
560
561 // Add/subtract it from the total, depending on whether the collection has just been ticked/unticked
562 if (((CheckListEntry) list.getSelectedValue()).isSelected()) {
563 total_exported_size += collection_size_built;
564 }
565 else {
566 total_exported_size -= collection_size_built;
567 }
568
569 // Update the size field
570 estimated_size_field.setText(Utility.formatFileLength(total_exported_size));
571 }
572 }
573
574
575 /** The OK button listener implementation. */
576 private class OKButtonListener
577 implements ActionListener {
578 private Component glass_pane;
579 private MouseListener mouse_blocker_listener;
580 private ProgressDialog progress_dialog;
581
582 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
583 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
584 * @see org.greenstone.gatherer.Configuration
585 * @see org.greenstone.gatherer.Gatherer
586 * @see org.greenstone.gatherer.util.Utility
587 */
588 public void actionPerformed(ActionEvent event) {
589 ///ystem.err.println("OK Clicked");
590 // Make sure there are some colls specified
591 selected_collections = list.getTicked();
592 error_message = new StringBuffer();
593
594 // Set the cursor to hourglass
595 glass_pane = getGlassPane();
596 mouse_blocker_listener = new MouseAdapter() {};
597 glass_pane.addMouseListener(mouse_blocker_listener);
598 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
599 glass_pane.setVisible(true);
600
601 // Export the selected collection.
602 ///ystem.err.println("Write CD-ROM/DVD image for named collections");
603 writeCDImageCollections();
604
605 // Show progress dialog
606 ///ystem.err.println("Showing progress dialog");
607 progress_dialog = new ProgressDialog();
608 progress_dialog.setVisible(true);
609 }
610
611 public void processComplete() {
612 ///ystem.err.println("Process complete");
613 // Dispose of progress dialog
614 progress_dialog.setVisible(false);
615 progress_dialog.dispose();
616 progress_dialog = null;
617
618 // unset the cursor
619 glass_pane.setVisible(false);
620 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
621 glass_pane.removeMouseListener(mouse_blocker_listener);
622 glass_pane = null;
623 mouse_blocker_listener= null;
624
625 if (successful) {
626 resultPrompt(true, error_message.toString());
627 } else {
628 resultPrompt(false, error_message.toString());
629 }
630 error_message = null;
631 }
632
633 private class ProgressDialog
634 extends ModalDialog {
635
636 private Dimension size = new Dimension(400,65);
637
638 public ProgressDialog() {
639 super(Gatherer.g_man, Dictionary.get("WriteCDImagePrompt.Title"), true);
640 this.setComponentOrientation(Dictionary.getOrientation());
641 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
642 setSize(size);
643 JPanel content_pane = (JPanel) getContentPane();
644 content_pane.setComponentOrientation(Dictionary.getOrientation());
645 JLabel progress_label = new JLabel(Dictionary.get("WriteCDImagePrompt.Progress_Label"));
646 progress_label.setComponentOrientation(Dictionary.getOrientation());
647
648 JProgressBar progress_bar = new JProgressBar();
649 progress_bar.setComponentOrientation(Dictionary.getOrientation());
650 progress_bar.setIndeterminate(true);
651 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
652 content_pane.setLayout(new BorderLayout());
653 content_pane.add(progress_label, BorderLayout.NORTH);
654 content_pane.add(progress_bar, BorderLayout.CENTER);
655 // Position
656 Rectangle frame_bounds = Gatherer.g_man.getBounds();
657 setLocation(frame_bounds.x + (frame_bounds.width - size.width) / 2, frame_bounds.y + (frame_bounds.height - size.height) / 2);
658 }
659 }
660 }
661}
Note: See TracBrowser for help on using the repository browser.