// Copyright 2003, FreeHEP.
package org.freehep.util;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.Collections;
import java.awt.Rectangle;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
/**
* Special property class which allows typed properties to be set and
* returned. It also allows the hookup of two default property objects
* to be searched if this property object does not contain the property.
*
* FIXME check what org.freehep.application.PropertyUtilities.java
* has to offer and merge, or not
*
* FIXME: This class does not seem general enough to be a "public" utility. Should be
* improved and merged with PropertyUtilities, or moved into the graphicsio package (tonyj)
*
* @author Mark Donszelmann
* @version $Id: UserProperties.java 8584 2006-08-10 23:06:37Z duns $
*/
public class UserProperties extends Properties {
/**
*
*/
private static final long serialVersionUID = 3297483251864528952L;
protected Properties altDefaults;
public UserProperties() {
super();
altDefaults = new Properties();
}
public UserProperties(Properties defaults) {
super(defaults);
altDefaults = new Properties();
}
/**
* Constructs UserProperties with a defaults and altDefaults table,
* which are searched in that order.
*/
public UserProperties(Properties defaults, Properties altDefaults) {
super(defaults);
this.altDefaults = altDefaults;
}
public Enumeration propertyNames() {
List list = new ArrayList();
for (Enumeration e = super.propertyNames(); e.hasMoreElements(); ) {
list.add(e.nextElement());
}
if (altDefaults != null) {
for (Enumeration e = altDefaults.propertyNames(); e.hasMoreElements(); ) {
list.add(e.nextElement());
}
}
return Collections.enumeration(list);
}
/**
* Copies properties, including its defaults into this UserProperties
*/
public void setProperties(Properties properties) {
for (Enumeration e=properties.propertyNames(); e.hasMoreElements(); ) {
String key = (String)e.nextElement();
setProperty(key, properties.getProperty(key));
}
}
public Object setProperty(String key, String value) {
if (value == null) return super.setProperty(key, "null");
return super.setProperty(key, value);
}
public Object setProperty(String key, String[] value) {
return setProperty(this, key, value);
}
public static Object setProperty(Properties properties, String key, String[] value) {
if (value == null) return properties.setProperty(key, "null");
StringBuffer sb = new StringBuffer();
for (int i=0; i
Ads help maintain this website.