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

Last change on this file since 17353 was 17353, checked in by ak19, 16 years ago

Fixed NPE that is thrown when the old_library_url was null

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