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

Last change on this file since 12633 was 12633, checked in by mdewsnip, 18 years ago

Kissed the horrible old plugins.dat and classifiers.dat files goodbye...

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