// 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,v 1.7 2003/09/23 00:49:57 tonyj Exp $ */ public class UserProperties extends Properties { 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