Project

General

Profile

Download (3.06 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 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
 *******************************************************************************/
11
package org.eclipse.draw2d;
12

    
13
import java.util.List;
14

    
15
import org.eclipse.draw2d.geometry.Dimension;
16
import org.eclipse.draw2d.geometry.Rectangle;
17

    
18
/**
19
 * Figures using the StackLayout as their layout manager have their children
20
 * placed on top of one another. Order of placement is determined by the order
21
 * in which the children were added, first child added placed on the bottom.
22
 */
23
public class StackLayout extends AbstractHintLayout {
24

    
25
	/**
26
	 * Returns the minimum size required by the input container. This is the
27
	 * size of the largest child of the container, as all other children fit
28
	 * into this size.
29
	 * 
30
	 * @see AbstractHintLayout#calculateMinimumSize(IFigure, int, int)
31
	 */
32
	protected Dimension calculateMinimumSize(IFigure figure, int wHint,
33
			int hHint) {
34
		if (wHint > -1)
35
			wHint = Math.max(0, wHint - figure.getInsets().getWidth());
36
		if (hHint > -1)
37
			hHint = Math.max(0, hHint - figure.getInsets().getHeight());
38
		Dimension d = new Dimension();
39
		List children = figure.getChildren();
40
		IFigure child;
41
		for (int i = 0; i < children.size(); i++) {
42
			child = (IFigure) children.get(i);
43
			if (!isObservingVisibility() || child.isVisible())
44
				d.union(child.getMinimumSize(wHint, hHint));
45
		}
46

    
47
		d.expand(figure.getInsets().getWidth(), figure.getInsets().getHeight());
48
		d.union(getBorderPreferredSize(figure));
49
		return d;
50

    
51
	}
52

    
53
	/**
54
	 * Calculates and returns the preferred size of the given figure. This is
55
	 * the union of the preferred sizes of the widest and the tallest of all its
56
	 * children.
57
	 * 
58
	 * @see AbstractLayout#calculatePreferredSize(IFigure, int, int)
59
	 */
60
	protected Dimension calculatePreferredSize(IFigure figure, int wHint,
61
			int hHint) {
62
		if (wHint > -1)
63
			wHint = Math.max(0, wHint - figure.getInsets().getWidth());
64
		if (hHint > -1)
65
			hHint = Math.max(0, hHint - figure.getInsets().getHeight());
66
		Dimension d = new Dimension();
67
		List children = figure.getChildren();
68
		IFigure child;
69
		for (int i = 0; i < children.size(); i++) {
70
			child = (IFigure) children.get(i);
71
			if (!isObservingVisibility() || child.isVisible())
72
				d.union(child.getPreferredSize(wHint, hHint));
73
		}
74

    
75
		d.expand(figure.getInsets().getWidth(), figure.getInsets().getHeight());
76
		d.union(getBorderPreferredSize(figure));
77
		return d;
78
	}
79

    
80
	/**
81
	 * @see org.eclipse.draw2d.LayoutManager#layout(IFigure)
82
	 */
83
	public void layout(IFigure figure) {
84
		Rectangle r = figure.getClientArea();
85
		List children = figure.getChildren();
86
		IFigure child;
87
		for (int i = 0; i < children.size(); i++) {
88
			child = (IFigure) children.get(i);
89
			child.setBounds(r);
90
		}
91
	}
92

    
93
}
(152-152/171)