diff dwtx/ui/forms/widgets/FormText.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 56fea7e5f0f9
children c3583c6ec027
line wrap: on
line diff
--- a/dwtx/ui/forms/widgets/FormText.d	Sun Aug 03 17:01:51 2008 +0200
+++ b/dwtx/ui/forms/widgets/FormText.d	Thu Aug 07 15:01:33 2008 +0200
@@ -79,8 +79,7 @@
 import dwt.dwthelper.utils;
 import dwt.dwthelper.InputStream;
 import tango.io.Stdout;
-import tango.util.collection.HashMap;
-import tango.util.collection.ArraySeq;
+import dwtx.dwtxhelper.Collection;
 
 /**
  * This class is a read-only text control that is capable of rendering wrapped
@@ -206,7 +205,7 @@
 
     private ListenerList listeners;
 
-    private HashMap!(String,Object) resourceTable;
+    private Hashtable resourceTable;
 
     private IHyperlinkSegment entered;
 
@@ -364,7 +363,7 @@
      *            the widget style
      */
     public this(Composite parent, int style) {
-        resourceTable = new HashMap!(String,Object);
+        resourceTable = new Hashtable();
         super(parent, DWT.NO_BACKGROUND | DWT.WRAP | style);
         setLayout(new FormTextLayout());
         model = new FormTextModel();
@@ -562,7 +561,7 @@
      *            an object of a type <samp>Image </samp>.
      */
     public void setImage(String key, Image image) {
-        resourceTable.add("i." ~ key, image); //$NON-NLS-1$
+        resourceTable.put("i." ~ key, image); //$NON-NLS-1$
     }
 
     /**
@@ -582,9 +581,9 @@
     public void setColor(String key, Color color) {
         String fullKey = "c." ~ key; //$NON-NLS-1$
         if (color is null)
-            resourceTable.removeKey(fullKey);
+            resourceTable.remove(fullKey);
         else
-            resourceTable.add(fullKey, color);
+            resourceTable.put(fullKey, color);
     }
 
     /**
@@ -604,9 +603,9 @@
     public void setFont(String key, Font font) {
         String fullKey = "f." ~ key; //$NON-NLS-1$
         if (font is null)
-            resourceTable.removeKey(fullKey);
+            resourceTable.remove(fullKey);
         else
-            resourceTable.add(fullKey, font);
+            resourceTable.put(fullKey, font);
         model.clearCache(fullKey);
     }
 
@@ -629,9 +628,9 @@
     public void setControl(String key, Control control) {
         String fullKey = "o." ~ key; //$NON-NLS-1$
         if (control is null)
-            resourceTable.removeKey(fullKey);
+            resourceTable.remove(fullKey);
         else
-            resourceTable.add(fullKey, control);
+            resourceTable.put(fullKey, control);
     }
 
     /**
@@ -648,7 +647,7 @@
         Font boldFont = cast(Font) resourceTable.get(FormTextModel.BOLD_FONT_ID);
         if (boldFont !is null) {
             FormFonts.getInstance().markFinished(boldFont);
-            resourceTable.removeKey(FormTextModel.BOLD_FONT_ID);
+            resourceTable.remove(FormTextModel.BOLD_FONT_ID);
         }
         ensureBoldFontPresent(getFont());
     }
@@ -1552,11 +1551,11 @@
     }
 
     private void ensureBoldFontPresent(Font regularFont) {
-        Font boldFont = resourceTable.containsKey(FormTextModel.BOLD_FONT_ID) ? cast(Font) resourceTable.get(FormTextModel.BOLD_FONT_ID) : null;
+        Font boldFont = cast(Font) resourceTable.get(FormTextModel.BOLD_FONT_ID);
         if (boldFont !is null)
             return;
         boldFont = FormFonts.getInstance().getBoldFont(getDisplay(), regularFont);
-        resourceTable.add(FormTextModel.BOLD_FONT_ID, boldFont);
+        resourceTable.put(FormTextModel.BOLD_FONT_ID, boldFont);
     }
 
     private void paint(PaintEvent e) {
@@ -1669,22 +1668,24 @@
                     .get(FormTextModel.BOLD_FONT_ID);
             if (boldFont !is null) {
                 FormFonts.getInstance().markFinished(boldFont);
-                resourceTable.removeKey(FormTextModel.BOLD_FONT_ID);
+                resourceTable.remove(FormTextModel.BOLD_FONT_ID);
             }
         }
-        ArraySeq!(String) imagesToRemove = new ArraySeq!(String);
-        foreach( key, obj; resourceTable ){
+        ArrayList imagesToRemove = new ArrayList();
+        for (Enumeration enm = resourceTable.keys(); enm.hasMoreElements();) {
+            String key = stringcast( enm.nextElement());
             if (key.startsWith(ImageSegment.SEL_IMAGE_PREFIX)) {
+                Object obj = resourceTable.get(key);
                 if (auto image = cast(Image)obj ) {
                     if (!image.isDisposed()) {
                         image.dispose();
-                        imagesToRemove.append(key);
+                        imagesToRemove.add(key);
                     }
                 }
             }
         }
         for (int i = 0; i < imagesToRemove.size(); i++) {
-            resourceTable.removeKey(imagesToRemove.get(i));
+            resourceTable.remove(imagesToRemove.get(i));
         }
     }