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

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

Here is the result of sixteen hours work over the weekend. I'm too tired to comment them all separately, but here are some of the highlights:
Rewrote how the 'base on collection' method actually retrieves and updates the collection configuration - ensuring the CDM.CollectionConfiguration class is used instead of the retarded Collection.CollectionConfiguration (which coincidently has had a name change to BasicCollectionConfiguration). Went through code search for places where the two versions had been confused. Rewrote large swathes of GDMDocument so as to differentiate between normal and extracted metadata - an attempt to prevent the snowballing extracted metadata problem. Fixed problem where GLI was correctly recieving the last few lines of an external process. The collection shortname is no longer visible, nor is the confusing double name for metadata elements. Also coloured folders in the trees are kaput. The users email is now saved as part of the GLI configuration and is used as appropriate to fill out collection fields. There are new options on the right click menus over trees to allow the expansion and collapsing of folders. 'Show Files' now shows all types (or at least 6 types) of image properly (arg, the plagues of copy and paste). 'Based On' collections are public, plugin list automatically moves to next entry if plugin removed (I guess we should do the same in every other screen?) and metadata arguments in plugins/classifiers are no longer editable. There are about a dozen other small things, but I can't remember them. Hope I remembered to set all of the files to UNIX line-endings.

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