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

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

Removed all occurrences of classes explicitly importing other classes in the same package.

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