changeset 102:0de61c6f08ca

Reduce static ctors
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Aug 2008 03:07:30 +0200
parents 1082a0fc2bb8
children 2d6540440fe6
files dwtx/draw2d/ButtonBorder.d dwtx/draw2d/ColorConstants.d
diffstat 2 files changed, 332 insertions(+), 105 deletions(-) [+]
line wrap: on
line diff
--- a/dwtx/draw2d/ButtonBorder.d	Sun Aug 03 02:17:46 2008 +0200
+++ b/dwtx/draw2d/ButtonBorder.d	Sun Aug 03 03:07:30 2008 +0200
@@ -44,28 +44,61 @@
  * Default button border.
  * @see SCHEMES#BUTTON
  */
-public static const Border BUTTON;
+private static const Border BUTTON_;
+public static ButtonScheme BUTTON(){
+    if( BUTTON_ is null ){
+        synchronized( ButtonScheme.classinfo ){
+            if( BUTTON_ is null ){
+                BUTTON_ = new ButtonBorder(SCHEMES.BUTTON);
+            }
+        }
+    }
+    return BUTTON_;
+}
 /**
  * Inverted hightlight colors from BUTTON.
  * @see SCHEMES#BUTTON_CONTRAST
  */
-public static const Border BUTTON_CONTRAST;
+private static const Border BUTTON_CONTRAST_;
+public static ButtonScheme BUTTON_CONTRAST(){
+    if( BUTTON_CONTRAST_ is null ){
+        synchronized( ButtonScheme.classinfo ){
+            if( BUTTON_CONTRAST_ is null ){
+                BUTTON_CONTRAST_ = new ButtonBorder(SCHEMES.BUTTON_CONTRAST);
+            }
+        }
+    }
+    return BUTTON_CONTRAST_;
+}
 /**
  * Used for scrollbar buttons.
  * @see SCHEMES#BUTTON_SCROLLBAR
  */
-public static const Border BUTTON_SCROLLBAR;
+private static const Border BUTTON_SCROLLBAR_;
+public static ButtonScheme BUTTON_SCROLLBAR(){
+    if( BUTTON_SCROLLBAR_ is null ){
+        synchronized( ButtonScheme.classinfo ){
+            if( BUTTON_SCROLLBAR_ is null ){
+                BUTTON_SCROLLBAR_ =  new ButtonBorder(SCHEMES.BUTTON_SCROLLBAR);
+            }
+        }
+    }
+    return BUTTON_SCROLLBAR_;
+}
 /**
  * Used for toolbar buttons.
  * @see SCHEMES#TOOLBAR
  */
