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

Last change on this file since 7151 was 7151, checked in by kjdon, 20 years ago

fixed some more static label sizes and deleted a lot of commented out stuff

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