new version with WorkingCopy Management
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / JavaColorManager.java
index a7a462b..3c57e1d 100644 (file)
@@ -20,20 +20,47 @@ import org.eclipse.swt.widgets.Display;
  * Java color manager.
  */
 public class JavaColorManager implements IColorManager, IColorManagerExtension {
-       
        protected Map fKeyTable= new HashMap(10);
        protected Map fDisplayTable= new HashMap(2);
-       
-       
+
+       /** 
+        * Flag which tells if the colors are automatically disposed when
+        * the current display gets disposed.
+        */
+       private boolean fAutoDisposeOnDisplayDispose;
+
+
+       /**
+        * Creates a new Java color manager which automatically
+        * disposes the allocated colors when the current display
+        * gets disposed.
+        */     
        public JavaColorManager() {
+               this(true);
+       }
+
+       /**
+        * Creates a new Java color manager.
+        * 
+        * @param autoDisposeOnDisplayDispose   if <code>true</code>  the color manager
+        * automatically disposes all managed colors when the current display gets disposed
+        * and all calls to {@link org.eclipse.jface.text.source.ISharedTextColors#dispose()} are ignored.
+        * 
+        * @since 2.1
+        */
+       public JavaColorManager(boolean autoDisposeOnDisplayDispose) {
+               fAutoDisposeOnDisplayDispose= autoDisposeOnDisplayDispose;
        }
        
-       private void dispose(Display display) {         
+       public void dispose(Display display) {
                Map colorTable= (Map) fDisplayTable.get(display);
                if (colorTable != null) {
                        Iterator e= colorTable.values().iterator();
-                       while (e.hasNext())
-                               ((Color) e.next()).dispose();
+                       while (e.hasNext()) {
+                               Color color= (Color)e.next();
+                               if (color != null && !color.isDisposed())
+                                       color.dispose();
+                       }
                }
        }
        
@@ -50,11 +77,13 @@ public class JavaColorManager implements IColorManager, IColorManagerExtension {
                if (colorTable == null) {
                        colorTable= new HashMap(10);
                        fDisplayTable.put(display, colorTable);
-                       display.disposeExec(new Runnable() {
-                               public void run() {
-                                       dispose(display);
-                               }
-                       });
+                       if (fAutoDisposeOnDisplayDispose) {
+                               display.disposeExec(new Runnable() {
+                                       public void run() {
+                                               dispose(display);
+                                       }
+                               });
+                       }
                }
                
                Color color= (Color) colorTable.get(rgb);
@@ -70,7 +99,8 @@ public class JavaColorManager implements IColorManager, IColorManagerExtension {
         * @see IColorManager#dispose
         */
        public void dispose() {
-               // nothing to dispose
+               if (!fAutoDisposeOnDisplayDispose)
+                       dispose(Display.getCurrent());
        }
        
        /*