Mercurial > projects > dwt-addons
changeset 37:e10d9c2648be
fix static interface and static this
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 06 Apr 2008 13:21:48 +0200 |
parents | b9ec89a5809c |
children | c884a1ab6db3 |
files | dwtx/jface/action/ExternalActionManager.d dwtx/jface/bindings/TriggerSequence.d dwtx/jface/bindings/keys/KeySequence.d dwtx/jface/bindings/keys/formatting/KeyFormatterFactory.d dwtx/jface/resource/JFaceResources.d dwtx/jface/window/Window.d |
diffstat | 6 files changed, 73 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/dwtx/jface/action/ExternalActionManager.d Sun Apr 06 13:19:51 2008 +0200 +++ b/dwtx/jface/action/ExternalActionManager.d Sun Apr 06 13:21:48 2008 +0200 @@ -361,7 +361,7 @@ * * @since 3.1 */ - public static interface IActiveChecker { + public interface IActiveChecker { /** * Checks whether the command with the given identifier should be * considered active. This can be used in systems using some kind of @@ -389,7 +389,7 @@ * * @since 3.2 */ - public static interface IBindingManagerCallback : ICallback { + public interface IBindingManagerCallback : ICallback { /** * <p> @@ -413,7 +413,7 @@ * * @since 3.0 */ - public static interface ICallback { + public interface ICallback { /** * <p>
--- a/dwtx/jface/bindings/TriggerSequence.d Sun Apr 06 13:19:51 2008 +0200 +++ b/dwtx/jface/bindings/TriggerSequence.d Sun Apr 06 13:21:48 2008 +0200 @@ -61,9 +61,11 @@ * May be empty. */ public this(Trigger[] triggers) { + /+ if (triggers is null) { throw new NullPointerException("The triggers cannot be null"); //$NON-NLS-1$ } + +/ for (int i = 0; i < triggers.length; i++) { if (triggers[i] is null) {
--- a/dwtx/jface/bindings/keys/KeySequence.d Sun Apr 06 13:19:51 2008 +0200 +++ b/dwtx/jface/bindings/keys/KeySequence.d Sun Apr 06 13:21:48 2008 +0200 @@ -202,7 +202,7 @@ protected this(KeyStroke[] keyStrokes) { super(keyStrokes); - for (int i = 0; i < triggers.length - 1; i++) { + for (int i = 0; i < cast(int)triggers.length - 1; i++) { KeyStroke keyStroke = cast(KeyStroke) triggers[i]; if (!keyStroke.isComplete()) {
--- a/dwtx/jface/bindings/keys/formatting/KeyFormatterFactory.d Sun Apr 06 13:19:51 2008 +0200 +++ b/dwtx/jface/bindings/keys/formatting/KeyFormatterFactory.d Sun Apr 06 13:21:48 2008 +0200 @@ -34,12 +34,12 @@ /** * The formatter that renders key bindings in a platform-dependent manner. */ - private static const IKeyFormatter FORMAL_KEY_FORMATTER; + private static /+const+/ IKeyFormatter FORMAL_KEY_FORMATTER; /** * The formatter that renders key bindings in a form similar to XEmacs */ - private static const IKeyFormatter EMACS_KEY_FORMATTER; + private static /+const+/ IKeyFormatter EMACS_KEY_FORMATTER; /** * The default formatter. This is normally the formal key formatter, but can @@ -47,10 +47,14 @@ */ private static IKeyFormatter defaultKeyFormatter; - static this(){ - FORMAL_KEY_FORMATTER = new FormalKeyFormatter(); - EMACS_KEY_FORMATTER = new EmacsKeyFormatter(); - defaultKeyFormatter = FORMAL_KEY_FORMATTER; + private static void check_static_init(){ + if( FORMAL_KEY_FORMATTER is null ){ + synchronized if( FORMAL_KEY_FORMATTER is null ){ + FORMAL_KEY_FORMATTER = new FormalKeyFormatter(); + EMACS_KEY_FORMATTER = new EmacsKeyFormatter(); + defaultKeyFormatter = FORMAL_KEY_FORMATTER; + } + } } /** @@ -59,6 +63,7 @@ * @return The default formatter; never <code>null</code>. */ public static final IKeyFormatter getDefault() { + check_static_init(); return defaultKeyFormatter; } @@ -68,6 +73,7 @@ * @return The Xemacs formatter; never <code>null</code>. */ public static final IKeyFormatter getEmacsKeyFormatter() { + check_static_init(); return EMACS_KEY_FORMATTER; } @@ -77,6 +83,7 @@ * @return The formal formatter; never <code>null</code>. */ public static final IKeyFormatter getFormalKeyFormatter() { + check_static_init(); return FORMAL_KEY_FORMATTER; } @@ -87,6 +94,7 @@ * the default key formatter. Must not be <code>null</code>. */ public static final void setDefault(IKeyFormatter defaultKeyFormatter) { + check_static_init(); if (defaultKeyFormatter is null) { throw new NullPointerException(); }
--- a/dwtx/jface/resource/JFaceResources.d Sun Apr 06 13:19:51 2008 +0200 +++ b/dwtx/jface/resource/JFaceResources.d Sun Apr 06 13:21:48 2008 +0200 @@ -64,8 +64,12 @@ * the associated display. */ private static Map!(Display,ResourceManager) registries; - static this(){ - registries = new HashMap!(Display,ResourceManager); + private static void init_registries(){ + if( registries is null ){ + synchronized if( registries is null ){ + registries = new HashMap!(Display,ResourceManager); + } + } } /** @@ -78,8 +82,12 @@ * The JFace resource bundle; eagerly initialized. */ private static /+final+/ ResourceBundle bundle; - static this(){ - bundle = ResourceBundle.getBundle("dwtx.jface.messages"); //$NON-NLS-1$ + private static void init_bundle(){ + if( bundle is null ){ + synchronized if( bundle is null ){ + bundle = ResourceBundle.getBundle("dwtx.jface.messages"); //$NON-NLS-1$ + } + } } /** @@ -179,6 +187,7 @@ * @return the resource bundle */ public static ResourceBundle getBundle() { + init_bundle(); return bundle; } @@ -206,6 +215,7 @@ * @return the global resource manager for the given display */ public static ResourceManager getResources(Display toQuery) { + init_registries(); ResourceManager reg = cast(ResourceManager) registries.get(toQuery); if (reg is null) { @@ -505,6 +515,7 @@ * @return the string */ public static String getString(String key) { + init_bundle(); try { return bundle.getString(key); } catch (MissingResourceException e) {
--- a/dwtx/jface/window/Window.d Sun Apr 06 13:19:51 2008 +0200 +++ b/dwtx/jface/window/Window.d Sun Apr 06 13:21:48 2008 +0200 @@ -119,7 +119,7 @@ * This interface defines a Exception Handler which can be set as a global * handler and will be called if an exception happens in the event loop. */ - public static interface IExceptionHandler { + public interface IExceptionHandler { /** * Handle the exception. * @@ -154,9 +154,14 @@ /** * The exception handler for this application. */ - private static IExceptionHandler exceptionHandler; - static this(){ - exceptionHandler = new DefaultExceptionHandler(); + private static IExceptionHandler exceptionHandler_; + private static IExceptionHandler exceptionHandler(){ + if( exceptionHandler_ is null ){ + synchronized if( exceptionHandler_ is null ){ + exceptionHandler_ = new DefaultExceptionHandler(); + } + } + return exceptionHandler_; } /** * The default orientation of the window. By default @@ -168,33 +173,38 @@ /** * Object used to locate the default parent for modal shells */ - private static IShellProvider defaultModalParent; - static this(){ - defaultModalParent = new class IShellProvider { - public Shell getShell() { - Display d = Display.getCurrent(); + private static IShellProvider defaultModalParent_; + private static IShellProvider defaultModalParent(){ + if( defaultModalParent_ is null ){ + synchronized if( defaultModalParent_ is null ){ + defaultModalParent_ = new class IShellProvider { + public Shell getShell() { + Display d = Display.getCurrent(); - if (d is null) { - return null; - } + if (d is null) { + return null; + } - Shell parent = d.getActiveShell(); + Shell parent = d.getActiveShell(); - // Make sure we don't pick a parent that has a modal child (this can lock the app) - if (parent is null) { - // If this is a top-level window, then there must not be any open modal windows. - parent = getModalChild(Display.getCurrent().getShells()); - } else { - // If we picked a parent with a modal child, use the modal child instead - Shell modalChild = getModalChild(parent.getShells()); - if (modalChild !is null) { - parent = modalChild; + // Make sure we don't pick a parent that has a modal child (this can lock the app) + if (parent is null) { + // If this is a top-level window, then there must not be any open modal windows. + parent = getModalChild(Display.getCurrent().getShells()); + } else { + // If we picked a parent with a modal child, use the modal child instead + Shell modalChild = getModalChild(parent.getShells()); + if (modalChild !is null) { + parent = modalChild; + } + } + + return parent; } - } - - return parent; + }; } - }; + } + return defaultModalParent_; } /** @@ -1043,7 +1053,7 @@ */ public static void setExceptionHandler(IExceptionHandler handler) { if ( cast(DefaultExceptionHandler)exceptionHandler ) { - exceptionHandler = handler; + exceptionHandler_ = handler; } } @@ -1056,7 +1066,7 @@ * @since 3.1 */ public static void setDefaultModalParent(IShellProvider provider) { - defaultModalParent = provider; + defaultModalParent_ = provider; } /**