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

Last change on this file since 32706 was 32706, checked in by ak19, 5 years ago

Committing the non-EDT related changes to GLI. More changes to setNamesRecursively: for GLI GUI buttons (class GLIButton) these are still standalone rather than compound widgets that contain further widgets within them. So want to set names of GLIButtons (and JButtons) to be their container-class.GLIButton.button-membervar-name. 2. Preferences dialog nulls member handles to important widgets whose names I want to set before the widget is even made visible. In testing mode, I want to prevent these from being set to null so I can set their names in order to access them.

  • Property svn:keywords set to Author Date Id Revision
File size: 53.2 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 HTTP = "HTTP";
59 static final public String HTTPS = "HTTPS";
60 static final public String FTP = "FTP";
61
62 static final public String CONNECTION_PREFS = "connection";
63 static final public String GENERAL_PREFS = "general";
64
65 static final private Dimension LABEL_SIZE = new Dimension(280, 25);
66 static final private Dimension ROW_SIZE = new Dimension(640, 25);
67 static final private Dimension SIZE = new Dimension(640, 345);
68 static final private String TRUE = "true";
69
70 private CheckList warning_preferences_check_list;
71 private EmailField email_field;
72 private JButton apply_button;
73 private JButton cancel_button;
74 private JButton chdir_button;
75 private JButton ok_button;
76 private JCheckBox show_file_size_checkbox;
77 private JCheckBox no_check_certificate_checkbox; // Set no_check_certificate when retrieving https URLs that have no (valid) certificate
78 private JCheckBox use_proxy_checkbox;
79 private JCheckBox view_extracted_metadata_checkbox;
80 private JCheckBox workflow_download;
81 private JCheckBox workflow_gather;
82 private JCheckBox workflow_enrich;
83 private JCheckBox workflow_design;
84 private JCheckBox workflow_create;
85 private JCheckBox workflow_format;
86 private JComboBox language_combobox;
87 private JComboBox servlet_combobox; // GS3
88 private JComboBox site_combobox; // GS3
89 private JRadioButton assistant_mode_radio_button;
90 private JRadioButton expert_mode_radio_button;
91 private JRadioButton librarian_mode_radio_button;
92 private JSpinner http_proxy_port_field;
93 private JSpinner https_proxy_port_field;
94 private JSpinner ftp_proxy_port_field;
95 private JTabbedPane tab_pane;
96 private JTextArea mode_description_textarea;
97 private JTextField font_field;
98 private JTextField gliserver_url_field;
99 private JTextField library_path_field;
100 private JTextField program_field;
101 private JTextField http_proxy_host_field;
102 private JTextField https_proxy_host_field;
103 private JTextField ftp_proxy_host_field;
104 private JTextField collect_dir_field;
105
106 private Preferences self;
107
108 private String current_site_selection;
109
110 public Preferences() {
111 this(GENERAL_PREFS);
112 }
113
114 public Preferences(String initial_view) {
115 // Initialize
116 super(Gatherer.g_man, true);
117 this.self = this;
118 setSize(SIZE);
119 setTitle(Dictionary.get("Preferences"));
120 setJMenuBar(new SimpleMenuBar("preferences"));
121
122 // Creation
123 JPanel content_pane = (JPanel) getContentPane();
124 content_pane.setComponentOrientation(Dictionary.getOrientation());
125 tab_pane = new JTabbedPane();
126 tab_pane.setComponentOrientation(Dictionary.getOrientation());
127 JPanel general_preferences = createGeneralPreferences();
128 general_preferences.setComponentOrientation(Dictionary.getOrientation());
129 tab_pane.addTab(Dictionary.get("Preferences.General"), null, general_preferences, Dictionary.get("Preferences.General_Tooltip"));
130 tab_pane.addTab(Dictionary.get("Preferences.Mode"), null, createModePreferences(), Dictionary.get("Preferences.Mode_Tooltip"));
131 // tab_pane.addTab(Dictionary.get("Preferences.Workflow"), null, createWorkflowPreferences(), Dictionary.get("Preferences.Workflow_Tooltip"));
132 JPanel connection_preferences = createConnectionPreferences();
133 connection_preferences.setComponentOrientation(Dictionary.getOrientation());
134 tab_pane.addTab(Dictionary.get("Preferences.Connection"), null, connection_preferences, Dictionary.get("Preferences.Connection_Tooltip"));
135 tab_pane.addTab(Dictionary.get("Preferences.Warnings"), null, createWarningPreferences(), Dictionary.get("Preferences.Warnings_Tooltip"));
136
137 JPanel button_pane = new JPanel();
138 button_pane.setComponentOrientation(Dictionary.getOrientation());
139 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
140
141 apply_button = new GLIButton(Dictionary.get("General.Apply"), Dictionary.get("General.Apply_Tooltip"));
142
143 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
144
145 // Connection
146 ok_button.addActionListener(new OKButtonListener(true));
147 apply_button.addActionListener(new OKButtonListener(false));
148 cancel_button.addActionListener(new CancelButtonListener());
149
150 // Layout
151 button_pane.setBorder(BorderFactory.createEmptyBorder(5,2,2,2));
152 button_pane.setLayout(new GridLayout(1,3,0,5));
153 button_pane.add(ok_button);
154 button_pane.add(apply_button);
155 button_pane.add(cancel_button);
156 button_pane.setComponentOrientation(Dictionary.getOrientation());
157
158 content_pane.setLayout(new BorderLayout());
159 content_pane.add(tab_pane, BorderLayout.CENTER);
160 content_pane.add(button_pane, BorderLayout.SOUTH);
161 content_pane.setComponentOrientation(Dictionary.getOrientation());
162
163 Dimension frame_size = Gatherer.g_man.getSize();
164 Point frame_location = Gatherer.g_man.getLocation();
165 setLocation(((frame_size.width - SIZE.width) / 2), ((frame_size.height - SIZE.height)));
166
167 // Bring the desired pane to the fore
168 if (initial_view.equals(CONNECTION_PREFS)) {
169 tab_pane.setSelectedComponent(connection_preferences);
170 }
171 else {
172 tab_pane.setSelectedComponent(general_preferences);
173 }
174
175 // Clean up if not in GLI GUI test mode
176 // If in test mode, I need widgets like tab_pane and buttons to exist
177 if(!TestingPreparation.TEST_MODE) {
178 general_preferences = null;
179 connection_preferences = null;
180 frame_location = null;
181 frame_size = null;
182 cancel_button = null;
183 ok_button = null;
184 button_pane = null;
185 tab_pane = null;
186 content_pane = null;
187 }
188
189 TestingPreparation.setNamesRecursively(this);
190
191 setVisible(true);
192 }
193
194 private JPanel createConnectionPreferences() {
195 JPanel program_pane = new JPanel();
196 program_pane.setComponentOrientation(Dictionary.getOrientation());
197 program_pane.setPreferredSize(ROW_SIZE);
198 JLabel program_label = new JLabel(Dictionary.get("Preferences.Connection.ProgramCommand"));
199 program_label.setPreferredSize(LABEL_SIZE);
200 program_label.setComponentOrientation(Dictionary.getOrientation());
201
202 program_field = new JTextField(Configuration.getPreviewCommand());
203 program_field.setCaretPosition(0);
204 program_field.setToolTipText(Dictionary.get("Preferences.Connection.ProgramCommand_Tooltip"));
205 program_field.setComponentOrientation(Dictionary.getOrientation());
206
207 JPanel library_path_pane = new JPanel();
208 library_path_pane.setPreferredSize(ROW_SIZE);
209 library_path_pane.setComponentOrientation(Dictionary.getOrientation());
210 JLabel library_path_label = new JLabel();
211 library_path_label.setPreferredSize(LABEL_SIZE);
212 library_path_label.setComponentOrientation(Dictionary.getOrientation());
213 String library_url_string = "";
214 if (Configuration.library_url != null) {
215 library_url_string = Configuration.library_url.toString();
216 }
217 library_path_field = new JTextField(library_url_string);
218 library_path_field.setCaretPosition(0);
219 library_path_field.setComponentOrientation(Dictionary.getOrientation());
220 if (Gatherer.GS3) {
221 library_path_label.setText(Dictionary.get("Preferences.Connection.Library_Path_GS3"));
222 library_path_field.setToolTipText(Dictionary.get("Preferences.Connection.Library_Path_Tooltip_GS3"));
223 } else {
224 library_path_label.setText(Dictionary.get("Preferences.Connection.Library_Path"));
225 library_path_field.setToolTipText(Dictionary.get("Preferences.Connection.Library_Path_Tooltip"));
226 }
227
228 // Disable this field when using the applet, as it is automatically determined
229 library_path_label.setEnabled(!Gatherer.isApplet);
230 library_path_field.setEnabled(!Gatherer.isApplet);
231
232 JPanel gliserver_url_pane = null;
233 JLabel gliserver_url_label = null;
234 if (Gatherer.isGsdlRemote && !Gatherer.GS3) {
235 gliserver_url_pane = new JPanel();
236 gliserver_url_pane.setPreferredSize(ROW_SIZE);
237 gliserver_url_label = new JLabel(Dictionary.get("Preferences.Connection.GLIServer_URL"));
238 gliserver_url_label.setPreferredSize(LABEL_SIZE);
239 gliserver_url_label.setComponentOrientation(Dictionary.getOrientation());
240 String gliserver_url_string = "";
241 if (Configuration.gliserver_url != null) {
242 gliserver_url_string = Configuration.gliserver_url.toString();
243 }
244 gliserver_url_field = new JTextField(gliserver_url_string);
245 gliserver_url_field.setComponentOrientation(Dictionary.getOrientation());
246 gliserver_url_field.setCaretPosition(0);
247 gliserver_url_field.setToolTipText(Dictionary.get("Preferences.Connection.GLIServer_URL_Tooltip"));
248
249 // Disable this field when using the applet, as it is automatically determined
250 gliserver_url_label.setEnabled(!Gatherer.isApplet);
251 gliserver_url_field.setEnabled(!Gatherer.isApplet);
252 }
253
254 JPanel site_pane = null;
255 JLabel site_label = null;
256 JPanel servlet_pane = null;
257 JLabel servlet_label = null;
258 if (Gatherer.GS3) {
259 site_pane = new JPanel();
260 site_pane.setPreferredSize(ROW_SIZE);
261 site_pane.setComponentOrientation(Dictionary.getOrientation());
262 site_label = new JLabel(Dictionary.get("Preferences.Connection.Site"));
263 site_label.setPreferredSize(LABEL_SIZE);
264 site_label.setComponentOrientation(Dictionary.getOrientation());
265 // what should we do if Gatherer.servlet_config.getSites() is null?
266 site_combobox = new JComboBox(Gatherer.servlet_config.getSites().toArray());
267 site_combobox.setOpaque(false);
268 site_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Site_Tooltip"));
269 site_combobox.setComponentOrientation(Dictionary.getOrientation());
270
271 servlet_pane = new JPanel();
272 servlet_pane.setPreferredSize(ROW_SIZE);
273 servlet_pane.setComponentOrientation(Dictionary.getOrientation());
274
275 servlet_label = new JLabel(Dictionary.get("Preferences.Connection.Servlet"));
276 servlet_label.setPreferredSize(LABEL_SIZE);
277 servlet_label.setComponentOrientation(Dictionary.getOrientation());
278 servlet_combobox = new JComboBox();
279 servlet_combobox.setOpaque(false);
280 servlet_combobox.setComponentOrientation(Dictionary.getOrientation());
281 // try to locate and select the current site
282 String this_site = Configuration.site_name;
283 for(int b = 0; b < site_combobox.getItemCount(); b++) {
284 String entry = (String) site_combobox.getItemAt(b);
285 if(this_site.equals(entry)) {
286 site_combobox.setSelectedIndex(b);
287 break;
288 }
289 }
290
291 // just in case its not the current one?
292 current_site_selection = (String)site_combobox.getSelectedItem();
293
294 ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);
295 if (servlet_options == null) {
296 servlet_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Servlet_Tooltip2"));
297 //servlet_combobox.setModel(new DefaultComboBoxModel());
298 servlet_combobox.setEnabled(false);
299 } else {
300 ///ystem.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
301
302 servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
303 servlet_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Servlet_Tooltip"));
304 servlet_combobox.setEnabled(true);
305 // try to locate and select the current servlet
306 String this_servlet = Configuration.getServletPath();
307 for(int b = 0; b < servlet_combobox.getItemCount(); b++) {
308 String entry = (String) servlet_combobox.getItemAt(b);
309 if(this_servlet.equals(entry)) {
310 servlet_combobox.setSelectedIndex(b);
311 break;
312 }
313 }
314
315 }
316 }
317
318 JPanel collect_dir_pane = new JPanel();
319 collect_dir_pane.setComponentOrientation(Dictionary.getOrientation());
320 collect_dir_pane.setPreferredSize(ROW_SIZE);
321 JLabel collect_dir_label = new JLabel(Dictionary.get("Preferences.Connection.CollectDirectory"));
322 collect_dir_label.setPreferredSize(LABEL_SIZE);
323 collect_dir_label.setComponentOrientation(Dictionary.getOrientation());
324 collect_dir_field = new JTextField(Gatherer.getCollectDirectoryPath());
325 //collect_dir_field = new JTextField(Configuration.getString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true));
326 collect_dir_field.setCaretPosition(0);
327 collect_dir_field.setToolTipText(Dictionary.get("Preferences.Connection.CollectDirectory_Tooltip"));
328 collect_dir_field.setEditable(false);
329 JButton chdir_button = new GLIButton(Dictionary.get("General.CD"), Dictionary.get("General.CD_Tooltip"));
330 chdir_button.addActionListener(new ChangeDirListener());
331 if(Gatherer.isGsdlRemote) { // disable changing directories for client GLI
332 chdir_button.setEnabled(false);
333 }
334
335 boolean no_check_cert_enabled = Configuration.get("general.no_check_certificate", true); // pass true to look in general rather than collection specific config file
336
337 boolean currently_enabled = Configuration.get("general.use_proxy", true);
338 // Creation
339 JPanel connection_pane = new JPanel();
340 connection_pane.setComponentOrientation(Dictionary.getOrientation());
341 no_check_certificate_checkbox = new JCheckBox(Dictionary.get("Preferences.Connection.No_Check_Certificate"));
342 no_check_certificate_checkbox.setToolTipText(Dictionary.get("Preferences.Connection.No_Check_Certificate_Tooltip"));
343 no_check_certificate_checkbox.setSelected(no_check_cert_enabled);
344 no_check_certificate_checkbox.setComponentOrientation(Dictionary.getOrientation());
345 no_check_certificate_checkbox.setPreferredSize(ROW_SIZE);
346
347 use_proxy_checkbox = new JCheckBox(Dictionary.get("Preferences.Connection.Use_Proxy"));
348 use_proxy_checkbox.setSelected(currently_enabled);
349 use_proxy_checkbox.setComponentOrientation(Dictionary.getOrientation());
350 use_proxy_checkbox.setPreferredSize(ROW_SIZE);
351
352
353 // Connection
354 no_check_certificate_checkbox.addActionListener(new NoCheckCertificateListener());
355 use_proxy_checkbox.addActionListener(new UseProxyListener());
356 if (Gatherer.GS3) {
357 site_combobox.addActionListener(new SiteComboboxListener());
358 }
359
360 // Layout
361 program_pane.setLayout(new BorderLayout());
362 program_pane.add(program_label, BorderLayout.LINE_START);
363 program_pane.add(program_field, BorderLayout.CENTER);
364
365 library_path_pane.setLayout(new BorderLayout());
366 library_path_pane.add(library_path_label, BorderLayout.LINE_START);
367 library_path_pane.add(library_path_field, BorderLayout.CENTER);
368
369 if (Gatherer.isGsdlRemote && !Gatherer.GS3) {
370 gliserver_url_pane.setLayout(new BorderLayout());
371 gliserver_url_pane.add(gliserver_url_label, BorderLayout.LINE_START);
372 gliserver_url_pane.add(gliserver_url_field, BorderLayout.CENTER);
373 }
374
375 if (Gatherer.GS3) {
376 site_pane.setLayout(new BorderLayout());
377 site_pane.add(site_label, BorderLayout.LINE_START);
378 site_pane.add(site_combobox, BorderLayout.CENTER);
379
380 servlet_pane.setLayout(new BorderLayout());
381 servlet_pane.add(servlet_label, BorderLayout.LINE_START);
382 servlet_pane.add(servlet_combobox, BorderLayout.CENTER);
383 }
384
385 collect_dir_pane.setLayout(new BorderLayout());
386 collect_dir_pane.add(collect_dir_label, BorderLayout.LINE_START);
387 collect_dir_pane.add(collect_dir_field, BorderLayout.CENTER);
388 collect_dir_pane.add(chdir_button, BorderLayout.LINE_END);
389
390
391 connection_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
392 connection_pane.setLayout(new GridLayout(10,1,0,2));
393 connection_pane.add(program_pane);
394 connection_pane.add(library_path_pane);
395 if (Gatherer.isGsdlRemote && !Gatherer.GS3) {
396 connection_pane.add(gliserver_url_pane);
397 }
398 if (Gatherer.GS3) {
399 connection_pane.add(site_pane);
400 connection_pane.add(servlet_pane);
401 }
402 connection_pane.add(collect_dir_pane);
403
404 connection_pane.add(no_check_certificate_checkbox);
405 connection_pane.add(use_proxy_checkbox);
406
407 // set up the proxy host and port fields for each of http, https and ftp
408 setupProxyHostPane(HTTP, connection_pane, currently_enabled, http_proxy_host_field, http_proxy_port_field);
409 setupProxyHostPane(HTTPS, connection_pane, currently_enabled, https_proxy_host_field, https_proxy_port_field);
410 setupProxyHostPane(FTP, connection_pane, currently_enabled, ftp_proxy_host_field, ftp_proxy_port_field);
411
412 return connection_pane;
413 }
414
415 private JPanel createGeneralPreferences() {
416 JPanel general_pane = new JPanel();
417 general_pane.setComponentOrientation(Dictionary.getOrientation());
418 // Build the model of available languages
419 ArrayList dictionary_model = new ArrayList();
420
421 // The new method makes use of the successor to the languages.dat file, classes/xml/languages.xml
422 NodeList language_elements = LanguageManager.LANGUAGES_DOCUMENT.getDocumentElement().getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
423 for(int i = 0; i < language_elements.getLength(); i++) {
424 Element language_element = (Element) language_elements.item(i);
425 if((language_element.hasAttribute(StaticStrings.GLI_ATTRIBUTE)
426 && (language_element.getAttribute(StaticStrings.GLI_ATTRIBUTE)).equalsIgnoreCase(StaticStrings.TRUE_STR))
427 || (language_element.hasAttribute(StaticStrings.MDS_ATTRIBUTE)
428 && (language_element.getAttribute(StaticStrings.MDS_ATTRIBUTE)).equalsIgnoreCase(StaticStrings.TRUE_STR)))
429 {
430 Locale locale = new Locale(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE));
431 String description = language_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
432 DictionaryEntry entry = new DictionaryEntry(description, locale);
433 if(!dictionary_model.contains(entry)) {
434 dictionary_model.add(entry);
435 }
436 entry = null;
437 description = null;
438 locale = null;
439 }
440 language_element = null;
441 }
442 language_elements = null;
443
444 // Users email
445 JPanel email_pane = new JPanel();
446 email_pane.setComponentOrientation(Dictionary.getOrientation());
447
448 JLabel email_label = new JLabel(Dictionary.get("Preferences.General.Email"));
449 email_label.setComponentOrientation(Dictionary.getOrientation());
450 email_label.setPreferredSize(LABEL_SIZE);
451
452 email_field = new EmailField(Configuration.getColor("coloring.error_background", false));
453 email_field.setText(Configuration.getEmail());
454 email_field.setToolTipText(Dictionary.get("Preferences.General.Email_Tooltip"));
455 email_field.setComponentOrientation(Dictionary.getOrientation());
456 // Font selection
457 JPanel font_pane = new JPanel();
458 font_pane.setComponentOrientation(Dictionary.getOrientation());
459
460 JLabel font_label = new JLabel(Dictionary.get("Preferences.General.Font"));
461 font_label.setComponentOrientation(Dictionary.getOrientation());
462 font_label.setPreferredSize(LABEL_SIZE);
463
464 font_field = new JTextField(Configuration.getString("general.font", true));
465 font_field.setToolTipText(Dictionary.get("Preferences.General.Font_Tooltip"));
466 font_field.setComponentOrientation(Dictionary.getOrientation());
467
468 // Extracted metadata
469 view_extracted_metadata_checkbox = new JCheckBox(Dictionary.get("Preferences.General.View_Extracted_Metadata"));
470 view_extracted_metadata_checkbox.setSelected(false);
471 view_extracted_metadata_checkbox.setComponentOrientation(Dictionary.getOrientation());
472
473 if (Configuration.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC)) {
474 view_extracted_metadata_checkbox.setSelected(true);
475 }
476 view_extracted_metadata_checkbox.setToolTipText(Dictionary.get("Preferences.General.View_Extracted_Metadata_Tooltip"));
477 view_extracted_metadata_checkbox.setComponentOrientation(Dictionary.getOrientation());
478
479 // Show file sizes
480 show_file_size_checkbox = new JCheckBox(Dictionary.get("Preferences.General.Show_File_Size"));
481 show_file_size_checkbox.setSelected(false);
482 show_file_size_checkbox.setComponentOrientation(Dictionary.getOrientation());
483
484 if (Configuration.get("general.show_file_size", Configuration.COLLECTION_SPECIFIC)) {
485 show_file_size_checkbox.setSelected(true);
486 }
487 show_file_size_checkbox.setToolTipText(Dictionary.get("Preferences.General.Show_File_Size_Tooltip"));
488
489 // Language
490 JPanel language_pane = new JPanel();
491 language_pane.setComponentOrientation(Dictionary.getOrientation());
492
493 JLabel language_label = new JLabel(Dictionary.get("Preferences.General.Interface_Language"));
494 language_label.setComponentOrientation(Dictionary.getOrientation());
495 language_label.setPreferredSize(LABEL_SIZE);
496
497 language_combobox = new JComboBox(dictionary_model.toArray());
498 language_combobox.setOpaque(false);
499 language_combobox.setToolTipText(Dictionary.get("Preferences.General.Interface_Language_Tooltip"));
500 language_combobox.setComponentOrientation(Dictionary.getOrientation());
501
502 // Try to locate and select the current language
503 // Else default to English
504 String language_code = Configuration.getLanguage();
505 int defaultIndex = 0;
506 DictionaryEntry defaultEntry = null;
507
508 int b = 0;
509 for (; b < language_combobox.getItemCount(); b++) {
510 DictionaryEntry entry = (DictionaryEntry) language_combobox.getItemAt(b);
511 if (language_code.equalsIgnoreCase(entry.getLocale().getLanguage())) {
512 language_combobox.setSelectedIndex(b);
513 break;
514 } else if (entry.getLocale().getLanguage().equalsIgnoreCase("en")) { // store English as fallback
515 defaultIndex = b;
516 defaultEntry = entry;
517 }
518 }
519 // if we cycled through and couldn't find the chosen language to load,
520 // then we set the Preferences' and Configuration's language to English
521 if (b == language_combobox.getItemCount()) {
522 language_combobox.setSelectedIndex(defaultIndex);
523 Configuration.setLocale("general.locale", true, defaultEntry.getLocale());
524 System.err.println("*** GLI doesn't yet support the language: " + language_code
525 + " and has therefore defaulted to: " + Configuration.getLanguage());
526 }
527
528 // Layout
529 email_pane.setLayout(new BorderLayout());
530 email_pane.add(email_label, BorderLayout.LINE_START);
531 email_pane.add(email_field, BorderLayout.CENTER);
532
533 language_pane.setLayout(new BorderLayout());
534 language_pane.add(language_label, BorderLayout.LINE_START);
535 language_pane.add(language_combobox, BorderLayout.CENTER);
536
537 font_pane.setLayout(new BorderLayout());
538 font_pane.add(font_label, BorderLayout.LINE_START);
539 font_pane.add(font_field, BorderLayout.CENTER);
540
541 general_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
542 general_pane.setLayout(new GridLayout(5,1,0,5));
543 general_pane.add(email_pane);
544 general_pane.add(language_pane);
545 general_pane.add(font_pane);
546 general_pane.add(view_extracted_metadata_checkbox);
547 general_pane.add(show_file_size_checkbox);
548
549 return general_pane;
550 }
551
552 private void setupProxyHostPane(String protocol, JPanel connection_pane, boolean isEnabled,
553 JTextField proxy_host_field, JSpinner proxy_port_field)
554 {
555 final Dimension WIDER_LABEL_SIZE = new Dimension(180, 25);
556 final Dimension NARROWER_LABEL_SIZE = new Dimension(60, 25);
557 final Dimension WIDER_ROW_SIZE = new Dimension(480, 25);
558 final Dimension NARROWER_ROW_SIZE = new Dimension(120, 25);
559
560 JPanel proxy_host_pane = new JPanel();
561 proxy_host_pane.setComponentOrientation(Dictionary.getOrientation());
562 proxy_host_pane.setPreferredSize(WIDER_ROW_SIZE);
563
564 JLabel proxy_host_label = new JLabel(Dictionary.get("Preferences.Connection."+protocol+"_Proxy_Host"));
565 proxy_host_label.setComponentOrientation(Dictionary.getOrientation());
566 proxy_host_label.setPreferredSize(WIDER_LABEL_SIZE);
567
568 proxy_host_field = new JTextField(Configuration.getString("general."+protocol+"_proxy_host", true));
569 proxy_host_field.setEnabled(isEnabled);
570 proxy_host_field.setToolTipText(Dictionary.get("Preferences.Connection."+protocol+"_Proxy_Host_Tooltip"));
571 proxy_host_field.setComponentOrientation(Dictionary.getOrientation());
572
573 JPanel proxy_port_pane = new JPanel();
574 proxy_port_pane.setComponentOrientation(Dictionary.getOrientation());
575 proxy_port_pane.setPreferredSize(NARROWER_ROW_SIZE);
576
577 JLabel proxy_port_label = new JLabel(Dictionary.get("Preferences.Connection.Proxy_Port"));
578 proxy_port_label.setPreferredSize(NARROWER_LABEL_SIZE);
579 proxy_port_label.setComponentOrientation(Dictionary.getOrientation());
580
581 String port_value = Configuration.getString("general."+protocol+"_proxy_port", true);
582 if(port_value.length() > 0) {
583 proxy_port_field = new JSpinner(new SpinnerNumberModel((new Integer(port_value)).intValue(), 0, 65535, 1));
584 }
585 else {
586 proxy_port_field = new JSpinner(new SpinnerNumberModel(0, 0, 65535, 1));
587 }
588 proxy_port_field.setEnabled(isEnabled);
589 proxy_port_field.setToolTipText(Dictionary.get("Preferences.Connection."+protocol+"_Proxy_Port_Tooltip"));
590
591
592 // Since the actual object member vars were null when this method is called
593 // need to ensure they are assigned the correct value now, else those refs will remain null
594 if(protocol.equals(HTTP)) {
595 http_proxy_host_field = proxy_host_field;
596 http_proxy_port_field = proxy_port_field;
597 } else if (protocol.equals(HTTPS)) {
598 https_proxy_host_field = proxy_host_field;
599 https_proxy_port_field = proxy_port_field;
600 } else if(protocol.equals(FTP)) {
601 ftp_proxy_host_field = proxy_host_field;
602 ftp_proxy_port_field = proxy_port_field;
603 }
604
605 proxy_host_pane.setLayout(new BorderLayout());
606 proxy_host_pane.add(proxy_host_label, BorderLayout.LINE_START);
607 proxy_host_pane.add(proxy_host_field, BorderLayout.CENTER);
608
609 proxy_port_pane.setLayout(new BorderLayout());
610 proxy_port_pane.add(proxy_port_label, BorderLayout.LINE_START);
611 proxy_port_pane.add(proxy_port_field, BorderLayout.CENTER);
612
613 //connection_pane.add(proxy_host_pane);
614 //connection_pane.add(proxy_port_pane);
615
616 JPanel proxy_panel = new JPanel();
617 proxy_panel.setLayout(new BorderLayout());
618 proxy_panel.add(proxy_host_pane, BorderLayout.WEST);
619 proxy_panel.add(proxy_port_pane, BorderLayout.CENTER);
620
621 connection_pane.add(proxy_panel);
622 }
623
624
625 /** Generate the controls for altering the detail mode.
626 * @return a JPanel of controls
627 */
628 private JPanel createModePreferences() {
629 // Create Controls
630 JPanel mode_panel = new JPanel();
631 mode_panel.setComponentOrientation(Dictionary.getOrientation());
632
633 JPanel button_panel = new JPanel();
634 button_panel.setComponentOrientation(Dictionary.getOrientation());
635
636 ButtonGroup mode_button_group = new ButtonGroup();
637
638 assistant_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Assistant"));
639 assistant_mode_radio_button.setOpaque(false);
640 assistant_mode_radio_button.setComponentOrientation(Dictionary.getOrientation());
641 mode_button_group.add(assistant_mode_radio_button);
642
643 expert_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Expert"));
644 expert_mode_radio_button.setOpaque(false);
645 expert_mode_radio_button.setComponentOrientation(Dictionary.getOrientation());
646 mode_button_group.add(expert_mode_radio_button);
647
648 librarian_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Librarian"));
649 librarian_mode_radio_button.setOpaque(false);
650 librarian_mode_radio_button.setComponentOrientation(Dictionary.getOrientation());
651 mode_button_group.add(librarian_mode_radio_button);
652
653
654 mode_description_textarea = new JTextArea();
655 mode_description_textarea.setComponentOrientation(Dictionary.getOrientation());
656 mode_description_textarea.setEditable(false);
657 mode_description_textarea.setLineWrap(true);
658 mode_description_textarea.setWrapStyleWord(true);
659 // Determine which value is already selected
660 switch(Configuration.getMode()) {
661 case Configuration.ASSISTANT_MODE:
662 assistant_mode_radio_button.setSelected(true);
663 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
664 break;
665 case Configuration.EXPERT_MODE:
666 expert_mode_radio_button.setSelected(true);
667 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
668 break;
669 default:
670 librarian_mode_radio_button.setSelected(true);
671 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
672 }
673 // Connection - when a radio button is selected we have to change the description
674 ModeRadioButtonListener listener = new ModeRadioButtonListener();
675 assistant_mode_radio_button.addActionListener(listener);
676 expert_mode_radio_button.addActionListener(listener);
677 librarian_mode_radio_button.addActionListener(listener);
678 listener = null;
679 // Layout
680 button_panel.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
681 button_panel.setLayout(new GridLayout(3,1,2,2));
682 button_panel.add(assistant_mode_radio_button);
683 button_panel.add(librarian_mode_radio_button);
684 button_panel.add(expert_mode_radio_button);
685
686 mode_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
687 mode_panel.setLayout(new BorderLayout());
688 mode_panel.add(button_panel, BorderLayout.NORTH);
689 mode_panel.add(new JScrollPane(mode_description_textarea), BorderLayout.CENTER);
690
691 return mode_panel;
692 }
693
694
695 /** The warning preferences are controlled through a checklist. */
696 private JPanel createWarningPreferences()
697 {
698 warning_preferences_check_list = new CheckList(false);
699 warning_preferences_check_list.setComponentOrientation(Dictionary.getOrientation());
700
701 // Read all the warnings from the general xml/config.xml file, and their values from the user config.xml file
702 Document general_config_xml_file_document = XMLTools.parseXMLFile("xml/config.xml", true);
703 NodeList argument_elements_nodelist = general_config_xml_file_document.getDocumentElement().getElementsByTagName("Argument");
704 for (int i = 0; i < argument_elements_nodelist.getLength(); i++) {
705 Element argument_element = (Element) argument_elements_nodelist.item(i);
706 String argument_element_name = argument_element.getAttribute("name");
707 if (argument_element_name.startsWith("warning.")) {
708 String warning_title = Dictionary.get(argument_element_name.substring("warning.".length()) + ".Title");
709 boolean warning_enabled = Configuration.get(argument_element_name, true);
710 CheckListEntry warning_entry = new CheckListEntry(warning_title, warning_enabled);
711 warning_entry.setProperty(argument_element_name);
712 warning_preferences_check_list.addEntry(warning_entry);
713 }
714 }
715
716 JPanel warning_preferences_pane = new JPanel();
717 warning_preferences_pane.setComponentOrientation(Dictionary.getOrientation());
718 warning_preferences_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
719 warning_preferences_pane.setLayout(new BorderLayout());
720 JScrollPane scrol_tmp = new JScrollPane(warning_preferences_check_list);
721 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
722 warning_preferences_pane.add(scrol_tmp, BorderLayout.CENTER);
723 return warning_preferences_pane;
724 }
725
726
727 private JPanel createWorkflowPreferences() {
728 // Read in the predefined configurations file
729 Vector predefined = new Vector();
730 Document predefined_document = XMLTools.parseXMLFile("xml/workflows.xml", true);
731 Element predefined_element = predefined_document.getDocumentElement();
732 NodeList workflow_elements = predefined_element.getElementsByTagName("Workflow");
733 for(int i = 0; i < workflow_elements.getLength(); i++) {
734 predefined.add(new WorkflowElementWrapper((Element)workflow_elements.item(i)));
735 }
736
737 // Creation
738 JPanel workflow_preferences_pane = new JPanel();
739 workflow_preferences_pane.setComponentOrientation(Dictionary.getOrientation());
740
741 JPanel checklist_pane = new JPanel();
742 checklist_pane.setComponentOrientation(Dictionary.getOrientation());
743
744 JLabel title_label = new JLabel(Dictionary.get("Preferences.Workflow.Title"));
745 title_label.setComponentOrientation(Dictionary.getOrientation());
746 title_label.setPreferredSize(ROW_SIZE);
747
748 workflow_download = new JCheckBox(Dictionary.get("GUI.Download")+" - "+Dictionary.get("GUI.Download_Tooltip"));
749 workflow_download.setComponentOrientation(Dictionary.getOrientation());
750 workflow_download.setSelected(Configuration.get("workflow.download", false) && Gatherer.isDownloadEnabled);
751 workflow_download.setPreferredSize(ROW_SIZE);
752
753 workflow_gather = new JCheckBox(Dictionary.get("GUI.Gather")+" - "+Dictionary.get("GUI.Gather_Tooltip"));
754 workflow_gather.setSelected(Configuration.get("workflow.gather", false));
755 workflow_gather.setPreferredSize(ROW_SIZE);
756 workflow_gather.setComponentOrientation(Dictionary.getOrientation());
757
758 workflow_enrich = new JCheckBox(Dictionary.get("GUI.Enrich")+" - "+Dictionary.get("GUI.Enrich_Tooltip"));
759 workflow_enrich.setSelected(Configuration.get("workflow.enrich", false));
760 workflow_enrich.setPreferredSize(ROW_SIZE);
761 workflow_enrich.setComponentOrientation(Dictionary.getOrientation());
762
763 workflow_design = new JCheckBox(Dictionary.get("GUI.Design")+" - "+Dictionary.get("GUI.Design_Tooltip"));
764 workflow_design.setSelected(Configuration.get("workflow.design", false));
765 workflow_design.setPreferredSize(ROW_SIZE);
766 workflow_design.setComponentOrientation(Dictionary.getOrientation());
767
768 workflow_create = new JCheckBox(Dictionary.get("GUI.Create")+" - "+Dictionary.get("GUI.Create_Tooltip"));
769 workflow_create.setSelected(Configuration.get("workflow.create", false));
770 workflow_create.setPreferredSize(ROW_SIZE);
771 workflow_create.setComponentOrientation(Dictionary.getOrientation());
772
773 workflow_format = new JCheckBox(Dictionary.get("GUI.Format")+" - "+Dictionary.get("GUI.Format_Tooltip"));
774 workflow_format.setSelected(Configuration.get("workflow.format", false));
775 workflow_format.setPreferredSize(ROW_SIZE);
776 workflow_format.setComponentOrientation(Dictionary.getOrientation());
777
778 JPanel predefined_pane = new JPanel();
779 predefined_pane.setComponentOrientation(Dictionary.getOrientation());
780
781 JLabel predefined_label = new JLabel(Dictionary.get("Preferences.Workflow.Predefined.Label"));
782 predefined_label.setComponentOrientation(Dictionary.getOrientation());
783
784 JComboBox predefined_combobox = new JComboBox(predefined);
785 predefined_combobox.setOpaque(false);
786 // Connection
787 predefined_combobox.addActionListener(new PredefinedActionListener());
788
789 // Layout
790 checklist_pane.setLayout(new BoxLayout(checklist_pane, BoxLayout.Y_AXIS));
791 checklist_pane.add(title_label);
792 if (Configuration.get("workflow.download", true)) {
793 checklist_pane.add(workflow_download);
794 }
795 if (Configuration.get("workflow.gather", true)) {
796 checklist_pane.add(workflow_gather);
797 }
798 if (Configuration.get("workflow.enrich", true)) {
799 checklist_pane.add(workflow_enrich);
800 }
801 if (Configuration.get("workflow.design", true)) {
802 checklist_pane.add(workflow_design);
803 }
804 if (Configuration.get("workflow.create", true)) {
805 checklist_pane.add(workflow_create);
806 }
807 if (Configuration.get("workflow.format", true)) {
808 checklist_pane.add(workflow_format);
809 }
810
811 predefined_pane.setLayout(new BorderLayout(5,0));
812 predefined_pane.add(predefined_label, BorderLayout.LINE_START);
813 predefined_pane.add(predefined_combobox, BorderLayout.CENTER);
814
815 workflow_preferences_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
816 workflow_preferences_pane.setLayout(new BorderLayout());
817 workflow_preferences_pane.add(checklist_pane, BorderLayout.CENTER);
818 workflow_preferences_pane.add(predefined_pane, BorderLayout.SOUTH);
819
820 return workflow_preferences_pane;
821 }
822
823 private class ChangeDirListener implements ActionListener {
824 public void actionPerformed(ActionEvent event) {
825 JFileChooser chooser = new JFileChooser(collect_dir_field.getText());
826 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
827 int returnVal = chooser.showOpenDialog(Preferences.this);
828 if(returnVal == JFileChooser.APPROVE_OPTION) {
829 collect_dir_field.setText(chooser.getSelectedFile().getAbsolutePath() + File.separator);
830 } // else collect_dir_field text remains as it is
831 }
832 }
833
834 private class OKButtonListener
835 implements ActionListener {
836 private boolean close;
837 public OKButtonListener(boolean close) {
838 this.close = close;
839 }
840
841 private void setProxyHostForProtocol(String protocol,
842 JTextField proxy_host_field,
843 JSpinner proxy_port_field)
844 {
845 Configuration.setString("general."+protocol+"_proxy_host", true, proxy_host_field.getText());
846 Configuration.setString("general."+protocol+"_proxy_port", true, proxy_port_field.getValue() + "");
847 }
848
849 public void actionPerformed(ActionEvent event)
850 {
851 // Several options requiring restarting the GLI to apply:
852 // interface font, interface language, changed gliserver url or library url
853 boolean restart_required = false;
854 boolean keep_collection_open = false;
855 String restart_message = "";
856
857
858 // Connection preferences
859 String program_str = program_field.getText();
860 if (program_str.length() > 0 && program_str.indexOf("%1") == -1) {
861 program_str = program_str + " %1";
862 }
863 Configuration.setPreviewCommand(program_str);
864
865 String old_library_url = (Configuration.library_url == null) ? null : Configuration.library_url.toString();
866 String library_url_string = library_path_field.getText();
867 if(old_library_url != null && !old_library_url.equals(library_url_string)) {
868
869 // If the server is remote and the library path's been changed, then GLI client needs restart
870 // If the server is local, GLI is going to work with the collection of GSDLPath anyway,
871 // even if the library path for previewing has changed
872 if (Gatherer.isGsdlRemote) {
873 restart_required = true;
874 restart_message = Dictionary.get("Preferences.General.Manual_Restart_Required");
875
876 }
877 if(Gatherer.c_man.getCollection() != null) {
878 // if the gliserver url has changed while a collection is open,
879 // close the open collection of the old library URL
880 Gatherer.g_man.saveThenCloseCurrentCollection();
881 Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true, "");
882 }
883 }
884 if (library_url_string.equals("")) {
885 Configuration.library_url = null;
886 }
887 else {
888 try {
889 Configuration.library_url = new URL(library_url_string);
890 }
891 catch (MalformedURLException exception) {
892 DebugStream.printStackTrace(exception);
893 }
894 }
895
896 Configuration.setString("general.library_url"+Configuration.gliPropertyNameSuffix(),
897 true, library_url_string);
898
899 if (Gatherer.isGsdlRemote && !Gatherer.GS3) {
900 String old_gliserver_url = Configuration.gliserver_url.toString();
901 String gliserver_url_string = gliserver_url_field.getText();
902 if(!old_gliserver_url.equals(gliserver_url_string)) {
903 restart_required = true;
904 restart_message = Dictionary.get("Preferences.General.Manual_Restart_Required");
905
906 if(Gatherer.c_man.getCollection() != null) {
907 // if the gliserver url has changed while a collection is open,
908 // close the open collection of the old gliserver URL
909 Gatherer.g_man.saveThenCloseCurrentCollection();
910 Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true, "");
911 }
912 }
913 if (gliserver_url_string.equals("")) {
914 Configuration.gliserver_url = null;
915 }
916 else {
917 try {
918 Configuration.gliserver_url = new URL(gliserver_url_string);
919 }
920 catch (MalformedURLException exception) {
921 DebugStream.printStackTrace(exception);
922 }
923 }
924 Configuration.setString("general.gliserver_url", true, gliserver_url_string);
925 }
926
927
928 boolean site_changed = false;
929 if (Gatherer.GS3) {
930 String current_site = Configuration.site_name;
931 String new_site =(String)site_combobox.getSelectedItem() ;
932 if (!new_site.equals(current_site)) {
933 site_changed = true;
934 }
935 Configuration.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem());
936 }
937
938 Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
939 setProxyHostForProtocol(HTTP, http_proxy_host_field, http_proxy_port_field);
940 setProxyHostForProtocol(HTTPS, https_proxy_host_field, https_proxy_port_field);
941 setProxyHostForProtocol(FTP, ftp_proxy_host_field, ftp_proxy_port_field);
942 Gatherer.setProxy();
943
944 // General preferences
945 Configuration.setEmail(email_field.getText());
946 Configuration.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, show_file_size_checkbox.isSelected());
947 Configuration.set("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC, view_extracted_metadata_checkbox.isSelected());
948
949
950 // GLI interface font
951 String current_font = Configuration.getString("general.font", true);
952 if (!current_font.equals(font_field.getText())) {
953 Configuration.setString("general.font", true, font_field.getText());
954 restart_required = true;
955 restart_message = Dictionary.get("Preferences.General.Restart_Required");
956
957 }
958
959 // GLI interface language
960 String current_lang = Configuration.getLanguage();
961 if (!current_lang.equals(((DictionaryEntry) language_combobox.getSelectedItem()).getLocale().getLanguage())) {
962 // need to save the collection before changing the locale otherwise it stuffs the metadata names up
963 if(Gatherer.c_man.getCollection() != null) {
964 Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true, Gatherer.c_man.getLoadedCollectionColFilePath());
965 Gatherer.g_man.saveThenCloseCurrentCollection();
966 keep_collection_open = true;
967 }
968
969 Configuration.setLocale("general.locale", Configuration.GENERAL_SETTING, ((DictionaryEntry) language_combobox.getSelectedItem()).getLocale());
970 restart_required = true;
971 restart_message = Dictionary.get("Preferences.General.Restart_Required");
972 }
973
974 // Inform the user that a restart is required, if necessary
975 if (restart_required) {
976 JOptionPane.showMessageDialog(Gatherer.g_man, restart_message, Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE);
977 }
978
979 // Mode preferences
980 int current_mode = Configuration.getMode();
981 int new_mode;
982 if (assistant_mode_radio_button.isSelected()) {
983 new_mode = Configuration.ASSISTANT_MODE;
984 }
985 else if (expert_mode_radio_button.isSelected()) {
986 new_mode = Configuration.EXPERT_MODE;
987 }
988 else {
989 new_mode = Configuration.LIBRARIAN_MODE;
990 }
991
992 // If there has been a change in modes, update the config, and also inform the persistant gui views that have a need to know
993 if (new_mode != current_mode) {
994 Configuration.setMode(new_mode);
995 Collection collection = Gatherer.c_man.getCollection();
996 if (collection != null) {
997 collection.cdm.modeChanged(new_mode);
998 }
999 Gatherer.g_man.modeChanged(new_mode);
1000 }
1001
1002 // Warning preferences
1003 ListModel warning_preferences_check_list_model = warning_preferences_check_list.getModel();
1004 for (int i = 0; i < warning_preferences_check_list_model.getSize(); i++) {
1005 CheckListEntry entry = (CheckListEntry) warning_preferences_check_list_model.getElementAt(i);
1006 Configuration.set(entry.getProperty(), true, entry.isSelected());
1007 }
1008
1009 if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection() != null && !Gatherer.isGsdlRemote) {
1010 // shut down the collection
1011 System.err.println("shutting down the collection");
1012 Gatherer.g_man.saveThenCloseCurrentCollection();
1013 }
1014
1015 // Workflow preferences
1016// Configuration.set("workflow.download", false, workflow_download.isSelected());
1017// Configuration.set("workflow.gather", false, workflow_gather.isSelected());
1018// Configuration.set("workflow.enrich", false, workflow_enrich.isSelected());
1019// Configuration.set("workflow.design", false, workflow_design.isSelected());
1020// Configuration.set("workflow.create", false, workflow_create.isSelected());
1021// Configuration.set("workflow.format", false, workflow_format.isSelected());
1022
1023// Gatherer.g_man.workflowUpdate("Download", workflow_download.isSelected());
1024// Gatherer.g_man.workflowUpdate("Gather", workflow_gather.isSelected());
1025// Gatherer.g_man.workflowUpdate("Enrich", workflow_enrich.isSelected());
1026// Gatherer.g_man.workflowUpdate("Design", (workflow_design.isSelected() && Configuration.getMode() > Configuration.ASSISTANT_MODE));
1027// Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());
1028// Gatherer.g_man.workflowUpdate("Format", workflow_format.isSelected());
1029
1030 // Always save configuration changes immediately (in case the GLI crashes)
1031 Configuration.save();
1032 if (Gatherer.isGsdlRemote && Gatherer.GS3 && site_changed ){
1033 Gatherer.remoteGreenstoneServer.downloadCollectionConfigurations();
1034 }
1035 // Refresh the GLI to account for the configuration changes
1036 Gatherer.refresh(Gatherer.PREFERENCES_CHANGED);
1037
1038 // If proxy is on but proxy details are incomplete, then can't continue
1039 if (use_proxy_checkbox.isSelected()
1040 && http_proxy_host_field.getText().equals("")
1041 && https_proxy_host_field.getText().equals("")
1042 && ftp_proxy_host_field.getText().equals("")) {
1043 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Preferences.Connection.Proxy_Host_Missing"),
1044 Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
1045 } else {
1046 // Hide dialog
1047 if (close) {
1048 self.dispose();
1049 }
1050 }
1051
1052 // collect directory change
1053 String newCollectPath = collect_dir_field.getText();
1054 if(!newCollectPath.endsWith(File.separator)) {
1055 newCollectPath += File.separator;
1056 }
1057 // wait cursor will display while changing the collect directory, need to work out what component to
1058 // display it on: main GLI frame or Preferences window, depending on if OK or Apply was pressed
1059 Container container = close ? Gatherer.g_man.getContentPane() : Preferences.this.getContentPane();
1060 Gatherer.collectDirectoryHasChanged(Gatherer.getCollectDirectoryPath(),
1061 newCollectPath, container);
1062 // will tell the server that the collect directory has changed and that
1063 // the workspace needs to be refreshed (Documents in Greenstone Collections)
1064
1065 if (restart_required) {
1066 if (keep_collection_open) {
1067 Gatherer.g_man.exitNoCollectionSave(Gatherer.EXIT_THEN_RESTART);
1068 } else {
1069 Gatherer.g_man.exit(Gatherer.EXIT_THEN_RESTART);
1070 }
1071 }
1072 }
1073 }
1074
1075 private class CancelButtonListener
1076 implements ActionListener {
1077 public void actionPerformed(ActionEvent event) {
1078 self.dispose();
1079 }
1080 }
1081
1082 private class DictionaryEntry
1083 implements Comparable {
1084 private Locale locale;
1085 private String description;
1086 public DictionaryEntry(Locale locale) {
1087 this.description = null;
1088 this.locale = locale;
1089 }
1090 public DictionaryEntry(String description, Locale locale) {
1091 this.description = description;
1092 this.locale = locale;
1093 }
1094 public int compareTo(Object object) {
1095 return toString().compareTo(object.toString());
1096 }
1097 public boolean equals(Object object) {
1098 return toString().equals(object.toString());
1099 }
1100 public Locale getLocale() {
1101 return locale;
1102 }
1103 public String toString() {
1104 if(description != null) {
1105 return description;
1106 }
1107 else {
1108 return locale.getDisplayName();
1109 }
1110 }
1111 }
1112
1113 /** This listener updates the mode description depending on what mode is selected. */
1114 private class ModeRadioButtonListener
1115 implements ActionListener {
1116 public void actionPerformed(ActionEvent event) {
1117 Object source = event.getSource();
1118 if(source == assistant_mode_radio_button) {
1119 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
1120 }
1121 else if(source == expert_mode_radio_button) {
1122 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
1123 }
1124 else {
1125 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
1126 }
1127 source = null;
1128 }
1129 }
1130
1131 private class PredefinedActionListener
1132 implements ActionListener {
1133 public void actionPerformed(ActionEvent event) {
1134 JComboBox cb = (JComboBox) event.getSource();
1135 WorkflowElementWrapper element = (WorkflowElementWrapper) cb.getSelectedItem();
1136 CheckboxUpdater task = new CheckboxUpdater(element);
1137 SwingUtilities.invokeLater(task);
1138 }
1139
1140 private class CheckboxUpdater
1141 implements Runnable {
1142 private WorkflowElementWrapper element;
1143 public CheckboxUpdater(WorkflowElementWrapper element) {
1144 this.element = element;
1145 }
1146 public void run() {
1147 workflow_download.setSelected(element.getEnabled("download"));
1148 workflow_gather.setSelected(element.getEnabled("gather"));
1149 workflow_enrich.setSelected(element.getEnabled("enrich"));
1150 workflow_design.setSelected(element.getEnabled("design"));
1151 workflow_create.setSelected(element.getEnabled("create"));
1152 workflow_format.setSelected(element.getEnabled("format"));
1153 }
1154 }
1155 }
1156
1157
1158 private class SiteComboboxListener
1159 implements ActionListener {
1160 private boolean ignore_event=false;
1161 public void actionPerformed(ActionEvent event) {
1162 System.err.println("event occurred "+event.paramString());
1163 String site = (String) site_combobox.getSelectedItem();
1164 System.err.println("The site changed to = "+site);
1165 if (!site.equals(current_site_selection)) {
1166 current_site_selection = site;
1167 System.err.println("changed the current selection");
1168
1169 ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);
1170 if (servlet_options == null) {
1171 ///ystem.err.println("no servlets for this site");
1172 servlet_combobox.setModel(new DefaultComboBoxModel());
1173 servlet_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Servlet_Tooltip2"));
1174 servlet_combobox.setEnabled(false);
1175
1176 } else {
1177 ///ystem.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
1178 servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
1179 servlet_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Servlet_Tooltip"));
1180 servlet_combobox.setEnabled(true);
1181 }
1182 if (Gatherer.isGsdlRemote){
1183 // Close the current collection, remove the lock on this file, ask to login to the new site, then download collection configurations of the site.
1184 if (Gatherer.c_man.getCollection()!=null){
1185 File lock_file = new File(Gatherer.c_man.getLoadedCollectionDirectoryPath() + "gli.lck");
1186 Gatherer.remoteGreenstoneServer.deleteCollectionFile(Gatherer.c_man.getLoadedCollectionName(),lock_file);
1187 Gatherer.g_man.closeCurrentCollection();
1188 }
1189 Configuration.site_name=site;
1190 Gatherer.remoteGreenstoneServer.set_remote_greenstone_server_authentication_to_null();
1191 Gatherer.remoteGreenstoneServer.downloadCollectionConfigurations();
1192 }
1193 }
1194 }
1195 }
1196
1197 private class NoCheckCertificateListener implements ActionListener {
1198 public void actionPerformed(ActionEvent event) {
1199 boolean isEnabled = no_check_certificate_checkbox.isSelected();
1200 Configuration.set("general.no_check_certificate", true, isEnabled);
1201 boolean no_check_cert_enabled = Configuration.get("general.no_check_certificate", true);
1202 }
1203 }
1204
1205 private class UseProxyListener
1206 implements ActionListener {
1207 public void actionPerformed(ActionEvent event) {
1208 boolean enabled = use_proxy_checkbox.isSelected();
1209 Configuration.set("general.use_proxy", true, enabled);
1210 // Fortunately this is already driven by the event thread.
1211 http_proxy_host_field.setEnabled(enabled);
1212 http_proxy_port_field.setEnabled(enabled);
1213 https_proxy_host_field.setEnabled(enabled);
1214 https_proxy_port_field.setEnabled(enabled);
1215 ftp_proxy_host_field.setEnabled(enabled);
1216 ftp_proxy_port_field.setEnabled(enabled);
1217 }
1218 }
1219
1220 private class WorkflowElementWrapper {
1221 private Element element;
1222 private String text;
1223 public WorkflowElementWrapper(Element element) {
1224 this.element = element;
1225 }
1226 public boolean getEnabled(String name) {
1227 boolean result = true;
1228 if(element.getAttribute(name).equalsIgnoreCase("false")) {
1229 result = false;
1230 }
1231 return result;
1232 }
1233 public String toString() {
1234 if (text == null) {
1235 text = Dictionary.get(element.getFirstChild().getNodeValue());
1236 }
1237 return text;
1238 }
1239 }
1240}
Note: See TracBrowser for help on using the repository browser.