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 | */
|
---|
27 | package org.greenstone.gatherer.gui;
|
---|
28 |
|
---|
29 | import java.awt.*;
|
---|
30 | import java.awt.event.*;
|
---|
31 | import java.io.*;
|
---|
32 | import java.net.*;
|
---|
33 | import java.util.*;
|
---|
34 | import javax.swing.*;
|
---|
35 | import javax.swing.event.*;
|
---|
36 | import javax.swing.plaf.*;
|
---|
37 | import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
|
---|
38 | import org.greenstone.gatherer.Configuration;
|
---|
39 | import org.greenstone.gatherer.GAuthenticator;
|
---|
40 | import org.greenstone.gatherer.DebugStream;
|
---|
41 | import org.greenstone.gatherer.Dictionary;
|
---|
42 | import org.greenstone.gatherer.Gatherer;
|
---|
43 | import org.greenstone.gatherer.cdm.ClassifierManager;
|
---|
44 | import org.greenstone.gatherer.cdm.LanguageManager;
|
---|
45 | import org.greenstone.gatherer.cdm.PluginManager;
|
---|
46 | import org.greenstone.gatherer.collection.Collection;
|
---|
47 | import org.greenstone.gatherer.gui.tree.DragTree;
|
---|
48 | import org.greenstone.gatherer.util.ArrayTools; // just for debug
|
---|
49 | import org.greenstone.gatherer.util.CheckList;
|
---|
50 | import org.greenstone.gatherer.util.CheckListEntry;
|
---|
51 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
52 | import org.greenstone.gatherer.util.XMLTools;
|
---|
53 | import org.w3c.dom.*;
|
---|
54 |
|
---|
55 | public class Preferences
|
---|
56 | extends ModalDialog
|
---|
57 | {
|
---|
58 | static final public String CONNECTION_PREFS = "connection";
|
---|
59 | static final public String GENERAL_PREFS = "general";
|
---|
60 |
|
---|
61 | static final private Dimension LABEL_SIZE = new Dimension(280, 25);
|
---|
62 | static final private Dimension ROW_SIZE = new Dimension(640, 25);
|
---|
63 | static final private Dimension SIZE = new Dimension(640, 345);
|
---|
64 | static final private String TRUE = "true";
|
---|
65 |
|
---|
66 | private CheckList warning_preferences_check_list;
|
---|
67 | private EmailField email_field;
|
---|
68 | private JButton apply_button;
|
---|
69 | private JButton cancel_button;
|
---|
70 | private JButton chdir_button;
|
---|
71 | private JButton ok_button;
|
---|
72 | private JCheckBox show_file_size_checkbox;
|
---|
73 | private JCheckBox use_proxy_checkbox;
|
---|
74 | private JCheckBox view_extracted_metadata_checkbox;
|
---|
75 | private JCheckBox workflow_download;
|
---|
76 | private JCheckBox workflow_gather;
|
---|
77 | private JCheckBox workflow_enrich;
|
---|
78 | private JCheckBox workflow_design;
|
---|
79 | private JCheckBox workflow_create;
|
---|
80 | private JCheckBox workflow_format;
|
---|
81 | private JComboBox language_combobox;
|
---|
82 | private JComboBox servlet_combobox; // GS3
|
---|
83 | private JComboBox site_combobox; // GS3
|
---|
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;
|
---|
88 | private JTabbedPane tab_pane;
|
---|
89 | private JTextArea mode_description_textarea;
|
---|
90 | private JTextField font_field;
|
---|
91 | private JTextField gliserver_url_field;
|
---|
92 | private JTextField library_path_field;
|
---|
93 | private JTextField program_field;
|
---|
94 | private JTextField proxy_host_field;
|
---|
95 | private JTextField collect_dir_field;
|
---|
96 |
|
---|
97 | private Preferences self;
|
---|
98 |
|
---|
99 | private String current_site_selection;
|
---|
100 |
|
---|
101 | public Preferences() {
|
---|
102 | this(GENERAL_PREFS);
|
---|
103 | }
|
---|
104 |
|
---|
105 | public Preferences(String initial_view) {
|
---|
106 | // Initialize
|
---|
107 | super(Gatherer.g_man, true);
|
---|
108 | this.self = this;
|
---|
109 | setSize(SIZE);
|
---|
110 | setTitle(Dictionary.get("Preferences"));
|
---|
111 | setJMenuBar(new SimpleMenuBar("preferences"));
|
---|
112 |
|
---|
113 | // Creation
|
---|
114 | JPanel content_pane = (JPanel) getContentPane();
|
---|
115 | content_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
116 | tab_pane = new JTabbedPane();
|
---|
117 | tab_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
118 | JPanel general_preferences = createGeneralPreferences();
|
---|
119 | general_preferences.setComponentOrientation(Dictionary.getOrientation());
|
---|
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"));
|
---|
122 | // tab_pane.addTab(Dictionary.get("Preferences.Workflow"), null, createWorkflowPreferences(), Dictionary.get("Preferences.Workflow_Tooltip"));
|
---|
123 | JPanel connection_preferences = createConnectionPreferences();
|
---|
124 | connection_preferences.setComponentOrientation(Dictionary.getOrientation());
|
---|
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 |
|
---|
128 | JPanel button_pane = new JPanel();
|
---|
129 | button_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
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 |
|
---|
136 | // Connection
|
---|
137 | ok_button.addActionListener(new OKButtonListener(true));
|
---|
138 | apply_button.addActionListener(new OKButtonListener(false));
|
---|
139 | cancel_button.addActionListener(new CancelButtonListener());
|
---|
140 |
|
---|
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);
|
---|
147 | button_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
148 |
|
---|
149 | content_pane.setLayout(new BorderLayout());
|
---|
150 | content_pane.add(tab_pane, BorderLayout.CENTER);
|
---|
151 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
152 | content_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
153 |
|
---|
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 |
|
---|
158 | // Bring the desired pane to the fore
|
---|
159 | if (initial_view.equals(CONNECTION_PREFS)) {
|
---|
160 | tab_pane.setSelectedComponent(connection_preferences);
|
---|
161 | }
|
---|
162 | else {
|
---|
163 | tab_pane.setSelectedComponent(general_preferences);
|
---|
164 | }
|
---|
165 |
|
---|
166 | // Clean up
|
---|
167 | general_preferences = null;
|
---|
168 | connection_preferences = null;
|
---|
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;
|
---|
176 |
|
---|
177 | setVisible(true);
|
---|
178 | }
|
---|
179 |
|
---|
180 | private JPanel createConnectionPreferences() {
|
---|
181 | JPanel program_pane = new JPanel();
|
---|
182 | program_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
183 | program_pane.setPreferredSize(ROW_SIZE);
|
---|
184 | JLabel program_label = new JLabel(Dictionary.get("Preferences.Connection.ProgramCommand"));
|
---|
185 | program_label.setPreferredSize(LABEL_SIZE);
|
---|
186 | program_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
187 |
|
---|
188 | program_field = new JTextField(Configuration.getPreviewCommand());
|
---|
189 | program_field.setCaretPosition(0);
|
---|
190 | program_field.setToolTipText(Dictionary.get("Preferences.Connection.ProgramCommand_Tooltip"));
|
---|
191 | program_field.setComponentOrientation(Dictionary.getOrientation());
|
---|
192 |
|
---|
193 | JPanel library_path_pane = new JPanel();
|
---|
194 | library_path_pane.setPreferredSize(ROW_SIZE);
|
---|
195 | library_path_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
196 | JLabel library_path_label = new JLabel();
|
---|
197 | library_path_label.setPreferredSize(LABEL_SIZE);
|
---|
198 | library_path_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
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);
|
---|
204 | library_path_field.setCaretPosition(0);
|
---|
205 | library_path_field.setComponentOrientation(Dictionary.getOrientation());
|
---|
206 | if (Gatherer.GS3) {
|
---|
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"));
|
---|
209 | } else {
|
---|
210 | library_path_label.setText(Dictionary.get("Preferences.Connection.Library_Path"));
|
---|
211 | library_path_field.setToolTipText(Dictionary.get("Preferences.Connection.Library_Path_Tooltip"));
|
---|
212 | }
|
---|
213 |
|
---|
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);
|
---|
217 |
|
---|
218 | JPanel gliserver_url_pane = null;
|
---|
219 | JLabel gliserver_url_label = null;
|
---|
220 | if (Gatherer.isGsdlRemote && !Gatherer.GS3) {
|
---|
221 | gliserver_url_pane = new JPanel();
|
---|
222 | gliserver_url_pane.setPreferredSize(ROW_SIZE);
|
---|
223 | gliserver_url_label = new JLabel(Dictionary.get("Preferences.Connection.GLIServer_URL"));
|
---|
224 | gliserver_url_label.setPreferredSize(LABEL_SIZE);
|
---|
225 | gliserver_url_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
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);
|
---|
231 | gliserver_url_field.setComponentOrientation(Dictionary.getOrientation());
|
---|
232 | gliserver_url_field.setCaretPosition(0);
|
---|
233 | gliserver_url_field.setToolTipText(Dictionary.get("Preferences.Connection.GLIServer_URL_Tooltip"));
|
---|
234 |
|
---|
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);
|
---|
238 | }
|
---|
239 |
|
---|
240 | JPanel site_pane = null;
|
---|
241 | JLabel site_label = null;
|
---|
242 | JPanel servlet_pane = null;
|
---|
243 | JLabel servlet_label = null;
|
---|
244 | if (Gatherer.GS3) {
|
---|
245 | site_pane = new JPanel();
|
---|
246 | site_pane.setPreferredSize(ROW_SIZE);
|
---|
247 | site_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
248 | site_label = new JLabel(Dictionary.get("Preferences.Connection.Site"));
|
---|
249 | site_label.setPreferredSize(LABEL_SIZE);
|
---|
250 | site_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
251 | // what should we do if Gatherer.servlet_config.getSites() is null?
|
---|
252 | site_combobox = new JComboBox(Gatherer.servlet_config.getSites().toArray());
|
---|
253 | site_combobox.setOpaque(false);
|
---|
254 | site_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Site_Tooltip"));
|
---|
255 | site_combobox.setComponentOrientation(Dictionary.getOrientation());
|
---|
256 |
|
---|
257 | servlet_pane = new JPanel();
|
---|
258 | servlet_pane.setPreferredSize(ROW_SIZE);
|
---|
259 | servlet_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
260 |
|
---|
261 | servlet_label = new JLabel(Dictionary.get("Preferences.Connection.Servlet"));
|
---|
262 | servlet_label.setPreferredSize(LABEL_SIZE);
|
---|
263 | servlet_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
264 | servlet_combobox = new JComboBox();
|
---|
265 | servlet_combobox.setOpaque(false);
|
---|
266 | servlet_combobox.setComponentOrientation(Dictionary.getOrientation());
|
---|
267 | // try to locate and select the current site
|
---|
268 | String this_site = Configuration.site_name;
|
---|
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) {
|
---|
282 | servlet_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Servlet_Tooltip2"));
|
---|
283 | //servlet_combobox.setModel(new DefaultComboBoxModel());
|
---|
284 | servlet_combobox.setEnabled(false);
|
---|
285 | } else {
|
---|
286 | ///ystem.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
|
---|
287 |
|
---|
288 | servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
|
---|
289 | servlet_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Servlet_Tooltip"));
|
---|
290 | servlet_combobox.setEnabled(true);
|
---|
291 | // try to locate and select the current servlet
|
---|
292 | String this_servlet = Configuration.getServletPath();
|
---|
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 | }
|
---|
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 | }
|
---|
320 |
|
---|
321 | boolean currently_enabled = Configuration.get("general.use_proxy", true);
|
---|
322 | // Creation
|
---|
323 | JPanel connection_pane = new JPanel();
|
---|
324 | connection_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
325 | use_proxy_checkbox = new JCheckBox(Dictionary.get("Preferences.Connection.Use_Proxy"));
|
---|
326 | use_proxy_checkbox.setSelected(currently_enabled);
|
---|
327 | use_proxy_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
328 | use_proxy_checkbox.setPreferredSize(ROW_SIZE);
|
---|
329 |
|
---|
330 | JPanel proxy_host_pane = new JPanel();
|
---|
331 | proxy_host_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
332 | proxy_host_pane.setPreferredSize(ROW_SIZE);
|
---|
333 |
|
---|
334 | JLabel proxy_host_label = new JLabel(Dictionary.get("Preferences.Connection.Proxy_Host"));
|
---|
335 | proxy_host_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
336 | proxy_host_label.setPreferredSize(LABEL_SIZE);
|
---|
337 |
|
---|
338 | proxy_host_field = new JTextField(Configuration.getString("general.proxy_host", true));
|
---|
339 | proxy_host_field.setEnabled(currently_enabled);
|
---|
340 | proxy_host_field.setToolTipText(Dictionary.get("Preferences.Connection.Proxy_Host_Tooltip"));
|
---|
341 | proxy_host_field.setComponentOrientation(Dictionary.getOrientation());
|
---|
342 |
|
---|
343 | JPanel proxy_port_pane = new JPanel();
|
---|
344 | proxy_port_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
345 | proxy_port_pane.setPreferredSize(ROW_SIZE);
|
---|
346 |
|
---|
347 | JLabel proxy_port_label = new JLabel(Dictionary.get("Preferences.Connection.Proxy_Port"));
|
---|
348 | proxy_port_label.setPreferredSize(LABEL_SIZE);
|
---|
349 | proxy_port_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
350 |
|
---|
351 | String port_value = Configuration.getString("general.proxy_port", true);
|
---|
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 | }
|
---|
358 | proxy_port_field.setEnabled(currently_enabled);
|
---|
359 | proxy_port_field.setToolTipText(Dictionary.get("Preferences.Connection.Proxy_Port_Tooltip"));
|
---|
360 |
|
---|
361 | // Connection
|
---|
362 | use_proxy_checkbox.addActionListener(new UseProxyListener());
|
---|
363 | if (Gatherer.GS3) {
|
---|
364 | site_combobox.addActionListener(new SiteComboboxListener());
|
---|
365 | }
|
---|
366 |
|
---|
367 | // Layout
|
---|
368 | program_pane.setLayout(new BorderLayout());
|
---|
369 | program_pane.add(program_label, BorderLayout.LINE_START);
|
---|
370 | program_pane.add(program_field, BorderLayout.CENTER);
|
---|
371 |
|
---|
372 | library_path_pane.setLayout(new BorderLayout());
|
---|
373 | library_path_pane.add(library_path_label, BorderLayout.LINE_START);
|
---|
374 | library_path_pane.add(library_path_field, BorderLayout.CENTER);
|
---|
375 |
|
---|
376 | if (Gatherer.isGsdlRemote && !Gatherer.GS3) {
|
---|
377 | gliserver_url_pane.setLayout(new BorderLayout());
|
---|
378 | gliserver_url_pane.add(gliserver_url_label, BorderLayout.LINE_START);
|
---|
379 | gliserver_url_pane.add(gliserver_url_field, BorderLayout.CENTER);
|
---|
380 | }
|
---|
381 |
|
---|
382 | if (Gatherer.GS3) {
|
---|
383 | site_pane.setLayout(new BorderLayout());
|
---|
384 | site_pane.add(site_label, BorderLayout.LINE_START);
|
---|
385 | site_pane.add(site_combobox, BorderLayout.CENTER);
|
---|
386 |
|
---|
387 | servlet_pane.setLayout(new BorderLayout());
|
---|
388 | servlet_pane.add(servlet_label, BorderLayout.LINE_START);
|
---|
389 | servlet_pane.add(servlet_combobox, BorderLayout.CENTER);
|
---|
390 | }
|
---|
391 |
|
---|
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 |
|
---|
397 | proxy_host_pane.setLayout(new BorderLayout());
|
---|
398 | proxy_host_pane.add(proxy_host_label, BorderLayout.LINE_START);
|
---|
399 | proxy_host_pane.add(proxy_host_field, BorderLayout.CENTER);
|
---|
400 |
|
---|
401 | proxy_port_pane.setLayout(new BorderLayout());
|
---|
402 | proxy_port_pane.add(proxy_port_label, BorderLayout.LINE_START);
|
---|
403 | proxy_port_pane.add(proxy_port_field, BorderLayout.CENTER);
|
---|
404 |
|
---|
405 | connection_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
406 | connection_pane.setLayout(new GridLayout(8,1,0,2));
|
---|
407 | connection_pane.add(program_pane);
|
---|
408 | connection_pane.add(library_path_pane);
|
---|
409 | if (Gatherer.isGsdlRemote && !Gatherer.GS3) {
|
---|
410 | connection_pane.add(gliserver_url_pane);
|
---|
411 | }
|
---|
412 | if (Gatherer.GS3) {
|
---|
413 | connection_pane.add(site_pane);
|
---|
414 | connection_pane.add(servlet_pane);
|
---|
415 | }
|
---|
416 | connection_pane.add(collect_dir_pane);
|
---|
417 |
|
---|
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();
|
---|
427 | general_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
428 | // Build the model of available languages
|
---|
429 | ArrayList dictionary_model = new ArrayList();
|
---|
430 |
|
---|
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);
|
---|
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 | {
|
---|
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 |
|
---|
454 | // Users email
|
---|
455 | JPanel email_pane = new JPanel();
|
---|
456 | email_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
457 |
|
---|
458 | JLabel email_label = new JLabel(Dictionary.get("Preferences.General.Email"));
|
---|
459 | email_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
460 | email_label.setPreferredSize(LABEL_SIZE);
|
---|
461 |
|
---|
462 | email_field = new EmailField(Configuration.getColor("coloring.error_background", false));
|
---|
463 | email_field.setText(Configuration.getEmail());
|
---|
464 | email_field.setToolTipText(Dictionary.get("Preferences.General.Email_Tooltip"));
|
---|
465 | email_field.setComponentOrientation(Dictionary.getOrientation());
|
---|
466 | // Font selection
|
---|
467 | JPanel font_pane = new JPanel();
|
---|
468 | font_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
469 |
|
---|
470 | JLabel font_label = new JLabel(Dictionary.get("Preferences.General.Font"));
|
---|
471 | font_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
472 | font_label.setPreferredSize(LABEL_SIZE);
|
---|
473 |
|
---|
474 | font_field = new JTextField(Configuration.getString("general.font", true));
|
---|
475 | font_field.setToolTipText(Dictionary.get("Preferences.General.Font_Tooltip"));
|
---|
476 | font_field.setComponentOrientation(Dictionary.getOrientation());
|
---|
477 |
|
---|
478 | // Extracted metadata
|
---|
479 | view_extracted_metadata_checkbox = new JCheckBox(Dictionary.get("Preferences.General.View_Extracted_Metadata"));
|
---|
480 | view_extracted_metadata_checkbox.setSelected(false);
|
---|
481 | view_extracted_metadata_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
482 |
|
---|
483 | if (Configuration.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC)) {
|
---|
484 | view_extracted_metadata_checkbox.setSelected(true);
|
---|
485 | }
|
---|
486 | view_extracted_metadata_checkbox.setToolTipText(Dictionary.get("Preferences.General.View_Extracted_Metadata_Tooltip"));
|
---|
487 | view_extracted_metadata_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
488 |
|
---|
489 | // Show file sizes
|
---|
490 | show_file_size_checkbox = new JCheckBox(Dictionary.get("Preferences.General.Show_File_Size"));
|
---|
491 | show_file_size_checkbox.setSelected(false);
|
---|
492 | show_file_size_checkbox.setComponentOrientation(Dictionary.getOrientation());
|
---|
493 |
|
---|
494 | if (Configuration.get("general.show_file_size", Configuration.COLLECTION_SPECIFIC)) {
|
---|
495 | show_file_size_checkbox.setSelected(true);
|
---|
496 | }
|
---|
497 | show_file_size_checkbox.setToolTipText(Dictionary.get("Preferences.General.Show_File_Size_Tooltip"));
|
---|
498 |
|
---|
499 | // Language
|
---|
500 | JPanel language_pane = new JPanel();
|
---|
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());
|
---|
505 | language_label.setPreferredSize(LABEL_SIZE);
|
---|
506 |
|
---|
507 | language_combobox = new JComboBox(dictionary_model.toArray());
|
---|
508 | language_combobox.setOpaque(false);
|
---|
509 | language_combobox.setToolTipText(Dictionary.get("Preferences.General.Interface_Language_Tooltip"));
|
---|
510 | language_combobox.setComponentOrientation(Dictionary.getOrientation());
|
---|
511 |
|
---|
512 | // Try to locate and select the current language
|
---|
513 | // Else default to English
|
---|
514 | String language_code = Configuration.getLanguage();
|
---|
515 | int defaultIndex = 0;
|
---|
516 | DictionaryEntry defaultEntry = null;
|
---|
517 |
|
---|
518 | int b = 0;
|
---|
519 | for (; b < language_combobox.getItemCount(); b++) {
|
---|
520 | DictionaryEntry entry = (DictionaryEntry) language_combobox.getItemAt(b);
|
---|
521 | if (language_code.equalsIgnoreCase(entry.getLocale().getLanguage())) {
|
---|
522 | language_combobox.setSelectedIndex(b);
|
---|
523 | break;
|
---|
524 | } else if (entry.getLocale().getLanguage().equalsIgnoreCase("en")) { // store English as fallback
|
---|
525 | defaultIndex = b;
|
---|
526 | defaultEntry = entry;
|
---|
527 | }
|
---|
528 | }
|
---|
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 | }
|
---|
537 |
|
---|
538 | // Layout
|
---|
539 | email_pane.setLayout(new BorderLayout());
|
---|
540 | email_pane.add(email_label, BorderLayout.LINE_START);
|
---|
541 | email_pane.add(email_field, BorderLayout.CENTER);
|
---|
542 |
|
---|
543 | language_pane.setLayout(new BorderLayout());
|
---|
544 | language_pane.add(language_label, BorderLayout.LINE_START);
|
---|
545 | language_pane.add(language_combobox, BorderLayout.CENTER);
|
---|
546 |
|
---|
547 | font_pane.setLayout(new BorderLayout());
|
---|
548 | font_pane.add(font_label, BorderLayout.LINE_START);
|
---|
549 | font_pane.add(font_field, BorderLayout.CENTER);
|
---|
550 |
|
---|
551 | general_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
552 | general_pane.setLayout(new GridLayout(5,1,0,5));
|
---|
553 | general_pane.add(email_pane);
|
---|
554 | general_pane.add(language_pane);
|
---|
555 | general_pane.add(font_pane);
|
---|
556 | general_pane.add(view_extracted_metadata_checkbox);
|
---|
557 | general_pane.add(show_file_size_checkbox);
|
---|
558 |
|
---|
559 | return general_pane;
|
---|
560 | }
|
---|
561 |
|
---|
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();
|
---|
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"));
|
---|
576 | assistant_mode_radio_button.setOpaque(false);
|
---|
577 | assistant_mode_radio_button.setComponentOrientation(Dictionary.getOrientation());
|
---|
578 | mode_button_group.add(assistant_mode_radio_button);
|
---|
579 |
|
---|
580 | expert_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Expert"));
|
---|
581 | expert_mode_radio_button.setOpaque(false);
|
---|
582 | expert_mode_radio_button.setComponentOrientation(Dictionary.getOrientation());
|
---|
583 | mode_button_group.add(expert_mode_radio_button);
|
---|
584 |
|
---|
585 | librarian_mode_radio_button = new JRadioButton(Dictionary.get("Preferences.Mode.Librarian"));
|
---|
586 | librarian_mode_radio_button.setOpaque(false);
|
---|
587 | librarian_mode_radio_button.setComponentOrientation(Dictionary.getOrientation());
|
---|
588 | mode_button_group.add(librarian_mode_radio_button);
|
---|
589 |
|
---|
590 |
|
---|
591 | mode_description_textarea = new JTextArea();
|
---|
592 | mode_description_textarea.setComponentOrientation(Dictionary.getOrientation());
|
---|
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
|
---|
597 | switch(Configuration.getMode()) {
|
---|
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));
|
---|
618 | button_panel.setLayout(new GridLayout(3,1,2,2));
|
---|
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 |
|
---|
631 |
|
---|
632 | /** The warning preferences are controlled through a checklist. */
|
---|
633 | private JPanel createWarningPreferences()
|
---|
634 | {
|
---|
635 | warning_preferences_check_list = new CheckList(false);
|
---|
636 | warning_preferences_check_list.setComponentOrientation(Dictionary.getOrientation());
|
---|
637 |
|
---|
638 | // Read all the warnings from the general xml/config.xml file, and their values from the user config.xml file
|
---|
639 | Document general_config_xml_file_document = XMLTools.parseXMLFile("xml/config.xml", true);
|
---|
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 | }
|
---|
651 | }
|
---|
652 |
|
---|
653 | JPanel warning_preferences_pane = new JPanel();
|
---|
654 | warning_preferences_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
655 | warning_preferences_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
656 | warning_preferences_pane.setLayout(new BorderLayout());
|
---|
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);
|
---|
660 | return warning_preferences_pane;
|
---|
661 | }
|
---|
662 |
|
---|
663 |
|
---|
664 | private JPanel createWorkflowPreferences() {
|
---|
665 | // Read in the predefined configurations file
|
---|
666 | Vector predefined = new Vector();
|
---|
667 | Document predefined_document = XMLTools.parseXMLFile("xml/workflows.xml", true);
|
---|
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 | }
|
---|
673 |
|
---|
674 | // Creation
|
---|
675 | JPanel workflow_preferences_pane = new JPanel();
|
---|
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());
|
---|
683 | title_label.setPreferredSize(ROW_SIZE);
|
---|
684 |
|
---|
685 | workflow_download = new JCheckBox(Dictionary.get("GUI.Download")+" - "+Dictionary.get("GUI.Download_Tooltip"));
|
---|
686 | workflow_download.setComponentOrientation(Dictionary.getOrientation());
|
---|
687 | workflow_download.setSelected(Configuration.get("workflow.download", false) && Gatherer.isDownloadEnabled);
|
---|
688 | workflow_download.setPreferredSize(ROW_SIZE);
|
---|
689 |
|
---|
690 | workflow_gather = new JCheckBox(Dictionary.get("GUI.Gather")+" - "+Dictionary.get("GUI.Gather_Tooltip"));
|
---|
691 | workflow_gather.setSelected(Configuration.get("workflow.gather", false));
|
---|
692 | workflow_gather.setPreferredSize(ROW_SIZE);
|
---|
693 | workflow_gather.setComponentOrientation(Dictionary.getOrientation());
|
---|
694 |
|
---|
695 | workflow_enrich = new JCheckBox(Dictionary.get("GUI.Enrich")+" - "+Dictionary.get("GUI.Enrich_Tooltip"));
|
---|
696 | workflow_enrich.setSelected(Configuration.get("workflow.enrich", false));
|
---|
697 | workflow_enrich.setPreferredSize(ROW_SIZE);
|
---|
698 | workflow_enrich.setComponentOrientation(Dictionary.getOrientation());
|
---|
699 |
|
---|
700 | workflow_design = new JCheckBox(Dictionary.get("GUI.Design")+" - "+Dictionary.get("GUI.Design_Tooltip"));
|
---|
701 | workflow_design.setSelected(Configuration.get("workflow.design", false));
|
---|
702 | workflow_design.setPreferredSize(ROW_SIZE);
|
---|
703 | workflow_design.setComponentOrientation(Dictionary.getOrientation());
|
---|
704 |
|
---|
705 | workflow_create = new JCheckBox(Dictionary.get("GUI.Create")+" - "+Dictionary.get("GUI.Create_Tooltip"));
|
---|
706 | workflow_create.setSelected(Configuration.get("workflow.create", false));
|
---|
707 | workflow_create.setPreferredSize(ROW_SIZE);
|
---|
708 | workflow_create.setComponentOrientation(Dictionary.getOrientation());
|
---|
709 |
|
---|
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);
|
---|
713 | workflow_format.setComponentOrientation(Dictionary.getOrientation());
|
---|
714 |
|
---|
715 | JPanel predefined_pane = new JPanel();
|
---|
716 | predefined_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
717 |
|
---|
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);
|
---|
722 | predefined_combobox.setOpaque(false);
|
---|
723 | // Connection
|
---|
724 | predefined_combobox.addActionListener(new PredefinedActionListener());
|
---|
725 |
|
---|
726 | // Layout
|
---|
727 | checklist_pane.setLayout(new BoxLayout(checklist_pane, BoxLayout.Y_AXIS));
|
---|
728 | checklist_pane.add(title_label);
|
---|
729 | if (Configuration.get("workflow.download", true)) {
|
---|
730 | checklist_pane.add(workflow_download);
|
---|
731 | }
|
---|
732 | if (Configuration.get("workflow.gather", true)) {
|
---|
733 | checklist_pane.add(workflow_gather);
|
---|
734 | }
|
---|
735 | if (Configuration.get("workflow.enrich", true)) {
|
---|
736 | checklist_pane.add(workflow_enrich);
|
---|
737 | }
|
---|
738 | if (Configuration.get("workflow.design", true)) {
|
---|
739 | checklist_pane.add(workflow_design);
|
---|
740 | }
|
---|
741 | if (Configuration.get("workflow.create", true)) {
|
---|
742 | checklist_pane.add(workflow_create);
|
---|
743 | }
|
---|
744 | if (Configuration.get("workflow.format", true)) {
|
---|
745 | checklist_pane.add(workflow_format);
|
---|
746 | }
|
---|
747 |
|
---|
748 | predefined_pane.setLayout(new BorderLayout(5,0));
|
---|
749 | predefined_pane.add(predefined_label, BorderLayout.LINE_START);
|
---|
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 |
|
---|
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 | }
|
---|
770 |
|
---|
771 | private class OKButtonListener
|
---|
772 | implements ActionListener {
|
---|
773 | private boolean close;
|
---|
774 | public OKButtonListener(boolean close) {
|
---|
775 | this.close = close;
|
---|
776 | }
|
---|
777 | public void actionPerformed(ActionEvent event)
|
---|
778 | {
|
---|
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;
|
---|
782 | boolean keep_collection_open = false;
|
---|
783 | String restart_message = "";
|
---|
784 |
|
---|
785 |
|
---|
786 | // Connection preferences
|
---|
787 | String program_str = program_field.getText();
|
---|
788 | if (program_str.length() > 0 && program_str.indexOf("%1") == -1) {
|
---|
789 | program_str = program_str + " %1";
|
---|
790 | }
|
---|
791 | Configuration.setPreviewCommand(program_str);
|
---|
792 |
|
---|
793 | String old_library_url = (Configuration.library_url == null) ? null : Configuration.library_url.toString();
|
---|
794 | String library_url_string = library_path_field.getText();
|
---|
795 | if(old_library_url != null && !old_library_url.equals(library_url_string)) {
|
---|
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");
|
---|
803 |
|
---|
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
|
---|
808 | Gatherer.g_man.saveThenCloseCurrentCollection();
|
---|
809 | Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true, "");
|
---|
810 | }
|
---|
811 | }
|
---|
812 | if (library_url_string.equals("")) {
|
---|
813 | Configuration.library_url = null;
|
---|
814 | }
|
---|
815 | else {
|
---|
816 | try {
|
---|
817 | Configuration.library_url = new URL(library_url_string);
|
---|
818 | }
|
---|
819 | catch (MalformedURLException exception) {
|
---|
820 | DebugStream.printStackTrace(exception);
|
---|
821 | }
|
---|
822 | }
|
---|
823 |
|
---|
824 | Configuration.setString("general.library_url"+Configuration.gliPropertyNameSuffix(),
|
---|
825 | true, library_url_string);
|
---|
826 |
|
---|
827 | if (Gatherer.isGsdlRemote && !Gatherer.GS3) {
|
---|
828 | String old_gliserver_url = Configuration.gliserver_url.toString();
|
---|
829 | String gliserver_url_string = gliserver_url_field.getText();
|
---|
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
|
---|
837 | Gatherer.g_man.saveThenCloseCurrentCollection();
|
---|
838 | Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true, "");
|
---|
839 | }
|
---|
840 | }
|
---|
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 | }
|
---|
854 |
|
---|
855 |
|
---|
856 | boolean site_changed = false;
|
---|
857 | if (Gatherer.GS3) {
|
---|
858 | String current_site = Configuration.site_name;
|
---|
859 | String new_site =(String)site_combobox.getSelectedItem() ;
|
---|
860 | if (!new_site.equals(current_site)) {
|
---|
861 | site_changed = true;
|
---|
862 | }
|
---|
863 | Configuration.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem());
|
---|
864 | }
|
---|
865 |
|
---|
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() + "");
|
---|
869 | Gatherer.setProxy();
|
---|
870 |
|
---|
871 | // General preferences
|
---|
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());
|
---|
875 |
|
---|
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;
|
---|
882 | restart_message = Dictionary.get("Preferences.General.Restart_Required");
|
---|
883 |
|
---|
884 | }
|
---|
885 |
|
---|
886 | // GLI interface language
|
---|
887 | String current_lang = Configuration.getLanguage();
|
---|
888 | if (!current_lang.equals(((DictionaryEntry) language_combobox.getSelectedItem()).getLocale().getLanguage())) {
|
---|
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 |
|
---|
896 | Configuration.setLocale("general.locale", Configuration.GENERAL_SETTING, ((DictionaryEntry) language_combobox.getSelectedItem()).getLocale());
|
---|
897 | restart_required = true;
|
---|
898 | restart_message = Dictionary.get("Preferences.General.Restart_Required");
|
---|
899 | }
|
---|
900 |
|
---|
901 | // Inform the user that a restart is required, if necessary
|
---|
902 | if (restart_required) {
|
---|
903 | JOptionPane.showMessageDialog(Gatherer.g_man, restart_message, Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE);
|
---|
904 | }
|
---|
905 |
|
---|
906 | // Mode preferences
|
---|
907 | int current_mode = Configuration.getMode();
|
---|
908 | int new_mode;
|
---|
909 | if (assistant_mode_radio_button.isSelected()) {
|
---|
910 | new_mode = Configuration.ASSISTANT_MODE;
|
---|
911 | }
|
---|
912 | else if (expert_mode_radio_button.isSelected()) {
|
---|
913 | new_mode = Configuration.EXPERT_MODE;
|
---|
914 | }
|
---|
915 | else {
|
---|
916 | new_mode = Configuration.LIBRARIAN_MODE;
|
---|
917 | }
|
---|
918 |
|
---|
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
|
---|
920 | if (new_mode != current_mode) {
|
---|
921 | Configuration.setMode(new_mode);
|
---|
922 | Collection collection = Gatherer.c_man.getCollection();
|
---|
923 | if (collection != null) {
|
---|
924 | collection.cdm.modeChanged(new_mode);
|
---|
925 | }
|
---|
926 | Gatherer.g_man.modeChanged(new_mode);
|
---|
927 | }
|
---|
928 |
|
---|
929 | // Warning preferences
|
---|
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++) {
|
---|
932 | CheckListEntry entry = (CheckListEntry) warning_preferences_check_list_model.getElementAt(i);
|
---|
933 | Configuration.set(entry.getProperty(), true, entry.isSelected());
|
---|
934 | }
|
---|
935 |
|
---|
936 | if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection() != null && !Gatherer.isGsdlRemote) {
|
---|
937 | // shut down the collection
|
---|
938 | System.err.println("shutting down the collection");
|
---|
939 | Gatherer.g_man.saveThenCloseCurrentCollection();
|
---|
940 | }
|
---|
941 |
|
---|
942 | // Workflow preferences
|
---|
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());
|
---|
949 |
|
---|
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());
|
---|
956 |
|
---|
957 | // Always save configuration changes immediately (in case the GLI crashes)
|
---|
958 | Configuration.save();
|
---|
959 | if (Gatherer.isGsdlRemote && Gatherer.GS3 && site_changed ){
|
---|
960 | Gatherer.remoteGreenstoneServer.downloadCollectionConfigurations();
|
---|
961 | }
|
---|
962 | // Refresh the GLI to account for the configuration changes
|
---|
963 | Gatherer.refresh(Gatherer.PREFERENCES_CHANGED);
|
---|
964 |
|
---|
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 | }
|
---|
974 | }
|
---|
975 |
|
---|
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 |
|
---|
989 | if (restart_required) {
|
---|
990 | if (keep_collection_open) {
|
---|
991 | Gatherer.g_man.exitNoCollectionSave(Gatherer.EXIT_THEN_RESTART);
|
---|
992 | } else {
|
---|
993 | Gatherer.g_man.exit(Gatherer.EXIT_THEN_RESTART);
|
---|
994 | }
|
---|
995 | }
|
---|
996 | }
|
---|
997 | }
|
---|
998 |
|
---|
999 | private class CancelButtonListener
|
---|
1000 | implements ActionListener {
|
---|
1001 | public void actionPerformed(ActionEvent event) {
|
---|
1002 | self.dispose();
|
---|
1003 | }
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | private class DictionaryEntry
|
---|
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 |
|
---|
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 |
|
---|
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() {
|
---|
1071 | workflow_download.setSelected(element.getEnabled("download"));
|
---|
1072 | workflow_gather.setSelected(element.getEnabled("gather"));
|
---|
1073 | workflow_enrich.setSelected(element.getEnabled("enrich"));
|
---|
1074 | workflow_design.setSelected(element.getEnabled("design"));
|
---|
1075 | workflow_create.setSelected(element.getEnabled("create"));
|
---|
1076 | workflow_format.setSelected(element.getEnabled("format"));
|
---|
1077 | }
|
---|
1078 | }
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 |
|
---|
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();
|
---|
1088 | System.err.println("The site changed to = "+site);
|
---|
1089 | if (!site.equals(current_site_selection)) {
|
---|
1090 | current_site_selection = site;
|
---|
1091 | System.err.println("changed the current selection");
|
---|
1092 |
|
---|
1093 | ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);
|
---|
1094 | if (servlet_options == null) {
|
---|
1095 | ///ystem.err.println("no servlets for this site");
|
---|
1096 | servlet_combobox.setModel(new DefaultComboBoxModel());
|
---|
1097 | servlet_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Servlet_Tooltip2"));
|
---|
1098 | servlet_combobox.setEnabled(false);
|
---|
1099 |
|
---|
1100 | } else {
|
---|
1101 | ///ystem.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
|
---|
1102 | servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
|
---|
1103 | servlet_combobox.setToolTipText(Dictionary.get("Preferences.Connection.Servlet_Tooltip"));
|
---|
1104 | servlet_combobox.setEnabled(true);
|
---|
1105 | }
|
---|
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){
|
---|
1109 | File lock_file = new File(Gatherer.c_man.getLoadedCollectionDirectoryPath() + "gli.lck");
|
---|
1110 | Gatherer.remoteGreenstoneServer.deleteCollectionFile(Gatherer.c_man.getLoadedCollectionName(),lock_file);
|
---|
1111 | Gatherer.g_man.closeCurrentCollection();
|
---|
1112 | }
|
---|
1113 | Configuration.site_name=site;
|
---|
1114 | Gatherer.remoteGreenstoneServer.set_remote_greenstone_server_authentication_to_null();
|
---|
1115 | Gatherer.remoteGreenstoneServer.downloadCollectionConfigurations();
|
---|
1116 | }
|
---|
1117 | }
|
---|
1118 | }
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | private class UseProxyListener
|
---|
1122 | implements ActionListener {
|
---|
1123 | public void actionPerformed(ActionEvent event) {
|
---|
1124 | boolean enabled = use_proxy_checkbox.isSelected();
|
---|
1125 | Configuration.set("general.use_proxy", true, enabled);
|
---|
1126 | // Fortunately this is already driven by the event thread.
|
---|
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() {
|
---|
1146 | if (text == null) {
|
---|
1147 | text = Dictionary.get(element.getFirstChild().getNodeValue());
|
---|
1148 | }
|
---|
1149 | return text;
|
---|
1150 | }
|
---|
1151 | }
|
---|
1152 | }
|
---|