-public static const Border TOOLBAR;
-
-static this(){
-    BUTTON = new ButtonBorder(SCHEMES.BUTTON);
-    BUTTON_CONTRAST = new ButtonBorder(SCHEMES.BUTTON_CONTRAST);
-    BUTTON_SCROLLBAR = new ButtonBorder(SCHEMES.BUTTON_SCROLLBAR);
-    TOOLBAR = new ButtonBorder(SCHEMES.TOOLBAR);
+private static const Border TOOLBAR_;
+public static ButtonScheme TOOLBAR(){
+    if( TOOLBAR_ is null ){
+        synchronized( ButtonScheme.classinfo ){
+            if( TOOLBAR_ is null ){
+                TOOLBAR_ = new ButtonBorder(SCHEMES.TOOLBAR);
+            }
+        }
+    }
+    return TOOLBAR_;
 }
 
 /**
@@ -193,39 +226,73 @@
     /**
      * Contrast button scheme
      */
-    static const ButtonScheme BUTTON_CONTRAST;
+    private static const ButtonScheme BUTTON_CONTRAST_;
+    static ButtonScheme BUTTON_CONTRAST(){
+        if( BUTTON_CONTRAST_ is null ){
+            synchronized( ButtonScheme.classinfo ){
+                if( BUTTON_CONTRAST_ is null ){
+                    BUTTON_CONTRAST_ = new ButtonScheme(
+                        [ColorConstants.button, ColorConstants.buttonLightest],
+                        DARKEST_DARKER
+                    );
+                }
+            }
+        }
+        return BUTTON_CONTRAST_;
+    }
     /**
      * Regular button scheme
      */
-    static const ButtonScheme BUTTON;
+    private static const ButtonScheme BUTTON_;
+    static ButtonScheme BUTTON(){
+        if( BUTTON_ is null ){
+            synchronized( ButtonScheme.classinfo ){
+                if( BUTTON_ is null ){
+                    BUTTON_ = new ButtonScheme(
+                        [ColorConstants.buttonLightest],
+                        DARKEST_DARKER
+                    );
+                }
+            }
+        }
+        return BUTTON_;
+    }
     /**
      * Toolbar button scheme
      */
-    static const ButtonScheme TOOLBAR;
+    private static const ButtonScheme TOOLBAR_;
+    static ButtonScheme TOOLBAR(){
+        if( TOOLBAR_ is null ){
+            synchronized( ButtonScheme.classinfo ){
+                if( TOOLBAR_ is null ){
+                    TOOLBAR_ = new ButtonScheme(
+                        [ColorConstants.buttonLightest],
+                        [ColorConstants.buttonDarker]
+                    );
+                }
+            }
+        }
+        return TOOLBAR_;
+    }
     /**
      * Scrollbar button scheme
      */
-    static const ButtonScheme BUTTON_SCROLLBAR;
-static this(){
-    BUTTON_CONTRAST = new ButtonScheme(
-        [ColorConstants.button, ColorConstants.buttonLightest],
-        DARKEST_DARKER
-    );
-    BUTTON = new ButtonScheme(
-        [ColorConstants.buttonLightest],
-        DARKEST_DARKER
-    );
-    TOOLBAR = new ButtonScheme(
-        [ColorConstants.buttonLightest],
-        [ColorConstants.buttonDarker]
-    );
-    BUTTON_SCROLLBAR = new ButtonScheme(
-        [ColorConstants.button, ColorConstants.buttonLightest],
-        DARKEST_DARKER,
-        [ColorConstants.buttonDarker],
-        [ColorConstants.buttonDarker]
-    );
-}
+    private static const ButtonScheme BUTTON_SCROLLBAR_;
+    static ButtonScheme BUTTON_SCROLLBAR(){
+        if( BUTTON_SCROLLBAR_ is null ){
+            synchronized( ButtonScheme.classinfo ){
+                if( BUTTON_SCROLLBAR_ is null ){
+                    BUTTON_SCROLLBAR_ = new ButtonScheme(
+                        [ColorConstants.button, ColorConstants.buttonLightest],
+                        DARKEST_DARKER,
+                        [ColorConstants.buttonDarker],
+                        [ColorConstants.buttonDarker]
+                    );
+                }
+            }
+        }
+        return BUTTON_SCROLLBAR_;
+    }
 }
 
 /**
--- a/dwtx/draw2d/ColorConstants.d	Sun Aug 03 02:17:46 2008 +0200
+++ b/dwtx/draw2d/ColorConstants.d	Sun Aug 03 03:07:30 2008 +0200
@@ -25,7 +25,6 @@
  */
 public struct ColorConstants {
 
-class SystemColorFactory {
     private static Color getColor(int which) {
         Display display = Display.getCurrent();
         if (display !is null)
@@ -42,155 +41,316 @@
             return result;
         }
     }
-}
 
 /**
  * @see DWT#COLOR_WIDGET_HIGHLIGHT_SHADOW
  */
-static const Color buttonLightest;
+private static Color buttonLightest_;
+public static Color buttonLightest(){
+    if( buttonLightest_ is null ){
+        buttonLightest_ = getColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
+    }
+    return buttonLightest_;
+}
 /**
  * @see DWT#COLOR_WIDGET_BACKGROUND
  */
-static const Color button;
+private static Color button_;
+public static Color button(){
+    if( button_ is null ){
+        button_ = getColor(DWT.COLOR_WIDGET_BACKGROUND);
+    }
+    return button_;
+}
 /**
  * @see DWT#COLOR_WIDGET_NORMAL_SHADOW
  */
-static const Color buttonDarker;
+private static Color buttonDarker_;
+public static Color buttonDarker(){
+    if( buttonDarker_ is null ){
+        buttonDarker_ = getColor(DWT.COLOR_WIDGET_NORMAL_SHADOW);
+    }
+    return buttonDarker_;
+}
 /**
  * @see DWT#COLOR_WIDGET_DARK_SHADOW
  */
