Extended config API + More config ui work

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@37 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2009-09-24 18:41:50 +00:00
parent a0384669cc
commit 52694ed9c9
11 changed files with 391 additions and 158 deletions

View file

@ -0,0 +1,101 @@
/************************************************************************
*
* Config.java
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2009 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.2 (2009-09-23)
*
*/
package writer2latex.api;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/** A complex option is a set of named keys, each pointing to a set of named attributes
*/
public class ComplexOption {
private Map<String,Map<String,String>> options = new HashMap<String,Map<String,String>>();
/** Clear the contents of the set
*
*/
public void clear() {
options.clear();
}
/** Remove an option from the set, if it exists
*
* @param sName the name of the key to remove
*/
public void remove(String sName) {
if (options.containsKey(sName)) {
options.remove(sName);
}
}
/** Define a key. If the key already exists, the old value will be replaced
*
* @param sName the name of the key. The name must be non-empty, otherwise the request will be ignored.
* @param attributes
*/
public void put(String sName, Map<String,String> attributes) {
if (sName!=null && sName.length()>0) {
options.put(sName, attributes);
}
}
/** Get the value belonging to a key
*
* @param sName the name of the key
* @return the attributes, or null if the option doesn't exist
*/
public Map<String,String> get(String sName) {
return options.get(sName);
}
/** Copy all values from another <code>ComplexOption</code>
* (overwrites existing values)
* @param co another instance of <code>ComplexOption</code>
*/
public void copyAll(ComplexOption co) {
for (String sName : co.keySet()) {
Map<String,String> attr = co.get(sName);
Map<String,String> newAttr = new HashMap<String,String>();
for (String sAttrName : attr.keySet()) {
newAttr.put(sAttrName, attr.get(sAttrName));
}
options.put(sName, newAttr);
}
}
/** Get the names of all options that are currently defined by this complex option
*
* @return all names as a <code>Set</code>
*/
public Set<String> keySet() {
return options.keySet();
}
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2009-09-20)
* Version 1.2 (2009-09-22)
*
*/
@ -31,8 +31,6 @@ import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.IllegalArgumentException;
import java.util.Map;
import java.util.Set;
/** This is an interface for configuration of a {@link Converter}.
* A configuration always supports simple name/value options.
@ -97,27 +95,12 @@ public interface Config {
*/
public String getOption(String sName);
/** Set a complex option
*
* @param sGroup the group to which this option belongs
* @param sName the name of this option
* @param attributes the attributes defining the values of this option
*/
public void setComplexOption(String sGroup, String sName, Map<String,String> attributes);
/** Get a complex option
*
* @param sGroup the group to which this option belongs
* @param sName the name of this option
* @return the attributes defining the values of this option
* @param sName the name of the complex option
* @return
*/
public Map<String,String> getComplexOption(String sGroup, String sName);
public ComplexOption getComplexOption(String sName);
/** Get the collection of complex options in a specific groups
*
* @param sGroup the name of the group of options
* @return the names of the currently defined options in this group
*/
public Set<String> getComplexOptions(String sGroup);
}