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

Last change on this file since 8881 was 8834, checked in by mdewsnip, 19 years ago

Removed some unnecessary code.

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