[5164] | 1 | package org.greenstone.gatherer.gui;
|
---|
| 2 |
|
---|
| 3 | import java.awt.*;
|
---|
| 4 | import java.awt.event.*;
|
---|
| 5 | import java.io.*;
|
---|
| 6 | import java.net.*;
|
---|
| 7 | import java.util.*;
|
---|
| 8 | import javax.swing.*;
|
---|
| 9 | import javax.swing.event.*;
|
---|
| 10 | import org.greenstone.gatherer.Configuration;
|
---|
| 11 | import org.greenstone.gatherer.Gatherer;
|
---|
| 12 | import org.greenstone.gatherer.checklist.CheckList;
|
---|
| 13 | import org.greenstone.gatherer.checklist.Entry;
|
---|
| 14 | import org.greenstone.gatherer.gui.GUIManager;
|
---|
| 15 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
| 16 | import org.greenstone.gatherer.gui.NumberField;
|
---|
| 17 | import org.greenstone.gatherer.gui.SimpleMenuBar;
|
---|
| 18 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
| 19 | import org.greenstone.gatherer.util.Utility;
|
---|
| 20 | import org.w3c.dom.*;
|
---|
| 21 |
|
---|
| 22 | public class Preferences
|
---|
| 23 | extends ModalDialog {
|
---|
| 24 |
|
---|
| 25 | private CheckList warning_preferences_check_list;
|
---|
| 26 | private JButton apply_button;
|
---|
| 27 | private JButton cancel_button;
|
---|
| 28 | private JButton ok_button;
|
---|
[5311] | 29 | private JCheckBox show_file_size_checkbox;
|
---|
[5164] | 30 | private JCheckBox use_proxy_checkbox;
|
---|
[5311] | 31 | private JCheckBox view_extracted_metadata_checkbox;
|
---|
[5164] | 32 | private JCheckBox workflow_browse;
|
---|
| 33 | private JCheckBox workflow_create;
|
---|
| 34 | private JCheckBox workflow_mirror;
|
---|
| 35 | private JCheckBox workflow_gather;
|
---|
| 36 | private JCheckBox workflow_enrich;
|
---|
| 37 | private JCheckBox workflow_design;
|
---|
| 38 | private JCheckBox workflow_export;
|
---|
| 39 | private JCheckBox workflow_preview;
|
---|
| 40 | private JComboBox language_combobox;
|
---|
| 41 | private JLabel language_label;
|
---|
| 42 | private JLabel library_path_label;
|
---|
| 43 | private JLabel predefined_label;
|
---|
| 44 | private JLabel proxy_host_label;
|
---|
| 45 | private JLabel proxy_port_label;
|
---|
| 46 | private JLabel title_label;
|
---|
| 47 | private JTabbedPane tab_pane;
|
---|
| 48 | private JTextField library_path_field;
|
---|
| 49 | private JTextField proxy_host_field;
|
---|
| 50 | private JTextField proxy_port_field;
|
---|
| 51 | private Preferences self;
|
---|
| 52 |
|
---|
| 53 | static final Dimension LABEL_SIZE = new Dimension(150, 25);
|
---|
| 54 | static final Dimension ROW_SIZE = new Dimension(450, 25);
|
---|
| 55 | static final Dimension SIZE = new Dimension(450, 345);
|
---|
| 56 | static final String TRUE = "true";
|
---|
| 57 |
|
---|
| 58 | public Preferences() {
|
---|
| 59 | // Initialize
|
---|
| 60 | super(Gatherer.g_man, true);
|
---|
| 61 | this.self = this;
|
---|
| 62 | setSize(SIZE);
|
---|
| 63 | setTitle("Preferences");
|
---|
| 64 | setJMenuBar(new SimpleMenuBar("10.2"));
|
---|
| 65 | // Creation
|
---|
| 66 | JPanel content_pane = (JPanel) getContentPane();
|
---|
| 67 | tab_pane = new JTabbedPane();
|
---|
| 68 | tab_pane.add("Preferences.General", createGeneralPreferences());
|
---|
| 69 | tab_pane.add("Preferences.Workflow", createWorkflowPreferences());
|
---|
| 70 | tab_pane.add("Preferences.Connection", createConnectionPreferences());
|
---|
| 71 | tab_pane.add("Preferences.Warnings", createWarningPreferences());
|
---|
| 72 |
|
---|
| 73 | JPanel button_pane = new JPanel();
|
---|
| 74 | ok_button = new JButton("General.OK");
|
---|
| 75 | apply_button = new JButton("General.Apply");
|
---|
| 76 | cancel_button = new JButton("General.Cancel");
|
---|
| 77 | // Connection
|
---|
| 78 | Gatherer.dictionary.register(this, null, false);
|
---|
| 79 | Gatherer.dictionary.register(tab_pane, null, false);
|
---|
| 80 | Gatherer.dictionary.register(ok_button, null, false);
|
---|
| 81 | Gatherer.dictionary.register(apply_button, null, false);
|
---|
| 82 | Gatherer.dictionary.register(cancel_button, null, false);
|
---|
| 83 | ok_button.addActionListener(new OKButtonListener(true));
|
---|
| 84 | apply_button.addActionListener(new OKButtonListener(false));
|
---|
| 85 | cancel_button.addActionListener(new CancelButtonListener());
|
---|
| 86 | // Layout
|
---|
| 87 | button_pane.setBorder(BorderFactory.createEmptyBorder(5,2,2,2));
|
---|
| 88 | button_pane.setLayout(new GridLayout(1,3,0,5));
|
---|
| 89 | button_pane.add(ok_button);
|
---|
| 90 | button_pane.add(apply_button);
|
---|
| 91 | button_pane.add(cancel_button);
|
---|
| 92 |
|
---|
| 93 | content_pane.setLayout(new BorderLayout());
|
---|
| 94 | content_pane.add(tab_pane, BorderLayout.CENTER);
|
---|
| 95 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
| 96 |
|
---|
| 97 | Dimension frame_size = Gatherer.g_man.getSize();
|
---|
| 98 | Point frame_location = Gatherer.g_man.getLocation();
|
---|
| 99 | //setLocation(frame_location.x + ((frame_size.width - SIZE.width) / 2), frame_location.y + ((frame_size.height - SIZE.height)));
|
---|
| 100 | setLocation(((frame_size.width - SIZE.width) / 2), ((frame_size.height - SIZE.height)));
|
---|
| 101 |
|
---|
| 102 | // Clean up
|
---|
| 103 | frame_location = null;
|
---|
| 104 | frame_size = null;
|
---|
| 105 | cancel_button = null;
|
---|
| 106 | ok_button = null;
|
---|
| 107 | button_pane = null;
|
---|
| 108 | tab_pane = null;
|
---|
| 109 | content_pane = null;
|
---|
| 110 | setVisible(true);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | private JPanel createConnectionPreferences() {
|
---|
| 114 | JPanel library_path_pane = new JPanel();
|
---|
| 115 | library_path_pane.setPreferredSize(ROW_SIZE);
|
---|
| 116 | library_path_label = new JLabel("Preferences.Connection.Library_Path");
|
---|
| 117 | library_path_label.setPreferredSize(LABEL_SIZE);
|
---|
| 118 | library_path_field = new JTextField(Gatherer.config.getString("general.exec_address", true));
|
---|
| 119 | library_path_field.setCaretPosition(0);
|
---|
| 120 |
|
---|
| 121 | boolean currently_enabled = Gatherer.config.get("general.use_proxy", true);
|
---|
| 122 | // Creation
|
---|
| 123 | JPanel connection_pane = new JPanel();
|
---|
| 124 | use_proxy_checkbox = new JCheckBox("Preferences.Connection.Use_Proxy", currently_enabled);
|
---|
| 125 | use_proxy_checkbox.setPreferredSize(ROW_SIZE);
|
---|
| 126 | JPanel proxy_host_pane = new JPanel();
|
---|
| 127 | proxy_host_pane.setPreferredSize(ROW_SIZE);
|
---|
| 128 | proxy_host_label = new JLabel("Preferences.Connection.Proxy_Host");
|
---|
| 129 | proxy_host_label.setPreferredSize(LABEL_SIZE);
|
---|
| 130 | proxy_host_field = new JTextField(Gatherer.config.getString("general.proxy_host", true));
|
---|
| 131 | proxy_host_field.setEnabled(currently_enabled);
|
---|
| 132 | JPanel proxy_port_pane = new JPanel();
|
---|
| 133 | proxy_port_pane.setPreferredSize(ROW_SIZE);
|
---|
| 134 | proxy_port_label = new JLabel("Preferences.Connection.Proxy_Port");
|
---|
| 135 | proxy_port_label.setPreferredSize(LABEL_SIZE);
|
---|
| 136 | proxy_port_field = new NumberField(Gatherer.config.getString("general.proxy_port", true));
|
---|
| 137 | proxy_port_field.setEnabled(currently_enabled);
|
---|
| 138 |
|
---|
| 139 | // Connection
|
---|
| 140 | Gatherer.dictionary.register(library_path_label, null, false);
|
---|
| 141 | Gatherer.dictionary.register(use_proxy_checkbox, null, false);
|
---|
| 142 | Gatherer.dictionary.register(proxy_host_label, null, false);
|
---|
| 143 | Gatherer.dictionary.register(proxy_port_label, null, false);
|
---|
| 144 | use_proxy_checkbox.addActionListener(new UseProxyListener());
|
---|
[5311] | 145 |
|
---|
[5164] | 146 | // Layout
|
---|
| 147 | library_path_pane.setLayout(new BorderLayout());
|
---|
| 148 | library_path_pane.add(library_path_label, BorderLayout.WEST);
|
---|
| 149 | library_path_pane.add(library_path_field, BorderLayout.CENTER);
|
---|
| 150 |
|
---|
| 151 | proxy_host_pane.setLayout(new BorderLayout());
|
---|
| 152 | proxy_host_pane.add(proxy_host_label, BorderLayout.WEST);
|
---|
| 153 | proxy_host_pane.add(proxy_host_field, BorderLayout.CENTER);
|
---|
| 154 |
|
---|
| 155 | proxy_port_pane.setLayout(new BorderLayout());
|
---|
| 156 | proxy_port_pane.add(proxy_port_label, BorderLayout.WEST);
|
---|
| 157 | proxy_port_pane.add(proxy_port_field, BorderLayout.CENTER);
|
---|
| 158 |
|
---|
| 159 | connection_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
| 160 | connection_pane.add(library_path_pane);
|
---|
| 161 | connection_pane.add(use_proxy_checkbox);
|
---|
| 162 | connection_pane.add(proxy_host_pane);
|
---|
| 163 | connection_pane.add(proxy_port_pane);
|
---|
| 164 |
|
---|
| 165 | return connection_pane;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | private JPanel createGeneralPreferences() {
|
---|
| 169 | JPanel general_pane = new JPanel();
|
---|
| 170 |
|
---|
| 171 | // Build the model of available languages
|
---|
| 172 | ArrayList dictionary_model = new ArrayList();
|
---|
| 173 |
|
---|
| 174 | Locale french = new Locale("fr","FR");
|
---|
| 175 | System.err.println("French locale: " + french);
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 | dictionary_model.add(new DictionaryEntry(Locale.ENGLISH));
|
---|
| 179 | File classes_folder = new File(Utility.BASE_DIR + StaticStrings.CLASSES_FOLDER);
|
---|
| 180 | File[] possible_dictionaries = classes_folder.listFiles();
|
---|
| 181 | for(int i = 0; i < possible_dictionaries.length; i++) {
|
---|
| 182 | String filename = possible_dictionaries[i].getName();
|
---|
| 183 | if(filename.endsWith(StaticStrings.PROPERTIES_FILE_EXTENSION) && filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) != -1) {
|
---|
| 184 | StringTokenizer tokenizer = new StringTokenizer(filename.substring(filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) + 1, filename.indexOf(StaticStrings.STOP_CHARACTER)), StaticStrings.UNDERSCORE_CHARACTER);
|
---|
| 185 | Locale locale = null;
|
---|
| 186 | switch(tokenizer.countTokens()) {
|
---|
| 187 | case 1:
|
---|
| 188 | locale = new Locale(tokenizer.nextToken().toLowerCase());
|
---|
| 189 | break;
|
---|
| 190 | case 2:
|
---|
| 191 | locale = new Locale(tokenizer.nextToken().toLowerCase(), tokenizer.nextToken().toUpperCase());
|
---|
| 192 | break;
|
---|
| 193 | }
|
---|
| 194 | tokenizer = null;
|
---|
| 195 | // Open the file and read the first line
|
---|
| 196 | String description = null;
|
---|
| 197 | try {
|
---|
| 198 | BufferedReader br = new BufferedReader(new FileReader(possible_dictionaries[i]));
|
---|
| 199 | String first_line = br.readLine();
|
---|
| 200 | br.close();
|
---|
| 201 | description = first_line.substring(first_line.indexOf(StaticStrings.COLON_CHARACTER) + 1);
|
---|
| 202 | }
|
---|
| 203 | catch(Exception error) {
|
---|
| 204 | }
|
---|
| 205 | DictionaryEntry entry = new DictionaryEntry(description, locale);
|
---|
| 206 | description = null;
|
---|
| 207 | locale = null;
|
---|
| 208 | if(!dictionary_model.contains(entry)) {
|
---|
| 209 | dictionary_model.add(entry);
|
---|
| 210 | }
|
---|
| 211 | entry = null;
|
---|
| 212 | }
|
---|
| 213 | filename = null;
|
---|
| 214 | }
|
---|
| 215 | possible_dictionaries = null;
|
---|
| 216 | classes_folder = null;
|
---|
| 217 |
|
---|
| 218 | // Extracted metadata
|
---|
[5311] | 219 | view_extracted_metadata_checkbox = new JCheckBox("Preferences.General.View_Extracted_Metadata", false);
|
---|
| 220 | if (Gatherer.config.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC)) {
|
---|
| 221 | view_extracted_metadata_checkbox.setSelected(true);
|
---|
[5164] | 222 | }
|
---|
| 223 |
|
---|
| 224 | // Show file sizes
|
---|
[5311] | 225 | show_file_size_checkbox = new JCheckBox("Preferences.General.Show_File_Size", false);
|
---|
| 226 | if (Gatherer.config.get("general.show_file_size", Configuration.COLLECTION_SPECIFIC)) {
|
---|
| 227 | show_file_size_checkbox.setSelected(true);
|
---|
[5164] | 228 | }
|
---|
| 229 |
|
---|
| 230 | // Language
|
---|
| 231 | JPanel language_pane = new JPanel();
|
---|
| 232 | language_label = new JLabel("Preferences.General.Interface_Language");
|
---|
| 233 | language_label.setPreferredSize(LABEL_SIZE);
|
---|
| 234 | language_combobox = new JComboBox(dictionary_model.toArray());
|
---|
| 235 |
|
---|
| 236 | // Connect
|
---|
[5311] | 237 | // Gatherer.dictionary.register(view_extracted_metadata_checkbox);
|
---|
| 238 | // Gatherer.dictionary.register(show_file_size_checkbox);
|
---|
[5164] | 239 | Gatherer.dictionary.register(language_label, null, false);
|
---|
| 240 | language_combobox.addActionListener(new LanguageComboboxListener());
|
---|
[5311] | 241 |
|
---|
[5164] | 242 | // Layout
|
---|
| 243 | language_pane.setLayout(new BorderLayout());
|
---|
| 244 | language_pane.add(language_label, BorderLayout.WEST);
|
---|
| 245 | language_pane.add(language_combobox, BorderLayout.CENTER);
|
---|
| 246 |
|
---|
| 247 | general_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
| 248 | general_pane.setLayout(new GridLayout(5,1,0,5));
|
---|
[5311] | 249 | general_pane.add(view_extracted_metadata_checkbox);
|
---|
| 250 | general_pane.add(show_file_size_checkbox);
|
---|
[5164] | 251 | general_pane.add(language_pane);
|
---|
| 252 |
|
---|
| 253 | return general_pane;
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | /** The warning preferences are controlled through a checklist. */
|
---|
| 257 | private JPanel createWarningPreferences() {
|
---|
| 258 | // Retrieve all of the warning preferences settings.
|
---|
| 259 | HashMap warning_preferences = Gatherer.config.getAll("warning\\..*", true);
|
---|
| 260 | warning_preferences_check_list = new CheckList(false);
|
---|
| 261 | for(Iterator keys = warning_preferences.keySet().iterator(); keys.hasNext(); ) {
|
---|
| 262 | String property = (String) keys.next();
|
---|
| 263 | String value = (String) warning_preferences.get(property);
|
---|
[5311] | 264 | // Remove 'warning.'
|
---|
[5164] | 265 | String title = Gatherer.dictionary.get(property.substring(8) + ".Title");
|
---|
| 266 | Entry entry = new Entry(title, value.equalsIgnoreCase(TRUE));
|
---|
| 267 | entry.setProperty(property);
|
---|
| 268 | warning_preferences_check_list.addEntry(entry);
|
---|
| 269 | }
|
---|
| 270 | // Creation
|
---|
| 271 | JPanel warning_preferences_pane = new JPanel();
|
---|
| 272 | // Connection
|
---|
| 273 | // Layout
|
---|
| 274 | warning_preferences_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
| 275 | warning_preferences_pane.setLayout(new BorderLayout());
|
---|
| 276 | warning_preferences_pane.add(new JScrollPane(warning_preferences_check_list), BorderLayout.CENTER);
|
---|
| 277 |
|
---|
| 278 | return warning_preferences_pane;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | private JPanel createWorkflowPreferences() {
|
---|
| 282 | // Read in the predefined configurations file.
|
---|
| 283 | Vector predefined = new Vector();
|
---|
| 284 | Document predefined_document = Utility.parse("xml/workflows.xml", true);
|
---|
| 285 | Element predefined_element = predefined_document.getDocumentElement();
|
---|
| 286 | NodeList workflow_elements = predefined_element.getElementsByTagName("Workflow");
|
---|
| 287 | for(int i = 0; i < workflow_elements.getLength(); i++) {
|
---|
| 288 | predefined.add(new WorkflowElementWrapper((Element)workflow_elements.item(i)));
|
---|
| 289 | }
|
---|
| 290 | // Creation
|
---|
| 291 | JPanel workflow_preferences_pane = new JPanel();
|
---|
| 292 | JPanel checklist_pane = new JPanel();
|
---|
| 293 | title_label = new JLabel("Preferences.Workflow.Title");
|
---|
| 294 | title_label.setPreferredSize(ROW_SIZE);
|
---|
| 295 | workflow_browse = new JCheckBox("Preferences.Workflow.Browse", Gatherer.config.get("workflow.browse", false));
|
---|
| 296 | workflow_browse.setPreferredSize(ROW_SIZE);
|
---|
| 297 | workflow_mirror = new JCheckBox("Preferences.Workflow.Mirror", Gatherer.config.get("workflow.mirror", false));
|
---|
| 298 | workflow_mirror.setPreferredSize(ROW_SIZE);
|
---|
| 299 | workflow_gather = new JCheckBox("Preferences.Workflow.Gather", Gatherer.config.get("workflow.gather", false));
|
---|
| 300 | workflow_gather.setPreferredSize(ROW_SIZE);
|
---|
| 301 | workflow_enrich = new JCheckBox("Preferences.Workflow.Enrich", Gatherer.config.get("workflow.enrich", false));
|
---|
| 302 | workflow_enrich.setPreferredSize(ROW_SIZE);
|
---|
| 303 | workflow_design = new JCheckBox("Preferences.Workflow.Design", Gatherer.config.get("workflow.design", false));
|
---|
| 304 | workflow_design.setPreferredSize(ROW_SIZE);
|
---|
| 305 | workflow_export = new JCheckBox("Preferences.Workflow.Export", Gatherer.config.get("workflow.export", false));
|
---|
| 306 | workflow_export.setPreferredSize(ROW_SIZE);
|
---|
| 307 | workflow_create = new JCheckBox("Preferences.Workflow.Create", Gatherer.config.get("workflow.create", false));
|
---|
| 308 | workflow_create.setPreferredSize(ROW_SIZE);
|
---|
| 309 | workflow_preview = new JCheckBox("Preferences.Workflow.Preview", Gatherer.config.get("workflow.preview", false));
|
---|
| 310 | workflow_preview.setPreferredSize(ROW_SIZE);
|
---|
| 311 | JPanel predefined_pane = new JPanel();
|
---|
| 312 | predefined_label = new JLabel("Preferences.Workflow.Predefined.Label");
|
---|
| 313 | predefined_label.setPreferredSize(new Dimension(150,25));
|
---|
| 314 | JComboBox predefined_combobox = new JComboBox(predefined);
|
---|
| 315 | // Connection
|
---|
| 316 | Gatherer.dictionary.register(title_label, null, false);
|
---|
| 317 | Gatherer.dictionary.register(workflow_browse, null, false);
|
---|
| 318 | Gatherer.dictionary.register(workflow_mirror, null, false);
|
---|
| 319 | Gatherer.dictionary.register(workflow_gather, null, false);
|
---|
| 320 | Gatherer.dictionary.register(workflow_enrich, null, false);
|
---|
| 321 | Gatherer.dictionary.register(workflow_design, null, false);
|
---|
| 322 | Gatherer.dictionary.register(workflow_export, null, false);
|
---|
| 323 | Gatherer.dictionary.register(workflow_create, null, false);
|
---|
| 324 | Gatherer.dictionary.register(workflow_preview, null, false);
|
---|
| 325 | Gatherer.dictionary.register(predefined_label, null, false);
|
---|
| 326 | predefined_combobox.addActionListener(new PredefinedActionListener());
|
---|
| 327 | // Layout
|
---|
| 328 | checklist_pane.setLayout(new BoxLayout(checklist_pane, BoxLayout.Y_AXIS));
|
---|
| 329 | checklist_pane.add(title_label);
|
---|
| 330 | if(Gatherer.config.get("workflow.browse", true)) {
|
---|
| 331 | checklist_pane.add(workflow_browse);
|
---|
| 332 | }
|
---|
| 333 | if(Gatherer.config.get("workflow.mirror", true)) {
|
---|
| 334 | checklist_pane.add(workflow_mirror);
|
---|
| 335 | }
|
---|
| 336 | if(Gatherer.config.get("workflow.gather", true)) {
|
---|
| 337 | checklist_pane.add(workflow_gather);
|
---|
| 338 | }
|
---|
| 339 | if(Gatherer.config.get("workflow.enrich", true)) {
|
---|
| 340 | checklist_pane.add(workflow_enrich);
|
---|
| 341 | }
|
---|
| 342 | if(Gatherer.config.get("workflow.design", true)) {
|
---|
| 343 | checklist_pane.add(workflow_design);
|
---|
| 344 | }
|
---|
| 345 | if(Gatherer.config.get("workflow.export", true)) {
|
---|
| 346 | checklist_pane.add(workflow_export);
|
---|
| 347 | }
|
---|
| 348 | if(Gatherer.config.get("workflow.create", true)) {
|
---|
| 349 | checklist_pane.add(workflow_create);
|
---|
| 350 | }
|
---|
| 351 | if(Gatherer.config.get("workflow.preview", true)) {
|
---|
| 352 | checklist_pane.add(workflow_preview);
|
---|
| 353 | }
|
---|
| 354 | predefined_pane.setLayout(new BorderLayout());
|
---|
| 355 | predefined_pane.add(predefined_label, BorderLayout.WEST);
|
---|
| 356 | predefined_pane.add(predefined_combobox, BorderLayout.CENTER);
|
---|
| 357 |
|
---|
| 358 | workflow_preferences_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
| 359 | workflow_preferences_pane.setLayout(new BorderLayout());
|
---|
| 360 | workflow_preferences_pane.add(checklist_pane, BorderLayout.CENTER);
|
---|
| 361 | workflow_preferences_pane.add(predefined_pane, BorderLayout.SOUTH);
|
---|
| 362 |
|
---|
| 363 | return workflow_preferences_pane;
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | public void dispose() {
|
---|
| 367 | // Deregister dictionary components
|
---|
| 368 |
|
---|
| 369 | // Connection
|
---|
| 370 | Gatherer.dictionary.deregister(library_path_label);
|
---|
| 371 | Gatherer.dictionary.deregister(use_proxy_checkbox);
|
---|
| 372 | Gatherer.dictionary.deregister(proxy_host_label);
|
---|
| 373 | Gatherer.dictionary.deregister(proxy_port_label);
|
---|
| 374 |
|
---|
| 375 | // General
|
---|
[5311] | 376 | Gatherer.dictionary.deregister(view_extracted_metadata_checkbox);
|
---|
| 377 | Gatherer.dictionary.deregister(show_file_size_checkbox);
|
---|
[5164] | 378 | Gatherer.dictionary.deregister(language_label);
|
---|
| 379 |
|
---|
| 380 | // Workflow
|
---|
| 381 | Gatherer.dictionary.deregister(title_label);
|
---|
| 382 | Gatherer.dictionary.deregister(workflow_browse);
|
---|
| 383 | Gatherer.dictionary.deregister(workflow_mirror);
|
---|
| 384 | Gatherer.dictionary.deregister(workflow_gather);
|
---|
| 385 | Gatherer.dictionary.deregister(workflow_enrich);
|
---|
| 386 | Gatherer.dictionary.deregister(workflow_design);
|
---|
| 387 | Gatherer.dictionary.deregister(workflow_export);
|
---|
| 388 | Gatherer.dictionary.deregister(workflow_create);
|
---|
| 389 | Gatherer.dictionary.deregister(workflow_preview);
|
---|
| 390 | Gatherer.dictionary.deregister(predefined_label);
|
---|
| 391 |
|
---|
| 392 | // Dialog
|
---|
| 393 | Gatherer.dictionary.deregister(this);
|
---|
| 394 | Gatherer.dictionary.deregister(tab_pane);
|
---|
| 395 | Gatherer.dictionary.deregister(ok_button);
|
---|
| 396 | Gatherer.dictionary.deregister(apply_button);
|
---|
| 397 | Gatherer.dictionary.deregister(cancel_button);
|
---|
| 398 | // Dispose
|
---|
| 399 | super.dispose();
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | private class OKButtonListener
|
---|
| 403 | implements ActionListener {
|
---|
| 404 | private boolean close;
|
---|
| 405 | public OKButtonListener(boolean close) {
|
---|
| 406 | this.close = close;
|
---|
| 407 | }
|
---|
| 408 | public void actionPerformed(ActionEvent event) {
|
---|
| 409 | // Submit the various changes.
|
---|
| 410 | // Connection preferences
|
---|
| 411 | String library_path_string = library_path_field.getText();
|
---|
| 412 | Gatherer.config.setString("general.exec_address", true, library_path_string);
|
---|
| 413 | if (!library_path_string.equals("")) {
|
---|
| 414 | try {
|
---|
| 415 | Gatherer.config.exec_address = new URL(library_path_string);
|
---|
| 416 | }
|
---|
| 417 | catch (MalformedURLException error) {
|
---|
| 418 | ///ystem.err.println("Error: Bad address: " + exec_address_string);
|
---|
| 419 | }
|
---|
| 420 | }
|
---|
| 421 | Gatherer.config.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
|
---|
| 422 | Gatherer.config.setString("general.proxy_host", true, proxy_host_field.getText());
|
---|
| 423 | Gatherer.config.setString("general.proxy_port", true, proxy_port_field.getText());
|
---|
| 424 | Gatherer.setProxy();
|
---|
| 425 |
|
---|
| 426 | // General preferences
|
---|
[5311] | 427 | Gatherer.config.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, show_file_size_checkbox.isSelected());
|
---|
[5164] | 428 | if(Gatherer.g_man.mirror_pane != null) {
|
---|
| 429 | Gatherer.g_man.mirror_pane.refreshTrees();
|
---|
| 430 | }
|
---|
| 431 | Gatherer.g_man.collection_pane.refreshTrees();
|
---|
| 432 | Gatherer.g_man.metaedit_pane.refreshTrees();
|
---|
| 433 |
|
---|
[5311] | 434 | Gatherer.config.set("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC, view_extracted_metadata_checkbox.isSelected());
|
---|
[5164] | 435 | Gatherer.g_man.metaedit_pane.valueChanged((TreeSelectionEvent) null); // Refresh metadata table
|
---|
| 436 |
|
---|
| 437 | Gatherer.config.setLocale("general.locale", Configuration.GENERAL_SETTING, ((DictionaryEntry)language_combobox.getSelectedItem()).getLocale());
|
---|
| 438 |
|
---|
| 439 | // Warning preferences
|
---|
| 440 | for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) {
|
---|
| 441 | Entry entry = warning_preferences_check_list.get(i);
|
---|
| 442 | Gatherer.config.set(entry.getProperty(), true, entry.isSelected());
|
---|
| 443 | }
|
---|
| 444 | // Workflow preferences
|
---|
| 445 | Gatherer.config.set("workflow.browse", false, workflow_browse.isSelected());
|
---|
| 446 | Gatherer.config.set("workflow.mirror", false, workflow_mirror.isSelected());
|
---|
| 447 | Gatherer.config.set("workflow.gather", false, workflow_gather.isSelected());
|
---|
| 448 | Gatherer.config.set("workflow.enrich", false, workflow_enrich.isSelected());
|
---|
| 449 | Gatherer.config.set("workflow.design", false, workflow_design.isSelected());
|
---|
| 450 | Gatherer.config.set("workflow.export", false, workflow_export.isSelected());
|
---|
| 451 | Gatherer.config.set("workflow.create", false, workflow_create.isSelected());
|
---|
| 452 | Gatherer.config.set("workflow.preview", false, workflow_preview.isSelected());
|
---|
| 453 | Gatherer.g_man.workflowUpdate("Browser", workflow_browse.isSelected());
|
---|
| 454 | Gatherer.g_man.workflowUpdate("Mirroring", workflow_mirror.isSelected());
|
---|
| 455 | Gatherer.g_man.workflowUpdate("Collection", workflow_gather.isSelected());
|
---|
| 456 | Gatherer.g_man.workflowUpdate("MetaEdit", workflow_enrich.isSelected());
|
---|
| 457 | Gatherer.g_man.workflowUpdate("Build", workflow_design.isSelected());
|
---|
| 458 | Gatherer.g_man.workflowUpdate("Export", workflow_export.isSelected());
|
---|
| 459 | Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());
|
---|
| 460 | Gatherer.g_man.workflowUpdate("Preview", workflow_preview.isSelected());
|
---|
| 461 | // Hide dialog
|
---|
| 462 | if(close) {
|
---|
| 463 | self.dispose();
|
---|
| 464 | }
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | private class CancelButtonListener
|
---|
| 469 | implements ActionListener {
|
---|
| 470 | public void actionPerformed(ActionEvent event) {
|
---|
| 471 | self.dispose();
|
---|
| 472 | }
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | private class DictionaryEntry
|
---|
| 476 | implements Comparable {
|
---|
| 477 | private Locale locale;
|
---|
| 478 | private String description;
|
---|
| 479 | public DictionaryEntry(Locale locale) {
|
---|
| 480 | this.description = null;
|
---|
| 481 | this.locale = locale;
|
---|
| 482 | }
|
---|
| 483 | public DictionaryEntry(String description, Locale locale) {
|
---|
| 484 | this.description = description;
|
---|
| 485 | this.locale = locale;
|
---|
| 486 | }
|
---|
| 487 | public int compareTo(Object object) {
|
---|
| 488 | return toString().compareTo(object.toString());
|
---|
| 489 | }
|
---|
| 490 | public boolean equals(Object object) {
|
---|
| 491 | return toString().equals(object.toString());
|
---|
| 492 | }
|
---|
| 493 | public Locale getLocale() {
|
---|
| 494 | return locale;
|
---|
| 495 | }
|
---|
| 496 | public String toString() {
|
---|
| 497 | if(description != null) {
|
---|
| 498 | return description;
|
---|
| 499 | }
|
---|
| 500 | else {
|
---|
| 501 | return locale.getDisplayName();
|
---|
| 502 | }
|
---|
| 503 | }
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | private class PredefinedActionListener
|
---|
| 507 | implements ActionListener {
|
---|
| 508 | public void actionPerformed(ActionEvent event) {
|
---|
| 509 | JComboBox cb = (JComboBox) event.getSource();
|
---|
| 510 | WorkflowElementWrapper element = (WorkflowElementWrapper) cb.getSelectedItem();
|
---|
| 511 | CheckboxUpdater task = new CheckboxUpdater(element);
|
---|
| 512 | SwingUtilities.invokeLater(task);
|
---|
| 513 | }
|
---|
| 514 |
|
---|
| 515 | private class CheckboxUpdater
|
---|
| 516 | implements Runnable {
|
---|
| 517 | private WorkflowElementWrapper element;
|
---|
| 518 | public CheckboxUpdater(WorkflowElementWrapper element) {
|
---|
| 519 | this.element = element;
|
---|
| 520 | }
|
---|
| 521 | public void run() {
|
---|
| 522 | workflow_browse.setSelected(element.getEnabled("browse"));
|
---|
| 523 | workflow_create.setSelected(element.getEnabled("create"));
|
---|
| 524 | workflow_mirror.setSelected(element.getEnabled("mirror"));
|
---|
| 525 | workflow_gather.setSelected(element.getEnabled("gather"));
|
---|
| 526 | workflow_enrich.setSelected(element.getEnabled("enrich"));
|
---|
| 527 | workflow_design.setSelected(element.getEnabled("design"));
|
---|
| 528 | workflow_export.setSelected(element.getEnabled("export"));
|
---|
| 529 | workflow_preview.setSelected(element.getEnabled("preview"));
|
---|
| 530 | }
|
---|
| 531 | }
|
---|
| 532 | }
|
---|
| 533 |
|
---|
| 534 | private class LanguageComboboxListener
|
---|
| 535 | implements ActionListener {
|
---|
| 536 | public void actionPerformed(ActionEvent event) {
|
---|
| 537 | // Retrieve the entry
|
---|
| 538 | DictionaryEntry entry = (DictionaryEntry) language_combobox.getSelectedItem();
|
---|
| 539 | if(entry != null) {
|
---|
| 540 | Gatherer.dictionary.changeDictionary(entry.getLocale());
|
---|
| 541 | // Display message
|
---|
| 542 | JOptionPane.showMessageDialog(Gatherer.g_man, Gatherer.dictionary.get("Preferences.General.Restart_Required"), Gatherer.dictionary.get("Preferences.General.Restart_Required"), JOptionPane.WARNING_MESSAGE);
|
---|
| 543 | }
|
---|
| 544 | }
|
---|
| 545 | }
|
---|
| 546 |
|
---|
| 547 | private class UseProxyListener
|
---|
| 548 | implements ActionListener {
|
---|
| 549 | public void actionPerformed(ActionEvent event) {
|
---|
| 550 | boolean enabled = use_proxy_checkbox.isSelected();
|
---|
| 551 | Gatherer.config.set("general.use_proxy", true, enabled);
|
---|
[5311] | 552 | // Fortunately this is already driven by the event thread.
|
---|
[5164] | 553 | proxy_host_field.setEnabled(enabled);
|
---|
| 554 | proxy_port_field.setEnabled(enabled);
|
---|
| 555 | }
|
---|
| 556 | }
|
---|
| 557 |
|
---|
| 558 | private class WorkflowElementWrapper {
|
---|
| 559 | private Element element;
|
---|
| 560 | private String text;
|
---|
| 561 | public WorkflowElementWrapper(Element element) {
|
---|
| 562 | this.element = element;
|
---|
| 563 | }
|
---|
| 564 | public boolean getEnabled(String name) {
|
---|
| 565 | boolean result = true;
|
---|
| 566 | if(element.getAttribute(name).equalsIgnoreCase("false")) {
|
---|
| 567 | result = false;
|
---|
| 568 | }
|
---|
| 569 | return result;
|
---|
| 570 | }
|
---|
| 571 | public String toString() {
|
---|
| 572 | if(text == null) {
|
---|
| 573 | text = element.getFirstChild().getNodeValue();
|
---|
| 574 | }
|
---|
| 575 | return text;
|
---|
| 576 | }
|
---|
| 577 | }
|
---|
| 578 | }
|
---|