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

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

When GS is local, it will use library_url_gs3 or library_url_gs2 and similarly open_collection_gs3 or open_collection_gs2 properties from the config file. (It still uses the default library_url and open_collection when GS is remote or if GLI is used with Fedora.) Method Configuration.gliPropertyNameSuffix() is added to return either the empty string or _gs2 or _gs3 in order to work out the property name in the situation. This change helps when running local GS2 and GS3 alternatively with GLI, as it preserves the library url and last opened collection for each separately.

  • Property svn:keywords set to Author Date Id Revision
File size: 38.6 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 // Connection preferences
653 String program_str = program_field.getText();
654 if (program_str.length() > 0 && program_str.indexOf("%1") == -1) {
655 program_str = program_str + " %1";
656 }
657 Configuration.setPreviewCommand(program_str);
658
659 String library_url_string = library_path_field.getText();
660 if (library_url_string.equals("")) {
661 Configuration.library_url = null;
662 }
663 else {
664 try {
665 Configuration.library_url = new URL(library_url_string);
666 }
667 catch (MalformedURLException exception) {
668 DebugStream.printStackTrace(exception);
669 }
670 }
671
672 Configuration.setString("general.library_url"+Configuration.gliPropertyNameSuffix(),
673 true, library_url_string);
674
675 if (Gatherer.isGsdlRemote && !Gatherer.GS3) {
676 String gliserver_url_string = gliserver_url_field.getText();
677 if (gliserver_url_string.equals("")) {
678 Configuration.gliserver_url = null;
679 }
680 else {
681 try {
682 Configuration.gliserver_url = new URL(gliserver_url_string);
683 }
684 catch (MalformedURLException exception) {
685 DebugStream.printStackTrace(exception);
686 }
687 }
688 Configuration.setString("general.gliserver_url", true, gliserver_url_string);
689 }
690
691 boolean site_changed = false;
692 if (Gatherer.GS3) {
693 String current_site = Configuration.site_name;
694 String new_site =(String)site_combobox.getSelectedItem() ;
695 if (!new_site.equals(current_site)) {
696 site_changed = true;
697 }
698 Configuration.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem());
699 }
700
701 Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
702 Configuration.setString("general.proxy_host", true, proxy_host_field.getText());
703 Configuration.setString("general.proxy_port", true, proxy_port_field.getValue() + "");
704 Gatherer.setProxy();
705
706 // General preferences
707 Configuration.setEmail(email_field.getText());
708 Configuration.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, show_file_size_checkbox.isSelected());
709 Configuration.set("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC, view_extracted_metadata_checkbox.isSelected());
710
711 // Two options requiring restarting the GLI to apply: interface font, and interface language
712 boolean restart_required = false;
713
714 // GLI interface font
715 String current_font = Configuration.getString("general.font", true);
716 if (!current_font.equals(font_field.getText())) {
717 Configuration.setString("general.font", true, font_field.getText());
718 restart_required = true;
719 }
720
721 // GLI interface language
722 String current_lang = Configuration.getLanguage();
723 if (!current_lang.equals(((DictionaryEntry) language_combobox.getSelectedItem()).getLocale().getLanguage())) {
724 Configuration.setLocale("general.locale", Configuration.GENERAL_SETTING, ((DictionaryEntry) language_combobox.getSelectedItem()).getLocale());
725 restart_required = true;
726 }
727
728 // Inform the user that a restart is required, if necessary
729 if (restart_required) {
730 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Preferences.General.Restart_Required"), Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE);
731 }
732
733 // Mode preferences
734 int current_mode = Configuration.getMode();
735 int new_mode;
736 if (assistant_mode_radio_button.isSelected()) {
737 new_mode = Configuration.ASSISTANT_MODE;
738 }
739 else if (systems_mode_radio_button.isSelected()) {
740 new_mode = Configuration.SYSTEMS_MODE;
741 }
742 else if (expert_mode_radio_button.isSelected()) {
743 new_mode = Configuration.EXPERT_MODE;
744 }
745 else {
746 new_mode = Configuration.LIBRARIAN_MODE;
747 }
748
749 // If there has been a change in modes, update the config, and also inform the persistant gui views that have a need to know
750 if (new_mode != current_mode) {
751 Configuration.setMode(new_mode);
752 Collection collection = Gatherer.c_man.getCollection();
753 if (collection != null) {
754 collection.cdm.modeChanged(new_mode);
755 }
756 Gatherer.g_man.modeChanged(new_mode);
757 }
758
759 // Warning preferences
760 ListModel warning_preferences_check_list_model = warning_preferences_check_list.getModel();
761 for (int i = 0; i < warning_preferences_check_list_model.getSize(); i++) {
762 CheckListEntry entry = (CheckListEntry) warning_preferences_check_list_model.getElementAt(i);
763 Configuration.set(entry.getProperty(), true, entry.isSelected());
764 }
765
766 if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection() != null && !Gatherer.isGsdlRemote) {
767 // shut down the collection
768 System.err.println("shutting down teh collection");
769 Gatherer.g_man.saveThenCloseCurrentCollection();
770 }
771
772 // Workflow preferences
773// Configuration.set("workflow.download", false, workflow_download.isSelected());
774// Configuration.set("workflow.gather", false, workflow_gather.isSelected());
775// Configuration.set("workflow.enrich", false, workflow_enrich.isSelected());
776// Configuration.set("workflow.design", false, workflow_design.isSelected());
777// Configuration.set("workflow.create", false, workflow_create.isSelected());
778// Configuration.set("workflow.format", false, workflow_format.isSelected());
779
780// Gatherer.g_man.workflowUpdate("Download", workflow_download.isSelected());
781// Gatherer.g_man.workflowUpdate("Gather", workflow_gather.isSelected());
782// Gatherer.g_man.workflowUpdate("Enrich", workflow_enrich.isSelected());
783// Gatherer.g_man.workflowUpdate("Design", (workflow_design.isSelected() && Configuration.getMode() > Configuration.ASSISTANT_MODE));
784// Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());
785// Gatherer.g_man.workflowUpdate("Format", workflow_format.isSelected());
786
787 // Always save configuration changes immediately (in case the GLI crashes)
788 Configuration.save();
789 if (Gatherer.isGsdlRemote && Gatherer.GS3 && site_changed ){
790 RemoteGreenstoneServer.downloadCollectionConfigurations();
791 }
792 // Refresh the GLI to account for the configuration changes
793 Gatherer.refresh(Gatherer.PREFERENCES_CHANGED);
794
795 // Hide dialog
796 if (close) {
797 self.dispose();
798 }
799
800 if (restart_required) {
801 Gatherer.g_man.exit(Gatherer.EXIT_THEN_RESTART);
802 }
803 }
804 }
805
806 private class CancelButtonListener
807 implements ActionListener {
808 public void actionPerformed(ActionEvent event) {
809 self.dispose();
810 }
811 }
812
813 private class DictionaryEntry
814 implements Comparable {
815 private Locale locale;
816 private String description;
817 public DictionaryEntry(Locale locale) {
818 this.description = null;
819 this.locale = locale;
820 }
821 public DictionaryEntry(String description, Locale locale) {
822 this.description = description;
823 this.locale = locale;
824 }
825 public int compareTo(Object object) {
826 return toString().compareTo(object.toString());
827 }
828 public boolean equals(Object object) {
829 return toString().equals(object.toString());
830 }
831 public Locale getLocale() {
832 return locale;
833 }
834 public String toString() {
835 if(description != null) {
836 return description;
837 }
838 else {
839 return locale.getDisplayName();
840 }
841 }
842 }
843
844 /** This listener updates the mode description depending on what mode is selected. */
845 private class ModeRadioButtonListener
846 implements ActionListener {
847 public void actionPerformed(ActionEvent event) {
848 Object source = event.getSource();
849 if(source == assistant_mode_radio_button) {
850 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
851 }
852 else if(source == expert_mode_radio_button) {
853 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
854 }
855 else if(source == systems_mode_radio_button) {
856 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));
857 }
858 else {
859 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
860 }
861 source = null;
862 }
863 }
864
865 private class PredefinedActionListener
866 implements ActionListener {
867 public void actionPerformed(ActionEvent event) {
868 JComboBox cb = (JComboBox) event.getSource();
869 WorkflowElementWrapper element = (WorkflowElementWrapper) cb.getSelectedItem();
870 CheckboxUpdater task = new CheckboxUpdater(element);
871 SwingUtilities.invokeLater(task);
872 }
873
874 private class CheckboxUpdater
875 implements Runnable {
876 private WorkflowElementWrapper element;
877 public CheckboxUpdater(WorkflowElementWrapper element) {
878 this.element = element;
879 }
880 public void run() {
881 workflow_download.setSelected(element.getEnabled("download"));
882 workflow_gather.setSelected(element.getEnabled("gather"));
883 workflow_enrich.setSelected(element.getEnabled("enrich"));
884 workflow_design.setSelected(element.getEnabled("design"));
885 workflow_create.setSelected(element.getEnabled("create"));
886 workflow_format.setSelected(element.getEnabled("format"));
887 }
888 }
889 }
890
891
892 private class SiteComboboxListener
893 implements ActionListener {
894 private boolean ignore_event=false;
895 public void actionPerformed(ActionEvent event) {
896 System.err.println("event occurred "+event.paramString());
897 String site = (String) site_combobox.getSelectedItem();
898 System.err.println("The site changed to = "+site);
899 if (!site.equals(current_site_selection)) {
900 current_site_selection = site;
901 System.err.println("changed the current selection");
902
903 ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);
904 if (servlet_options == null) {
905 ///ystem.err.println("no servlets for this site");
906 servlet_combobox.setModel(new DefaultComboBoxModel());
907 servlet_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Servlet_Tooltip2"));
908 servlet_combobox.setEnabled(false);
909
910 } else {
911 ///ystem.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
912 servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
913 servlet_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Servlet_Tooltip"));
914 servlet_combobox.setEnabled(true);
915 }
916 if (Gatherer.isGsdlRemote){
917 // Close the current collection, remove the lock on this file, ask to login to the new site, then download collection configurations of the site.
918 if (Gatherer.c_man.getCollection()!=null){
919 File lock_file = new File(Gatherer.c_man.getLoadedCollectionDirectoryPath() + "gli.lck");
920 RemoteGreenstoneServer.deleteCollectionFile(Gatherer.c_man.getLoadedCollectionName(),lock_file);
921 Gatherer.g_man.closeCurrentCollection();
922 }
923 Configuration.site_name=site;
924 RemoteGreenstoneServer.set_remote_greenstone_server_authentication_to_null();
925 RemoteGreenstoneServer.downloadCollectionConfigurations();
926 }
927 }
928 }
929 }
930
931 private class UseProxyListener
932 implements ActionListener {
933 public void actionPerformed(ActionEvent event) {
934 boolean enabled = use_proxy_checkbox.isSelected();
935 Configuration.set("general.use_proxy", true, enabled);
936 // Fortunately this is already driven by the event thread.
937 proxy_host_field.setEnabled(enabled);
938 proxy_port_field.setEnabled(enabled);
939 }
940 }
941
942 private class WorkflowElementWrapper {
943 private Element element;
944 private String text;
945 public WorkflowElementWrapper(Element element) {
946 this.element = element;
947 }
948 public boolean getEnabled(String name) {
949 boolean result = true;
950 if(element.getAttribute(name).equalsIgnoreCase("false")) {
951 result = false;
952 }
953 return result;
954 }
955 public String toString() {
956 if (text == null) {
957 text = Dictionary.get(element.getFirstChild().getNodeValue());
958 }
959 return text;
960 }
961 }
962}
Note: See TracBrowser for help on using the repository browser.