diff dwtx/draw2d/SimpleEtchedBorder.d @ 103:2d6540440fe6

Replace static ctors with lazy init.
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Aug 2008 17:01:51 +0200
parents 95307ad235d9
children
line wrap: on
line diff
--- a/dwtx/draw2d/SimpleEtchedBorder.d	Sun Aug 03 03:07:30 2008 +0200
+++ b/dwtx/draw2d/SimpleEtchedBorder.d	Sun Aug 03 17:01:51 2008 +0200
@@ -30,15 +30,36 @@
 {
 
 /** The singleton instance of this class */
-public static const Border singleton;
+private static Border singleton_;
 
 /** The insets */
-protected static const Insets INSETS;
+private static Insets INSETS_;
+
+public static Border singleton(){
+    if( !initStaticCtor_done ) initStaticCtor();
+    assert(singleton_);
+    return singleton_;
+}
+protected static Insets INSETS(){
+    if( !initStaticCtor_done ) initStaticCtor();
+    assert(INSETS_);
+    return INSETS_;
+}
 
-static this(){
-    singleton = new SimpleEtchedBorder();
-    INSETS = new Insets(2);
+private static bool initStaticCtor_done = false;
+private static void initStaticCtor(){
+    synchronized( SimpleEtchedBorder.classinfo ){
+        if( !initStaticCtor_done ){
+            singleton_ = new SimpleEtchedBorder();
+            INSETS_ = new Insets(2);
+            initStaticCtor_done = true;
+        }
+    }
 }
+
+
+
+
 /**
  * Constructs a default border having a two pixel wide border.
  *