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

Last change on this file since 14371 was 14371, checked in by qq6, 17 years ago

if the loaded collection is not null,delete the gli.lck file when the current site is changed in the remote gli3

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