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

Last change on this file since 29011 was 22831, checked in by ak19, 14 years ago

For ticket 152 (moveable collectdir): busy cursor when changing a collectdir takes some time to finish.

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