source: trunk/gli/src/org/greenstone/gatherer/Configuration.java@ 6086

Last change on this file since 6086 was 6086, checked in by jmt12, 20 years ago

Moved the special folder 'shortcuts' from collection based to shared for the installation of gli. This caused some added fun when it turned out one of the workspace tree refreshes was blocking the AWTEvent thread, despite me putting tests in place to stop that from happening. It had never reared its ugly head before, as there were never any shortcut collections being mapped when a collection had been closed, or when GLI was exiting before.

  • Property svn:keywords set to Author Date Id Revision
File size: 32.4 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 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer;
38
39import java.awt.*;
40import java.io.*;
41import java.lang.ref.*;
42import java.net.*;
43import java.util.*;
44import javax.swing.*;
45import javax.swing.plaf.*;
46import org.greenstone.gatherer.msm.MSMUtils;
47import org.greenstone.gatherer.util.StaticStrings;
48import org.greenstone.gatherer.util.Utility;
49import org.w3c.dom.*;
50
51/** This class stores the various configurable settings inside the Gatherer, both during a session, and between sessions in the form of XML. However not all data members are retained during xml serialization. To further improve efficiency, the property-name -> DOM Element pairs are stored in a SoftReferenced Hashtable.
52 * @author John Thompson, Greenstone Digital Library, University of Waikato
53 * @version 2.3
54 */
55public class Configuration
56 extends Hashtable {
57
58 static final public boolean COLLECTION_SPECIFIC = true;
59 static final public boolean GENERAL_SETTING = true;
60
61 /** The string identifying an argument's name attribute. */
62 static final private String ARGUMENT_NAME = "name";
63 /** The name of the general Gatherer configuration file. */
64 static final private String CONFIG_XML = "config.xml";
65 /** The name of the root element of the subtree containing gatherer configuration options. This is required as the document itself may contain several other subtrees of settings (such as in the case of a '.col' file). */
66 static final private String GATHERER_CONFIG = "GathererConfig";
67 /** The string identifying an argument element. */
68 static final private String GATHERER_CONFIG_ARGUMENT = "Argument";
69
70 static final private String GENERAL_EMAIL_SETTING = "general.email";
71 /** The name of a Name Element. */
72 static final private String NAME = "Name";
73 /** The name of the other arguments element. */
74 static final private String OTHER = "Other";
75 /** The name of an information Element within the Other subtree. */
76 static final private String OTHER_INFO = "Info";
77 /** The name of the general Gatherer configuration template. */
78 static final private String TEMPLATE_CONFIG_XML = "xml/config.xml";
79 /** The first of two patterns used during tokenization, this pattern handles a comma separated list. */
80 static final private String TOKENIZER_PATTERN1 = " ,\n\t";
81 /** The second of two patterns used during tokenization, this pattern handles an underscore separated list. */
82 static final private String TOKENIZER_PATTERN2 = "_\n\t";
83
84 public File exec_file;
85 /** The path (or url) to the webserver which is serving the Greenstone collection. */
86 public String exec_path = null;
87 /** The path to the Greenstone Suite installation directory. */
88 public String gsdl_path = "";
89 /** The path to the PERL executable, up to and including Perl.exe. */
90 public String perl_path = "";
91 /** The password for the proxy server indicated above. */
92 public String proxy_pass = null;
93 /** The username for the proxy server indicated above. */
94 public String proxy_user = null;
95 /** The language selected for the interface. Currently hard-wired. */
96 public String interface_language = "en";
97 /** The screen size of the desktop the Gatherer will be displayed on. */
98 public Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
99 /** Collection level configuration (which in some cases overrides general configuration. */
100 private Document collection_config;
101 /** The general configuration settings. */
102 private Document general_config;
103
104 /** The element, from glis config file, that contains the various directory mappings. */
105 private Element directory_mappings_element;
106
107 private int cache_hit = 0;
108 private int cache_miss = 0;
109 public URL exec_address = null;
110
111 /** Constructor.
112 * @param gsdl_path The path to the Greenstone directory as a <strong>String</strong>.
113 * @param exec_path A <strong>String</strong> containing the path or url to the webserver serving the greenstone collections.
114 * @param perl_path The path to the PERL executable, as a <strong>String</strong>.
115 */
116 public Configuration(String gsdl_path, String exec_path, String perl_path) {
117 super();
118 this.gsdl_path = gsdl_path;
119 this.exec_path = exec_path;
120 // The exec_path may contain an url address, in which case we blindly use that and leave it up to the user to worry about settings and resetting.
121 Gatherer.println("EXEC_PATH = " + exec_path);
122 if(exec_path != null && exec_path.length() > 0) {
123 try {
124 exec_address = new URL(exec_path);
125 }
126 catch (MalformedURLException error) {
127 ///ystem.err.println("Not an address.");
128 }
129 }
130 // If the above failed, then its up to us to try and figure out what to do.
131 if(exec_address == null) {
132 // Try building a file from the given exec_path
133 try {
134 File local_file = new File(exec_path);
135 if(local_file.exists()) {
136 // All good. I hope.
137 exec_file = local_file;
138 }
139 else {
140 ///ystem.err.println("No local library at given file path.");
141 }
142 }
143 // All sorts of errors might be thrown by a bogus file path.
144 catch (Exception error) {
145 Gatherer.println("Not a valid file.");
146 }
147 // We can generate the path to where the local library should be and use that if it is there.
148 if(exec_file == null) {
149 File server_exe = new File(gsdl_path + Utility.SERVER_EXE);
150 if(server_exe.exists()) {
151 exec_file = server_exe;
152 }
153 else {
154 ///ystem.err.println("No local library.");
155 }
156 }
157 // If we get to here with no exec_address nor an exec_file its just plain not going to work.
158 }
159 else {
160 ///ystem.err.println("exec_address != null -> " + exec_address);
161 }
162 ///ystem.err.println("Perl path.");
163 this.perl_path = perl_path;
164 // Ensure the perl path includes exe under windoze
165 if(Utility.isWindows() && !perl_path.toLowerCase().endsWith(".exe")) {
166 if(!perl_path.endsWith(File.separator)) {
167 perl_path = perl_path + File.separator;
168 }
169 perl_path = perl_path + "perl.exe";
170 }
171 // Try to reload the configuration.
172 File config_xml = new File(CONFIG_XML);
173 if(config_xml.exists()) {
174 general_config = Utility.parse(CONFIG_XML, false);
175 }
176 // If that fails retrieve the default configuration file from our xml library, which I'll personally guarantee to work.
177 if(general_config == null) {
178 general_config = Utility.parse(TEMPLATE_CONFIG_XML, true);
179 Gatherer.println("Loaded default Gatherer configuration template.");
180 }
181 else {
182 Gatherer.println("Loaded current Gatherer configuration.");
183 }
184
185 // Determine the Directory Mappings element
186 directory_mappings_element = (Element) MSMUtils.getNodeFromNamed(general_config.getDocumentElement(), StaticStrings.DIRECTORY_MAPPINGS_ELEMENT);
187
188 // Re-establish the color settings.
189 updateUI();
190
191 // If we have no exec_address, see if one was specified in the config file
192 if (exec_address == null) {
193 String exec_address_string = getString("general.exec_address", true);
194 if (!exec_address_string.equals("")) {
195 try {
196 exec_address = new URL(exec_address_string);
197 }
198 catch (MalformedURLException error) {
199 ///ystem.err.println("Error: Bad address: " + exec_address_string);
200 }
201 }
202 }
203
204 Gatherer.println("EXEC_FILE = " + exec_file);
205 Gatherer.println("EXEC_ADDRESS = " + exec_address);
206 }
207
208 /** Add a special directory mapping. */
209 public boolean addDirectoryMapping(String name, File file) {
210 boolean result = false;
211 try {
212 // Ensure the name isn't already in use.
213 boolean found = false;
214 NodeList mappings = directory_mappings_element.getElementsByTagName(StaticStrings.MAPPING_ELEMENT);
215 for(int i = 0; !found && i < mappings.getLength(); i++) {
216 Element mapping_element = (Element) mappings.item(i);
217 if(mapping_element.getAttribute(StaticStrings.NAME_ATTRIBUTE).equalsIgnoreCase(name)) {
218 found = true;
219 }
220 mapping_element = null;
221 }
222 // Otherwise add the mapping.
223 if(!found) {
224 Element mapping_element = general_config.createElement(StaticStrings.MAPPING_ELEMENT);
225 mapping_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
226 mapping_element.setAttribute(StaticStrings.FILE_ATTRIBUTE, file.toString());
227 directory_mappings_element.appendChild(mapping_element);
228 result = true;
229 mapping_element = null;
230 }
231 mappings = null;
232 }
233 catch (Exception exception) {
234 Gatherer.printStackTrace(exception);
235 }
236 return result;
237 } /** addDirectoryMapping(String name, String file) **/
238
239 /** The default get action retrieves the named property from the desired configuration, and returns a true or false. */
240 public boolean get(String property, boolean general) {
241 String raw = getString(property, general);
242 return (raw != null && raw.equalsIgnoreCase("true"));
243 }
244
245 /** Retrieve all of the configuration preferences which match a certain string. They are returned as a hash map of property names to String objects. */
246 public HashMap getAll(String property_pattern, boolean general) {
247 HashMap properties = new HashMap();
248 try {
249 // Locate the appropriate element
250 Element document_element = null;
251 if(general) {
252 document_element = general_config.getDocumentElement();
253 }
254 else if(collection_config != null) {
255 document_element = collection_config.getDocumentElement();
256 }
257 if(document_element != null) {
258 // Retrieve the Gatherer element
259 Element gatherer_element = (Element) MSMUtils.getNodeFromNamed(document_element, GATHERER_CONFIG);
260 NodeList arguments = gatherer_element.getElementsByTagName(GATHERER_CONFIG_ARGUMENT);
261 for(int i = 0; i < arguments.getLength(); i++) {
262 Element argument_element = (Element) arguments.item(i);
263 if(argument_element.getAttribute(ARGUMENT_NAME).matches(property_pattern)) {
264 String result = MSMUtils.getValue(argument_element);
265 // Store a mapping in the cache. Sometimes we will overwrite an existing value (say for collection and general level workflow options) but the processing overhead of detecting these clashes far exceeds any savings.
266 put(argument_element.getAttribute(ARGUMENT_NAME) + general, new SoftReference(argument_element));
267 // Add mapping to the properties we're going to return
268 properties.put(argument_element.getAttribute(ARGUMENT_NAME), result);
269 }
270 }
271 }
272 }
273 catch(Exception error) {
274 }
275 return properties;
276 }
277
278 /** Retrieve the information subtree containing the arguments for the desired external program. If the program has marked superclasses append their arguments as well. */
279 public Element getArguments(String filename) {
280 Element argument_element = null;
281 try {
282 // Retrieve the other information subtree.
283 Element document_element = general_config.getDocumentElement();
284 Element other_element = (Element) MSMUtils.getNodeFromNamed(document_element, OTHER);
285 NodeList argument_elements = other_element.getElementsByTagName(OTHER_INFO);
286 for(int i = 0; argument_element == null && i < argument_elements.getLength(); i++) {
287 Element possible_element = (Element) argument_elements.item(i);
288 Element possible_name_element = (Element) MSMUtils.getNodeFromNamed(possible_element, NAME);
289 String possible_name = MSMUtils.getValue(possible_name_element);
290 ///ystem.err.println("Does " + possible_name + " equal " + filename);
291 if(possible_name.equalsIgnoreCase(filename)) {
292 argument_element = possible_element;
293 }
294 possible_name = null;
295 possible_name_element = null;
296 possible_element = null;
297 }
298 argument_elements = null;
299 other_element = null;
300 document_element = null;
301 }
302 catch(Exception error) {
303 }
304 return argument_element;
305 }
306
307 /** Retrieve the value of the named property as a Rectangle. */
308 public Rectangle getBounds(String property, boolean general) {
309 Rectangle result = null;
310 try {
311 String raw = getString(property, general);
312 // Rectangle is (x, y, width, height)
313 StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN1);
314 int x = Integer.parseInt(tokenizer.nextToken());
315 int y = Integer.parseInt(tokenizer.nextToken());
316 int width = Integer.parseInt(tokenizer.nextToken());
317 int height = Integer.parseInt(tokenizer.nextToken());
318 result = new Rectangle(x, y, width, height);
319 }
320 catch(Exception error) {
321 Gatherer.printStackTrace(error);
322 }
323 return result;
324 }
325
326 /** Retrieve the value of the named property as a Color. */
327 public Color getColor(String property, boolean general) {
328 Color result = Color.white; // Default
329 try {
330 String raw = getString(property, general);
331 // Color is a RGB triplet list, comma separated (also remove whitespace)
332 StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN1);
333 int red = Integer.parseInt(tokenizer.nextToken());
334 int green = Integer.parseInt(tokenizer.nextToken());
335 int blue = Integer.parseInt(tokenizer.nextToken());
336 result = new Color(red, green, blue);
337 }
338 catch(Exception error) {
339 Gatherer.printStackTrace(error);
340 }
341 return result;
342 }
343
344 /** Retrieve the value of the named property as a Dimension. */
345 /* private Dimension getDimension(String property, boolean general) {
346 Dimension result = new Dimension(100, 100); // Default
347 try {
348 String raw = getString(property, general);
349 // Dimension is a width by height pair, comma separated (also remove whitespace)
350 StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN1);
351 int width = Integer.parseInt(tokenizer.nextToken());
352 int height = Integer.parseInt(tokenizer.nextToken());
353 result = new Dimension(width, height);
354 }
355 catch(Exception error) {
356 Gatherer.printStackTrace(error);
357 }
358 return result;
359 } */
360
361 /** Retrieve the special directory mappings associated with this collection.
362 * @return A <strong>HashMap</strong> containing mappings from names to directories.
363 */
364 public HashMap getDirectoryMappings() {
365 HashMap special_directories = new HashMap();
366 try {
367 // Ensure the name isn't already in use.
368 boolean found = false;
369 NodeList mappings = directory_mappings_element.getElementsByTagName(StaticStrings.MAPPING_ELEMENT);
370 for(int i = 0; !found && i < mappings.getLength(); i++) {
371 Element mapping_element = (Element) mappings.item(i);
372 String name = mapping_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
373 File file = new File(mapping_element.getAttribute(StaticStrings.FILE_ATTRIBUTE));
374 special_directories.put(name, file);
375 file = null;
376 name = null;
377 mapping_element = null;
378 }
379 mappings = null;
380 }
381 catch(Exception exception) {
382 Gatherer.printStackTrace(exception);
383 }
384 return special_directories;
385 } /** getDirectoryMappings() */
386
387 /** Retrieve the current users email. These are always stored in the general settings.
388 * @return the email address, if it is set, as a String
389 */
390 public String getEmail() {
391 String email = getString(GENERAL_EMAIL_SETTING, true);
392 return (email.length() > 0 ? email : null);
393 }
394
395 /** Retrieve the value of the named property as a FontUIResource. */
396 public FontUIResource getFont(String property, boolean general) {
397 FontUIResource result = new FontUIResource("Times New Roman", Font.PLAIN, 10);
398 try {
399 String raw = getString(property, general);
400 // Font is a face, style, size triplet.
401 StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN1);
402 String face = tokenizer.nextToken();
403 int style = Font.PLAIN;
404 String temp = tokenizer.nextToken().toUpperCase();
405 if(temp.equals("BOLD")) {
406 style = Font.BOLD;
407 }
408 else if(temp.equals("ITALIC")) {
409 style = Font.ITALIC;
410 }
411 int size = Integer.parseInt(tokenizer.nextToken());
412 result = new FontUIResource(face, style, size);
413 }
414 catch(Exception error) {
415 Gatherer.printStackTrace(error);
416 }
417 return result;
418 }
419
420 /** Retrieve the value of the named property as an integer. */
421 public int getInt(String property, boolean general) {
422 int result = -1;
423 try {
424 String raw = getString(property, general);
425 result = Integer.parseInt(raw);
426 }
427 catch(Exception error) {
428 Gatherer.printStackTrace(error);
429 }
430 return result;
431 }
432
433 /** Retrieve the value of the named property as a Locale. */
434 public Locale getLocale(String property, boolean general) {
435 Locale result = Locale.getDefault();
436 try {
437 String raw = getString(property, general);
438 // Locale is a underscore separated code.
439 StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN2);
440 String language = tokenizer.nextToken();
441 if(tokenizer.hasMoreTokens()) {
442 String country = tokenizer.nextToken();
443 result = new Locale(language, country);
444 }
445 else {
446 result = new Locale(language);
447 }
448 }
449 catch(Exception error) {
450 Gatherer.printStackTrace(error);
451 }
452 return result;
453 }
454
455 /** Retrieve the value of the named property, and noting whether we consult the general or collection specific configuration. */
456 public String getString(String property, boolean general) {
457 // Its up to this method to find the appropriate node and retrieve the data itself.
458 String result = "";
459 try {
460 // First of all we look in the cache to see if we have a match.
461 SoftReference reference = (SoftReference) get(property + general);
462 if(reference != null) {
463 Element argument_element = (Element) reference.get();
464 if(argument_element != null) {
465 cache_hit++;
466 result = MSMUtils.getValue(argument_element);
467 }
468 }
469 // We may have missed in the cache, or the reference may have been consumed.
470 if(result.length() == 0) {
471 cache_miss++;
472 // Locate the appropriate element
473 Element document_element = null;
474 if(general) {
475 document_element = general_config.getDocumentElement();
476 }
477 else if(collection_config != null) {
478 document_element = collection_config.getDocumentElement();
479 }
480 if(document_element != null) {
481 // Retrieve the Gatherer element
482 Element gatherer_element = (Element) MSMUtils.getNodeFromNamed(document_element, GATHERER_CONFIG);
483 NodeList arguments = gatherer_element.getElementsByTagName(GATHERER_CONFIG_ARGUMENT);
484 for(int i = 0; result.length() == 0 && i < arguments.getLength(); i++) {
485 Element argument_element = (Element) arguments.item(i);
486 if(argument_element.getAttribute(ARGUMENT_NAME).equalsIgnoreCase(property)) {
487 result = MSMUtils.getValue(argument_element);
488 // Store a mapping in the cache. Sometimes we will overwrite an existing value (say for collection and general level workflow options) but the processing overhead of detecting these clashes far exceeds any savings.
489 put(property + general, new SoftReference(argument_element));
490 }
491 }
492 }
493 }
494 }
495 catch (Exception error) {
496 Gatherer.printStackTrace(error);
497 }
498 // If we still have no result, and the search was made in the collection configuration, retrieve the general one instead.
499 if(result.length() == 0 && !general) {
500 result = getString(property, true);
501 }
502 return result;
503 }
504
505 /** Retrieve the path to the PERL scripts within the Greenstone directory.
506 * @return A <strong>String</strong> containing the path.
507 */
508 public String getScriptPath() {
509 return gsdl_path + "bin" + File.separator + "script" + File.separator;
510 }
511
512 /** Remove a previously defined special directory mapping.
513 * @param name The name of the mapping to remove as a <strong>String</strong>.
514 * @return The <strong>File</strong> of the mapping removed.
515 */
516 public File removeDirectoryMapping(String name) {
517 File file = null;
518 try {
519 // Ensure the name isn't already in use.
520 boolean found = false;
521 NodeList mappings = directory_mappings_element.getElementsByTagName(StaticStrings.MAPPING_ELEMENT);
522 for(int i = 0; !found && i < mappings.getLength(); i++) {
523 Element mapping_element = (Element) mappings.item(i);
524 if(mapping_element.getAttribute(StaticStrings.NAME_ATTRIBUTE).equalsIgnoreCase(name)) {
525 file = new File(MSMUtils.getValue(mapping_element));
526 directory_mappings_element.removeChild(mapping_element);
527 found = true;
528 }
529 mapping_element = null;
530 }
531 mappings = null;
532 }
533 catch(Exception error) {
534 Gatherer.printStackTrace(error);
535 }
536 return file;
537 } /** removeDirectoryMapping(String name) */
538
539 /** Export the general configuration to file. */
540 public void save() {
541 ///ystem.err.println("Hits " + cache_hit + " vs Misses " + cache_miss);
542 Utility.export(general_config, Utility.BASE_DIR + CONFIG_XML);
543 }
544
545 /** Set the named property, from the specified configuration, using the given boolean value. */
546 public void set(String property, boolean general, boolean value) {
547 if(property.startsWith("workflow")) {
548 Gatherer.println("Set property: " + property + ", general=" + general + ", value=" + value);
549 }
550 setString(property, general, (value ? "true" : "false"));
551 }
552
553 /** Add a subtree of argument information to the other arguments part of the general configuration. This overwrites any such existing subtree. */
554 public void setArguments(Element arguments_element) {
555 try {
556 Element document_element = general_config.getDocumentElement();
557 Element other_element = (Element) MSMUtils.getNodeFromNamed(document_element, OTHER);
558 // Retrieve the name of the information
559 Element arguments_name_element = (Element)MSMUtils.getNodeFromNamed(arguments_element, NAME);
560 String filename = MSMUtils.getValue(arguments_element);
561 // Find any argument information subtree starting with the same name
562 Element obsolete_arguments_element = getArguments(filename);
563 // Create a copy of the arguments_element within our tree (import).
564 Element our_arguments_element = (Element) general_config.importNode(arguments_element, true);
565 // Now we insert this new node into the tree. If a previous node exists we replace it instead.
566 if(obsolete_arguments_element == null) {
567 other_element.appendChild(our_arguments_element);
568 }
569 else {
570 other_element.replaceChild(our_arguments_element, obsolete_arguments_element);
571 }
572 our_arguments_element = null;
573 obsolete_arguments_element = null;
574 filename = null;
575 arguments_name_element = null;
576 other_element = null;
577 document_element = null;
578 }
579 catch (Exception error) {
580 Gatherer.println("Error in Configuration.setArguments(): " + error);
581 Gatherer.printStackTrace(error);
582 }
583 }
584
585 /** Set the collection configuration. */
586 public void setCollectionConfiguration(Document collection_config) {
587 // clear the cached values
588 clear();
589 this.collection_config = collection_config;
590 updateUI();
591 ///atherer.println("Collection configuration set.");
592 }
593
594 /** Set the named property, from the specified configuration, using the given Rectangle value. */
595 public void setBounds(String property, boolean general, Rectangle value) {
596 StringBuffer text = new StringBuffer("");
597 text.append(value.x);
598 text.append(", ");
599 text.append(value.y);
600 text.append(", ");
601 text.append(value.width);
602 text.append(", ");
603 text.append(value.height);
604 setString(property, general, text.toString());
605 }
606
607 /** Set the named property, from the specified configuration, using the given Color value. */
608 public void setColor(String property, boolean general, Color value) {
609 StringBuffer text = new StringBuffer("");
610 text.append(value.getRed());
611 text.append(", ");
612 text.append(value.getGreen());
613 text.append(", ");
614 text.append(value.getBlue());
615 setString(property, general, text.toString());
616 }
617
618 /** Set the named property, from the specified configuration, using the given Dimension value. */
619 /* private void setDimension(String property, boolean general, Dimension value) {
620 StringBuffer text = new StringBuffer("");
621 text.append(value.width);
622 text.append(", ");
623 text.append(value.height);
624 setString(property, general, text.toString());
625 } */
626
627 /** Establish the current users email.
628 * @param email the email as a String
629 */
630 public void setEmail(String email) {
631 setString(GENERAL_EMAIL_SETTING, true, email);
632 }
633
634 /** Set the named property, from the specified configuration, using the given Font value. */
635 public void setFont(String property, boolean general, Font value) {
636 StringBuffer text = new StringBuffer("");
637 text.append(value.getName());
638 text.append(", ");
639 switch(value.getStyle()) {
640 case Font.BOLD:
641 text.append("BOLD");
642 break;
643 case Font.ITALIC:
644 text.append("ITALIC");
645 break;
646 default:
647 text.append("PLAIN");
648 }
649 text.append(", ");
650 text.append(value.getSize());
651 setString(property, general, text.toString());
652 }
653
654 /** Set the named property, from the specified configuration, using the given integer value. */
655 /* private void setInt(String property, boolean general, int value) {
656 setString(property, general, String.valueOf(value));
657 } */
658
659 /** Set the named property, from the specified configuration, using the given Locale value. */
660 public void setLocale(String property, boolean general, Locale value) {
661 StringBuffer text = new StringBuffer("");
662 text.append(value.getLanguage());
663 String country = value.getCountry();
664 if(country != null && country.length() > 0) {
665 text.append("_");
666 text.append(country);
667 }
668 country = null;
669 setString(property, general, text.toString());
670 }
671
672 /** Sets the value of the named property argument using the given string. */
673 public void setString(String property, boolean general, String value) {
674 Gatherer.println("Set configuration property: " + property + " = " + value + (general ? "" : " [Collection]"));
675 try {
676 Document document = general_config;
677 if(!general && collection_config != null) {
678 document = collection_config;
679 }
680 if(document != null) {
681 Element argument_element = null;
682 // Try to retrieve from cache
683 SoftReference reference = (SoftReference) get(property + general);
684 if(reference != null) {
685 argument_element = (Element) reference.get();
686 }
687 if(argument_element == null) {
688 Element document_element = document.getDocumentElement();
689 Element gatherer_element = (Element) MSMUtils.getNodeFromNamed(document_element, GATHERER_CONFIG);
690 NodeList arguments = document_element.getElementsByTagName(GATHERER_CONFIG_ARGUMENT);
691 boolean found = false;
692 for(int i = 0; argument_element == null && i < arguments.getLength(); i++) {
693 Element possible_element = (Element) arguments.item(i);
694 if(possible_element.getAttribute(ARGUMENT_NAME).equalsIgnoreCase(property)) {
695 argument_element = possible_element;
696 }
697 }
698 // If argument element is still null, create it in the target document.
699 if(argument_element == null) {
700 argument_element = document.createElement(GATHERER_CONFIG_ARGUMENT);
701 argument_element.setAttribute(ARGUMENT_NAME, property);
702 gatherer_element.appendChild(argument_element);
703 }
704 // Update cache
705 put(property + general, new SoftReference(argument_element));
706
707 }
708 if(value == null) {
709 value = "";
710 }
711 // Now remove any current text node children.
712 NodeList children = argument_element.getChildNodes();
713 for(int i = 0; i < children.getLength(); i++) {
714 argument_element.removeChild(children.item(i));
715 }
716 // Add a new text node child with the new value
717 argument_element.appendChild(document.createTextNode(value));
718 }
719 }
720 catch (Exception error) {
721 }
722 }
723
724 private void updateUI() {
725 // Buttons
726 UIManager.put("Button.select", new ColorUIResource(getColor("coloring.button_selected_background", false)));
727 UIManager.put("Button.background", new ColorUIResource(getColor("coloring.button_background", false)));
728 UIManager.put("Button.foreground", new ColorUIResource(getColor("coloring.button_foreground", false)));
729
730 UIManager.put("ToggleButton.background", new ColorUIResource(getColor("coloring.button_background", false)));
731 UIManager.put("ToggleButton.foreground", new ColorUIResource(getColor("coloring.button_foreground", false)));
732 UIManager.put("ToggleButton.select", new ColorUIResource(getColor("coloring.button_selected_background", false)));
733
734 // All the things with a lovely Collection green background
735 UIManager.put("OptionPane.background", new ColorUIResource(getColor("coloring.collection_heading_background", false)));
736 UIManager.put("Panel.background", new ColorUIResource(getColor("coloring.collection_heading_background", false)));
737 UIManager.put("Label.background", new ColorUIResource(getColor("coloring.collection_heading_background", false)));
738 UIManager.put("TabbedPane.background", new ColorUIResource(getColor("coloring.collection_heading_background", false)));
739 UIManager.put("SplitPane.background", new ColorUIResource(getColor("coloring.collection_heading_background", false)));
740 UIManager.put("CheckBox.background", new ColorUIResource(getColor("coloring.collection_heading_background", false)));
741
742
743 // Editable coloring
744 UIManager.put("ComboBox.background", new ColorUIResource(getColor("coloring.collection_tree_background", false))); // Indicate clickable
745 UIManager.put("Tree.background", new ColorUIResource(getColor("coloring.collection_tree_background", false)));
746 UIManager.put("Tree.textBackground", new ColorUIResource(getColor("coloring.collection_tree_background", false)));
747 UIManager.put("ProgressBar.background", new ColorUIResource(getColor("coloring.collection_tree_background", false)));
748 UIManager.put("TextArea.background", new ColorUIResource(getColor("coloring.collection_tree_background", false)));
749 UIManager.put("TextField.background", new ColorUIResource(getColor("coloring.editable_background", false)));
750 UIManager.put("Table.background", new ColorUIResource(getColor("coloring.collection_tree_background", false)));
751 UIManager.put("List.background", new ColorUIResource(getColor("coloring.collection_tree_background", false)));
752 UIManager.put("RadioButton.background", new ColorUIResource(getColor("coloring.collection_tree_background", false)));
753
754 // Selection color
755 UIManager.put("TabbedPane.selected", new ColorUIResource(getColor("coloring.collection_selection_background", false)));
756 UIManager.put("Tree.selectionBackground", new ColorUIResource(getColor("coloring.collection_selection_background", false)));
757 UIManager.put("ComboBox.selectionBackground", new ColorUIResource(getColor("coloring.collection_selection_background", false)));
758 UIManager.put("ProgressBar.selectionBackground", new ColorUIResource(getColor("coloring.collection_selection_background", false)));
759 UIManager.put("TextArea.selectionBackground", new ColorUIResource(getColor("coloring.collection_selection_background", false)));
760 UIManager.put("TextField.selectionBackground", new ColorUIResource(getColor("coloring.collection_selection_background", false)));
761 UIManager.put("List.selectionBackground", new ColorUIResource(getColor("coloring.collection_selection_background", false)));
762
763 // Scroll bar stuff
764 UIManager.put("ScrollBar.background", new ColorUIResource(getColor("coloring.scrollbar_background", false)));
765 UIManager.put("ScrollBar.thumb", new ColorUIResource(getColor("coloring.scrollbar_foreground", false)));
766 if (Gatherer.g_man != null) {
767 JPanel pane = (JPanel) Gatherer.g_man.getContentPane();
768 pane.updateUI();
769 // Also update all of the tabs according to workflow.
770 Gatherer.g_man.workflowUpdate("Hunt", get("workflow.browse", false));
771 Gatherer.g_man.workflowUpdate("Mirror", get("workflow.mirror", false));
772 Gatherer.g_man.workflowUpdate("Gather", get("workflow.gather", false));
773 Gatherer.g_man.workflowUpdate("Enrich", get("workflow.enrich", false));
774 Gatherer.g_man.workflowUpdate("Design", get("workflow.design", false));
775 Gatherer.g_man.workflowUpdate("Export", get("workflow.export", false));
776 Gatherer.g_man.workflowUpdate("Create", get("workflow.create", false));
777 Gatherer.g_man.workflowUpdate("Preview", get("workflow.preview", false));
778 }
779 }
780}
Note: See TracBrowser for help on using the repository browser.