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

Last change on this file since 11181 was 10726, checked in by mdewsnip, 19 years ago

(MAJOR CHANGE) This is the remote Greenstone building functionality implemented for the West Yorkshire Fire and Rescue Service. It allows collections to be built without having a local version of Greenstone, using either a stand-alone version of the GLI or the applet.

The collections are stored on the server (allowing people to collaborate on collections -- but not at the same time), and only what is necessary to let the user edit the collection is downloaded. Any changes to the collection are uploaded to the server.

An access restriction mechanism is implemented which uses the standard Greenstone user database to control who has access to collections.

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