Mercurial > projects > dwt-addons
diff dwtx/jface/dialogs/DialogSettings.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | 7ffeace6c47f |
children | 1470d66733fa |
line wrap: on
line diff
--- a/dwtx/jface/dialogs/DialogSettings.d Sun Aug 03 17:01:51 2008 +0200 +++ b/dwtx/jface/dialogs/DialogSettings.d Thu Aug 07 15:01:33 2008 +0200 @@ -14,10 +14,6 @@ import dwtx.jface.dialogs.IDialogSettings; -import tango.util.collection.model.Map; -import tango.util.collection.model.Seq; -import tango.util.collection.HashMap; -import tango.util.collection.ArraySeq; static import tango.text.xml.Document; static import tango.text.xml.SaxParser; @@ -26,6 +22,7 @@ import dwt.dwthelper.utils; +import dwtx.dwtxhelper.Collection; static import dwt.dwthelper.OutputStream; static import tango.text.convert.Integer; static import tango.text.convert.Float; @@ -75,14 +72,14 @@ /* A Map of DialogSettings representing each sections in a DialogSettings. It maps the DialogSettings' name to the DialogSettings */ - private Map!(String,IDialogSettings) sections; + private Map sections; /* A Map with all the keys and values of this sections. Either the keys an values are restricted to strings. */ - private Map!(String,String) items; + private Map items; // A Map with all the keys mapped to array of strings. - private Map!(String,String[]) arrayItems; + private Map arrayItems; private static const String TAG_SECTION = "section";//$NON-NLS-1$ @@ -106,9 +103,9 @@ */ public this(String sectionName) { name = sectionName; - items = new HashMap!(String,String); - arrayItems = new HashMap!(String,String[]); - sections = new HashMap!(String,IDialogSettings); + items = new HashMap(); + arrayItems = new HashMap(); + sections = new HashMap(); } /* (non-Javadoc) @@ -124,35 +121,35 @@ * Method declared on IDialogSettings. */ public void addSection(IDialogSettings section) { - sections.add(section.getName(), section); + sections.put(stringcast(section.getName()), cast(Object)section); } /* (non-Javadoc) * Method declared on IDialogSettings. */ public String get(String key) { - return items.get(key); + return stringcast(items.get(stringcast(key))); } /* (non-Javadoc) * Method declared on IDialogSettings. */ public String[] getArray(String key) { - return arrayItems.get(key); + return stringArrayFromObject(arrayItems.get(stringcast(key))); } /* (non-Javadoc) * Method declared on IDialogSettings. */ public bool getBoolean(String key) { - return items.get(key) == "true"; + return stringcast(items.get(stringcast(key))) == "true"; } /* (non-Javadoc) * Method declared on IDialogSettings. */ public double getDouble(String key) { - String setting = items.get(key); + String setting = stringcast(items.get(stringcast(key))); if (setting is null) { throw new NumberFormatException( "There is no setting associated with the key \"" ~ key ~ "\"");//$NON-NLS-1$ //$NON-NLS-2$ @@ -165,7 +162,7 @@ * Method declared on IDialogSettings. */ public float getFloat(String key) { - String setting = items.get(key); + String setting = stringcast(items.get(stringcast(key))); if (setting is null) { throw new NumberFormatException( "There is no setting associated with the key \"" ~ key ~ "\"");//$NON-NLS-1$ //$NON-NLS-2$ @@ -178,7 +175,7 @@ * Method declared on IDialogSettings. */ public int getInt(String key) { - String setting = items.get(key); + String setting = stringcast(items.get(stringcast(key))); if (setting is null) { //new Integer(null) will throw a NumberFormatException and meet our spec, but this message //is clearer. @@ -193,7 +190,7 @@ * Method declared on IDialogSettings. */ public long getLong(String key) { - String setting = items.get(key); + String setting = stringcast(items.get(stringcast(key))); if (setting is null) { //new Long(null) will throw a NumberFormatException and meet our spec, but this message //is clearer. @@ -215,14 +212,16 @@ * Method declared on IDialogSettings. */ public IDialogSettings getSection(String sectionName) { - return sections.get(sectionName); + return cast(IDialogSettings) sections.get(stringcast(sectionName)); } /* (non-Javadoc) * Method declared on IDialogSettings. */ public IDialogSettings[] getSections() { - return sections.toArray(); + Collection values = sections.values(); + IDialogSettings[] result = arraycast!(IDialogSettings)( values.toArray() ); + return result; } /* (non-Javadoc) @@ -275,7 +274,7 @@ if( root is n.parent() ){ String key = n.getAttribute(TAG_KEY).value().dup; String value = n.getAttribute(TAG_VALUE).value().dup; - items.add(key, value); + items.put(stringcast(key), stringcast(value)); } } foreach( n; root.query[TAG_LIST].dup ){ @@ -288,7 +287,7 @@ valueList ~= node.getAttribute(TAG_VALUE).value().dup; } } - arrayItems.add(key, valueList ); + arrayItems.put(stringcast(key), new ArrayWrapperString2(valueList) ); } } foreach( n; root.query[TAG_SECTION].dup ){ @@ -304,7 +303,7 @@ * Method declared on IDialogSettings. */ public void put(String key, String[] value) { - arrayItems.add(key, value); + arrayItems.put(stringcast(key), new ArrayWrapperString2(value)); } /* (non-Javadoc) @@ -339,7 +338,7 @@ * Method declared on IDialogSettings. */ public void put(String key, String value) { - items.add(key, value); + items.put(stringcast(key), stringcast(value)); } /* (non-Javadoc) @@ -371,35 +370,37 @@ * Save the settings in the <code>document</code>. */ private void save(XMLWriter out_) { - HashMap!(String,String) attributes = new HashMap!(String,String); - attributes.add(TAG_NAME, name is null ? "" : name); //$NON-NLS-1$ + HashMap attributes = new HashMap(2); + attributes.put(stringcast(TAG_NAME), stringcast(name is null ? "" : name)); //$NON-NLS-1$ out_.startTag(TAG_SECTION, attributes); attributes.clear(); + Object EMPTY_STR = new ArrayWrapperString(""); foreach( key,value; items ){ - attributes.add(TAG_KEY, key is null ? "" : key); //$NON-NLS-1$ - String string = value;cast(String) items.get(key); - attributes.add(TAG_VALUE, string is null ? "" : string); //$NON-NLS-1$ + attributes.put(stringcast(TAG_KEY), key is null ? EMPTY_STR : key); //$NON-NLS-1$ + String string = stringcast(value);//cast(String) items.get(stringcast(key)); + attributes.put(stringcast(TAG_VALUE), stringcast(string is null ? "" : string)); //$NON-NLS-1$ out_.printTag(TAG_ITEM, attributes, true); } attributes.clear(); foreach( key,value; arrayItems ){ - attributes.add(TAG_KEY, key is null ? "" : key); //$NON-NLS-1$ + attributes.put(stringcast(TAG_KEY), key is null ? EMPTY_STR : key); //$NON-NLS-1$ out_.startTag(TAG_LIST, attributes); attributes.clear(); + String[] strValues = stringArrayFromObject(value); if (value !is null) { - for (int index = 0; index < value.length; index++) { - String string = value[index]; - attributes.add(TAG_VALUE, string is null ? "" : string); //$NON-NLS-1$ + for (int index = 0; index < strValues.length; index++) { + String string = strValues[index]; + attributes.put(stringcast(TAG_VALUE), stringcast(string is null ? "" : string)); //$NON-NLS-1$ out_.printTag(TAG_ITEM, attributes, true); } } out_.endTag(TAG_LIST); attributes.clear(); } - foreach( name, section; sections ){ - section.save(out_); + for (Iterator i = sections.values().iterator(); i.hasNext();) { + (cast(DialogSettings) i.next()).save(out_); } out_.endTag(TAG_SECTION); } @@ -448,20 +449,22 @@ * @param parameters map of parameters * @param close should the tag be ended automatically (=> empty tag) */ - public void printTag(String name, HashMap!(String,String) parameters, bool close) { + public void printTag(String name, HashMap parameters, bool close) { printTag(name, parameters, true, true, close); } - private void printTag(String name, HashMap!(String,String) parameters, bool shouldTab, bool newLine, bool close) { + private void printTag(String name, HashMap parameters, bool shouldTab, bool newLine, bool close) { StringBuffer sb = new StringBuffer(); sb.append('<'); sb.append(name); if (parameters !is null) { - foreach( key, value; parameters ){ + for (Enumeration e = Collections.enumeration(parameters.keySet()); e.hasMoreElements();) { sb.append(" "); //$NON-NLS-1$ + String key = stringcast( e.nextElement()); sb.append(key); sb.append("=\""); //$NON-NLS-1$ - sb.append(xmlEscape(value.dup)); + //sb.append(getEscaped(String.valueOf(parameters.get(key)))); + sb.append(xmlEscape(stringcast(parameters.get(stringcast(key))))); sb.append("\""); //$NON-NLS-1$ } } @@ -485,12 +488,12 @@ * @param name the name of the tag * @param parameters map of parameters */ - public void startTag(String name, HashMap!(String,String) parameters) { + public void startTag(String name, HashMap parameters) { startTag(name, parameters, true); tab++; } - private void startTag(String name, HashMap!(String,String) parameters, bool newLine) { + private void startTag(String name, HashMap parameters, bool newLine) { printTag(name, parameters, true, newLine, false); } }