Mercurial > projects > dwt2
comparison 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 |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.draw2d.LayeredPane; | |
14 | |
15 import java.lang.all; | |
16 import org.eclipse.draw2d.Layer; | |
17 import org.eclipse.draw2d.IFigure; | |
18 import org.eclipse.draw2d.StackLayout; | |
19 | |
20 /** | |
21 * A figure capable of holding any number of layers. Only layers can be added to this | |
22 * figure. Layers are added to this figure with thier respective keys, which are used to | |
23 * identify them. | |
24 */ | |
25 public class LayeredPane | |
26 : Layer | |
27 { | |
28 | |
29 private List layerKeys; | |
30 | |
31 /** | |
32 * Constructs a new layered pane with no layers in it. | |
33 */ | |
34 public this() { | |
35 layerKeys = new ArrayList(); | |
36 setLayoutManager(new StackLayout()); | |
37 } | |
38 | |
39 /** | |
40 * Adds the given layer figure, identifiable with the given key, at the specified index. | |
41 * While adding the layer, it informs the surrounding layers of the addition. | |
42 * | |
43 * @param figure the layer | |
44 * @param layerKey the layer's key | |
45 * @param index the index where the layer should be added | |
46 * @since 2.0 | |
47 */ | |
48 public void add(IFigure figure, Object layerKey, int index) { | |
49 if (index is -1) | |
50 index = layerKeys.size(); | |
51 super.add(figure, null, index); | |
52 layerKeys.add(index, layerKey); | |
53 } | |
54 | |
55 /** | |
56 * Adds the given layer, identifiable with the given key, under the <i>after</i> layer | |
57 * provided in the input. | |
58 * | |
59 * @param layer the layer | |
60 * @param key the layer's key | |
61 * @param after the layer under which the input layer should be added | |
62 * @since 2.0 | |
63 */ | |
64 public void addLayerAfter(Layer layer, Object key, Object after) { | |
65 int index = layerKeys.indexOf(after); | |
66 add(layer, key, ++index); | |
67 } | |
68 | |
69 /** | |
70 * Adds the given layer, identifiable with the given key, above the <i>before</i> layer | |
71 * provided in the input. | |
72 * | |
73 * @param layer the layer | |
74 * @param key the layer's key | |
75 * @param before the layer above which the input layer should be added | |
76 * @since 2.0 | |
77 */ | |
78 public void addLayerBefore(Layer layer, Object key, Object before) { | |
79 int index = layerKeys.indexOf(before); | |
80 add(layer, key, index); | |
81 } | |
82 | |
83 /** | |
84 * Returns the layer identified by the key given in the input. | |
85 * | |
86 * @param key the key to identify the desired layer | |
87 * @return the desired layer | |
88 * @since 2.0 | |
89 */ | |
90 public Layer getLayer(Object key) { | |
91 int index = layerKeys.indexOf(key); | |
92 if (index is -1) | |
93 return null; | |
94 return cast(Layer)getChildren().get(index); | |
95 } | |
96 | |
97 /** | |
98 * Returns the layer at the specified index in this pane. | |
99 * | |
100 * @param index the index of the desired layer | |
101 * @return the desired layer | |
102 * @since 2.0 | |
103 */ | |
104 protected Layer getLayer(int index) { | |
105 return cast(Layer)getChildren().get(index); | |
106 } | |
107 | |
108 /** | |
109 * @see org.eclipse.draw2d.IFigure#remove(org.eclipse.draw2d.IFigure) | |
110 */ | |
111 public void remove(IFigure figure) { | |
112 int index = getChildren().indexOf(cast(Object)figure); | |
113 if (index !is -1) | |
114 layerKeys.remove(index); | |
115 super.remove(figure); | |
116 } | |
117 | |
118 /** | |
119 * Removes the layer identified by the given key from this layered pane. | |
120 * | |
121 * @param key the key of the layer to be removed | |
122 * @since 2.0 | |
123 */ | |
124 public void removeLayer(Object key) { | |
125 removeLayer(layerKeys.indexOf(key)); | |
126 } | |
127 | |
128 /** | |
129 * Removes the given layer from this layered pane. | |
130 * | |
131 * @deprecated call {@link IFigure#remove(IFigure)} instead | |
132 * @param layer the layer to be removed | |
133 * @since 2.0 | |
134 */ | |
135 public void removeLayer(IFigure layer) { | |
136 remove(layer); | |
137 } | |
138 | |
139 /** | |
140 * Removes the layer at the specified index from the list of layers in this layered pane. | |
141 * It collapses the layers, occupying the space vacated by the removed layer. | |
142 * | |
143 * @param index the index of the layer to be removed | |
144 * @since 2.0 | |
145 */ | |
146 protected void removeLayer(int index) { | |
147 Layer removeLayer = getLayer(index); | |
148 remove(removeLayer); | |
149 } | |
150 | |
151 } |