Mercurial > projects > dwt-addons
changeset 101:1082a0fc2bb8
First Draw2D example running
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Aug 2008 02:17:46 +0200 |
parents | 86617aa6b5dd |
children | 0de61c6f08ca |
files | dwtx/draw2d/ConnectionRouter.d dwtx/draw2d/Figure.d dwtx/draw2d/FigureUtilities.d dwtx/draw2d/SWTGraphics.d dwtx/draw2d/TextUtilities.d dwtx/draw2d/geometry/Dimension.d dwtx/draw2d/geometry/Point.d dwtx/draw2d/geometry/Rectangle.d dwtx/dwtxhelper/Collection.d res/dwtx.draw2d.checkboxenabledoff.gif res/dwtx.draw2d.checkboxenabledon.gif |
diffstat | 11 files changed, 218 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/dwtx/draw2d/ConnectionRouter.d Sun Aug 03 00:54:29 2008 +0200 +++ b/dwtx/draw2d/ConnectionRouter.d Sun Aug 03 02:17:46 2008 +0200 @@ -88,12 +88,20 @@ } } + /** * The default router for Connections. */ -public static const ConnectionRouter ConnectionRouter_NULL; - -static this(){ - ConnectionRouter_NULL = new NullConnectionRouter(); +private static NullConnectionRouter ConnectionRouter_NULL_; +public static NullConnectionRouter ConnectionRouter_NULL(){ + if( ConnectionRouter_NULL_ is null ){ + synchronized( NullConnectionRouter.classinfo ){ + if( ConnectionRouter_NULL_ is null ){ + ConnectionRouter_NULL_ = new NullConnectionRouter(); + } + } + } + return ConnectionRouter_NULL_; } +
--- a/dwtx/draw2d/Figure.d Sun Aug 03 00:54:29 2008 +0200 +++ b/dwtx/draw2d/Figure.d Sun Aug 03 02:17:46 2008 +0200 @@ -303,8 +303,12 @@ if (getFlag(FLAG_REALIZED)) throw new RuntimeException("addNotify() should not be called multiple times"); //$NON-NLS-1$ setFlag(FLAG_REALIZED, true); - for (int i = 0; i < children.size(); i++) + assert(children); + for (int i = 0; i < children.size(); i++){ + assert(children.get(i)); + assert(cast(IFigure)children.get(i)); (cast(IFigure)children.get(i)).addNotify(); + } } /** @@ -1791,10 +1795,18 @@ /** * The singleton instance. */ - public static const TreeSearch INSTANCE; - static this(){ - INSTANCE = new IdentitySearch(); + private static IdentitySearch INSTANCE_; + public static IdentitySearch INSTANCE(){ + if( INSTANCE_ is null ){ + synchronized( IdentitySearch.classinfo ){ + if( INSTANCE_ is null ){ + INSTANCE_ = new IdentitySearch(); + } + } + } + return INSTANCE_; } + private this() { } /** * Always returns <code>true</code>. @@ -1908,15 +1920,23 @@ /** * An UpdateManager that does nothing. */ -protected static const UpdateManager NO_MANAGER; -static this(){ - NO_MANAGER = new class() UpdateManager { - public void addDirtyRegion (IFigure figure, int x, int y, int w, int h) { } - public void addInvalidFigure(IFigure f) { } - public void performUpdate() { } - public void performUpdate(Rectangle region) { } - public void setRoot(IFigure root) { } - public void setGraphicsSource(GraphicsSource gs) { } - }; +private static UpdateManager NO_MANAGER_; +protected static UpdateManager NO_MANAGER(){ + if( NO_MANAGER_ is null ){ + synchronized( Figure.classinfo ){ + if( NO_MANAGER_ is null ){ + NO_MANAGER_ = new class() UpdateManager { + public void addDirtyRegion (IFigure figure, int x, int y, int w, int h) { } + public void addInvalidFigure(IFigure f) { } + public void performUpdate() { } + public void performUpdate(Rectangle region) { } + public void setRoot(IFigure root) { } + public void setGraphicsSource(GraphicsSource gs) { } + }; + } + } + } + return NO_MANAGER_; } + }
--- a/dwtx/draw2d/FigureUtilities.d Sun Aug 03 00:54:29 2008 +0200 +++ b/dwtx/draw2d/FigureUtilities.d Sun Aug 03 02:17:46 2008 +0200 @@ -36,10 +36,17 @@ private static GC gc; private static Font appliedFont; private static FontMetrics metrics; -private static Color ghostFillColor; -static this(){ - ghostFillColor = new Color(null, 31, 31, 31); +private static Color ghostFillColor_; +private static Color ghostFillColor(){ + if( ghostFillColor_ is null ){ + synchronized( FigureUtilities.classinfo ){ + if( ghostFillColor_ is null ){ + ghostFillColor_ = new Color(null, 31, 31, 31); + } + } + } + return ghostFillColor_; } /**
--- a/dwtx/draw2d/SWTGraphics.d Sun Aug 03 00:54:29 2008 +0200 +++ b/dwtx/draw2d/SWTGraphics.d Sun Aug 03 02:17:46 2008 +0200 @@ -74,6 +74,17 @@ int graphicHints; int lineWidth; Clipping relativeClip; + + this(){ + } + this(LazyState other){ + bgColor = other.bgColor; + fgColor = other.fgColor; + font = other.font; + graphicHints = other.graphicHints; + lineWidth = other.lineWidth; + relativeClip = other.relativeClip; + } } static class RectangleClipping : Clipping { @@ -165,16 +176,18 @@ this(){ } + this(State other){ + super(other); + affineMatrix = other.affineMatrix.dup; + alpha = other.alpha; + bgPattern = other.bgPattern; + dx = other.dx; + dy = other.dy; + fgPattern = other.fgPattern; + lineDash = other.lineDash.dup; + } public Object clone() { - auto res = new State; - res.affineMatrix = this.affineMatrix.dup; - res.alpha = this.alpha; - res.bgPattern = this.bgPattern; - res.dx = this.dx; - res.dy = this.dy; - res.fgPattern = this.fgPattern; - res.lineDash = this.lineDash.dup; - return res; + return new State(this); } /**
--- a/dwtx/draw2d/TextUtilities.d Sun Aug 03 00:54:29 2008 +0200 +++ b/dwtx/draw2d/TextUtilities.d Sun Aug 03 02:17:46 2008 +0200 @@ -33,12 +33,17 @@ /** * a singleton default instance */ - public static TextUtilities INSTANCE; - - static this(){ - INSTANCE = new TextUtilities(); + private static TextUtilities INSTANCE_; + public static TextUtilities INSTANCE(){ + if( INSTANCE_ is null ){ + synchronized( TextUtilities.classinfo ){ + if( INSTANCE_ is null ){ + INSTANCE_ = new TextUtilities(); + } + } + } + return INSTANCE_; } - /** * Returns the Dimensions of <i>s</i> in Font <i>f</i>. *
--- a/dwtx/draw2d/geometry/Dimension.d Sun Aug 03 00:54:29 2008 +0200 +++ b/dwtx/draw2d/geometry/Dimension.d Sun Aug 03 02:17:46 2008 +0200 @@ -31,10 +31,16 @@ { /**A singleton for use in short calculations. Use to avoid newing unnecessary objects.*/ -public static const Dimension SINGLETON; - -static this(){ - SINGLETON = new Dimension(); +private static Dimension SINGLETON_; +public static Dimension SINGLETON(){ + if( SINGLETON_ is null ){ + synchronized( Dimension.classinfo ){ + if( SINGLETON_ is null ){ + SINGLETON_ = new Dimension(); + } + } + } + return SINGLETON_; } /**The width.*/
--- a/dwtx/draw2d/geometry/Point.d Sun Aug 03 00:54:29 2008 +0200 +++ b/dwtx/draw2d/geometry/Point.d Sun Aug 03 02:17:46 2008 +0200 @@ -33,10 +33,16 @@ static final long serialVersionUID = 1; /**A singleton for use in short calculations*/ -public static const Point SINGLETON; - -static this(){ - SINGLETON = new Point(); +private static Point SINGLETON_; +public static Point SINGLETON(){ + if( SINGLETON_ is null ){ + synchronized( Point.classinfo ){ + if( SINGLETON_ is null ){ + SINGLETON_ = new Point(); + } + } + } + return SINGLETON_; } /**x value*/
--- a/dwtx/draw2d/geometry/Rectangle.d Sun Aug 03 00:54:29 2008 +0200 +++ b/dwtx/draw2d/geometry/Rectangle.d Sun Aug 03 02:17:46 2008 +0200 @@ -40,12 +40,17 @@ public int height; /**A singleton for use in short calculations. Use to avoid newing unnecessary objects.*/ -public static const Rectangle SINGLETON; - -static this(){ - SINGLETON = new Rectangle(); +private static Rectangle SINGLETON_; +public static Rectangle SINGLETON(){ + if( SINGLETON_ is null ){ + synchronized( Rectangle.classinfo ){ + if( SINGLETON_ is null ){ + SINGLETON_ = new Rectangle(); + } + } + } + return SINGLETON_; } - static final long serialVersionUID = 1; /**
--- a/dwtx/dwtxhelper/Collection.d Sun Aug 03 00:54:29 2008 +0200 +++ b/dwtx/dwtxhelper/Collection.d Sun Aug 03 02:17:46 2008 +0200 @@ -4,6 +4,7 @@ static import tango.util.container.CircularList; static import tango.util.container.HashMap; +static import tango.util.container.HashSet; static import tango.util.container.SortedMap; static import tango.util.container.more.Vector; @@ -110,7 +111,17 @@ } class Collections { - public static List EMPTY_LIST; + private static List EMPTY_LIST_; + public static List EMPTY_LIST(){ + if( EMPTY_LIST_ is null ){ + synchronized(Collections.classinfo ){ + if( EMPTY_LIST_ is null ){ + EMPTY_LIST_ = new ArrayList(0); + } + } + } + return EMPTY_LIST_; + } public static List unmodifiableList( List list ){ return null; @@ -169,7 +180,9 @@ return false; } public Object get(Object key){ - implMissing( __FILE__, __LINE__ ); + if( auto v = key in map ){ + return *v; + } return null; } public override hash_t toHash(){ @@ -179,8 +192,11 @@ return map.isEmpty(); } public Set keySet(){ - implMissing( __FILE__, __LINE__ ); - return null; + HashSet res = new HashSet(); + foreach( k, v; map ){ + res.add(k); + } + return res; } public Object put(Object key, Object value){ Object res = null; @@ -310,24 +326,33 @@ } class HashSet : Set { - public this(){} - public this(Collection c){} - public this(int initialCapacity){} - public this(int initialCapacity, float loadFactor){} + alias tango.util.container.HashSet.HashSet!(Object) SetType; + private SetType set; + + public this(){ + set = new SetType(); + } + public this(Collection c){ + implMissing( __FILE__, __LINE__ ); + } + public this(int initialCapacity){ + implMissing( __FILE__, __LINE__ ); + } + public this(int initialCapacity, float loadFactor){ + implMissing( __FILE__, __LINE__ ); + } public bool add(Object o){ - implMissing( __FILE__, __LINE__ ); - return false; + return set.add(o); } public bool addAll(Collection c){ implMissing( __FILE__, __LINE__ ); return false; } public void clear(){ - implMissing( __FILE__, __LINE__ ); + set.clear(); } public bool contains(Object o){ - implMissing( __FILE__, __LINE__ ); - return false; + return set.contains(o); } public bool containsAll(Collection c){ implMissing( __FILE__, __LINE__ ); @@ -342,16 +367,29 @@ return 0; } public bool isEmpty(){ - implMissing( __FILE__, __LINE__ ); - return false; + return set.isEmpty(); + } + class LocalIterator : Iterator { + SetType.Iterator iter; + Object nextElem; + this( SetType.Iterator iter){ + this.iter = iter; + } + public bool hasNext(){ + return iter.next(nextElem); + } + public Object next(){ + return nextElem; + } + public void remove(){ + iter.remove(); + } } public Iterator iterator(){ - implMissing( __FILE__, __LINE__ ); - return null; + return new LocalIterator(set.iterator()); } public bool remove(Object o){ - implMissing( __FILE__, __LINE__ ); - return false; + return set.remove(o); } public bool removeAll(Collection c){ implMissing( __FILE__, __LINE__ ); @@ -362,8 +400,7 @@ return false; } public int size(){ - implMissing( __FILE__, __LINE__ ); - return 0; + return set.size(); } public Object[] toArray(){ implMissing( __FILE__, __LINE__ ); @@ -939,12 +976,13 @@ implMissing( __FILE__, __LINE__ ); } void add(int index, Object element){ - implMissing( __FILE__, __LINE__ ); + data.length = data.length +1; + System.arraycopy( data, index, data, index+1, data.length - index -1 ); + data[index] = element; } bool add(Object o){ - - implMissing( __FILE__, __LINE__ ); - return false; + data ~= o; + return true; } bool addAll(Collection c){ implMissing( __FILE__, __LINE__ ); @@ -955,10 +993,20 @@ return false; } void clear(){ - implMissing( __FILE__, __LINE__ ); + data.length = 0; } bool contains(Object o){ - implMissing( __FILE__, __LINE__ ); + foreach( v; data ){ + if( o is v ){ + return true; + } + if(( o is null ) || ( v is null )){ + continue; + } + if( o == v ){ + return true; + } + } return false; } bool containsAll(Collection c){ @@ -1009,9 +1057,27 @@ bool isEmpty(){ return data.length is 0; } + class LocalIterator : Iterator{ + int idx = 0; + public this(){ + } + public bool hasNext(){ + return idx < data.length; + } + public Object next(){ + Object res = data[idx]; + idx++; + return res; + } + public void remove(){ + implMissing( __FILE__, __LINE__ ); + this.outer.remove(idx); + idx--; + } + } + Iterator iterator(){ - implMissing( __FILE__, __LINE__ ); - return null; + return new LocalIterator(); } int lastIndexOf(Object o){ foreach_reverse( i, v; data ){ @@ -1037,7 +1103,7 @@ } Object remove(int index){ Object res = data[index]; - data[ index .. $-1] = data[ index+1 .. $ ]; + System.arraycopy( data, index+1, data, index, data.length - index - 1 ); data.length = data.length -1; return res; } @@ -1054,12 +1120,12 @@ return false; } Object set(int index, Object element){ - implMissing( __FILE__, __LINE__ ); - return null; + Object res = data[index]; + data[index] = element; + return res; } int size(){ - implMissing( __FILE__, __LINE__ ); - return 0; + return data.length; } List subList(int fromIndex, int toIndex){ implMissing( __FILE__, __LINE__ );