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

Last change on this file since 6642 was 6642, checked in by jmt12, 20 years ago

Further tweaks, fixes and changes to the mirroring stuff, the highlight of which is the new log files. I've also removed the speech marks from around login and pass. While this means you can't have a login or pass with spaces in it, it does save me a lot of effort. Rather than tell people about the further options, they now click on a button to open the preferences window and show the further options. Also fixed a horrendeously subtle bug when trying to update the FileSystemModel - stupid race conditions

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