Mercurial > projects > dwt-addons
diff dwtx/draw2d/LayeredPane.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/LayeredPane.d Sun Aug 03 00:52:14 2008 +0200 @@ -0,0 +1,152 @@ +/******************************************************************************* + * 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.LayeredPane; + +import dwt.dwthelper.utils; +import dwtx.dwtxhelper.Collection; +import dwtx.draw2d.Layer; +import dwtx.draw2d.IFigure; +import dwtx.draw2d.StackLayout; + +/** + * A figure capable of holding any number of layers. Only layers can be added to this + * figure. Layers are added to this figure with thier respective keys, which are used to + * identify them. + */ +public class LayeredPane + : Layer +{ + +private List layerKeys; + +/** + * Constructs a new layered pane with no layers in it. + */ +public this() { + layerKeys = new ArrayList(); + setLayoutManager(new StackLayout()); +} + +/** + * Adds the given layer figure, identifiable with the given key, at the specified index. + * While adding the layer, it informs the surrounding layers of the addition. + * + * @param figure the layer + * @param layerKey the layer's key + * @param index the index where the layer should be added + * @since 2.0 + */ +public void add(IFigure figure, Object layerKey, int index) { + if (index is -1) + index = layerKeys.size(); + super.add(figure, null, index); + layerKeys.add(index, layerKey); +} + +/** + * Adds the given layer, identifiable with the given key, under the <i>after</i> layer + * provided in the input. + * + * @param layer the layer + * @param key the layer's key + * @param after the layer under which the input layer should be added + * @since 2.0 + */ +public void addLayerAfter(Layer layer, Object key, Object after) { + int index = layerKeys.indexOf(after); + add(layer, key, ++index); +} + +/** + * Adds the given layer, identifiable with the given key, above the <i>before</i> layer + * provided in the input. + * + * @param layer the layer + * @param key the layer's key + * @param before the layer above which the input layer should be added + * @since 2.0 + */ +public void addLayerBefore(Layer layer, Object key, Object before) { + int index = layerKeys.indexOf(before); + add(layer, key, index); +} + +/** + * Returns the layer identified by the key given in the input. + * + * @param key the key to identify the desired layer + * @return the desired layer + * @since 2.0 + */ +public Layer getLayer(Object key) { + int index = layerKeys.indexOf(key); + if (index is -1) + return null; + return cast(Layer)getChildren().get(index); +} + +/** + * Returns the layer at the specified index in this pane. + * + * @param index the index of the desired layer + * @return the desired layer + * @since 2.0 + */ +protected Layer getLayer(int index) { + return cast(Layer)getChildren().get(index); +} + +/** + * @see dwtx.draw2d.IFigure#remove(dwtx.draw2d.IFigure) + */ +public void remove(IFigure figure) { + int index = getChildren().indexOf(cast(Object)figure); + if (index !is -1) + layerKeys.remove(index); + super.remove(figure); +} + +/** + * Removes the layer identified by the given key from this layered pane. + * + * @param key the key of the layer to be removed + * @since 2.0 + */ +public void removeLayer(Object key) { + removeLayer(layerKeys.indexOf(key)); +} + +/** + * Removes the given layer from this layered pane. + * + * @deprecated call {@link IFigure#remove(IFigure)} instead + * @param layer the layer to be removed + * @since 2.0 + */ +public void removeLayer(IFigure layer) { + remove(layer); +} + +/** + * Removes the layer at the specified index from the list of layers in this layered pane. + * It collapses the layers, occupying the space vacated by the removed layer. + * + * @param index the index of the layer to be removed + * @since 2.0 + */ +protected void removeLayer(int index) { + Layer removeLayer = getLayer(index); + remove(removeLayer); +} + +}