Mercurial > projects > dwt-addons
diff dwtx/draw2d/CompoundBorder.d @ 98:95307ad235d9
Added Draw2d code, still work in progress
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Aug 2008 00:52:14 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/draw2d/CompoundBorder.d Sun Aug 03 00:52:14 2008 +0200 @@ -0,0 +1,137 @@ +/******************************************************************************* + * 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 dwtx.draw2d.CompoundBorder; + +import dwt.dwthelper.utils; + +import dwtx.draw2d.geometry.Dimension; +import dwtx.draw2d.geometry.Insets; + +import dwtx.draw2d.AbstractBorder; +import dwtx.draw2d.Border; +import dwtx.draw2d.IFigure; +import dwtx.draw2d.Graphics; + +/** + * CompoundBorder allows for the nesting of two borders. The nested borders are referred + * to as the <i>inner</i> and <i>outer</i> borders. + */ +public class CompoundBorder + : AbstractBorder +{ + +/** The inner Border. */ +protected Border inner; +/** The outer Border. */ +protected Border outer; + +/** + * Constructs a default CompoundBorder with no borders under it. + * + * @since 2.0 + */ +public this() { } + +/** + * Constructs a CompoundBorder with the two borders specified as input. + * + * @param outer Border which is drawn on the outside + * @param inner Border which is drawn inside the outer border + * + * @since 2.0 + */ +public this(Border outer, Border inner) { + this.outer = outer; + this.inner = inner; +} + +/** + * Returns the inner border of this CompoundBorder. + * + * @return The inner border + * @since 2.0 + */ +public Border getInnerBorder() { + return inner; +} + +/** + * Returns the total insets required to hold both the inner and outer borders of this + * CompoundBorder. + * + * @param figure Figure for which this is the border + * @return The total insets for this border + * @since 2.0 + */ +public Insets getInsets(IFigure figure) { + Insets insets = null; + if (inner !is null) + insets = inner.getInsets(figure); + else + insets = new Insets(); + if (outer !is null) { + Insets moreInsets = outer.getInsets(figure); + insets = insets.getAdded(moreInsets); + } + return insets; +} + +/** + * @see dwtx.draw2d.Border#getPreferredSize(IFigure) + */ +public Dimension getPreferredSize(IFigure fig) { + Dimension prefSize = new Dimension(inner.getPreferredSize(fig)); + Insets outerInsets = outer.getInsets(fig); + prefSize.expand(outerInsets.getWidth(), outerInsets.getHeight()); + prefSize.union_(outer.getPreferredSize(fig)); + return prefSize; +} + +/** + * Returns the outer border of this CompoundBorder. + * + * @return The outer border + * @since 2.0 + */ +public Border getOuterBorder() { + return outer; +} + +/** + * Returns <code>true</code> if this border is opaque. Return value is dependent on the + * opaque state of both the borders it contains. Both borders have to be opaque for this + * border to be opaque. In the absence of any of the borders, this border is not opaque. + * + * @return <code>true</code> if this border is opaque + */ +public bool isOpaque() { + return ((inner !is null) ? inner.isOpaque() : false) + && ((outer !is null) ? outer.isOpaque() : false); +} + +/** + * @see dwtx.draw2d.Border#paint(IFigure, Graphics, Insets) + */ +public void paint(IFigure figure, Graphics g, Insets insets) { + if (outer !is null) { + g.pushState(); + outer.paint(figure, g, insets); + g.popState(); + + insets = insets.getAdded(outer.getInsets(figure)); + } + if (inner !is null) + inner.paint(figure, g, insets); +} + +}