Mercurial > projects > dwt2
diff org.eclipse.draw2d/src/org/eclipse/draw2d/LayeredPane.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 | dbfb303e8fb0 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.eclipse.draw2d/src/org/eclipse/draw2d/LayeredPane.d Sat Mar 14 18:23:29 2009 +0100 @@ -0,0 +1,151 @@ +/******************************************************************************* + * 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.LayeredPane; + +import java.lang.all; +import org.eclipse.draw2d.Layer; +import org.eclipse.draw2d.IFigure; +import org.eclipse.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 org.eclipse.draw2d.IFigure#remove(org.eclipse.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); +} + +}