-static const Color buttonDarkest;
+private static Color buttonDarkest_;
+public static Color buttonDarkest(){
+    if( buttonDarkest_ is null ){
+        buttonDarkest_ = getColor(DWT.COLOR_WIDGET_DARK_SHADOW);
+    }
+    return buttonDarkest_;
+}
 
 /**
  * @see DWT#COLOR_LIST_BACKGROUND
  */
-static const Color listBackground;
+private static Color listBackground_;
+public static Color listBackground(){
+    if( listBackground_ is null ){
+        listBackground_ = getColor(DWT.COLOR_LIST_BACKGROUND);
+    }
+    return listBackground_;
+}
 /**
  * @see DWT#COLOR_LIST_FOREGROUND
  */
-static const Color listForeground;
+private static Color listForeground_;
+public static Color listForeground(){
+    if( listForeground_ is null ){
+        listForeground_ = getColor(DWT.COLOR_LIST_FOREGROUND);
+    }
+    return listForeground_;
+}
 
 /**
  * @see DWT#COLOR_WIDGET_BACKGROUND
  */
-static const Color menuBackground;
+private static Color menuBackground_;
+public static Color menuBackground(){
+    if( menuBackground_ is null ){
+        menuBackground_ = getColor(DWT.COLOR_WIDGET_BACKGROUND);
+    }
+    return menuBackground_;
+}
 /**
  * @see DWT#COLOR_WIDGET_FOREGROUND
  */
-static const Color menuForeground;
+private static Color menuForeground_;
+public static Color menuForeground(){
+    if( menuForeground_ is null ){
+        menuForeground_ = getColor(DWT.COLOR_WIDGET_FOREGROUND);
+    }
+    return menuForeground_;
+}
 /**
  * @see DWT#COLOR_LIST_SELECTION
  */
-static const Color menuBackgroundSelected;
+private static Color menuBackgroundSelected_;
+public static Color menuBackgroundSelected(){
+    if( menuBackgroundSelected_ is null ){
+        menuBackgroundSelected_ = getColor(DWT.COLOR_LIST_SELECTION);
+    }
+    return menuBackgroundSelected_;
+}
 /**
  * @see DWT#COLOR_LIST_SELECTION_TEXT
  */
-static const Color menuForegroundSelected;
+private static Color menuForegroundSelected_;
+public static Color menuForegroundSelected(){
+    if( menuForegroundSelected_ is null ){
+        menuForegroundSelected_ = getColor(DWT.COLOR_LIST_SELECTION_TEXT);
+    }
+    return menuForegroundSelected_;
+}
 
 /**
  * @see DWT#COLOR_TITLE_BACKGROUND
  */
-static const Color titleBackground;
+private static Color titleBackground_;
+public static Color titleBackground(){
+    if( titleBackground_ is null ){
+        titleBackground_ = getColor(DWT.COLOR_TITLE_BACKGROUND);
+    }
+    return titleBackground_;
+}
 /**
  * @see DWT#COLOR_TITLE_BACKGROUND_GRADIENT
  */
-static const Color titleGradient;
+private static Color titleGradient_;
+public static Color titleGradient(){
+    if( titleGradient_ is null ){
+        titleGradient_ = getColor(DWT.COLOR_TITLE_BACKGROUND_GRADIENT);
+    }
+    return titleGradient_;
+}
 /**
  * @see DWT#COLOR_TITLE_FOREGROUND
  */
-static const Color titleForeground;
+private static Color titleForeground_;
+public static Color titleForeground(){
+    if( titleForeground_ is null ){
+        titleForeground_ = getColor(DWT.COLOR_TITLE_FOREGROUND);
+    }
+    return titleForeground_;
+}
 /**
  * @see DWT#COLOR_TITLE_INACTIVE_FOREGROUND
  */
-static const Color titleInactiveForeground;
+private static Color titleInactiveForeground_;
+public static Color titleInactiveForeground(){
+    if( titleInactiveForeground_ is null ){
+        titleInactiveForeground_ = getColor(DWT.COLOR_TITLE_INACTIVE_FOREGROUND);
+    }
+    return titleInactiveForeground_;
+}
 /**
  * @see DWT#COLOR_TITLE_INACTIVE_BACKGROUND
  */
