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

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

added a comment

  • Property svn:keywords set to Author Date Id Revision
File size: 36.8 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.ArrayTools; // just for debug
51import org.greenstone.gatherer.util.StaticStrings;
52import org.greenstone.gatherer.util.Utility;
53import org.w3c.dom.*;
54
55public class Preferences
56 extends ModalDialog {
57
58 static final public String CONNECTION_PREFS = "connection";
59 static final public String GENERAL_PREFS = "general";
60
61
62 static final private Dimension LABEL_SIZE = new Dimension(280, 25);
63 static final private Dimension ROW_SIZE = new Dimension(640, 25);
64 static final private Dimension SIZE = new Dimension(640, 345);
65 static final private String TRUE = "true";
66
67 private CheckList warning_preferences_check_list;
68 private EmailField email_field;
69 private JButton apply_button;
70 private JButton cancel_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_create;
76 private JCheckBox workflow_mirror;
77 private JCheckBox workflow_gather;
78 private JCheckBox workflow_enrich;
79 private JCheckBox workflow_design;
80 private JCheckBox workflow_export;
81 private JComboBox language_combobox;
82 private JComboBox servlet_combobox; // GS3
83 private JComboBox site_combobox; // GS3
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 title_label;
92 private JPanel servlet_pane;
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 JTabbedPane tab_pane;
99 private JTextArea mode_description_textarea;
100 private JTextField library_path_field;
101 private JTextField program_field;
102 private JTextField proxy_host_field;
103 private Preferences self;
104
105 private String current_site_selection;
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 library_path_field = new JTextField(Gatherer.config.getString("general.exec_address", true));
201 library_path_field.setCaretPosition(0);
202 if (Gatherer.GS3) {
203 Dictionary.registerText(library_path_label, "Preferences.Connection.Library_Path_GS3");
204 Dictionary.registerTooltip(library_path_field, "Preferences.Connection.Library_Path_Tooltip_GS3");
205 } else {
206 Dictionary.registerText(library_path_label, "Preferences.Connection.Library_Path");
207 Dictionary.registerTooltip(library_path_field, "Preferences.Connection.Library_Path_Tooltip");
208 }
209
210
211 JPanel site_pane = null;
212 JLabel site_label = null;
213 JLabel servlet_label = null;
214 if (Gatherer.GS3) {
215 site_pane = new JPanel();
216 site_pane.setPreferredSize(ROW_SIZE);
217 site_label = new JLabel();
218 Dictionary.registerText(site_label, "Preferences.Connection.Site");
219 site_label.setPreferredSize(LABEL_SIZE);
220 // what should we do if Gatherer.servlet_config.getSites() is null?
221 site_combobox = new JComboBox(Gatherer.servlet_config.getSites().toArray());
222 Dictionary.registerTooltip(site_combobox, "Preferences.Connection.Site_Tooltip");
223 servlet_pane = new JPanel();
224 servlet_pane.setPreferredSize(ROW_SIZE);
225 servlet_label = new JLabel();
226 Dictionary.registerText(servlet_label, "Preferences.Connection.Servlet");
227 servlet_label.setPreferredSize(LABEL_SIZE);
228 servlet_combobox = new JComboBox();
229 // try to locate and select the current site
230 String this_site = Gatherer.config.site_name;
231 for(int b = 0; b < site_combobox.getItemCount(); b++) {
232 String entry = (String) site_combobox.getItemAt(b);
233 if(this_site.equals(entry)) {
234 site_combobox.setSelectedIndex(b);
235 break;
236 }
237 }
238
239 // just in case its not the current one?
240 current_site_selection = (String)site_combobox.getSelectedItem();
241
242 ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);
243 if (servlet_options == null) {
244 //servlet_combobox.setModel(new DefaultComboBoxModel());
245 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip2");
246 servlet_combobox.setEnabled(false);
247 } else {
248 System.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
249
250 servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
251 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip");
252 servlet_combobox.setEnabled(true);
253 // try to locate and select the current servlet
254 String this_servlet = Gatherer.config.getServletPath();
255 for(int b = 0; b < servlet_combobox.getItemCount(); b++) {
256 String entry = (String) servlet_combobox.getItemAt(b);
257 if(this_servlet.equals(entry)) {
258 servlet_combobox.setSelectedIndex(b);
259 break;
260 }
261 }
262
263 }
264 }
265
266 boolean currently_enabled = Gatherer.config.get("general.use_proxy", true);
267 // Creation
268 JPanel connection_pane = new JPanel();
269 use_proxy_checkbox = new JCheckBox();
270 use_proxy_checkbox.setSelected(currently_enabled);
271 Dictionary.registerText(use_proxy_checkbox, "Preferences.Connection.Use_Proxy");
272
273 use_proxy_checkbox.setPreferredSize(ROW_SIZE);
274 JPanel proxy_host_pane = new JPanel();
275 proxy_host_pane.setPreferredSize(ROW_SIZE);
276 proxy_host_label = new JLabel();
277 proxy_host_label.setPreferredSize(LABEL_SIZE);
278 Dictionary.registerText(proxy_host_label, "Preferences.Connection.Proxy_Host");
279 proxy_host_field = new JTextField(Gatherer.config.getString("general.proxy_host", true));
280 proxy_host_field.setEnabled(currently_enabled);
281 Dictionary.registerTooltip(proxy_host_field, "Preferences.Connection.Proxy_Host_Tooltip");
282 JPanel proxy_port_pane = new JPanel();
283 proxy_port_pane.setPreferredSize(ROW_SIZE);
284 proxy_port_label = new JLabel();
285 proxy_port_label.setPreferredSize(LABEL_SIZE);
286 Dictionary.registerText(proxy_port_label, "Preferences.Connection.Proxy_Port");
287 String port_value = Gatherer.config.getString("general.proxy_port", true);
288 if(port_value.length() > 0) {
289 proxy_port_field = new JSpinner(new SpinnerNumberModel((new Integer(port_value)).intValue(), 0, 65535, 1));
290 }
291 else {
292 proxy_port_field = new JSpinner(new SpinnerNumberModel(0, 0, 65535, 1));
293 }
294 proxy_port_field.setEnabled(currently_enabled);
295 Dictionary.registerTooltip(proxy_port_field, "Preferences.Connection.Proxy_Port_Tooltip");
296
297 // Connection
298 use_proxy_checkbox.addActionListener(new UseProxyListener());
299 if (Gatherer.GS3) {
300 site_combobox.addActionListener(new SiteComboboxListener());
301 }
302 // Layout
303 program_pane.setLayout(new BorderLayout());
304 program_pane.add(program_label, BorderLayout.WEST);
305 program_pane.add(program_field, BorderLayout.CENTER);
306
307 library_path_pane.setLayout(new BorderLayout());
308 library_path_pane.add(library_path_label, BorderLayout.WEST);
309 library_path_pane.add(library_path_field, BorderLayout.CENTER);
310
311 if (Gatherer.GS3) {
312 site_pane.setLayout(new BorderLayout());
313 site_pane.add(site_label, BorderLayout.WEST);
314 site_pane.add(site_combobox, BorderLayout.CENTER);
315
316 servlet_pane.setLayout(new BorderLayout());
317 servlet_pane.add(servlet_label, BorderLayout.WEST);
318 servlet_pane.add(servlet_combobox, BorderLayout.CENTER);
319 }
320 proxy_host_pane.setLayout(new BorderLayout());
321 proxy_host_pane.add(proxy_host_label, BorderLayout.WEST);
322 proxy_host_pane.add(proxy_host_field, BorderLayout.CENTER);
323
324 proxy_port_pane.setLayout(new BorderLayout());
325 proxy_port_pane.add(proxy_port_label, BorderLayout.WEST);
326 proxy_port_pane.add(proxy_port_field, BorderLayout.CENTER);
327
328 connection_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
329 connection_pane.setLayout(new GridLayout(8,1,0,2));
330 connection_pane.add(program_pane);
331 connection_pane.add(library_path_pane);
332 if (Gatherer.GS3) {
333 connection_pane.add(site_pane);
334 connection_pane.add(servlet_pane);
335 }
336 connection_pane.add(use_proxy_checkbox);
337 connection_pane.add(proxy_host_pane);
338 connection_pane.add(proxy_port_pane);
339
340 return connection_pane;
341 }
342
343 private JPanel createGeneralPreferences() {
344 JPanel general_pane = new JPanel();
345
346 // Build the model of available languages
347 ArrayList dictionary_model = new ArrayList();
348
349 // Old method for determining what languages should be available in the combobox
350 /*
351 dictionary_model.add(new DictionaryEntry(Locale.ENGLISH));
352 File classes_folder = new File(Utility.BASE_DIR + StaticStrings.CLASSES_FOLDER);
353 File[] possible_dictionaries = classes_folder.listFiles();
354 for(int i = 0; i < possible_dictionaries.length; i++) {
355 String filename = possible_dictionaries[i].getName();
356 if(filename.endsWith(StaticStrings.PROPERTIES_FILE_EXTENSION) && filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) != -1) {
357 StringTokenizer tokenizer = new StringTokenizer(filename.substring(filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) + 1, filename.indexOf(StaticStrings.STOP_CHARACTER)), StaticStrings.UNDERSCORE_CHARACTER);
358 Locale locale = null;
359 switch(tokenizer.countTokens()) {
360 case 1:
361 locale = new Locale(tokenizer.nextToken().toLowerCase());
362 break;
363 case 2:
364 locale = new Locale(tokenizer.nextToken().toLowerCase(), tokenizer.nextToken().toUpperCase());
365 break;
366 }
367 tokenizer = null;
368 // Open the file and read the first line
369 String description = null;
370 try {
371 BufferedReader br = new BufferedReader(new FileReader(possible_dictionaries[i]));
372 String first_line = br.readLine();
373 br.close();
374 description = first_line.substring(first_line.indexOf(StaticStrings.COLON_CHARACTER) + 1);
375 }
376 catch(Exception error) {
377 }
378 DictionaryEntry entry = new DictionaryEntry(description, locale);
379 description = null;
380 locale = null;
381 if(!dictionary_model.contains(entry)) {
382 dictionary_model.add(entry);
383 }
384 entry = null;
385 }
386 filename = null;
387 }
388 possible_dictionaries = null;
389 classes_folder = null;
390 */
391
392 // The new method makes use of the successor to the languages.dat file, classes/xml/languages.xml
393 NodeList language_elements = LanguageManager.LANGUAGES_DOCUMENT.getDocumentElement().getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
394 for(int i = 0; i < language_elements.getLength(); i++) {
395 Element language_element = (Element) language_elements.item(i);
396 if((language_element.getAttribute(StaticStrings.GLI_ATTRIBUTE)).equalsIgnoreCase(StaticStrings.TRUE_STR) || (language_element.getAttribute(StaticStrings.MDS_ATTRIBUTE)).equalsIgnoreCase(StaticStrings.TRUE_STR)) {
397 Locale locale = new Locale(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE));
398 String description = language_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
399 DictionaryEntry entry = new DictionaryEntry(description, locale);
400 if(!dictionary_model.contains(entry)) {
401 dictionary_model.add(entry);
402 }
403 entry = null;
404 description = null;
405 locale = null;
406 }
407 language_element = null;
408 }
409 language_elements = null;
410
411 // Users email
412 JPanel email_pane = new JPanel();
413 email_label = new JLabel();
414 email_label.setPreferredSize(LABEL_SIZE);
415 Dictionary.registerText(email_label, "Preferences.General.Email");
416 email_field = new EmailField(Gatherer.config.getColor("coloring.error_background", false));
417 email_field.setText(Gatherer.config.getEmail());
418 Dictionary.registerTooltip(email_field, "Preferences.General.Email_Tooltip");
419
420 // Extracted metadata
421 view_extracted_metadata_checkbox = new JCheckBox();
422 view_extracted_metadata_checkbox.setSelected(false);
423 if (Gatherer.config.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC)) {
424 view_extracted_metadata_checkbox.setSelected(true);
425 }
426 Dictionary.registerBoth(view_extracted_metadata_checkbox, "Preferences.General.View_Extracted_Metadata", "Preferences.General.View_Extracted_Metadata_Tooltip");
427
428 // Show file sizes
429 show_file_size_checkbox = new JCheckBox();
430 show_file_size_checkbox.setSelected(false);
431 if (Gatherer.config.get("general.show_file_size", Configuration.COLLECTION_SPECIFIC)) {
432 show_file_size_checkbox.setSelected(true);
433 }
434 Dictionary.registerBoth(show_file_size_checkbox, "Preferences.General.Show_File_Size", "Preferences.General.Show_File_Size_Tooltip");
435
436 // Language
437 JPanel language_pane = new JPanel();
438 language_label = new JLabel();
439 language_label.setPreferredSize(LABEL_SIZE);
440 Dictionary.registerText(language_label, "Preferences.General.Interface_Language");
441 language_combobox = new JComboBox(dictionary_model.toArray());
442 Dictionary.registerTooltip(language_combobox, "Preferences.General.Interface_Language_Tooltip");
443 // Try to locate and select the current language
444 String language_code = Gatherer.config.getLanguage();
445 for(int b = 0; b < language_combobox.getItemCount(); b++) {
446 DictionaryEntry entry = (DictionaryEntry) language_combobox.getItemAt(b);
447 if(language_code.equalsIgnoreCase(entry.getLocale().getLanguage())) {
448 language_combobox.setSelectedIndex(b);
449 }
450 }
451
452 // Connect
453 language_combobox.addActionListener(new LanguageComboboxListener());
454
455 // Layout
456 email_pane.setLayout(new BorderLayout());
457 email_pane.add(email_label, BorderLayout.WEST);
458 email_pane.add(email_field, BorderLayout.CENTER);
459
460 language_pane.setLayout(new BorderLayout());
461 language_pane.add(language_label, BorderLayout.WEST);
462 language_pane.add(language_combobox, BorderLayout.CENTER);
463
464 general_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
465 general_pane.setLayout(new GridLayout(5,1,0,5));
466 general_pane.add(email_pane);
467 general_pane.add(language_pane);
468 general_pane.add(view_extracted_metadata_checkbox);
469 general_pane.add(show_file_size_checkbox);
470
471 return general_pane;
472 }
473
474 /** Generate the controls for altering the detail mode.
475 * @return a JPanel of controls
476 */
477 private JPanel createModePreferences() {
478 // Create Controls
479 JPanel mode_panel = new JPanel();
480 JPanel button_panel = new JPanel();
481 ButtonGroup mode_button_group = new ButtonGroup();
482 assistant_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Assistant"));
483 assistant_mode_radio_button.setOpaque(false);
484 mode_button_group.add(assistant_mode_radio_button);
485 expert_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Expert"));
486 expert_mode_radio_button.setOpaque(false);
487 mode_button_group.add(expert_mode_radio_button);
488 librarian_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Librarian"));
489 librarian_mode_radio_button.setOpaque(false);
490 mode_button_group.add(librarian_mode_radio_button);
491 systems_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Systems"));
492 systems_mode_radio_button.setOpaque(false);
493 mode_button_group.add(systems_mode_radio_button);
494 mode_description_textarea = new JTextArea();
495 mode_description_textarea.setEditable(false);
496 mode_description_textarea.setLineWrap(true);
497 mode_description_textarea.setWrapStyleWord(true);
498 // Determine which value is already selected
499 switch(Gatherer.config.getMode()) {
500 case Configuration.ASSISTANT_MODE:
501 assistant_mode_radio_button.setSelected(true);
502 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
503 break;
504 case Configuration.SYSTEMS_MODE:
505 systems_mode_radio_button.setSelected(true);
506 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));
507 break;
508 case Configuration.EXPERT_MODE:
509 expert_mode_radio_button.setSelected(true);
510 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
511 break;
512 default:
513 librarian_mode_radio_button.setSelected(true);
514 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
515 }
516 // Connection - when a radio button is selected we have to change the description
517 ModeRadioButtonListener listener = new ModeRadioButtonListener();
518 assistant_mode_radio_button.addActionListener(listener);
519 expert_mode_radio_button.addActionListener(listener);
520 librarian_mode_radio_button.addActionListener(listener);
521 systems_mode_radio_button.addActionListener(listener);
522 listener = null;
523 // Layout
524 button_panel.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
525 button_panel.setLayout(new GridLayout(4,1,2,2));
526 button_panel.add(assistant_mode_radio_button);
527 button_panel.add(librarian_mode_radio_button);
528 button_panel.add(systems_mode_radio_button);
529 button_panel.add(expert_mode_radio_button);
530
531 mode_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
532 mode_panel.setLayout(new BorderLayout());
533 mode_panel.add(button_panel, BorderLayout.NORTH);
534 mode_panel.add(new JScrollPane(mode_description_textarea), BorderLayout.CENTER);
535
536 return mode_panel;
537 }
538
539 /** The warning preferences are controlled through a checklist. */
540 private JPanel createWarningPreferences() {
541 // Retrieve all of the warning preferences settings.
542 HashMap warning_preferences = Gatherer.config.getAll("warning\\..*", true);
543 warning_preferences_check_list = new CheckList(false);
544 for(Iterator keys = warning_preferences.keySet().iterator(); keys.hasNext(); ) {
545 String property = (String) keys.next();
546 String value = (String) warning_preferences.get(property);
547 // Remove 'warning.'
548 String title = Dictionary.get(property.substring(8) + ".Title");
549 Entry entry = new Entry(title, value.equalsIgnoreCase(TRUE));
550 entry.setProperty(property);
551 warning_preferences_check_list.addEntry(entry);
552 }
553 // Creation
554 JPanel warning_preferences_pane = new JPanel();
555 // Connection
556 // Layout
557 warning_preferences_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
558 warning_preferences_pane.setLayout(new BorderLayout());
559 warning_preferences_pane.add(new JScrollPane(warning_preferences_check_list), BorderLayout.CENTER);
560
561 return warning_preferences_pane;
562 }
563
564 private JPanel createWorkflowPreferences() {
565 // Read in the predefined configurations file
566 Vector predefined = new Vector();
567 Document predefined_document = Utility.parse("xml/workflows.xml", true);
568 Element predefined_element = predefined_document.getDocumentElement();
569 NodeList workflow_elements = predefined_element.getElementsByTagName("Workflow");
570 for(int i = 0; i < workflow_elements.getLength(); i++) {
571 predefined.add(new WorkflowElementWrapper((Element)workflow_elements.item(i)));
572 }
573
574 // Creation
575 JPanel workflow_preferences_pane = new JPanel();
576 JPanel checklist_pane = new JPanel();
577 title_label = new JLabel();
578 title_label.setPreferredSize(ROW_SIZE);
579 Dictionary.registerText(title_label, "Preferences.Workflow.Title");
580
581 workflow_mirror = new JCheckBox();
582 workflow_mirror.setSelected(Gatherer.config.get("workflow.mirror", false));
583 workflow_mirror.setPreferredSize(ROW_SIZE);
584 Dictionary.registerText(workflow_mirror, "Preferences.Workflow.Mirror");
585
586 workflow_gather = new JCheckBox();
587 workflow_gather.setSelected(Gatherer.config.get("workflow.gather", false));
588 workflow_gather.setPreferredSize(ROW_SIZE);
589 Dictionary.registerText(workflow_gather, "Preferences.Workflow.Gather");
590
591 workflow_enrich = new JCheckBox();
592 workflow_enrich.setSelected(Gatherer.config.get("workflow.enrich", false));
593 workflow_enrich.setPreferredSize(ROW_SIZE);
594 Dictionary.registerText(workflow_enrich, "Preferences.Workflow.Enrich");
595
596 workflow_design = new JCheckBox();
597 workflow_design.setSelected(Gatherer.config.get("workflow.design", false));
598 workflow_design.setPreferredSize(ROW_SIZE);
599 Dictionary.registerText(workflow_design, "Preferences.Workflow.Design");
600
601 workflow_export = new JCheckBox();
602 workflow_export.setSelected(Gatherer.config.get("workflow.export", false));
603 workflow_export.setPreferredSize(ROW_SIZE);
604 Dictionary.registerText(workflow_export, "Preferences.Workflow.Export");
605
606 workflow_create = new JCheckBox();
607 workflow_create.setSelected(Gatherer.config.get("workflow.create", false));
608 workflow_create.setPreferredSize(ROW_SIZE);
609 Dictionary.registerText(workflow_create, "Preferences.Workflow.Create");
610
611 JPanel predefined_pane = new JPanel();
612 predefined_label = new JLabel();
613 Dictionary.registerText(predefined_label, "Preferences.Workflow.Predefined.Label");
614 JComboBox predefined_combobox = new JComboBox(predefined);
615
616 // Connection
617 predefined_combobox.addActionListener(new PredefinedActionListener());
618
619 // Layout
620 checklist_pane.setLayout(new BoxLayout(checklist_pane, BoxLayout.Y_AXIS));
621 checklist_pane.add(title_label);
622 if (Gatherer.config.get("workflow.mirror", true)) {
623 checklist_pane.add(workflow_mirror);
624 }
625 if (Gatherer.config.get("workflow.gather", true)) {
626 checklist_pane.add(workflow_gather);
627 }
628 if (Gatherer.config.get("workflow.enrich", true)) {
629 checklist_pane.add(workflow_enrich);
630 }
631 if (Gatherer.config.get("workflow.design", true)) {
632 checklist_pane.add(workflow_design);
633 }
634 if (Gatherer.config.get("workflow.export", true)) {
635 checklist_pane.add(workflow_export);
636 }
637 if (Gatherer.config.get("workflow.create", true)) {
638 checklist_pane.add(workflow_create);
639 }
640
641 predefined_pane.setLayout(new BorderLayout(5,0));
642 predefined_pane.add(predefined_label, BorderLayout.WEST);
643 predefined_pane.add(predefined_combobox, BorderLayout.CENTER);
644
645 workflow_preferences_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
646 workflow_preferences_pane.setLayout(new BorderLayout());
647 workflow_preferences_pane.add(checklist_pane, BorderLayout.CENTER);
648 workflow_preferences_pane.add(predefined_pane, BorderLayout.SOUTH);
649
650 return workflow_preferences_pane;
651 }
652
653
654 private class OKButtonListener
655 implements ActionListener {
656 private boolean close;
657 public OKButtonListener(boolean close) {
658 this.close = close;
659 }
660 public void actionPerformed(ActionEvent event) {
661 // Submit the various changes
662 // Connection preferences
663 String program_str = program_field.getText();
664 if(program_str.length() > 0 && program_str.indexOf("%1") == -1) {
665 program_str = program_str + " %1";
666 }
667 Gatherer.config.setPreviewCommand(program_str);
668
669 String library_path_string = library_path_field.getText();
670 Gatherer.config.setString("general.exec_address", true, library_path_string);
671 if (!library_path_string.equals("")) {
672 try {
673 Gatherer.config.exec_address = new URL(library_path_string);
674 }
675 catch (MalformedURLException error) {
676 ///ystem.err.println("Error: Bad address: " + exec_address_string);
677 }
678 }
679 boolean site_changed = false;
680 if (Gatherer.GS3) {
681 String current_site = Gatherer.config.site_name;
682 String new_site =(String)site_combobox.getSelectedItem() ;
683 if (!new_site.equals(current_site)) {
684 site_changed = true;
685 }
686 Gatherer.config.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem());
687 }
688
689 Gatherer.config.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
690 Gatherer.config.setString("general.proxy_host", true, proxy_host_field.getText());
691 Gatherer.config.setString("general.proxy_port", true, proxy_port_field.getValue() + "");
692 Gatherer.setProxy();
693
694 // General preferences
695 Gatherer.config.setEmail(email_field.getText());
696
697 Gatherer.config.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, show_file_size_checkbox.isSelected());
698 // Force both workspace and collection trees to redraw
699 if (Gatherer.g_man != null) {
700 Gatherer.g_man.refreshWorkspaceTree(DragTree.TREE_DISPLAY_CHANGED);
701 Gatherer.g_man.refreshCollectionTree(DragTree.TREE_DISPLAY_CHANGED);
702 }
703
704 Gatherer.config.set("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC, view_extracted_metadata_checkbox.isSelected());
705 Gatherer.g_man.enrich_pane.valueChanged((TreeSelectionEvent) null); // Refresh metadata table
706
707 String current_lang = Gatherer.config.getLanguage();
708 String new_lang = ((DictionaryEntry)language_combobox.getSelectedItem()).getLocale().getLanguage();
709 if (!current_lang.equals(new_lang)) {
710 Gatherer.config.setLocale("general.locale", Configuration.GENERAL_SETTING, ((DictionaryEntry)language_combobox.getSelectedItem()).getLocale());
711 // delete the plugins and classifiers.dat files
712 PlugInManager.clearPlugInCache();
713 ClassifierManager.clearClassifierCache();
714 }
715
716 // Mode preferences
717 int current_mode = Gatherer.config.getMode();
718 int new_mode;
719 if(assistant_mode_radio_button.isSelected()) {
720 new_mode = Configuration.ASSISTANT_MODE;
721 }
722 else if(systems_mode_radio_button.isSelected()) {
723 new_mode = Configuration.SYSTEMS_MODE;
724 }
725 else if(expert_mode_radio_button.isSelected()) {
726 new_mode = Configuration.EXPERT_MODE;
727 }
728 else {
729 new_mode = Configuration.LIBRARIAN_MODE;
730 }
731 // If there has been a change in modes, update the config, and also inform the persistant gui views that have a need to know
732 if(new_mode != current_mode) {
733 Gatherer.config.setMode(new_mode);
734 Collection collection = Gatherer.c_man.getCollection();
735 if (collection != null) {
736 collection.cdm.modeChanged(new_mode);
737 }
738 Gatherer.g_man.modeChanged(new_mode);
739 }
740 // Warning preferences
741 for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) {
742 Entry entry = warning_preferences_check_list.get(i);
743 Gatherer.config.set(entry.getProperty(), true, entry.isSelected());
744 }
745
746 if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection()!=null) {
747 // shut down the collection
748 System.err.println("shutting down teh collection");
749 Gatherer.g_man.closeCurrentCollection();
750 }
751
752 // Workflow preferences
753 // Gatherer.config.set("workflow.mirror", false, workflow_mirror.isSelected());
754 // Gatherer.config.set("workflow.gather", false, workflow_gather.isSelected());
755 // Gatherer.config.set("workflow.enrich", false, workflow_enrich.isSelected());
756 // Gatherer.config.set("workflow.design", false, workflow_design.isSelected());
757 // Gatherer.config.set("workflow.export", false, workflow_export.isSelected());
758 // Gatherer.config.set("workflow.create", false, workflow_create.isSelected());
759 // Gatherer.g_man.workflowUpdate("Mirror", workflow_mirror.isSelected());
760 // Gatherer.g_man.workflowUpdate("Gather", workflow_gather.isSelected());
761 // Gatherer.g_man.workflowUpdate("Enrich", workflow_enrich.isSelected());
762 // Gatherer.g_man.workflowUpdate("Design", (workflow_design.isSelected() && Gatherer.config.getMode() > Configuration.ASSISTANT_MODE));
763 // Gatherer.g_man.workflowUpdate("Export", workflow_export.isSelected());
764 // Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());
765
766 // Always save configuration changes immediately (in case the GLI crashes)
767 Gatherer.config.save();
768
769 // Hide dialog
770 if(close) {
771 self.dispose();
772 }
773 }
774 }
775
776 private class CancelButtonListener
777 implements ActionListener {
778 public void actionPerformed(ActionEvent event) {
779 self.dispose();
780 }
781 }
782
783 private class DictionaryEntry
784 implements Comparable {
785 private Locale locale;
786 private String description;
787 public DictionaryEntry(Locale locale) {
788 this.description = null;
789 this.locale = locale;
790 }
791 public DictionaryEntry(String description, Locale locale) {
792 this.description = description;
793 this.locale = locale;
794 }
795 public int compareTo(Object object) {
796 return toString().compareTo(object.toString());
797 }
798 public boolean equals(Object object) {
799 return toString().equals(object.toString());
800 }
801 public Locale getLocale() {
802 return locale;
803 }
804 public String toString() {
805 if(description != null) {
806 return description;
807 }
808 else {
809 return locale.getDisplayName();
810 }
811 }
812 }
813
814 /** This listener updates the mode description depending on what mode is selected. */
815 private class ModeRadioButtonListener
816 implements ActionListener {
817 public void actionPerformed(ActionEvent event) {
818 Object source = event.getSource();
819 if(source == assistant_mode_radio_button) {
820 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
821 }
822 else if(source == expert_mode_radio_button) {
823 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
824 }
825 else if(source == systems_mode_radio_button) {
826 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));
827 }
828 else {
829 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
830 }
831 source = null;
832 }
833 }
834
835 private class PredefinedActionListener
836 implements ActionListener {
837 public void actionPerformed(ActionEvent event) {
838 JComboBox cb = (JComboBox) event.getSource();
839 WorkflowElementWrapper element = (WorkflowElementWrapper) cb.getSelectedItem();
840 CheckboxUpdater task = new CheckboxUpdater(element);
841 SwingUtilities.invokeLater(task);
842 }
843
844 private class CheckboxUpdater
845 implements Runnable {
846 private WorkflowElementWrapper element;
847 public CheckboxUpdater(WorkflowElementWrapper element) {
848 this.element = element;
849 }
850 public void run() {
851 workflow_create.setSelected(element.getEnabled("create"));
852 workflow_mirror.setSelected(element.getEnabled("mirror"));
853 workflow_gather.setSelected(element.getEnabled("gather"));
854 workflow_enrich.setSelected(element.getEnabled("enrich"));
855 workflow_design.setSelected(element.getEnabled("design"));
856 workflow_export.setSelected(element.getEnabled("export"));
857 }
858 }
859 }
860
861 private class LanguageComboboxListener
862 implements ActionListener {
863 public void actionPerformed(ActionEvent event) {
864 // Retrieve the entry
865 DictionaryEntry entry = (DictionaryEntry) language_combobox.getSelectedItem();
866 if(entry != null) {
867 //Gatherer.dictionary.changeDictionary(entry.getLocale());
868 // Display message
869 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Preferences.General.Restart_Required"), Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE);
870 }
871 }
872 }
873
874 private class SiteComboboxListener
875 implements ActionListener {
876 private boolean ignore_event=false;
877 public void actionPerformed(ActionEvent event) {
878 System.err.println("event occurred "+event.paramString());
879 String site = (String) site_combobox.getSelectedItem();
880 System.err.println("new site = "+site);
881 if (!site.equals(current_site_selection)) {
882 current_site_selection = site;
883 System.err.println("changed the current selection");
884 ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);
885 if (servlet_options == null) {
886 System.err.println("no servlets for this site");
887 servlet_combobox.setModel(new DefaultComboBoxModel());
888 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip2");
889 servlet_combobox.setEnabled(false);
890
891 } else {
892 System.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
893 servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
894 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip");
895 servlet_combobox.setEnabled(true);
896 }
897 }
898 }
899 }
900
901 private class UseProxyListener
902 implements ActionListener {
903 public void actionPerformed(ActionEvent event) {
904 boolean enabled = use_proxy_checkbox.isSelected();
905 Gatherer.config.set("general.use_proxy", true, enabled);
906 // Fortunately this is already driven by the event thread.
907 proxy_host_field.setEnabled(enabled);
908 proxy_port_field.setEnabled(enabled);
909 }
910 }
911
912 private class WorkflowElementWrapper {
913 private Element element;
914 private String text;
915 public WorkflowElementWrapper(Element element) {
916 this.element = element;
917 }
918 public boolean getEnabled(String name) {
919 boolean result = true;
920 if(element.getAttribute(name).equalsIgnoreCase("false")) {
921 result = false;
922 }
923 return result;
924 }
925 public String toString() {
926 if(text == null) {
927 text = element.getFirstChild().getNodeValue();
928 }
929 return text;
930 }
931 }
932}
Note: See TracBrowser for help on using the repository browser.