source: trunk/gli/src/org/greenstone/gatherer/gui/Preferences.java@ 7183

Last change on this file since 7183 was 7183, checked in by mdewsnip, 20 years ago

Disabled the Workflows panel for two reasons - the strings haven't been translated into French/Spanish/Russian, and you can mess around with it and turn on the Mirror etc. panels which aren't complete.

  • Property svn:keywords set to Author Date Id Revision
File size: 34.3 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 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.gui;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.io.*;
32import java.net.*;
33import java.util.*;
34import javax.swing.*;
35import javax.swing.event.*;
36import org.greenstone.gatherer.Configuration;
37import org.greenstone.gatherer.Dictionary;
38import org.greenstone.gatherer.Gatherer;
39import org.greenstone.gatherer.cdm.ClassifierManager;
40import org.greenstone.gatherer.cdm.LanguageManager;
41import org.greenstone.gatherer.cdm.PlugInManager;
42import org.greenstone.gatherer.checklist.CheckList;
43import org.greenstone.gatherer.checklist.Entry;
44import org.greenstone.gatherer.collection.Collection;
45import org.greenstone.gatherer.gui.EmailField;
46import org.greenstone.gatherer.gui.GLIButton;
47import org.greenstone.gatherer.gui.ModalDialog;
48import org.greenstone.gatherer.gui.SimpleMenuBar;
49import org.greenstone.gatherer.gui.tree.DragTree;
50import org.greenstone.gatherer.util.StaticStrings;
51import org.greenstone.gatherer.util.Utility;
52import org.w3c.dom.*;
53
54public class Preferences
55 extends ModalDialog {
56
57 static final public String CONNECTION_PREFS = "connection";
58 static final public String GENERAL_PREFS = "general";
59
60
61 static final private Dimension LABEL_SIZE = new Dimension(280, 25);
62 static final private Dimension ROW_SIZE = new Dimension(640, 25);
63 static final private Dimension SIZE = new Dimension(640, 345);
64 static final private String TRUE = "true";
65
66 private CheckList warning_preferences_check_list;
67 private EmailField email_field;
68 private JButton apply_button;
69 private JButton cancel_button;
70 private JButton clear_cache_button;
71 private JButton ok_button;
72 private JCheckBox show_file_size_checkbox;
73 private JCheckBox use_proxy_checkbox;
74 private JCheckBox view_extracted_metadata_checkbox;
75 private JCheckBox workflow_browse;
76 private JCheckBox workflow_create;
77 private JCheckBox workflow_mirror;
78 private JCheckBox workflow_gather;
79 private JCheckBox workflow_enrich;
80 private JCheckBox workflow_design;
81 private JCheckBox workflow_export;
82 private JCheckBox workflow_preview;
83 private JComboBox language_combobox;
84 private JLabel email_label;
85 private JLabel language_label;
86 private JLabel library_path_label;
87 private JLabel predefined_label;
88 private JLabel program_label;
89 private JLabel proxy_host_label;
90 private JLabel proxy_port_label;
91 //private JLabel recursion_depth_label;
92 private JLabel title_label;
93 private JRadioButton assistant_mode_radio_button;
94 private JRadioButton expert_mode_radio_button;
95 private JRadioButton librarian_mode_radio_button;
96 private JRadioButton systems_mode_radio_button;
97 private JSpinner proxy_port_field;
98 //private JSpinner recursion_depth_spinner;
99 private JTabbedPane tab_pane;
100 private JTextArea mode_description_textarea;
101 private JTextField library_path_field;
102 private JTextField program_field;
103 private JTextField proxy_host_field;
104 private Preferences self;
105
106 public Preferences() {
107 this(GENERAL_PREFS);
108 }
109
110 public Preferences(String initial_view) {
111 // Initialize
112 super(Gatherer.g_man, true);
113 this.self = this;
114 setSize(SIZE);
115 Dictionary.registerText(this, "Preferences");
116 setJMenuBar(new SimpleMenuBar("preferences"));
117
118 // Creation
119 JPanel content_pane = (JPanel) getContentPane();
120 tab_pane = new JTabbedPane();
121 JPanel general_preferences = createGeneralPreferences();
122 tab_pane.add("Preferences.General", general_preferences);
123 tab_pane.add("Preferences.Mode", createModePreferences());
124 // !! Temporarily disabled for the UNESCO CD-ROM !!
125 // tab_pane.add("Preferences.Workflow", createWorkflowPreferences());
126 JPanel connection_preferences = createConnectionPreferences();
127 tab_pane.add("Preferences.Connection", connection_preferences);
128 tab_pane.add("Preferences.Warnings", createWarningPreferences());
129 Dictionary.register(tab_pane);
130
131 JPanel button_pane = new JPanel();
132 ok_button = new GLIButton();
133 ok_button.setMnemonic(KeyEvent.VK_O);
134 Dictionary.registerBoth(ok_button, "General.OK", "General.OK_Tooltip");
135 apply_button = new GLIButton();
136 apply_button.setMnemonic(KeyEvent.VK_A);
137 Dictionary.registerBoth(apply_button, "General.Apply", "General.Apply_Tooltip");
138 cancel_button = new GLIButton();
139 cancel_button.setMnemonic(KeyEvent.VK_C);
140 Dictionary.registerBoth(cancel_button, "General.Cancel", "General.Cancel_Tooltip");
141
142 // Connection
143 ok_button.addActionListener(new OKButtonListener(true));
144 apply_button.addActionListener(new OKButtonListener(false));
145 cancel_button.addActionListener(new CancelButtonListener());
146
147 // Layout
148 button_pane.setBorder(BorderFactory.createEmptyBorder(5,2,2,2));
149 button_pane.setLayout(new GridLayout(1,3,0,5));
150 button_pane.add(ok_button);
151 button_pane.add(apply_button);
152 button_pane.add(cancel_button);
153
154 content_pane.setLayout(new BorderLayout());
155 content_pane.add(tab_pane, BorderLayout.CENTER);
156 content_pane.add(button_pane, BorderLayout.SOUTH);
157
158 Dimension frame_size = Gatherer.g_man.getSize();
159 Point frame_location = Gatherer.g_man.getLocation();
160 //setLocation(frame_location.x + ((frame_size.width - SIZE.width) / 2), frame_location.y + ((frame_size.height - SIZE.height)));
161 setLocation(((frame_size.width - SIZE.width) / 2), ((frame_size.height - SIZE.height)));
162
163 // Bring the desired pane to the fore
164 if(initial_view.equals(CONNECTION_PREFS)) {
165 tab_pane.setSelectedComponent(connection_preferences);
166 }
167 else {
168 tab_pane.setSelectedComponent(general_preferences);
169 }
170
171
172 // Clean up
173 general_preferences = null;
174 connection_preferences = null;
175 frame_location = null;
176 frame_size = null;
177 cancel_button = null;
178 ok_button = null;
179 button_pane = null;
180 tab_pane = null;
181 content_pane = null;
182
183 setVisible(true);
184 }
185
186 private JPanel createConnectionPreferences() {
187 JPanel program_pane = new JPanel();
188 program_pane.setPreferredSize(ROW_SIZE);
189 program_label = new JLabel();
190 program_label.setPreferredSize(LABEL_SIZE);
191 Dictionary.registerText(program_label, "Preferences.Connection.ProgramCommand");
192 program_field = new JTextField(Gatherer.config.getPreviewCommand());
193 program_field.setCaretPosition(0);
194 Dictionary.registerTooltip(program_field, "Preferences.Connection.ProgramCommand_Tooltip");
195
196 JPanel library_path_pane = new JPanel();
197 library_path_pane.setPreferredSize(ROW_SIZE);
198 library_path_label = new JLabel();
199 library_path_label.setPreferredSize(LABEL_SIZE);
200 Dictionary.registerText(library_path_label, "Preferences.Connection.Library_Path");
201 library_path_field = new JTextField(Gatherer.config.getString("general.exec_address", true));
202 library_path_field.setCaretPosition(0);
203 Dictionary.registerTooltip(library_path_field, "Preferences.Connection.Library_Path_Tooltip");
204
205 boolean currently_enabled = Gatherer.config.get("general.use_proxy", true);
206 // Creation
207 JPanel connection_pane = new JPanel();
208 use_proxy_checkbox = new JCheckBox();
209 use_proxy_checkbox.setSelected(currently_enabled);
210 Dictionary.registerText(use_proxy_checkbox, "Preferences.Connection.Use_Proxy");
211
212 use_proxy_checkbox.setPreferredSize(ROW_SIZE);
213 JPanel proxy_host_pane = new JPanel();
214 proxy_host_pane.setPreferredSize(ROW_SIZE);
215 proxy_host_label = new JLabel();
216 proxy_host_label.setPreferredSize(LABEL_SIZE);
217 Dictionary.registerText(proxy_host_label, "Preferences.Connection.Proxy_Host");
218 proxy_host_field = new JTextField(Gatherer.config.getString("general.proxy_host", true));
219 proxy_host_field.setEnabled(currently_enabled);
220 Dictionary.registerTooltip(proxy_host_field, "Preferences.Connection.Proxy_Host_Tooltip");
221 JPanel proxy_port_pane = new JPanel();
222 proxy_port_pane.setPreferredSize(ROW_SIZE);
223 proxy_port_label = new JLabel();
224 proxy_port_label.setPreferredSize(LABEL_SIZE);
225 Dictionary.registerText(proxy_port_label, "Preferences.Connection.Proxy_Port");
226 String port_value = Gatherer.config.getString("general.proxy_port", true);
227 if(port_value.length() > 0) {
228 proxy_port_field = new JSpinner(new SpinnerNumberModel((new Integer(port_value)).intValue(), 0, 65535, 1));
229 }
230 else {
231 proxy_port_field = new JSpinner(new SpinnerNumberModel(0, 0, 65535, 1));
232 }
233 proxy_port_field.setEnabled(currently_enabled);
234 Dictionary.registerTooltip(proxy_port_field, "Preferences.Connection.Proxy_Port_Tooltip");
235
236 /** @todo - add to dictionary. Bet you're getting sick of these by now! */
237 clear_cache_button = new GLIButton("Preferences.Connection.Clear_Cache");
238
239 // Connection
240 use_proxy_checkbox.addActionListener(new UseProxyListener());
241 clear_cache_button.addActionListener(new ClearCacheListener());
242
243 // Layout
244 program_pane.setLayout(new BorderLayout());
245 program_pane.add(program_label, BorderLayout.WEST);
246 program_pane.add(program_field, BorderLayout.CENTER);
247
248 library_path_pane.setLayout(new BorderLayout());
249 library_path_pane.add(library_path_label, BorderLayout.WEST);
250 library_path_pane.add(library_path_field, BorderLayout.CENTER);
251
252 proxy_host_pane.setLayout(new BorderLayout());
253 proxy_host_pane.add(proxy_host_label, BorderLayout.WEST);
254 proxy_host_pane.add(proxy_host_field, BorderLayout.CENTER);
255
256 proxy_port_pane.setLayout(new BorderLayout());
257 proxy_port_pane.add(proxy_port_label, BorderLayout.WEST);
258 proxy_port_pane.add(proxy_port_field, BorderLayout.CENTER);
259
260 connection_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
261 connection_pane.setLayout(new GridLayout(8,1,0,2));
262 connection_pane.add(program_pane);
263 connection_pane.add(library_path_pane);
264 connection_pane.add(use_proxy_checkbox);
265 connection_pane.add(proxy_host_pane);
266 connection_pane.add(proxy_port_pane);
267 if(Gatherer.config.get(StaticStrings.WORKFLOW_MIRROR, true)) {
268 connection_pane.add(clear_cache_button);
269 }
270
271 return connection_pane;
272 }
273
274 private JPanel createGeneralPreferences() {
275 JPanel general_pane = new JPanel();
276
277 // Build the model of available languages
278 ArrayList dictionary_model = new ArrayList();
279
280 // Old method for determining what languages should be available in the combobox
281 /*
282 dictionary_model.add(new DictionaryEntry(Locale.ENGLISH));
283 File classes_folder = new File(Utility.BASE_DIR + StaticStrings.CLASSES_FOLDER);
284 File[] possible_dictionaries = classes_folder.listFiles();
285 for(int i = 0; i < possible_dictionaries.length; i++) {
286 String filename = possible_dictionaries[i].getName();
287 if(filename.endsWith(StaticStrings.PROPERTIES_FILE_EXTENSION) && filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) != -1) {
288 StringTokenizer tokenizer = new StringTokenizer(filename.substring(filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) + 1, filename.indexOf(StaticStrings.STOP_CHARACTER)), StaticStrings.UNDERSCORE_CHARACTER);
289 Locale locale = null;
290 switch(tokenizer.countTokens()) {
291 case 1:
292 locale = new Locale(tokenizer.nextToken().toLowerCase());
293 break;
294 case 2:
295 locale = new Locale(tokenizer.nextToken().toLowerCase(), tokenizer.nextToken().toUpperCase());
296 break;
297 }
298 tokenizer = null;
299 // Open the file and read the first line
300 String description = null;
301 try {
302 BufferedReader br = new BufferedReader(new FileReader(possible_dictionaries[i]));
303 String first_line = br.readLine();
304 br.close();
305 description = first_line.substring(first_line.indexOf(StaticStrings.COLON_CHARACTER) + 1);
306 }
307 catch(Exception error) {
308 }
309 DictionaryEntry entry = new DictionaryEntry(description, locale);
310 description = null;
311 locale = null;
312 if(!dictionary_model.contains(entry)) {
313 dictionary_model.add(entry);
314 }
315 entry = null;
316 }
317 filename = null;
318 }
319 possible_dictionaries = null;
320 classes_folder = null;
321 */
322
323 // The new method makes use of the successor to the languages.dat file, classes/xml/languages.xml
324 NodeList language_elements = LanguageManager.LANGUAGES_DOCUMENT.getDocumentElement().getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
325 for(int i = 0; i < language_elements.getLength(); i++) {
326 Element language_element = (Element) language_elements.item(i);
327 if((language_element.getAttribute(StaticStrings.GLI_ATTRIBUTE)).equalsIgnoreCase(StaticStrings.TRUE_STR) || (language_element.getAttribute(StaticStrings.MDS_ATTRIBUTE)).equalsIgnoreCase(StaticStrings.TRUE_STR)) {
328 Locale locale = new Locale(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE));
329 String description = language_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
330 DictionaryEntry entry = new DictionaryEntry(description, locale);
331 if(!dictionary_model.contains(entry)) {
332 dictionary_model.add(entry);
333 }
334 entry = null;
335 description = null;
336 locale = null;
337 }
338 language_element = null;
339 }
340 language_elements = null;
341
342 // Users email
343 JPanel email_pane = new JPanel();
344 email_label = new JLabel();
345 email_label.setPreferredSize(LABEL_SIZE);
346 Dictionary.registerText(email_label, "Preferences.General.Email");
347 email_field = new EmailField(Gatherer.config.getColor("coloring.error_background", false));
348 email_field.setText(Gatherer.config.getEmail());
349 Dictionary.registerTooltip(email_field, "Preferences.General.Email_Tooltip");
350
351 // Extracted metadata
352 view_extracted_metadata_checkbox = new JCheckBox();
353 view_extracted_metadata_checkbox.setSelected(false);
354 if (Gatherer.config.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC)) {
355 view_extracted_metadata_checkbox.setSelected(true);
356 }
357 Dictionary.registerBoth(view_extracted_metadata_checkbox, "Preferences.General.View_Extracted_Metadata", "Preferences.General.View_Extracted_Metadata_Tooltip");
358
359 // Show file sizes
360 show_file_size_checkbox = new JCheckBox();
361 show_file_size_checkbox.setSelected(false);
362 if (Gatherer.config.get("general.show_file_size", Configuration.COLLECTION_SPECIFIC)) {
363 show_file_size_checkbox.setSelected(true);
364 }
365 Dictionary.registerBoth(show_file_size_checkbox, "Preferences.General.Show_File_Size", "Preferences.General.Show_File_Size_Tooltip");
366
367 // Language
368 JPanel language_pane = new JPanel();
369 language_label = new JLabel();
370 language_label.setPreferredSize(LABEL_SIZE);
371 Dictionary.registerText(language_label, "Preferences.General.Interface_Language");
372 language_combobox = new JComboBox(dictionary_model.toArray());
373 Dictionary.registerTooltip(language_combobox, "Preferences.General.Interface_Language_Tooltip");
374 // Try to locate and select the current language
375 String language_code = Gatherer.config.getLanguage();
376 for(int b = 0; b < language_combobox.getItemCount(); b++) {
377 DictionaryEntry entry = (DictionaryEntry) language_combobox.getItemAt(b);
378 if(language_code.equalsIgnoreCase(entry.getLocale().getLanguage())) {
379 language_combobox.setSelectedIndex(b);
380 }
381 }
382
383 // Recursion
384 /*
385 JPanel recursion_depth_pane = new JPanel();
386 recursion_depth_label = new JLabel();
387 recursion_depth_label.setPreferredSize(LABEL_SIZE);
388 Dictionary.registerText(recursion_depth_label, "Preferences.General.Recursion_Depth");
389 recursion_depth_spinner = new JSpinner(new SpinnerNumberModel(Gatherer.config.getInt("general.max_folder_depth", Configuration.COLLECTION_SPECIFIC), 0, Integer.MAX_VALUE, 1));
390 Dictionary.registerTooltip(recursion_depth_spinner, "Preferences.General.Recursion_Depth_Tooltip");
391 */
392
393 // Connect
394 language_combobox.addActionListener(new LanguageComboboxListener());
395
396 // Layout
397 email_pane.setLayout(new BorderLayout());
398 email_pane.add(email_label, BorderLayout.WEST);
399 email_pane.add(email_field, BorderLayout.CENTER);
400
401 language_pane.setLayout(new BorderLayout());
402 language_pane.add(language_label, BorderLayout.WEST);
403 language_pane.add(language_combobox, BorderLayout.CENTER);
404
405 //recursion_depth_pane.setLayout(new BorderLayout());
406 //recursion_depth_pane.add(recursion_depth_label, BorderLayout.WEST);
407 //recursion_depth_pane.add(recursion_depth_spinner, BorderLayout.CENTER);
408
409 general_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
410 general_pane.setLayout(new GridLayout(5,1,0,5));
411 general_pane.add(email_pane);
412 general_pane.add(language_pane);
413 //general_pane.add(recursion_depth_pane);
414 general_pane.add(view_extracted_metadata_checkbox);
415 general_pane.add(show_file_size_checkbox);
416
417 return general_pane;
418 }
419
420 /** Generate the controls for altering the detail mode.
421 * @return a JPanel of controls
422 */
423 private JPanel createModePreferences() {
424 // Create Controls
425 JPanel mode_panel = new JPanel();
426 JPanel button_panel = new JPanel();
427 ButtonGroup mode_button_group = new ButtonGroup();
428 assistant_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Assistant"));
429 assistant_mode_radio_button.setOpaque(false);
430 mode_button_group.add(assistant_mode_radio_button);
431 expert_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Expert"));
432 expert_mode_radio_button.setOpaque(false);
433 mode_button_group.add(expert_mode_radio_button);
434 librarian_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Librarian"));
435 librarian_mode_radio_button.setOpaque(false);
436 mode_button_group.add(librarian_mode_radio_button);
437 systems_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Systems"));
438 systems_mode_radio_button.setOpaque(false);
439 mode_button_group.add(systems_mode_radio_button);
440 mode_description_textarea = new JTextArea();
441 mode_description_textarea.setEditable(false);
442 mode_description_textarea.setLineWrap(true);
443 mode_description_textarea.setWrapStyleWord(true);
444 // Determine which value is already selected
445 switch(Gatherer.config.getMode()) {
446 case Configuration.ASSISTANT_MODE:
447 assistant_mode_radio_button.setSelected(true);
448 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
449 break;
450 case Configuration.SYSTEMS_MODE:
451 systems_mode_radio_button.setSelected(true);
452 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));
453 break;
454 case Configuration.EXPERT_MODE:
455 expert_mode_radio_button.setSelected(true);
456 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
457 break;
458 default:
459 librarian_mode_radio_button.setSelected(true);
460 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
461 }
462 // Connection - when a radio button is selected we have to change the description
463 ModeRadioButtonListener listener = new ModeRadioButtonListener();
464 assistant_mode_radio_button.addActionListener(listener);
465 expert_mode_radio_button.addActionListener(listener);
466 librarian_mode_radio_button.addActionListener(listener);
467 systems_mode_radio_button.addActionListener(listener);
468 listener = null;
469 // Layout
470 button_panel.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
471 button_panel.setLayout(new GridLayout(4,1,2,2));
472 button_panel.add(assistant_mode_radio_button);
473 button_panel.add(librarian_mode_radio_button);
474 button_panel.add(systems_mode_radio_button);
475 button_panel.add(expert_mode_radio_button);
476
477 mode_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
478 mode_panel.setLayout(new BorderLayout());
479 mode_panel.add(button_panel, BorderLayout.NORTH);
480 mode_panel.add(new JScrollPane(mode_description_textarea), BorderLayout.CENTER);
481
482 return mode_panel;
483 }
484
485 /** The warning preferences are controlled through a checklist. */
486 private JPanel createWarningPreferences() {
487 // Retrieve all of the warning preferences settings.
488 HashMap warning_preferences = Gatherer.config.getAll("warning\\..*", true);
489 warning_preferences_check_list = new CheckList(false);
490 for(Iterator keys = warning_preferences.keySet().iterator(); keys.hasNext(); ) {
491 String property = (String) keys.next();
492 String value = (String) warning_preferences.get(property);
493 // Remove 'warning.'
494 String title = Dictionary.get(property.substring(8) + ".Title");
495 Entry entry = new Entry(title, value.equalsIgnoreCase(TRUE));
496 entry.setProperty(property);
497 warning_preferences_check_list.addEntry(entry);
498 }
499 // Creation
500 JPanel warning_preferences_pane = new JPanel();
501 // Connection
502 // Layout
503 warning_preferences_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
504 warning_preferences_pane.setLayout(new BorderLayout());
505 warning_preferences_pane.add(new JScrollPane(warning_preferences_check_list), BorderLayout.CENTER);
506
507 return warning_preferences_pane;
508 }
509
510 private JPanel createWorkflowPreferences() {
511 // Read in the predefined configurations file
512 Vector predefined = new Vector();
513 Document predefined_document = Utility.parse("xml/workflows.xml", true);
514 Element predefined_element = predefined_document.getDocumentElement();
515 NodeList workflow_elements = predefined_element.getElementsByTagName("Workflow");
516 for(int i = 0; i < workflow_elements.getLength(); i++) {
517 predefined.add(new WorkflowElementWrapper((Element)workflow_elements.item(i)));
518 }
519
520 // Creation
521 JPanel workflow_preferences_pane = new JPanel();
522 JPanel checklist_pane = new JPanel();
523 title_label = new JLabel();
524 title_label.setPreferredSize(ROW_SIZE);
525 Dictionary.registerText(title_label, "Preferences.Workflow.Title");
526
527 workflow_browse = new JCheckBox();
528 workflow_browse.setSelected(Gatherer.config.get("workflow.browse", false));
529 workflow_browse.setPreferredSize(ROW_SIZE);
530 Dictionary.registerText(workflow_browse, "Preferences.Workflow.Browse");
531
532 workflow_mirror = new JCheckBox();
533 workflow_mirror.setSelected(Gatherer.config.get("workflow.mirror", false));
534 workflow_mirror.setPreferredSize(ROW_SIZE);
535 Dictionary.registerText(workflow_mirror, "Preferences.Workflow.Mirror");
536
537 workflow_gather = new JCheckBox();
538 workflow_gather.setSelected(Gatherer.config.get("workflow.gather", false));
539 workflow_gather.setPreferredSize(ROW_SIZE);
540 Dictionary.registerText(workflow_gather, "Preferences.Workflow.Gather");
541
542 workflow_enrich = new JCheckBox();
543 workflow_enrich.setSelected(Gatherer.config.get("workflow.enrich", false));
544 workflow_enrich.setPreferredSize(ROW_SIZE);
545 Dictionary.registerText(workflow_enrich, "Preferences.Workflow.Enrich");
546
547 workflow_design = new JCheckBox();
548 workflow_design.setSelected(Gatherer.config.get("workflow.design", false));
549 workflow_design.setPreferredSize(ROW_SIZE);
550 Dictionary.registerText(workflow_design, "Preferences.Workflow.Design");
551
552 workflow_export = new JCheckBox();
553 workflow_export.setSelected(Gatherer.config.get("workflow.export", false));
554 workflow_export.setPreferredSize(ROW_SIZE);
555 Dictionary.registerText(workflow_export, "Preferences.Workflow.Export");
556
557 workflow_create = new JCheckBox();
558 workflow_create.setSelected(Gatherer.config.get("workflow.create", false));
559 workflow_create.setPreferredSize(ROW_SIZE);
560 Dictionary.registerText(workflow_create, "Preferences.Workflow.Create");
561
562 workflow_preview = new JCheckBox();
563 workflow_preview.setSelected(Gatherer.config.get("workflow.preview", false));
564 workflow_preview.setPreferredSize(ROW_SIZE);
565 Dictionary.registerText(workflow_preview, "Preferences.Workflow.Preview");
566
567 JPanel predefined_pane = new JPanel();
568 predefined_label = new JLabel();
569 Dictionary.registerText(predefined_label, "Preferences.Workflow.Predefined.Label");
570 JComboBox predefined_combobox = new JComboBox(predefined);
571
572 // Connection
573 predefined_combobox.addActionListener(new PredefinedActionListener());
574
575 // Layout
576 checklist_pane.setLayout(new BoxLayout(checklist_pane, BoxLayout.Y_AXIS));
577 checklist_pane.add(title_label);
578 if (Gatherer.config.get("workflow.browse", true)) {
579 checklist_pane.add(workflow_browse);
580 }
581 if (Gatherer.config.get("workflow.mirror", true)) {
582 checklist_pane.add(workflow_mirror);
583 }
584 if (Gatherer.config.get("workflow.gather", true)) {
585 checklist_pane.add(workflow_gather);
586 }
587 if (Gatherer.config.get("workflow.enrich", true)) {
588 checklist_pane.add(workflow_enrich);
589 }
590 if (Gatherer.config.get("workflow.design", true)) {
591 checklist_pane.add(workflow_design);
592 }
593 if (Gatherer.config.get("workflow.export", true)) {
594 checklist_pane.add(workflow_export);
595 }
596 if (Gatherer.config.get("workflow.create", true)) {
597 checklist_pane.add(workflow_create);
598 }
599 if (Gatherer.config.get("workflow.preview", true)) {
600 checklist_pane.add(workflow_preview);
601 }
602 predefined_pane.setLayout(new BorderLayout(5,0));
603 predefined_pane.add(predefined_label, BorderLayout.WEST);
604 predefined_pane.add(predefined_combobox, BorderLayout.CENTER);
605
606 workflow_preferences_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
607 workflow_preferences_pane.setLayout(new BorderLayout());
608 workflow_preferences_pane.add(checklist_pane, BorderLayout.CENTER);
609 workflow_preferences_pane.add(predefined_pane, BorderLayout.SOUTH);
610
611 return workflow_preferences_pane;
612 }
613
614
615 private class OKButtonListener
616 implements ActionListener {
617 private boolean close;
618 public OKButtonListener(boolean close) {
619 this.close = close;
620 }
621 public void actionPerformed(ActionEvent event) {
622 // Submit the various changes.
623 // Connection preferences
624 String program_str = program_field.getText();
625 if(program_str.length() > 0 && program_str.indexOf("%1") == -1) {
626 program_str = program_str + " %1";
627 }
628 Gatherer.config.setPreviewCommand(program_str);
629
630 String library_path_string = library_path_field.getText();
631 Gatherer.config.setString("general.exec_address", true, library_path_string);
632 if (!library_path_string.equals("")) {
633 try {
634 Gatherer.config.exec_address = new URL(library_path_string);
635 }
636 catch (MalformedURLException error) {
637 ///ystem.err.println("Error: Bad address: " + exec_address_string);
638 }
639 }
640 Gatherer.config.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
641 Gatherer.config.setString("general.proxy_host", true, proxy_host_field.getText());
642 Gatherer.config.setString("general.proxy_port", true, proxy_port_field.getValue() + "");
643 Gatherer.setProxy();
644
645 // General preferences
646 Gatherer.config.setEmail(email_field.getText());
647
648 Gatherer.config.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, show_file_size_checkbox.isSelected());
649 Gatherer.g_man.refreshTrees(DragTree.TREE_DISPLAY_CHANGED);
650
651 Gatherer.config.set("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC, view_extracted_metadata_checkbox.isSelected());
652 Gatherer.g_man.enrich_pane.valueChanged((TreeSelectionEvent) null); // Refresh metadata table
653
654 String current_lang = Gatherer.config.getLanguage();
655 String new_lang = ((DictionaryEntry)language_combobox.getSelectedItem()).getLocale().getLanguage();
656 if (!current_lang.equals(new_lang)) {
657 Gatherer.config.setLocale("general.locale", Configuration.GENERAL_SETTING, ((DictionaryEntry)language_combobox.getSelectedItem()).getLocale());
658 // delete the plugins and classifiers.dat files
659 PlugInManager.clearPlugInCache();
660 ClassifierManager.clearClassifierCache();
661 }
662 //Gatherer.config.setInt("general.max_folder_depth", Configuration.COLLECTION_SPECIFIC, ((Integer)recursion_depth_spinner.getValue()).intValue());
663
664 // Mode preferences
665 int current_mode = Gatherer.config.getMode();
666 int new_mode;
667 if(assistant_mode_radio_button.isSelected()) {
668 new_mode = Configuration.ASSISTANT_MODE;
669 }
670 else if(systems_mode_radio_button.isSelected()) {
671 new_mode = Configuration.SYSTEMS_MODE;
672 }
673 else if(expert_mode_radio_button.isSelected()) {
674 new_mode = Configuration.EXPERT_MODE;
675 }
676 else {
677 new_mode = Configuration.LIBRARIAN_MODE;
678 }
679 // If there has been a change in modes, update the config, and also inform the persistant gui views that have a need to know
680 if(new_mode != current_mode) {
681 Gatherer.config.setMode(new_mode);
682 Collection collection = Gatherer.c_man.getCollection();
683 if (collection != null) {
684 collection.cdm.modeChanged(new_mode);
685 }
686 Gatherer.g_man.modeChanged(new_mode);
687 }
688 // Warning preferences
689 for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) {
690 Entry entry = warning_preferences_check_list.get(i);
691 Gatherer.config.set(entry.getProperty(), true, entry.isSelected());
692 }
693 // Workflow preferences
694 Gatherer.config.set("workflow.browse", false, workflow_browse.isSelected());
695 Gatherer.config.set("workflow.mirror", false, workflow_mirror.isSelected());
696 Gatherer.config.set("workflow.gather", false, workflow_gather.isSelected());
697 Gatherer.config.set("workflow.enrich", false, workflow_enrich.isSelected());
698 Gatherer.config.set("workflow.design", false, workflow_design.isSelected());
699 Gatherer.config.set("workflow.export", false, workflow_export.isSelected());
700 Gatherer.config.set("workflow.create", false, workflow_create.isSelected());
701 Gatherer.config.set("workflow.preview", false, workflow_preview.isSelected());
702 Gatherer.g_man.workflowUpdate("Hunt", workflow_browse.isSelected());
703 Gatherer.g_man.workflowUpdate("Mirror", workflow_mirror.isSelected());
704 Gatherer.g_man.workflowUpdate("Gather", workflow_gather.isSelected());
705 Gatherer.g_man.workflowUpdate("Enrich", workflow_enrich.isSelected());
706 Gatherer.g_man.workflowUpdate("Design", (workflow_design.isSelected() && Gatherer.config.getMode() > Configuration.ASSISTANT_MODE));
707 Gatherer.g_man.workflowUpdate("Export", workflow_export.isSelected());
708 Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());
709 Gatherer.g_man.workflowUpdate("Preview", workflow_preview.isSelected());
710 // Hide dialog
711 if(close) {
712 self.dispose();
713 }
714 }
715 }
716
717 private class CancelButtonListener
718 implements ActionListener {
719 public void actionPerformed(ActionEvent event) {
720 self.dispose();
721 }
722 }
723
724 private class ClearCacheListener
725 implements ActionListener {
726 public void actionPerformed(ActionEvent event) {
727 // Retrieve the cache folder and delete it.
728 Utility.delete(Utility.getCacheDir());
729 }
730 }
731
732 private class DictionaryEntry
733 implements Comparable {
734 private Locale locale;
735 private String description;
736 public DictionaryEntry(Locale locale) {
737 this.description = null;
738 this.locale = locale;
739 }
740 public DictionaryEntry(String description, Locale locale) {
741 this.description = description;
742 this.locale = locale;
743 }
744 public int compareTo(Object object) {
745 return toString().compareTo(object.toString());
746 }
747 public boolean equals(Object object) {
748 return toString().equals(object.toString());
749 }
750 public Locale getLocale() {
751 return locale;
752 }
753 public String toString() {
754 if(description != null) {
755 return description;
756 }
757 else {
758 return locale.getDisplayName();
759 }
760 }
761 }
762
763 /** This listener updates the mode description depending on what mode is selected. */
764 private class ModeRadioButtonListener
765 implements ActionListener {
766 public void actionPerformed(ActionEvent event) {
767 Object source = event.getSource();
768 if(source == assistant_mode_radio_button) {
769 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
770 }
771 else if(source == expert_mode_radio_button) {
772 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
773 }
774 else if(source == systems_mode_radio_button) {
775 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));
776 }
777 else {
778 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
779 }
780 source = null;
781 }
782 }
783
784 private class PredefinedActionListener
785 implements ActionListener {
786 public void actionPerformed(ActionEvent event) {
787 JComboBox cb = (JComboBox) event.getSource();
788 WorkflowElementWrapper element = (WorkflowElementWrapper) cb.getSelectedItem();
789 CheckboxUpdater task = new CheckboxUpdater(element);
790 SwingUtilities.invokeLater(task);
791 }
792
793 private class CheckboxUpdater
794 implements Runnable {
795 private WorkflowElementWrapper element;
796 public CheckboxUpdater(WorkflowElementWrapper element) {
797 this.element = element;
798 }
799 public void run() {
800 workflow_browse.setSelected(element.getEnabled("browse"));
801 workflow_create.setSelected(element.getEnabled("create"));
802 workflow_mirror.setSelected(element.getEnabled("mirror"));
803 workflow_gather.setSelected(element.getEnabled("gather"));
804 workflow_enrich.setSelected(element.getEnabled("enrich"));
805 workflow_design.setSelected(element.getEnabled("design"));
806 workflow_export.setSelected(element.getEnabled("export"));
807 workflow_preview.setSelected(element.getEnabled("preview"));
808 }
809 }
810 }
811
812 private class LanguageComboboxListener
813 implements ActionListener {
814 public void actionPerformed(ActionEvent event) {
815 // Retrieve the entry
816 DictionaryEntry entry = (DictionaryEntry) language_combobox.getSelectedItem();
817 if(entry != null) {
818 //Gatherer.dictionary.changeDictionary(entry.getLocale());
819 // Display message
820 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Preferences.General.Restart_Required"), Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE);
821 }
822 }
823 }
824
825 private class UseProxyListener
826 implements ActionListener {
827 public void actionPerformed(ActionEvent event) {
828 boolean enabled = use_proxy_checkbox.isSelected();
829 Gatherer.config.set("general.use_proxy", true, enabled);
830 // Fortunately this is already driven by the event thread.
831 proxy_host_field.setEnabled(enabled);
832 proxy_port_field.setEnabled(enabled);
833 }
834 }
835
836 private class WorkflowElementWrapper {
837 private Element element;
838 private String text;
839 public WorkflowElementWrapper(Element element) {
840 this.element = element;
841 }
842 public boolean getEnabled(String name) {
843 boolean result = true;
844 if(element.getAttribute(name).equalsIgnoreCase("false")) {
845 result = false;
846 }
847 return result;
848 }
849 public String toString() {
850 if(text == null) {
851 text = element.getFirstChild().getNodeValue();
852 }
853 return text;
854 }
855 }
856}
Note: See TracBrowser for help on using the repository browser.