source: trunk/gli/src/org/greenstone/gatherer/gems/GEMSPreferences.java@ 8930

Last change on this file since 8930 was 8884, checked in by mdewsnip, 19 years ago

Moved the two CheckList classes into the util package, and removed the checklist package.

  • Property svn:keywords set to Author Date Id Revision
File size: 27.5 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.gems;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.io.*;
32import java.net.*;
33import java.util.*;
34import java.util.Vector;
35import javax.swing.*;
36import javax.swing.event.*;
37import org.greenstone.gatherer.Configuration;
38import org.greenstone.gatherer.Dictionary;
39import org.greenstone.gatherer.Gatherer;
40import org.greenstone.gatherer.cdm.LanguageManager;
41import org.greenstone.gatherer.collection.Collection;
42import org.greenstone.gatherer.gui.tree.DragTree;
43import org.greenstone.gatherer.gui.*;
44import org.greenstone.gatherer.util.ArrayTools; // just for debug
45import org.greenstone.gatherer.util.StaticStrings;
46import org.greenstone.gatherer.util.Utility;
47import org.w3c.dom.*;
48
49public class GEMSPreferences extends ModalDialog {
50
51 static final public String CONNECTION_PREFS = "connection";
52 static final public String GENERAL_PREFS = "general";
53
54
55 static final private Dimension LABEL_SIZE = new Dimension(280, 25);
56 static final private Dimension ROW_SIZE = new Dimension(640, 25);
57 static final private Dimension SIZE = new Dimension(640, 345);
58 static final private String TRUE = "true";
59
60 // private CheckList warning_preferences_check_list;
61 private EmailField email_field;
62 private JButton apply_button;
63 private JButton cancel_button;
64 private JButton ok_button;
65 private JCheckBox use_subfields_checkbox;
66
67 private JCheckBox use_proxy_checkbox;
68 private JCheckBox view_extracted_metadata_checkbox;
69
70 private JCheckBox workflow_create;
71 private JCheckBox workflow_mirror;
72 private JCheckBox workflow_gather;
73 private JCheckBox workflow_enrich;
74 private JCheckBox workflow_design;
75 private JCheckBox workflow_export;
76 private JComboBox language_combobox;
77 private JList language_limited_jlist;
78
79 private JComboBox servlet_combobox; // GS3
80 private JComboBox site_combobox; // GS3
81 private JLabel interface_language_label;
82 private JLabel language_label;
83 private JLabel library_path_label;
84 private JLabel predefined_label;
85 private JLabel program_label;
86 private JLabel proxy_host_label;
87 private JLabel proxy_port_label;
88 private JLabel title_label;
89 private JPanel servlet_pane;
90 private JRadioButton assistant_mode_radio_button;
91 private JRadioButton expert_mode_radio_button;
92 private JRadioButton librarian_mode_radio_button;
93 private JRadioButton systems_mode_radio_button;
94 private JSpinner proxy_port_field;
95 private JTabbedPane tab_pane;
96 private JTextArea mode_description_textarea;
97 private JTextField library_path_field;
98 private JTextField program_field;
99 private JTextField proxy_host_field;
100 private GEMSPreferences self;
101
102 private String current_site_selection;
103 public GEMSPreferences() {
104 this(GENERAL_PREFS);
105 }
106
107 public GEMSPreferences(String initial_view) {
108 // Initialize
109 super(Gatherer.g_man, true);
110 this.self = this;
111 setSize(SIZE);
112 Dictionary.registerText(this, "Preferences");
113 setJMenuBar(new SimpleMenuBar("preferences"));
114
115 // Creation
116 JPanel content_pane = (JPanel) getContentPane();
117 tab_pane = new JTabbedPane();
118 JPanel general_preferences = createGeneralPreferences();
119 tab_pane.add("Preferences.General", general_preferences);
120 //tab_pane.add("Preferences.Mode", createModePreferences());
121 // !! Temporarily disabled for the UNESCO CD-ROM !!
122 // tab_pane.add("Preferences.Workflow", createWorkflowPreferences());
123 //JPanel connection_preferences = createConnectionPreferences();
124 //tab_pane.add("Preferences.Connection", connection_preferences);
125 //tab_pane.add("Preferences.Warnings", createWarningPreferences());
126
127 Dictionary.register(tab_pane);
128
129 JPanel button_pane = new JPanel();
130 ok_button = new GLIButton();
131 ok_button.setMnemonic(KeyEvent.VK_O);
132
133 Dictionary.registerBoth(ok_button, "General.OK", "General.OK_Tooltip");
134 apply_button = new GLIButton();
135 apply_button.setMnemonic(KeyEvent.VK_A);
136 Dictionary.registerBoth(apply_button, "General.Apply", "General.Apply_Tooltip");
137 cancel_button = new GLIButton();
138 cancel_button.setMnemonic(KeyEvent.VK_C);
139 Dictionary.registerBoth(cancel_button, "General.Cancel", "General.Cancel_Tooltip");
140
141 // Connection
142 ok_button.addActionListener(new OKButtonListener(true));
143 apply_button.addActionListener(new OKButtonListener(false));
144 cancel_button.addActionListener(new CancelButtonListener());
145
146 // Layout
147 button_pane.setBorder(org.greenstone.gatherer.gui.BorderFactory.createEmptyBorder(5,2,2,2));
148 button_pane.setLayout(new GridLayout(1,3,0,5));
149 button_pane.add(ok_button);
150 button_pane.add(apply_button);
151 button_pane.add(cancel_button);
152
153 content_pane.setLayout(new BorderLayout());
154 content_pane.add(tab_pane, BorderLayout.CENTER);
155 content_pane.add(button_pane, BorderLayout.SOUTH);
156
157 Dimension frame_size;// = Gatherer.g_man.getSize();
158 Point frame_location;// = Gatherer.g_man.getLocation();
159 //setLocation(frame_location.x + ((frame_size.width - SIZE.width) / 2), frame_location.y + ((frame_size.height - SIZE.height)));
160 //setLocation(((frame_size.width - SIZE.width) / 2), ((frame_size.height - SIZE.height)));
161 setLocation(400, 300);
162
163
164 tab_pane.setSelectedComponent(general_preferences);
165
166
167
168 // Clean up
169 general_preferences = null;
170 //connection_preferences = null;
171 frame_location = null;
172 frame_size = null;
173 cancel_button = null;
174 ok_button = null;
175 button_pane = null;
176 tab_pane = null;
177 content_pane = null;
178
179 setVisible(true);
180 }
181
182 private JPanel createGeneralPreferences() {
183 JPanel general_pane = new JPanel();
184
185 // Build the model of available languages
186 ArrayList dictionary_model = new ArrayList();
187
188 // Old method for determining what languages should be available in the combobox
189 /*
190 dictionary_model.add(new DictionaryEntry(Locale.ENGLISH));
191 File classes_folder = new File(Utility.BASE_DIR + StaticStrings.CLASSES_FOLDER);
192 File[] possible_dictionaries = classes_folder.listFiles();
193 for(int i = 0; i < possible_dictionaries.length; i++) {
194 String filename = possible_dictionaries[i].getName();
195 if(filename.endsWith(StaticStrings.PROPERTIES_FILE_EXTENSION) && filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) != -1) {
196 StringTokenizer tokenizer = new StringTokenizer(filename.substring(filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) + 1, filename.indexOf(StaticStrings.STOP_CHARACTER)), StaticStrings.UNDERSCORE_CHARACTER);
197 Locale locale = null;
198 switch(tokenizer.countTokens()) {
199 case 1:
200 locale = new Locale(tokenizer.nextToken().toLowerCase());
201 break;
202 case 2:
203 locale = new Locale(tokenizer.nextToken().toLowerCase(), tokenizer.nextToken().toUpperCase());
204 break;
205 }
206 tokenizer = null;
207 // Open the file and read the first line
208 String description = null;
209 try {
210 BufferedReader br = new BufferedReader(new FileReader(possible_dictionaries[i]));
211 String first_line = br.readLine();
212 br.close();
213 description = first_line.substring(first_line.indexOf(StaticStrings.COLON_CHARACTER) + 1);
214 }
215 catch(Exception error) {
216 }
217 DictionaryEntry entry = new DictionaryEntry(description, locale);
218 description = null;
219 locale = null;
220 if(!dictionary_model.contains(entry)) {
221 dictionary_model.add(entry);
222 }
223 entry = null;
224 }
225 filename = null;
226 }
227 possible_dictionaries = null;
228 classes_folder = null;
229 */
230
231 // The new method makes use of the successor to the languages.dat file, classes/xml/languages.xml
232 NodeList language_elements = LanguageManager.LANGUAGES_DOCUMENT.getDocumentElement().getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
233 for(int i = 0; i < language_elements.getLength(); i++) {
234 Element language_element = (Element) language_elements.item(i);
235 if((language_element.getAttribute(StaticStrings.GLI_ATTRIBUTE)).equalsIgnoreCase(StaticStrings.TRUE_STR) || (language_element.getAttribute(StaticStrings.MDS_ATTRIBUTE)).equalsIgnoreCase(StaticStrings.TRUE_STR)) {
236 Locale locale = new Locale(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE));
237 String description = language_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
238 DictionaryEntry entry = new DictionaryEntry(description, locale);
239 if(!dictionary_model.contains(entry)) {
240 dictionary_model.add(entry);
241 }
242 entry = null;
243 description = null;
244 locale = null;
245 }
246 language_element = null;
247 }
248 language_elements = null;
249
250 // Users email
251 JPanel lang_limited_pane = new JPanel();
252 interface_language_label = new JLabel();
253 interface_language_label.setPreferredSize(LABEL_SIZE);
254
255
256 Dictionary.registerText(interface_language_label, "GEMS.Preferences.Selected_Languages_Tooltip");
257 email_field = new EmailField(Configuration.getColor("coloring.error_background", false));
258 email_field.setText(Configuration.getEmail());
259 Dictionary.registerTooltip(email_field, "GEMS.Preferences.Selected_Languages_Tooltip");
260
261 // Extracted metadata
262
263 //Dictionary.registerBoth(view_extracted_metadata_checkbox, "Preferences.General.View_Extracted_Metadata", "Preferences.General.View_Extracted_Metadata_Tooltip");
264
265 // Show file sizes
266 use_subfields_checkbox = new JCheckBox();
267 JLabel use_subfields_checkbox_label = new JLabel();
268 use_subfields_checkbox_label.setPreferredSize(new Dimension(225, 30));
269 use_subfields_checkbox.setSelected(false);
270 use_subfields_checkbox.setVisible(false);
271 use_subfields_checkbox_label.setVisible(false);
272
273 // String blah = Configuration.getString("coloring.workspace_tree_background",true);
274 // System.out.println("before"+ blah);
275
276 if (Configuration.get("GEMS.Preferences.Use_Subfields", true)) {
277 use_subfields_checkbox.setSelected(true);
278 }
279 Dictionary.registerBoth(use_subfields_checkbox_label, "GEMS.Preferences.Use_Subfields", "GEMS.Preferences.Use_Subfields_Tooltip");
280
281 // Language
282 JPanel language_pane = new JPanel();
283 language_label = new JLabel();
284 language_label.setPreferredSize(LABEL_SIZE);
285
286
287 Dictionary.registerText(language_label, "Preferences.General.Interface_Language");
288 language_combobox = new JComboBox(dictionary_model.toArray());
289 Dictionary.registerTooltip(language_combobox, "Preferences.General.Interface_Language_Tooltip");
290 // Try to locate and select the current language
291 String language_code = Configuration.getLanguage();
292 for(int b = 0; b < language_combobox.getItemCount(); b++) {
293 DictionaryEntry entry = (DictionaryEntry) language_combobox.getItemAt(b);
294 if(language_code.equalsIgnoreCase(entry.getLocale().getLanguage())) {
295 language_combobox.setSelectedIndex(b);
296 }
297 }
298
299 //create language_limited_jlist
300 //String [] newer = {"blah", "asfd", "dfjdddd", "blee11" ,"asdfsdfsdf", "asdfdsf","asdfsdfsdf", "asdfdsf","asdfsdfsdf", "asdfdsf","safd", "safd", "safd", "safd"};
301
302
303
304 //create language selected box, and high light the apprpropate ones
305 int [] selectedLanguages = new int[300];
306 int selectedLanguagesLength = 0;
307
308
309 //GemsLanguageManager gemsLangManager = new GemsLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml");
310 GEMSLanguageManager gemsLangManager = new GEMSLanguageManager(Configuration.gsdl_path + "/gli/classes/xml/languages.xml");
311
312
313 language_limited_jlist = new JList(gemsLangManager.getLanguageCodesToArray());
314 String enabled_languages = Configuration.getString("GEMS.Preferences.Selected_Languages", true);
315 //we have a string : enabled_languages that contains an array of strings delimited by comma's
316 String []enabled_languages_split = enabled_languages.split(",");
317 Object []language_codes_array = gemsLangManager.getLanguageCodesToArray();
318
319 //System.out.println("before: " +enabled_languages_split[0].toString() + " meh: " + enabled_languages);
320 Vector selected = new Vector();
321
322 //for each enabled_languages_split
323 //check which languages match, and store the index in selectedLanguages
324 for(int k = 0; k < enabled_languages_split.length; k++) {
325
326 for(int p =0; p < language_codes_array.length; p++){
327
328 //if the codes match, then include the index p into the vector selectedLanguages
329 if (language_codes_array[p].toString().toLowerCase().trim().compareTo(enabled_languages_split[k].toLowerCase().trim()) == 0)
330 {
331 // System.out.println(language_codes_array[p].toString().toLowerCase().trim() + " " + enabled_languages_split[k].toLowerCase().trim());
332
333 // selected.add(p);
334 selectedLanguages[selectedLanguagesLength] = p;
335 selectedLanguagesLength++;
336 language_limited_jlist.addSelectionInterval(p,p);
337 }
338
339
340 }
341
342
343 }
344
345 //selectedLanguages should contain the indices of the languages that should be selected as
346 //stated in enabled_languages
347
348 //language_limited_jlist.setSelectedIndices(selectedLanguages);
349 // language_limited_jlist.addSelectionInterval(1,1);
350 //language_limited_jlist.setSelectedIndex(1);
351
352 //because the very first language(index 0) gets chosen no matter what...
353 //then I unselected the 0 index, and then check the config file to see if that particular language is
354 //indeed selected
355 // language_limited_jlist.set
356
357
358
359
360 // Connect
361 language_combobox.addActionListener(new LanguageComboboxListener());
362
363 // Layout
364
365 JScrollPane langScrollPane = new JScrollPane(language_limited_jlist);
366
367 //langScrollPane.getViewport().setView(language_limited_jlist);
368
369 // langScrollPane.setSize(175, 100);
370 langScrollPane.setPreferredSize(new Dimension(100, 100));
371 lang_limited_pane.setLayout(new GridLayout(1,3));
372 lang_limited_pane.add(interface_language_label);
373 lang_limited_pane.add(langScrollPane);
374
375
376 language_pane.setLayout(new BorderLayout());
377 language_pane.add(language_label, BorderLayout.WEST);
378 language_pane.add(language_combobox, BorderLayout.CENTER);
379
380 general_pane.setBorder(org.greenstone.gatherer.gui.BorderFactory.createEmptyBorder(5,5,5,5));
381 //general_pane.setLayout(new GridLayout(4,1,0,5));
382 general_pane.setLayout(null);
383
384 general_pane.add(lang_limited_pane);
385 general_pane.add(language_pane);
386 //general_pane.add(view_extracted_metadata_checkbox);
387 general_pane.add(use_subfields_checkbox);
388 general_pane.add(use_subfields_checkbox_label);
389 Insets general_pane_insets = general_pane.getInsets();
390
391 lang_limited_pane.setBounds(20+general_pane_insets.left, 20+general_pane_insets.top,
392 lang_limited_pane.getPreferredSize().width, lang_limited_pane.getPreferredSize().height);
393
394 language_pane.setBounds(20+general_pane_insets.left, 130+general_pane_insets.top,
395 language_pane.getPreferredSize().width, language_pane.getPreferredSize().height);
396
397 use_subfields_checkbox_label.setBounds(20+general_pane_insets.left, 200+general_pane_insets.top,
398 use_subfields_checkbox_label.getPreferredSize().width, use_subfields_checkbox_label.getPreferredSize().height);
399
400 use_subfields_checkbox.setBounds(295+general_pane_insets.left, 200+general_pane_insets.top,
401 use_subfields_checkbox.getPreferredSize().width, use_subfields_checkbox.getPreferredSize().height);
402
403 return general_pane;
404 }
405
406
407 private class OKButtonListener
408 implements ActionListener {
409 private boolean close;
410 public OKButtonListener(boolean close) {
411 this.close = close;
412 }
413 public void actionPerformed(ActionEvent event) {
414 // Submit the various changes
415 // Connection preferences
416 /* String program_str = program_field.getText();
417 if(program_str.length() > 0 && program_str.indexOf("%1") == -1) {
418 program_str = program_str + " %1";
419 }
420 Configuration.setPreviewCommand(program_str);
421
422 boolean site_changed = false;
423 if (Gatherer.GS3) {
424 String current_site = Configuration.site_name;
425 String new_site =(String)site_combobox.getSelectedItem() ;
426 if (!new_site.equals(current_site)) {
427 site_changed = true;
428 }
429 Configuration.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem());
430 }
431
432 Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
433 Configuration.setString("general.proxy_host", true, proxy_host_field.getText());
434 Configuration.setString("general.proxy_port", true, proxy_port_field.getValue() + "");
435 Gatherer.setProxy();
436
437 // General preferences
438 Configuration.setEmail(email_field.getText());
439
440 Configuration.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, use_subfields_checkbox.isSelected());
441 // Force both workspace and collection trees to redraw
442 if (Gatherer.g_man != null) {
443 Gatherer.g_man.refreshWorkspaceTree(DragTree.TREE_DISPLAY_CHANGED);
444 Gatherer.g_man.refreshCollectionTree(DragTree.TREE_DISPLAY_CHANGED);
445 }
446*/
447 //save selected languages list box
448
449 //goes here
450
451 //save subfield checkbox
452
453 Configuration.set("Gems.Preferences.Use_Subfields", true, use_subfields_checkbox.isSelected());
454 // Gatherer.g_man.enrich_pane.valueChanged((TreeSelectionEvent) null); // Refresh metadata table
455
456
457 //save interface language
458 String current_lang = Configuration.getLanguage();
459 String new_lang = ((DictionaryEntry)language_combobox.getSelectedItem()).getLocale().getLanguage();
460 if (!current_lang.equals(new_lang)) {
461 Configuration.setLocale("general.locale", Configuration.GENERAL_SETTING, ((DictionaryEntry)language_combobox.getSelectedItem()).getLocale());
462 }
463
464
465
466 //////////////////////save language limited jlist selections
467
468 Vector stringVector = new Vector();
469
470 Object[] selectedValues = language_limited_jlist.getSelectedValues();
471 String concatString = new String();
472
473 for(int k = 0; k < selectedValues.length; k++) {
474 // System.out.println(language_limited_jlist.getComponent(0).toString());//allSelectedLanguages[k]
475
476 //System.out.println(selectedValues[k]);
477
478 if(selectedValues.length-k > 1)
479 concatString = concatString.concat(selectedValues[k].toString() +",");
480 else
481 concatString = concatString.concat(selectedValues[k].toString());
482
483 }
484
485
486 // System.out.println("final cat string: "+ concatString);
487
488
489 Configuration.setString("GEMS.Preferences.Selected_Languages",true, concatString);
490
491 ///////////////////
492/*
493 // Mode preferences
494 int current_mode = Configuration.getMode();
495 int new_mode;
496 if(assistant_mode_radio_button.isSelected()) {
497 new_mode = Configuration.ASSISTANT_MODE;
498 }
499 else if(systems_mode_radio_button.isSelected()) {
500 new_mode = Configuration.SYSTEMS_MODE;
501 }
502 else if(expert_mode_radio_button.isSelected()) {
503 new_mode = Configuration.EXPERT_MODE;
504 }
505 else {
506 new_mode = Configuration.LIBRARIAN_MODE;
507 }
508 // If there has been a change in modes, update the config, and also inform the persistant gui views that have a need to know
509 if(new_mode != current_mode) {
510 Configuration.setMode(new_mode);
511 Collection collection = Gatherer.c_man.getCollection();
512 if (collection != null) {
513 collection.cdm.modeChanged(new_mode);
514 }
515 Gatherer.g_man.modeChanged(new_mode);
516 }
517 // Warning preferences
518 for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) {
519 Entry entry = warning_preferences_check_list.get(i);
520 Configuration.set(entry.getProperty(), true, entry.isSelected());
521 }
522
523 if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection()!=null) {
524 // shut down the collection
525 System.err.println("shutting down teh collection");
526 Gatherer.g_man.closeCurrentCollection();
527 }
528*/
529 // Workflow preferences
530 // Configuration.set("workflow.mirror", false, workflow_mirror.isSelected());
531 // Configuration.set("workflow.gather", false, workflow_gather.isSelected());
532 // Configuration.set("workflow.enrich", false, workflow_enrich.isSelected());
533 // Configuration.set("workflow.design", false, workflow_design.isSelected());
534 // Configuration.set("workflow.export", false, workflow_export.isSelected());
535 // Configuration.set("workflow.create", false, workflow_create.isSelected());
536 // Gatherer.g_man.workflowUpdate("Mirror", workflow_mirror.isSelected());
537 // Gatherer.g_man.workflowUpdate("Gather", workflow_gather.isSelected());
538 // Gatherer.g_man.workflowUpdate("Enrich", workflow_enrich.isSelected());
539 // Gatherer.g_man.workflowUpdate("Design", (workflow_design.isSelected() && Configuration.getMode() > Configuration.ASSISTANT_MODE));
540 // Gatherer.g_man.workflowUpdate("Export", workflow_export.isSelected());
541 // Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());
542
543 // Always save configuration changes immediately (in case the GLI crashes)
544 Configuration.save();
545
546 // Hide dialog
547 if(close) {
548 self.dispose();
549 }
550 }
551 }
552
553 private class CancelButtonListener
554 implements ActionListener {
555 public void actionPerformed(ActionEvent event) {
556 self.dispose();
557 }
558 }
559
560 private class DictionaryEntry
561 implements Comparable {
562 private Locale locale;
563 private String description;
564 public DictionaryEntry(Locale locale) {
565 this.description = null;
566 this.locale = locale;
567 }
568 public DictionaryEntry(String description, Locale locale) {
569 this.description = description;
570 this.locale = locale;
571 }
572 public int compareTo(Object object) {
573 return toString().compareTo(object.toString());
574 }
575 public boolean equals(Object object) {
576 return toString().equals(object.toString());
577 }
578 public Locale getLocale() {
579 return locale;
580 }
581 public String toString() {
582 if(description != null) {
583 return description;
584 }
585 else {
586 return locale.getDisplayName();
587 }
588 }
589 }
590
591 /** This listener updates the mode description depending on what mode is selected. */
592 private class ModeRadioButtonListener
593 implements ActionListener {
594 public void actionPerformed(ActionEvent event) {
595 Object source = event.getSource();
596 if(source == assistant_mode_radio_button) {
597 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
598 }
599 else if(source == expert_mode_radio_button) {
600 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
601 }
602 else if(source == systems_mode_radio_button) {
603 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));
604 }
605 else {
606 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
607 }
608 source = null;
609 }
610 }
611
612 private class PredefinedActionListener
613 implements ActionListener {
614 public void actionPerformed(ActionEvent event) {
615 JComboBox cb = (JComboBox) event.getSource();
616 WorkflowElementWrapper element = (WorkflowElementWrapper) cb.getSelectedItem();
617 CheckboxUpdater task = new CheckboxUpdater(element);
618 SwingUtilities.invokeLater(task);
619 }
620
621 private class CheckboxUpdater
622 implements Runnable {
623 private WorkflowElementWrapper element;
624 public CheckboxUpdater(WorkflowElementWrapper element) {
625 this.element = element;
626 }
627 public void run() {
628 workflow_create.setSelected(element.getEnabled("create"));
629 workflow_mirror.setSelected(element.getEnabled("mirror"));
630 workflow_gather.setSelected(element.getEnabled("gather"));
631 workflow_enrich.setSelected(element.getEnabled("enrich"));
632 workflow_design.setSelected(element.getEnabled("design"));
633 workflow_export.setSelected(element.getEnabled("export"));
634 }
635 }
636 }
637
638 private class LanguageComboboxListener
639 implements ActionListener {
640 public void actionPerformed(ActionEvent event) {
641 // Retrieve the entry
642 DictionaryEntry entry = (DictionaryEntry) language_combobox.getSelectedItem();
643 if(entry != null) {
644 //Gatherer.dictionary.changeDictionary(entry.getLocale());
645 // Display message
646 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Preferences.General.Restart_Required"), Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE);
647 }
648 }
649 }
650
651 private class SiteComboboxListener
652 implements ActionListener {
653 private boolean ignore_event=false;
654 public void actionPerformed(ActionEvent event) {
655 System.err.println("event occurred "+event.paramString());
656 String site = (String) site_combobox.getSelectedItem();
657 System.err.println("new site = "+site);
658 if (!site.equals(current_site_selection)) {
659 current_site_selection = site;
660 System.err.println("changed the current selection");
661 ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);
662 if (servlet_options == null) {
663 System.err.println("no servlets for this site");
664 servlet_combobox.setModel(new DefaultComboBoxModel());
665 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip2");
666 servlet_combobox.setEnabled(false);
667
668 } else {
669 System.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
670 servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
671 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip");
672 servlet_combobox.setEnabled(true);
673 }
674 }
675 }
676 }
677
678 private class UseProxyListener
679 implements ActionListener {
680 public void actionPerformed(ActionEvent event) {
681 boolean enabled = use_proxy_checkbox.isSelected();
682 Configuration.set("general.use_proxy", true, enabled);
683 // Fortunately this is already driven by the event thread.
684 proxy_host_field.setEnabled(enabled);
685 proxy_port_field.setEnabled(enabled);
686 }
687 }
688
689 private class WorkflowElementWrapper {
690 private Element element;
691 private String text;
692 public WorkflowElementWrapper(Element element) {
693 this.element = element;
694 }
695 public boolean getEnabled(String name) {
696 boolean result = true;
697 if(element.getAttribute(name).equalsIgnoreCase("false")) {
698 result = false;
699 }
700 return result;
701 }
702 public String toString() {
703 if(text == null) {
704 text = element.getFirstChild().getNodeValue();
705 }
706 return text;
707 }
708 }
709}
Note: See TracBrowser for help on using the repository browser.