source: branches/gsdl-2_70-distribution-branch/gli/src/org/greenstone/gatherer/gui/Preferences.java@ 11699

Last change on this file since 11699 was 11699, checked in by kjdon, 18 years ago

Michael's changes to disable library and gliserver url fields in the applet, for the branch

  • Property svn:keywords set to Author Date Id Revision
File size: 37.1 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.gui;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.io.*;
32import java.net.*;
33import java.util.*;
34import javax.swing.*;
35import javax.swing.event.*;
36import javax.swing.plaf.*;
37import org.greenstone.gatherer.Configuration;
38import org.greenstone.gatherer.DebugStream;
39import org.greenstone.gatherer.Dictionary;
40import org.greenstone.gatherer.Gatherer;
41import org.greenstone.gatherer.cdm.ClassifierManager;
42import org.greenstone.gatherer.cdm.LanguageManager;
43import org.greenstone.gatherer.cdm.PluginManager;
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.CheckList;
48import org.greenstone.gatherer.util.CheckListEntry;
49import org.greenstone.gatherer.util.StaticStrings;
50import org.greenstone.gatherer.util.XMLTools;
51import org.w3c.dom.*;
52
53public class Preferences
54 extends ModalDialog
55{
56 static final public String CONNECTION_PREFS = "connection";
57 static final public String GENERAL_PREFS = "general";
58
59 static final private Dimension LABEL_SIZE = new Dimension(280, 25);
60 static final private Dimension ROW_SIZE = new Dimension(640, 25);
61 static final private Dimension SIZE = new Dimension(640, 345);
62 static final private String TRUE = "true";
63
64 private CheckList warning_preferences_check_list;
65 private EmailField email_field;
66 private JButton apply_button;
67 private JButton cancel_button;
68 private JButton ok_button;
69 private JCheckBox show_file_size_checkbox;
70 private JCheckBox use_proxy_checkbox;
71 private JCheckBox view_extracted_metadata_checkbox;
72 private JCheckBox workflow_download;
73 private JCheckBox workflow_gather;
74 private JCheckBox workflow_enrich;
75 private JCheckBox workflow_design;
76 private JCheckBox workflow_create;
77 private JComboBox language_combobox;
78 private JComboBox servlet_combobox; // GS3
79 private JComboBox site_combobox; // GS3
80 private JRadioButton assistant_mode_radio_button;
81 private JRadioButton expert_mode_radio_button;
82 private JRadioButton librarian_mode_radio_button;
83 private JRadioButton systems_mode_radio_button;
84 private JSpinner proxy_port_field;
85 private JTabbedPane tab_pane;
86 private JTextArea mode_description_textarea;
87 private JTextField font_field;
88 private JTextField gliserver_url_field;
89 private JTextField library_path_field;
90 private JTextField program_field;
91 private JTextField proxy_host_field;
92 private Preferences self;
93
94 private String current_site_selection;
95
96 public Preferences() {
97 this(GENERAL_PREFS);
98 }
99
100 public Preferences(String initial_view) {
101 // Initialize
102 super(Gatherer.g_man, true);
103 this.self = this;
104 setSize(SIZE);
105 Dictionary.registerText(this, "Preferences");
106 setJMenuBar(new SimpleMenuBar("preferences"));
107
108 // Creation
109 JPanel content_pane = (JPanel) getContentPane();
110 tab_pane = new JTabbedPane();
111 JPanel general_preferences = createGeneralPreferences();
112 tab_pane.add("Preferences.General", general_preferences); // Also uses "Preferences.General_Tooltip"
113 tab_pane.add("Preferences.Mode", createModePreferences()); // Also uses "Preferences.Mode_Tooltip"
114 tab_pane.add("Preferences.Workflow", createWorkflowPreferences()); // Also uses "Preferences.Workflow_Tooltip"
115 JPanel connection_preferences = createConnectionPreferences();
116 tab_pane.add("Preferences.Connection", connection_preferences); // Also uses "Preferences.Connection_Tooltip"
117 tab_pane.add("Preferences.Warnings", createWarningPreferences()); // Also uses "Preferences.Warnings_Tooltip"
118 Dictionary.register(tab_pane);
119
120 JPanel button_pane = new JPanel();
121 ok_button = new GLIButton();
122 ok_button.setMnemonic(KeyEvent.VK_O);
123 Dictionary.registerBoth(ok_button, "General.OK", "General.OK_Tooltip");
124 apply_button = new GLIButton();
125 apply_button.setMnemonic(KeyEvent.VK_A);
126 Dictionary.registerBoth(apply_button, "General.Apply", "General.Apply_Tooltip");
127 cancel_button = new GLIButton();
128 cancel_button.setMnemonic(KeyEvent.VK_C);
129 Dictionary.registerBoth(cancel_button, "General.Cancel", "General.Cancel_Tooltip");
130
131 // Connection
132 ok_button.addActionListener(new OKButtonListener(true));
133 apply_button.addActionListener(new OKButtonListener(false));
134 cancel_button.addActionListener(new CancelButtonListener());
135
136 // Layout
137 button_pane.setBorder(BorderFactory.createEmptyBorder(5,2,2,2));
138 button_pane.setLayout(new GridLayout(1,3,0,5));
139 button_pane.add(ok_button);
140 button_pane.add(apply_button);
141 button_pane.add(cancel_button);
142
143 content_pane.setLayout(new BorderLayout());
144 content_pane.add(tab_pane, BorderLayout.CENTER);
145 content_pane.add(button_pane, BorderLayout.SOUTH);
146
147 Dimension frame_size = Gatherer.g_man.getSize();
148 Point frame_location = Gatherer.g_man.getLocation();
149 setLocation(((frame_size.width - SIZE.width) / 2), ((frame_size.height - SIZE.height)));
150
151 // Bring the desired pane to the fore
152 if (initial_view.equals(CONNECTION_PREFS)) {
153 tab_pane.setSelectedComponent(connection_preferences);
154 }
155 else {
156 tab_pane.setSelectedComponent(general_preferences);
157 }
158
159 // Clean up
160 general_preferences = null;
161 connection_preferences = null;
162 frame_location = null;
163 frame_size = null;
164 cancel_button = null;
165 ok_button = null;
166 button_pane = null;
167 tab_pane = null;
168 content_pane = null;
169
170 setVisible(true);
171 }
172
173 private JPanel createConnectionPreferences() {
174 JPanel program_pane = new JPanel();
175 program_pane.setPreferredSize(ROW_SIZE);
176 JLabel program_label = new JLabel();
177 program_label.setPreferredSize(LABEL_SIZE);
178 Dictionary.registerText(program_label, "Preferences.Connection.ProgramCommand");
179 program_field = new JTextField(Configuration.getPreviewCommand());
180 program_field.setCaretPosition(0);
181 Dictionary.registerTooltip(program_field, "Preferences.Connection.ProgramCommand_Tooltip");
182
183 JPanel library_path_pane = new JPanel();
184 library_path_pane.setPreferredSize(ROW_SIZE);
185 JLabel library_path_label = new JLabel();
186 library_path_label.setPreferredSize(LABEL_SIZE);
187 String library_url_string = "";
188 if (Configuration.library_url != null) {
189 library_url_string = Configuration.library_url.toString();
190 }
191 library_path_field = new JTextField(library_url_string);
192 library_path_field.setCaretPosition(0);
193 if (Gatherer.GS3) {
194 Dictionary.registerText(library_path_label, "Preferences.Connection.Library_Path_GS3");
195 Dictionary.registerTooltip(library_path_field, "Preferences.Connection.Library_Path_Tooltip_GS3");
196 } else {
197 Dictionary.registerText(library_path_label, "Preferences.Connection.Library_Path");
198 Dictionary.registerTooltip(library_path_field, "Preferences.Connection.Library_Path_Tooltip");
199 }
200 // Disable this field when using the applet, as it is automatically determined
201 library_path_label.setEnabled(!Gatherer.isApplet);
202 library_path_field.setEnabled(!Gatherer.isApplet);
203
204 JPanel gliserver_url_pane = null;
205 JLabel gliserver_url_label = null;
206 if (Gatherer.isGsdlRemote) {
207 gliserver_url_pane = new JPanel();
208 gliserver_url_pane.setPreferredSize(ROW_SIZE);
209 gliserver_url_label = new JLabel();
210 gliserver_url_label.setPreferredSize(LABEL_SIZE);
211 String gliserver_url_string = "";
212 if (Configuration.gliserver_url != null) {
213 gliserver_url_string = Configuration.gliserver_url.toString();
214 }
215 gliserver_url_field = new JTextField(gliserver_url_string);
216 gliserver_url_field.setCaretPosition(0);
217 Dictionary.registerText(gliserver_url_label, "Preferences.Connection.GLIServer_URL");
218 Dictionary.registerTooltip(gliserver_url_field, "Preferences.Connection.GLIServer_URL_Tooltip");
219
220 // Disable this field when using the applet, as it is automatically determined
221 gliserver_url_label.setEnabled(!Gatherer.isApplet);
222 gliserver_url_field.setEnabled(!Gatherer.isApplet);
223 }
224
225 JPanel site_pane = null;
226 JLabel site_label = null;
227 JPanel servlet_pane = null;
228 JLabel servlet_label = null;
229 if (Gatherer.GS3) {
230 site_pane = new JPanel();
231 site_pane.setPreferredSize(ROW_SIZE);
232 site_label = new JLabel();
233 Dictionary.registerText(site_label, "Preferences.Connection.Site");
234 site_label.setPreferredSize(LABEL_SIZE);
235 // what should we do if Gatherer.servlet_config.getSites() is null?
236 site_combobox = new JComboBox(Gatherer.servlet_config.getSites().toArray());
237 Dictionary.registerTooltip(site_combobox, "Preferences.Connection.Site_Tooltip");
238 servlet_pane = new JPanel();
239 servlet_pane.setPreferredSize(ROW_SIZE);
240 servlet_label = new JLabel();
241 Dictionary.registerText(servlet_label, "Preferences.Connection.Servlet");
242 servlet_label.setPreferredSize(LABEL_SIZE);
243 servlet_combobox = new JComboBox();
244 // try to locate and select the current site
245 String this_site = Configuration.site_name;
246 for(int b = 0; b < site_combobox.getItemCount(); b++) {
247 String entry = (String) site_combobox.getItemAt(b);
248 if(this_site.equals(entry)) {
249 site_combobox.setSelectedIndex(b);
250 break;
251 }
252 }
253
254 // just in case its not the current one?
255 current_site_selection = (String)site_combobox.getSelectedItem();
256
257 ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);
258 if (servlet_options == null) {
259 //servlet_combobox.setModel(new DefaultComboBoxModel());
260 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip2");
261 servlet_combobox.setEnabled(false);
262 } else {
263 System.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
264
265 servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
266 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip");
267 servlet_combobox.setEnabled(true);
268 // try to locate and select the current servlet
269 String this_servlet = Configuration.getServletPath();
270 for(int b = 0; b < servlet_combobox.getItemCount(); b++) {
271 String entry = (String) servlet_combobox.getItemAt(b);
272 if(this_servlet.equals(entry)) {
273 servlet_combobox.setSelectedIndex(b);
274 break;
275 }
276 }
277
278 }
279 }
280
281 boolean currently_enabled = Configuration.get("general.use_proxy", true);
282 // Creation
283 JPanel connection_pane = new JPanel();
284 use_proxy_checkbox = new JCheckBox();
285 use_proxy_checkbox.setSelected(currently_enabled);
286 Dictionary.registerText(use_proxy_checkbox, "Preferences.Connection.Use_Proxy");
287
288 use_proxy_checkbox.setPreferredSize(ROW_SIZE);
289 JPanel proxy_host_pane = new JPanel();
290 proxy_host_pane.setPreferredSize(ROW_SIZE);
291 JLabel proxy_host_label = new JLabel();
292 proxy_host_label.setPreferredSize(LABEL_SIZE);
293 Dictionary.registerText(proxy_host_label, "Preferences.Connection.Proxy_Host");
294 proxy_host_field = new JTextField(Configuration.getString("general.proxy_host", true));
295 proxy_host_field.setEnabled(currently_enabled);
296 Dictionary.registerTooltip(proxy_host_field, "Preferences.Connection.Proxy_Host_Tooltip");
297 JPanel proxy_port_pane = new JPanel();
298 proxy_port_pane.setPreferredSize(ROW_SIZE);
299 JLabel proxy_port_label = new JLabel();
300 proxy_port_label.setPreferredSize(LABEL_SIZE);
301 Dictionary.registerText(proxy_port_label, "Preferences.Connection.Proxy_Port");
302 String port_value = Configuration.getString("general.proxy_port", true);
303 if(port_value.length() > 0) {
304 proxy_port_field = new JSpinner(new SpinnerNumberModel((new Integer(port_value)).intValue(), 0, 65535, 1));
305 }
306 else {
307 proxy_port_field = new JSpinner(new SpinnerNumberModel(0, 0, 65535, 1));
308 }
309 proxy_port_field.setEnabled(currently_enabled);
310 Dictionary.registerTooltip(proxy_port_field, "Preferences.Connection.Proxy_Port_Tooltip");
311
312 // Connection
313 use_proxy_checkbox.addActionListener(new UseProxyListener());
314 if (Gatherer.GS3) {
315 site_combobox.addActionListener(new SiteComboboxListener());
316 }
317
318 // Layout
319 program_pane.setLayout(new BorderLayout());
320 program_pane.add(program_label, BorderLayout.WEST);
321 program_pane.add(program_field, BorderLayout.CENTER);
322
323 library_path_pane.setLayout(new BorderLayout());
324 library_path_pane.add(library_path_label, BorderLayout.WEST);
325 library_path_pane.add(library_path_field, BorderLayout.CENTER);
326
327 if (Gatherer.isGsdlRemote) {
328 gliserver_url_pane.setLayout(new BorderLayout());
329 gliserver_url_pane.add(gliserver_url_label, BorderLayout.WEST);
330 gliserver_url_pane.add(gliserver_url_field, BorderLayout.CENTER);
331 }
332
333 if (Gatherer.GS3) {
334 site_pane.setLayout(new BorderLayout());
335 site_pane.add(site_label, BorderLayout.WEST);
336 site_pane.add(site_combobox, BorderLayout.CENTER);
337
338 servlet_pane.setLayout(new BorderLayout());
339 servlet_pane.add(servlet_label, BorderLayout.WEST);
340 servlet_pane.add(servlet_combobox, BorderLayout.CENTER);
341 }
342
343 proxy_host_pane.setLayout(new BorderLayout());
344 proxy_host_pane.add(proxy_host_label, BorderLayout.WEST);
345 proxy_host_pane.add(proxy_host_field, BorderLayout.CENTER);
346
347 proxy_port_pane.setLayout(new BorderLayout());
348 proxy_port_pane.add(proxy_port_label, BorderLayout.WEST);
349 proxy_port_pane.add(proxy_port_field, BorderLayout.CENTER);
350
351 connection_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
352 connection_pane.setLayout(new GridLayout(8,1,0,2));
353 connection_pane.add(program_pane);
354 connection_pane.add(library_path_pane);
355 if (Gatherer.isGsdlRemote) {
356 connection_pane.add(gliserver_url_pane);
357 }
358 if (Gatherer.GS3) {
359 connection_pane.add(site_pane);
360 connection_pane.add(servlet_pane);
361 }
362 connection_pane.add(use_proxy_checkbox);
363 connection_pane.add(proxy_host_pane);
364 connection_pane.add(proxy_port_pane);
365
366 return connection_pane;
367 }
368
369 private JPanel createGeneralPreferences() {
370 JPanel general_pane = new JPanel();
371
372 // Build the model of available languages
373 ArrayList dictionary_model = new ArrayList();
374
375 // The new method makes use of the successor to the languages.dat file, classes/xml/languages.xml
376 NodeList language_elements = LanguageManager.LANGUAGES_DOCUMENT.getDocumentElement().getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
377 for(int i = 0; i < language_elements.getLength(); i++) {
378 Element language_element = (Element) language_elements.item(i);
379 if((language_element.getAttribute(StaticStrings.GLI_ATTRIBUTE)).equalsIgnoreCase(StaticStrings.TRUE_STR) || (language_element.getAttribute(StaticStrings.MDS_ATTRIBUTE)).equalsIgnoreCase(StaticStrings.TRUE_STR)) {
380 Locale locale = new Locale(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE));
381 String description = language_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
382 DictionaryEntry entry = new DictionaryEntry(description, locale);
383 if(!dictionary_model.contains(entry)) {
384 dictionary_model.add(entry);
385 }
386 entry = null;
387 description = null;
388 locale = null;
389 }
390 language_element = null;
391 }
392 language_elements = null;
393
394 // Users email
395 JPanel email_pane = new JPanel();
396 JLabel email_label = new JLabel();
397 email_label.setPreferredSize(LABEL_SIZE);
398 Dictionary.registerText(email_label, "Preferences.General.Email");
399 email_field = new EmailField(Configuration.getColor("coloring.error_background", false));
400 email_field.setText(Configuration.getEmail());
401 Dictionary.registerTooltip(email_field, "Preferences.General.Email_Tooltip");
402
403 // Font selection
404 JPanel font_pane = new JPanel();
405 JLabel font_label = new JLabel();
406 font_label.setPreferredSize(LABEL_SIZE);
407 Dictionary.registerText(font_label, "Preferences.General.Font");
408 font_field = new JTextField(Configuration.getString("general.font", true));
409 Dictionary.registerTooltip(font_field, "Preferences.General.Font_Tooltip");
410
411 // Extracted metadata
412 view_extracted_metadata_checkbox = new JCheckBox();
413 view_extracted_metadata_checkbox.setSelected(false);
414 if (Configuration.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC)) {
415 view_extracted_metadata_checkbox.setSelected(true);
416 }
417 Dictionary.registerBoth(view_extracted_metadata_checkbox, "Preferences.General.View_Extracted_Metadata", "Preferences.General.View_Extracted_Metadata_Tooltip");
418
419 // Show file sizes
420 show_file_size_checkbox = new JCheckBox();
421 show_file_size_checkbox.setSelected(false);
422 if (Configuration.get("general.show_file_size", Configuration.COLLECTION_SPECIFIC)) {
423 show_file_size_checkbox.setSelected(true);
424 }
425 Dictionary.registerBoth(show_file_size_checkbox, "Preferences.General.Show_File_Size", "Preferences.General.Show_File_Size_Tooltip");
426
427 // Language
428 JPanel language_pane = new JPanel();
429 JLabel language_label = new JLabel();
430 language_label.setPreferredSize(LABEL_SIZE);
431 Dictionary.registerText(language_label, "Preferences.General.Interface_Language");
432 language_combobox = new JComboBox(dictionary_model.toArray());
433 Dictionary.registerTooltip(language_combobox, "Preferences.General.Interface_Language_Tooltip");
434 // Try to locate and select the current language
435 String language_code = Configuration.getLanguage();
436 for (int b = 0; b < language_combobox.getItemCount(); b++) {
437 DictionaryEntry entry = (DictionaryEntry) language_combobox.getItemAt(b);
438 if (language_code.equalsIgnoreCase(entry.getLocale().getLanguage())) {
439 language_combobox.setSelectedIndex(b);
440 break;
441 }
442 }
443
444 // Layout
445 email_pane.setLayout(new BorderLayout());
446 email_pane.add(email_label, BorderLayout.WEST);
447 email_pane.add(email_field, BorderLayout.CENTER);
448
449 language_pane.setLayout(new BorderLayout());
450 language_pane.add(language_label, BorderLayout.WEST);
451 language_pane.add(language_combobox, BorderLayout.CENTER);
452
453 font_pane.setLayout(new BorderLayout());
454 font_pane.add(font_label, BorderLayout.WEST);
455 font_pane.add(font_field, BorderLayout.CENTER);
456
457 general_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
458 general_pane.setLayout(new GridLayout(5,1,0,5));
459 general_pane.add(email_pane);
460 general_pane.add(language_pane);
461 general_pane.add(font_pane);
462 general_pane.add(view_extracted_metadata_checkbox);
463 general_pane.add(show_file_size_checkbox);
464
465 return general_pane;
466 }
467
468 /** Generate the controls for altering the detail mode.
469 * @return a JPanel of controls
470 */
471 private JPanel createModePreferences() {
472 // Create Controls
473 JPanel mode_panel = new JPanel();
474 JPanel button_panel = new JPanel();
475 ButtonGroup mode_button_group = new ButtonGroup();
476 assistant_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Assistant"));
477 assistant_mode_radio_button.setOpaque(false);
478 mode_button_group.add(assistant_mode_radio_button);
479 expert_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Expert"));
480 expert_mode_radio_button.setOpaque(false);
481 mode_button_group.add(expert_mode_radio_button);
482 librarian_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Librarian"));
483 librarian_mode_radio_button.setOpaque(false);
484 mode_button_group.add(librarian_mode_radio_button);
485 systems_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Systems"));
486 systems_mode_radio_button.setOpaque(false);
487 mode_button_group.add(systems_mode_radio_button);
488 mode_description_textarea = new JTextArea();
489 mode_description_textarea.setEditable(false);
490 mode_description_textarea.setLineWrap(true);
491 mode_description_textarea.setWrapStyleWord(true);
492 // Determine which value is already selected
493 switch(Configuration.getMode()) {
494 case Configuration.ASSISTANT_MODE:
495 assistant_mode_radio_button.setSelected(true);
496 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
497 break;
498 case Configuration.SYSTEMS_MODE:
499 systems_mode_radio_button.setSelected(true);
500 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));
501 break;
502 case Configuration.EXPERT_MODE:
503 expert_mode_radio_button.setSelected(true);
504 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
505 break;
506 default:
507 librarian_mode_radio_button.setSelected(true);
508 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
509 }
510 // Connection - when a radio button is selected we have to change the description
511 ModeRadioButtonListener listener = new ModeRadioButtonListener();
512 assistant_mode_radio_button.addActionListener(listener);
513 expert_mode_radio_button.addActionListener(listener);
514 librarian_mode_radio_button.addActionListener(listener);
515 systems_mode_radio_button.addActionListener(listener);
516 listener = null;
517 // Layout
518 button_panel.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
519 button_panel.setLayout(new GridLayout(4,1,2,2));
520 button_panel.add(assistant_mode_radio_button);
521 button_panel.add(librarian_mode_radio_button);
522 button_panel.add(systems_mode_radio_button);
523 button_panel.add(expert_mode_radio_button);
524
525 mode_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
526 mode_panel.setLayout(new BorderLayout());
527 mode_panel.add(button_panel, BorderLayout.NORTH);
528 mode_panel.add(new JScrollPane(mode_description_textarea), BorderLayout.CENTER);
529
530 return mode_panel;
531 }
532
533
534 /** The warning preferences are controlled through a checklist. */
535 private JPanel createWarningPreferences()
536 {
537 warning_preferences_check_list = new CheckList(false);
538
539 // Read all the warnings from the general xml/config.xml file, and their values from the user config.xml file
540 Document general_config_xml_file_document = XMLTools.parseXMLFile("xml/config.xml", true);
541 NodeList argument_elements_nodelist = general_config_xml_file_document.getDocumentElement().getElementsByTagName("Argument");
542 for (int i = 0; i < argument_elements_nodelist.getLength(); i++) {
543 Element argument_element = (Element) argument_elements_nodelist.item(i);
544 String argument_element_name = argument_element.getAttribute("name");
545 if (argument_element_name.startsWith("warning.")) {
546 String warning_title = Dictionary.get(argument_element_name.substring("warning.".length()) + ".Title");
547 boolean warning_enabled = Configuration.get(argument_element_name, true);
548 CheckListEntry warning_entry = new CheckListEntry(warning_title, warning_enabled);
549 warning_entry.setProperty(argument_element_name);
550 warning_preferences_check_list.addEntry(warning_entry);
551 }
552 }
553
554 JPanel warning_preferences_pane = new JPanel();
555 warning_preferences_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
556 warning_preferences_pane.setLayout(new BorderLayout());
557 warning_preferences_pane.add(new JScrollPane(warning_preferences_check_list), BorderLayout.CENTER);
558 return warning_preferences_pane;
559 }
560
561
562 private JPanel createWorkflowPreferences() {
563 // Read in the predefined configurations file
564 Vector predefined = new Vector();
565 Document predefined_document = XMLTools.parseXMLFile("xml/workflows.xml", true);
566 Element predefined_element = predefined_document.getDocumentElement();
567 NodeList workflow_elements = predefined_element.getElementsByTagName("Workflow");
568 for(int i = 0; i < workflow_elements.getLength(); i++) {
569 predefined.add(new WorkflowElementWrapper((Element)workflow_elements.item(i)));
570 }
571
572 // Creation
573 JPanel workflow_preferences_pane = new JPanel();
574 JPanel checklist_pane = new JPanel();
575 JLabel title_label = new JLabel();
576 title_label.setPreferredSize(ROW_SIZE);
577 Dictionary.registerText(title_label, "Preferences.Workflow.Title");
578
579 workflow_download = new JCheckBox();
580 workflow_download.setSelected(Configuration.get("workflow.download", false));
581 workflow_download.setPreferredSize(ROW_SIZE);
582 Dictionary.registerText(workflow_download, "Preferences.Workflow.Download");
583
584 workflow_gather = new JCheckBox();
585 workflow_gather.setSelected(Configuration.get("workflow.gather", false));
586 workflow_gather.setPreferredSize(ROW_SIZE);
587 Dictionary.registerText(workflow_gather, "Preferences.Workflow.Gather");
588
589 workflow_enrich = new JCheckBox();
590 workflow_enrich.setSelected(Configuration.get("workflow.enrich", false));
591 workflow_enrich.setPreferredSize(ROW_SIZE);
592 Dictionary.registerText(workflow_enrich, "Preferences.Workflow.Enrich");
593
594 workflow_design = new JCheckBox();
595 workflow_design.setSelected(Configuration.get("workflow.design", false));
596 workflow_design.setPreferredSize(ROW_SIZE);
597 Dictionary.registerText(workflow_design, "Preferences.Workflow.Design");
598
599 workflow_create = new JCheckBox();
600 workflow_create.setSelected(Configuration.get("workflow.create", false));
601 workflow_create.setPreferredSize(ROW_SIZE);
602 Dictionary.registerText(workflow_create, "Preferences.Workflow.Create");
603
604 JPanel predefined_pane = new JPanel();
605 JLabel predefined_label = new JLabel();
606 Dictionary.registerText(predefined_label, "Preferences.Workflow.Predefined.Label");
607 JComboBox predefined_combobox = new JComboBox(predefined);
608
609 // Connection
610 predefined_combobox.addActionListener(new PredefinedActionListener());
611
612 // Layout
613 checklist_pane.setLayout(new BoxLayout(checklist_pane, BoxLayout.Y_AXIS));
614 checklist_pane.add(title_label);
615 if (Configuration.get("workflow.download", true)) {
616 checklist_pane.add(workflow_download);
617 }
618 if (Configuration.get("workflow.gather", true)) {
619 checklist_pane.add(workflow_gather);
620 }
621 if (Configuration.get("workflow.enrich", true)) {
622 checklist_pane.add(workflow_enrich);
623 }
624 if (Configuration.get("workflow.design", true)) {
625 checklist_pane.add(workflow_design);
626 }
627 if (Configuration.get("workflow.create", true)) {
628 checklist_pane.add(workflow_create);
629 }
630
631 predefined_pane.setLayout(new BorderLayout(5,0));
632 predefined_pane.add(predefined_label, BorderLayout.WEST);
633 predefined_pane.add(predefined_combobox, BorderLayout.CENTER);
634
635 workflow_preferences_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
636 workflow_preferences_pane.setLayout(new BorderLayout());
637 workflow_preferences_pane.add(checklist_pane, BorderLayout.CENTER);
638 workflow_preferences_pane.add(predefined_pane, BorderLayout.SOUTH);
639
640 return workflow_preferences_pane;
641 }
642
643
644 private class OKButtonListener
645 implements ActionListener {
646 private boolean close;
647 public OKButtonListener(boolean close) {
648 this.close = close;
649 }
650 public void actionPerformed(ActionEvent event)
651 {
652 // Connection preferences
653 String program_str = program_field.getText();
654 if (program_str.length() > 0 && program_str.indexOf("%1") == -1) {
655 program_str = program_str + " %1";
656 }
657 Configuration.setPreviewCommand(program_str);
658
659 String library_url_string = library_path_field.getText();
660 if (library_url_string.equals("")) {
661 Configuration.library_url = null;
662 }
663 else {
664 try {
665 Configuration.library_url = new URL(library_url_string);
666 }
667 catch (MalformedURLException exception) {
668 DebugStream.printStackTrace(exception);
669 }
670 }
671 Configuration.setString("general.library_url", true, library_url_string);
672
673 if (Gatherer.isGsdlRemote) {
674 String gliserver_url_string = gliserver_url_field.getText();
675 if (gliserver_url_string.equals("")) {
676 Configuration.gliserver_url = null;
677 }
678 else {
679 try {
680 Configuration.gliserver_url = new URL(gliserver_url_string);
681 }
682 catch (MalformedURLException exception) {
683 DebugStream.printStackTrace(exception);
684 }
685 }
686 Configuration.setString("general.gliserver_url", true, gliserver_url_string);
687 }
688
689 boolean site_changed = false;
690 if (Gatherer.GS3) {
691 String current_site = Configuration.site_name;
692 String new_site =(String)site_combobox.getSelectedItem() ;
693 if (!new_site.equals(current_site)) {
694 site_changed = true;
695 }
696 Configuration.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem());
697 }
698
699 Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
700 Configuration.setString("general.proxy_host", true, proxy_host_field.getText());
701 Configuration.setString("general.proxy_port", true, proxy_port_field.getValue() + "");
702 Gatherer.setProxy();
703
704 // General preferences
705 Configuration.setEmail(email_field.getText());
706 Configuration.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, show_file_size_checkbox.isSelected());
707 Configuration.set("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC, view_extracted_metadata_checkbox.isSelected());
708
709 // Two options requiring restarting the GLI to apply: interface font, and interface language
710 boolean restart_required = false;
711
712 // GLI interface font
713 String current_font = Configuration.getString("general.font", true);
714 if (!current_font.equals(font_field.getText())) {
715 Configuration.setString("general.font", true, font_field.getText());
716 restart_required = true;
717 }
718
719 // GLI interface language
720 String current_lang = Configuration.getLanguage();
721 if (!current_lang.equals(((DictionaryEntry) language_combobox.getSelectedItem()).getLocale().getLanguage())) {
722 Configuration.setLocale("general.locale", Configuration.GENERAL_SETTING, ((DictionaryEntry) language_combobox.getSelectedItem()).getLocale());
723 restart_required = true;
724
725 // Delete the plugins.dat and classifiers.dat files
726 PluginManager.clearPluginCache();
727 ClassifierManager.clearClassifierCache();
728 }
729
730 // Inform the user that a restart is required, if necessary
731 if (restart_required) {
732 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Preferences.General.Restart_Required"), Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE);
733 }
734
735 // Mode preferences
736 int current_mode = Configuration.getMode();
737 int new_mode;
738 if (assistant_mode_radio_button.isSelected()) {
739 new_mode = Configuration.ASSISTANT_MODE;
740 }
741 else if (systems_mode_radio_button.isSelected()) {
742 new_mode = Configuration.SYSTEMS_MODE;
743 }
744 else if (expert_mode_radio_button.isSelected()) {
745 new_mode = Configuration.EXPERT_MODE;
746 }
747 else {
748 new_mode = Configuration.LIBRARIAN_MODE;
749 }
750
751 // If there has been a change in modes, update the config, and also inform the persistant gui views that have a need to know
752 if (new_mode != current_mode) {
753 Configuration.setMode(new_mode);
754 Collection collection = Gatherer.c_man.getCollection();
755 if (collection != null) {
756 collection.cdm.modeChanged(new_mode);
757 }
758 Gatherer.g_man.modeChanged(new_mode);
759 }
760
761 // Warning preferences
762 ListModel warning_preferences_check_list_model = warning_preferences_check_list.getModel();
763 for (int i = 0; i < warning_preferences_check_list_model.getSize(); i++) {
764 CheckListEntry entry = (CheckListEntry) warning_preferences_check_list_model.getElementAt(i);
765 Configuration.set(entry.getProperty(), true, entry.isSelected());
766 }
767
768 if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection() != null) {
769 // shut down the collection
770 System.err.println("shutting down teh collection");
771 Gatherer.g_man.saveThenCloseCurrentCollection();
772 }
773
774 // Workflow preferences
775 Configuration.set("workflow.download", false, workflow_download.isSelected());
776 Configuration.set("workflow.gather", false, workflow_gather.isSelected());
777 Configuration.set("workflow.enrich", false, workflow_enrich.isSelected());
778 Configuration.set("workflow.design", false, workflow_design.isSelected());
779 Configuration.set("workflow.create", false, workflow_create.isSelected());
780 Gatherer.g_man.workflowUpdate("Download", workflow_download.isSelected());
781 Gatherer.g_man.workflowUpdate("Gather", workflow_gather.isSelected());
782 Gatherer.g_man.workflowUpdate("Enrich", workflow_enrich.isSelected());
783 Gatherer.g_man.workflowUpdate("Design", (workflow_design.isSelected() && Configuration.getMode() > Configuration.ASSISTANT_MODE));
784 Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());
785
786 // Always save configuration changes immediately (in case the GLI crashes)
787 Configuration.save();
788
789 // Refresh the GLI to account for the configuration changes
790 Gatherer.refresh(Gatherer.PREFERENCES_CHANGED);
791
792 // Hide dialog
793 if (close) {
794 self.dispose();
795 }
796 }
797 }
798
799 private class CancelButtonListener
800 implements ActionListener {
801 public void actionPerformed(ActionEvent event) {
802 self.dispose();
803 }
804 }
805
806 private class DictionaryEntry
807 implements Comparable {
808 private Locale locale;
809 private String description;
810 public DictionaryEntry(Locale locale) {
811 this.description = null;
812 this.locale = locale;
813 }
814 public DictionaryEntry(String description, Locale locale) {
815 this.description = description;
816 this.locale = locale;
817 }
818 public int compareTo(Object object) {
819 return toString().compareTo(object.toString());
820 }
821 public boolean equals(Object object) {
822 return toString().equals(object.toString());
823 }
824 public Locale getLocale() {
825 return locale;
826 }
827 public String toString() {
828 if(description != null) {
829 return description;
830 }
831 else {
832 return locale.getDisplayName();
833 }
834 }
835 }
836
837 /** This listener updates the mode description depending on what mode is selected. */
838 private class ModeRadioButtonListener
839 implements ActionListener {
840 public void actionPerformed(ActionEvent event) {
841 Object source = event.getSource();
842 if(source == assistant_mode_radio_button) {
843 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
844 }
845 else if(source == expert_mode_radio_button) {
846 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
847 }
848 else if(source == systems_mode_radio_button) {
849 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));
850 }
851 else {
852 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
853 }
854 source = null;
855 }
856 }
857
858 private class PredefinedActionListener
859 implements ActionListener {
860 public void actionPerformed(ActionEvent event) {
861 JComboBox cb = (JComboBox) event.getSource();
862 WorkflowElementWrapper element = (WorkflowElementWrapper) cb.getSelectedItem();
863 CheckboxUpdater task = new CheckboxUpdater(element);
864 SwingUtilities.invokeLater(task);
865 }
866
867 private class CheckboxUpdater
868 implements Runnable {
869 private WorkflowElementWrapper element;
870 public CheckboxUpdater(WorkflowElementWrapper element) {
871 this.element = element;
872 }
873 public void run() {
874 workflow_download.setSelected(element.getEnabled("download"));
875 workflow_gather.setSelected(element.getEnabled("gather"));
876 workflow_enrich.setSelected(element.getEnabled("enrich"));
877 workflow_design.setSelected(element.getEnabled("design"));
878 workflow_create.setSelected(element.getEnabled("create"));
879 }
880 }
881 }
882
883
884 private class SiteComboboxListener
885 implements ActionListener {
886 private boolean ignore_event=false;
887 public void actionPerformed(ActionEvent event) {
888 System.err.println("event occurred "+event.paramString());
889 String site = (String) site_combobox.getSelectedItem();
890 System.err.println("new site = "+site);
891 if (!site.equals(current_site_selection)) {
892 current_site_selection = site;
893 System.err.println("changed the current selection");
894 ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);
895 if (servlet_options == null) {
896 System.err.println("no servlets for this site");
897 servlet_combobox.setModel(new DefaultComboBoxModel());
898 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip2");
899 servlet_combobox.setEnabled(false);
900
901 } else {
902 System.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
903 servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
904 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip");
905 servlet_combobox.setEnabled(true);
906 }
907 }
908 }
909 }
910
911 private class UseProxyListener
912 implements ActionListener {
913 public void actionPerformed(ActionEvent event) {
914 boolean enabled = use_proxy_checkbox.isSelected();
915 Configuration.set("general.use_proxy", true, enabled);
916 // Fortunately this is already driven by the event thread.
917 proxy_host_field.setEnabled(enabled);
918 proxy_port_field.setEnabled(enabled);
919 }
920 }
921
922 private class WorkflowElementWrapper {
923 private Element element;
924 private String text;
925 public WorkflowElementWrapper(Element element) {
926 this.element = element;
927 }
928 public boolean getEnabled(String name) {
929 boolean result = true;
930 if(element.getAttribute(name).equalsIgnoreCase("false")) {
931 result = false;
932 }
933 return result;
934 }
935 public String toString() {
936 if (text == null) {
937 text = Dictionary.get(element.getFirstChild().getNodeValue());
938 }
939 return text;
940 }
941 }
942}
Note: See TracBrowser for help on using the repository browser.