Mercurial > projects > dwt-mac
diff dwt/custom/StackLayout.d @ 41:6337764516f1
Sync dwt/custom with dwt-linux (took copy of complete folder)
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 07 Oct 2008 16:29:55 +0200 |
parents | 380af2bdd8e5 |
children |
line wrap: on
line diff
--- a/dwt/custom/StackLayout.d Tue Oct 07 14:41:31 2008 +0200 +++ b/dwt/custom/StackLayout.d Tue Oct 07 16:29:55 2008 +0200 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,30 +7,41 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> *******************************************************************************/ -module dwt.custom; +module dwt.custom.StackLayout; + +import dwt.dwthelper.utils; + -import dwt.*; -import dwt.graphics.*; -import dwt.widgets.*; +import dwt.DWT; +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +import dwt.widgets.Composite; +import dwt.widgets.Control; +import dwt.widgets.Layout; + +import tango.util.Convert; +static import tango.text.Util; /** * This Layout stacks all the controls one on top of the other and resizes all controls * to have the same size and location. * The control specified in topControl is visible and all other controls are not visible. - * Users must set the topControl value to flip between the visible items and then call + * Users must set the topControl value to flip between the visible items and then call * layout() on the composite which has the StackLayout. - * - * <p> Here is an example which places ten buttons in a stack layout and + * + * <p> Here is an example which places ten buttons in a stack layout and * flips between them: - * + * * <pre><code> * public static void main(String[] args) { * Display display = new Display(); * Shell shell = new Shell(display); * shell.setLayout(new GridLayout()); - * + * * final Composite parent = new Composite(shell, DWT.NONE); * parent.setLayoutData(new GridData(GridData.FILL_BOTH)); * final StackLayout layout = new StackLayout(); @@ -41,7 +52,7 @@ * bArray[i].setText("Button "+i); * } * layout.topControl = bArray[0]; - * + * * Button b = new Button(shell, DWT.PUSH); * b.setText("Show Next Button"); * final int[] index = new int[1]; @@ -52,18 +63,22 @@ * parent.layout(); * } * }); - * + * * shell.open(); * while (shell !is null && !shell.isDisposed()) { * if (!display.readAndDispatch()) - * display.sleep(); - * } + * display.sleep(); + * } * } * </code></pre> + * + * @see <a href="http://www.eclipse.org/swt/snippets/#stacklayout">StackLayout snippets</a> + * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: LayoutExample</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class StackLayout : Layout { - + /** * marginWidth specifies the number of pixels of horizontal margin * that will be placed along the left and right edges of the layout. @@ -85,7 +100,7 @@ */ public Control topControl; -protected Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) { +protected override Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) { Control children[] = composite.getChildren(); int maxWidth = 0; int maxHeight = 0; @@ -101,11 +116,11 @@ return new Point(width, height); } -protected bool flushCache(Control control) { +protected override bool flushCache(Control control) { return true; } -protected void layout(Composite composite, bool flushCache) { +protected override void layout(Composite composite, bool flushCache) { Control children[] = composite.getChildren(); Rectangle rect = composite.getClientArea(); rect.x += marginWidth; @@ -115,30 +130,30 @@ for (int i = 0; i < children.length; i++) { children[i].setBounds(rect); children[i].setVisible(children[i] is topControl); - + } } String getName () { - String String = getClass ().getName (); - int index = String.lastIndexOf ('.'); - if (index is -1) return String; - return String.substring (index + 1, String.length ()); + String string = this.classinfo.name; + int index = tango.text.Util.locatePrior( string ,'.'); + if (index is string.length ) return string; + return string[ index + 1 .. $ ]; } /** - * Returns a String containing a concise, human-readable + * Returns a string containing a concise, human-readable * description of the receiver. * - * @return a String representation of the layout + * @return a string representation of the layout */ -public String toString () { - String String = getName ()+" {"; - if (marginWidth !is 0) String += "marginWidth="+marginWidth+" "; - if (marginHeight !is 0) String += "marginHeight="+marginHeight+" "; - if (topControl !is null) String += "topControl="+topControl+" "; - String = String.trim(); - String += "}"; - return String; +public override String toString () { + String string = getName ()~" {"; + if (marginWidth !is 0) string ~= "marginWidth="~to!(String)(marginWidth)~" "; + if (marginHeight !is 0) string ~= "marginHeight="~to!(String)(marginHeight)~" "; + if (topControl !is null) string ~= "topControl="~to!(String)(topControl)~" "; + string = tango.text.Util.trim(string); + string ~= "}"; + return string; } }