Mercurial > projects > dwt2
diff org.eclipse.draw2d/src/org/eclipse/draw2d/geometry/Insets.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children | 6f068362a363 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.eclipse.draw2d/src/org/eclipse/draw2d/geometry/Insets.d Sat Mar 14 18:23:29 2009 +0100 @@ -0,0 +1,190 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> + *******************************************************************************/ +module org.eclipse.draw2d.geometry.Insets; + +import java.lang.all; +import tango.text.convert.Format; + +/** + * Stores four integers for top, left, bottom, and right measurements. + */ +public class Insets + : Cloneable/+, java.io.Serializable+/ +{ + +/** distance from left */ +public int left; +/** distance from top*/ +public int top; +/** distance from bottom*/ +public int bottom; +/** distance from right */ +public int right; + +static final long serialVersionUID = 1; + +/** + * Constructs an Insets with all zeroes. + * @since 2.0 + */ +public this() { } + +/** + * Constructs a new Insets with initial values the same as the provided Insets. + * @param i The insets to copy. + * @since 2.0 + */ +public this(Insets i) { + this(i.top, i.left, i.bottom, i.right); +} + +/** + * Constructs a new Insets with all the sides set to the speicifed value. + * @param i Value applied to all sides of new Insets. + * @since 2.0 + */ +public this(int i) { + this(i, i, i, i); +} + +/** + * Creates a new Insets with the specified top, left, bottom, and right values. + * @param top Value of the top space. + * @param left Value of the left space. + * @param bottom Value of the bottom space. + * @param right Value of the right space. + * @since 2.0 + */ +public this(int top, int left, int bottom, int right) { + this.top = top; + this.left = left; + this.bottom = bottom; + this.right = right; +} + +/** + * Adds the values of the specified Insets to this Insets' values. + * @return <code>this</code> for convenience + * @param insets the Insets being added + * @since 2.0 + */ +public Insets add(Insets insets) { + top += insets.top; + bottom += insets.bottom; + left += insets.left; + right += insets.right; + return this; +} + +/** + * Test for equality. + * The Insets are equal if their top, left, bottom, and + * right values are equivalent. + * + * @param o Object being tested for equality. + * @return true if all values are the same. + * @since 2.0 + */ +public override int opEquals(Object o) { + if (auto i = cast(Insets)o ) { + return i.top is top + && i.bottom is bottom + && i.left is left + && i.right is right; + } + return false; +} + +/** + * Creates an Insets representing the sum of this Insets with the specified Insets. + * @param insets Insets to be added + * @return A new Insets + * @since 2.0 + */ +public Insets getAdded(Insets insets) { + return (new Insets(this)).add(insets); +} + +/** + * Returns the height for this Insets, equal to <code>top</code> + <code>bottom</code>. + * @return The sum of top + bottom + * @see #getWidth() + * @since 2.0 + */ +public int getHeight() { + return top + bottom; +} + +/** + * Creates a new Insets with transposed values. + * Top and Left are transposed. + * Bottom and Right are transposed. + * @return New Insets with the transposed values. + * @since 2.0 + */ +public Insets getTransposed() { + return (new Insets(this)).transpose(); +} + +/** + * Returns the width for this Insets, equal to <code>left</code> + <code>right</code>. + * @return The sum of left + right + * @see #getHeight() + * @since 2.0 + */ +public int getWidth() { + return left + right; +} + +/** + * @see java.lang.Object#toHash() + */ +public override hash_t toHash() { + return top * 7 + left * 2 + bottom * 31 + right * 37; +} + + +/** + * Returns true if all values are 0. + * @return true if all values are 0 + * @since 2.0 + */ +public bool isEmpty() { + return (left is 0 && right is 0 && top is 0 && bottom is 0); +} + +/** + * @return String representation. + * @since 2.0 + */ +public override String toString() { + return Format( "Insets(t={}, l={}, b={}, r={})", top, left, bottom, right ); +} + +/** + * Transposes this object. Top and Left are exchanged. Bottom and Right are exchanged. + * Can be used in orientation changes. + * @return <code>this</code> for convenience + * @since 2.0 + */ +public Insets transpose() { + int temp = top; + top = left; + left = temp; + temp = right; + right = bottom; + bottom = temp; + return this; +} + +}