-static const Color titleInactiveBackground;
+private static Color titleInactiveBackground_;
+public static Color titleInactiveBackground(){
+    if( titleInactiveBackground_ is null ){
+        titleInactiveBackground_ = getColor(DWT.COLOR_TITLE_INACTIVE_BACKGROUND);
+    }
+    return titleInactiveBackground_;
+}
 /**
  * @see DWT#COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT
  */
-static const Color titleInactiveGradient;
+private static Color titleInactiveGradient_;
+public static Color titleInactiveGradient(){
+    if( titleInactiveGradient_ is null ){
+        titleInactiveGradient_ = getColor(DWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT);
+    }
+    return titleInactiveGradient_;
+}
 
 /**
  * @see DWT#COLOR_INFO_FOREGROUND
  */
-static const Color tooltipForeground;
+private static Color tooltipForeground_;
+public static Color tooltipForeground(){
+    if( tooltipForeground_ is null ){
+        tooltipForeground_ = getColor(DWT.COLOR_INFO_FOREGROUND);
+    }
+    return tooltipForeground_;
+}
 /**
  * @see DWT#COLOR_INFO_BACKGROUND
  */
-static const Color tooltipBackground;
+private static Color tooltipBackground_;
+public static Color tooltipBackground(){
+    if( tooltipBackground_ is null ){
+        tooltipBackground_ = getColor(DWT.COLOR_INFO_BACKGROUND);
+    }
+    return tooltipBackground_;
+}
 
 /*
  * Misc. colors
  */
 /** One of the pre-defined colors */
-static const Color white;
+private static Color white_;
+public static Color white(){
+    if( white_ is null ){
+        white_ = new Color(null, 255, 255, 255);
+    }
+    return white_;
+}
 /** One of the pre-defined colors */
-static const Color lightGray;
+private static Color lightGray_;
+public static Color lightGray(){
+    if( lightGray_ is null ){
+        lightGray_ = new Color(null, 192, 192, 192);
+    }
+    return lightGray_;
+}
 /** One of the pre-defined colors */
-static const Color gray;
+private static Color gray_;
+public static Color gray(){
+    if( gray_ is null ){
+        gray_ = new Color(null, 128, 128, 128);
+    }
+    return gray_;
+}
 /** One of the pre-defined colors */
-static const Color darkGray;
+private static Color darkGray_;
+public static Color darkGray(){
+    if( darkGray_ is null ){
+        darkGray_ = new Color(null,  64,  64,  64);
+    }
+    return darkGray_;
+}
 /** One of the pre-defined colors */
-static const Color black;
+private static Color black_;
+public static Color black(){
+    if( black_ is null ){
+        black_ = new Color(null,   0,   0,   0);
+    }
+    return black_;
+}
 /** One of the pre-defined colors */
-static const Color red;
+private static Color red_;
+public static Color red(){
+    if( red_ is null ){
+        red_ = new Color(null, 255,   0,   0);
+    }
+    return red_;
+}
 /** One of the pre-defined colors */
-static const Color orange;
+private static Color orange_;
+public static Color orange(){
+    if( orange_ is null ){
+        orange_ = new Color(null, 255, 196,   0);
+    }
+    return orange_;
+}
 /** One of the pre-defined colors */
-static const Color yellow;
+private static Color yellow_;
+public static Color yellow(){
+    if( yellow_ is null ){
+        yellow_ = new Color(null, 255, 255,   0);
+    }
+    return yellow_;
+}
 /** One of the pre-defined colors */
-static const Color green;
+private static Color green_;
+public static Color green(){
+    if( green_ is null ){
+        green_ = new Color(null,   0, 255,   0);
+    }
+    return green_;
+}
 /** One of the pre-defined colors */
-static const Color lightGreen;
+private static Color lightGreen_;
+public static Color lightGreen(){
+    if( lightGreen_ is null ){
+        lightGreen_ = new Color(null,  96, 255,  96);
+    }
+    return lightGreen_;
+}
 /** One of the pre-defined colors */
-static const Color darkGreen;
+private static Color darkGreen_;
+public static Color darkGreen(){
+    if( darkGreen_ is null ){
+        darkGreen_ = new Color(null,   0, 127,   0);
+    }
+    return darkGreen_;
+}
 /** One of the pre-defined colors */
-static const Color cyan;
+private static Color cyan_;
+public static Color cyan(){
+    if( cyan_ is null ){
+        cyan_ = new Color(null,   0, 255, 255);
+    }
+    return cyan_;
+}
 /** One of the pre-defined colors */
-static const Color lightBlue;
+private static Color lightBlue_;
+public static Color lightBlue(){
+    if( lightBlue_ is null ){
+        lightBlue_ = new Color(null, 127, 127, 255);
+    }
+    return lightBlue_;
+}
 /** One of the pre-defined colors */
-static const Color blue;
+private static Color blue_;
+public static Color blue(){
+    if( blue_ is null ){
+        blue_ = new Color(null,   0,   0, 255);
+    }
+    return blue_;
+}
 /** One of the pre-defined colors */
-static const Color darkBlue;
-
+private static Color darkBlue_;
+public static Color darkBlue(){
+    if( darkBlue_ is null ){
+        darkBlue_ = new Color(null,   0,   0, 127);
+    }
+    return darkBlue_;
+}
 
-static this(){
-    buttonLightest          = SystemColorFactory.getColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
-    button                  = SystemColorFactory.getColor(DWT.COLOR_WIDGET_BACKGROUND);
-    buttonDarker            = SystemColorFactory.getColor(DWT.COLOR_WIDGET_NORMAL_SHADOW);
-    buttonDarkest           = SystemColorFactory.getColor(DWT.COLOR_WIDGET_DARK_SHADOW);
-    listBackground          = SystemColorFactory.getColor(DWT.COLOR_LIST_BACKGROUND);
-    listForeground          = SystemColorFactory.getColor(DWT.COLOR_LIST_FOREGROUND);
-    menuBackground          = SystemColorFactory.getColor(DWT.COLOR_WIDGET_BACKGROUND);
-    menuForeground          = SystemColorFactory.getColor(DWT.COLOR_WIDGET_FOREGROUND);
-    menuBackgroundSelected  = SystemColorFactory.getColor(DWT.COLOR_LIST_SELECTION);
-    menuForegroundSelected  = SystemColorFactory.getColor(DWT.COLOR_LIST_SELECTION_TEXT);
-    titleBackground         = SystemColorFactory.getColor(DWT.COLOR_TITLE_BACKGROUND);
-    titleGradient           = SystemColorFactory.getColor(DWT.COLOR_TITLE_BACKGROUND_GRADIENT);
-    titleForeground         = SystemColorFactory.getColor(DWT.COLOR_TITLE_FOREGROUND);
-    titleInactiveForeground = SystemColorFactory.getColor(DWT.COLOR_TITLE_INACTIVE_FOREGROUND);
-    titleInactiveBackground = SystemColorFactory.getColor(DWT.COLOR_TITLE_INACTIVE_BACKGROUND);
-    titleInactiveGradient   = SystemColorFactory.getColor(DWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT);
-    tooltipForeground       = SystemColorFactory.getColor(DWT.COLOR_INFO_FOREGROUND);
-    tooltipBackground       = SystemColorFactory.getColor(DWT.COLOR_INFO_BACKGROUND);
-    white      = new Color(null, 255, 255, 255);
-    lightGray  = new Color(null, 192, 192, 192);
-    gray       = new Color(null, 128, 128, 128);
-    darkGray   = new Color(null,  64,  64,  64);
-    black      = new Color(null,   0,   0,   0);
-    red        = new Color(null, 255,   0,   0);
-    orange     = new Color(null, 255, 196,   0);
-    yellow     = new Color(null, 255, 255,   0);
-    green      = new Color(null,   0, 255,   0);
-    lightGreen = new Color(null,  96, 255,  96);
-    darkGreen  = new Color(null,   0, 127,   0);
-    cyan       = new Color(null,   0, 255, 255);
-    lightBlue  = new Color(null, 127, 127, 255);
-    blue       = new Color(null,   0,   0, 255);
-    darkBlue   = new Color(null,   0,   0, 127);
-}
 }