Project

General

Profile

Download (4.61 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 org.eclipse.draw2d.geometry.Dimension;
14

    
15
/**
16
 * Provides generic support for LayoutManagers.
17
 */
18
public abstract class AbstractLayout implements LayoutManager {
19

    
20
	/**
21
	 * The cached preferred size.
22
	 */
23
	protected Dimension preferredSize;
24

    
25
	/**
26
	 * Whether or not this layout pays attention to visiblity of figures when
27
	 * calculating its bounds. By default, false.
28
	 */
29
	protected boolean isObservingVisibility = false;
30

    
31
	/**
32
	 * This method is now {@link #calculatePreferredSize(IFigure, int, int)}.
33
	 * 
34
	 * @param container
35
	 *            the figure
36
	 */
37
	protected final void calculatePreferredSize(IFigure container) {
38
	}
39

    
40
	/**
41
	 * Calculates the preferred size of the given figure, using width and height
42
	 * hints.
43
	 * 
44
	 * @param container
45
	 *            The figure
46
	 * @param wHint
47
	 *            The width hint
48
	 * @param hHint
49
	 *            The height hint
50
	 * @return The preferred size
51
	 */
52
	protected abstract Dimension calculatePreferredSize(IFigure container,
53
			int wHint, int hHint);
54

    
55
	/**
56
	 * Returns the preferred size of the figure's border.
57
	 * 
58
	 * @param container
59
	 *            The figure that the border is on
60
	 * @return The border's preferred size
61
	 */
62
	protected Dimension getBorderPreferredSize(IFigure container) {
63
		if (container.getBorder() == null)
64
			return new Dimension();
65
		return container.getBorder().getPreferredSize(container);
66
	}
67

    
68
	/**
69
	 * Returns the constraint for the given figure.
70
	 * 
71
	 * @param child
72
	 *            The figure
73
	 * @return The constraint
74
	 */
75
	public Object getConstraint(IFigure child) {
76
		return null;
77
	}
78

    
79
	/**
80
	 * This method is now {@link #getMinimumSize(IFigure, int, int)}.
81
	 * 
82
	 * @param container
83
	 *            the figure
84
	 */
85
	public final void getMinimumSize(IFigure container) {
86
	}
87

    
88
	/**
89
	 * @see org.eclipse.draw2d.LayoutManager#getMinimumSize(IFigure, int, int)
90
	 */
91
	public Dimension getMinimumSize(IFigure container, int wHint, int hHint) {
92
		return getPreferredSize(container, wHint, hHint);
93
	}
94

    
95
	/**
96
	 * Returns the preferred size of the given figure, using width and height
97
	 * hints. If the preferred size is cached, that size is returned. Otherwise,
98
	 * {@link #calculatePreferredSize(IFigure, int, int)} is called.
99
	 * 
100
	 * @param container
101
	 *            The figure
102
	 * @param wHint
103
	 *            The width hint
104
	 * @param hHint
105
	 *            The height hint
106
	 * @return The preferred size
107
	 */
108
	public Dimension getPreferredSize(IFigure container, int wHint, int hHint) {
109
		if (preferredSize == null)
110
			preferredSize = calculatePreferredSize(container, wHint, hHint);
111
		return preferredSize;
112
	}
113

    
114
	/**
115
	 * This method is now {@link #getPreferredSize(IFigure, int, int)}.
116
	 * 
117
	 * @param container
118
	 *            the figure
119
	 */
120
	public final void getPreferredSize(IFigure container) {
121
	}
122

    
123
	/**
124
	 * @see org.eclipse.draw2d.LayoutManager#invalidate()
125
	 */
126
	public void invalidate() {
127
		preferredSize = null;
128
	}
129

    
130
	/**
131
	 * Removes any cached information about the given figure.
132
	 * 
133
	 * @param child
134
	 *            the child that is invalidated
135
	 */
136
	protected void invalidate(IFigure child) {
137
		invalidate();
138
	}
139

    
140
	/**
141
	 * Returns whether or not this layout pays attention to visiblity when
142
	 * calculating its bounds.
143
	 * 
144
	 * @return true if invisible figures should not contribute to this layout's
145
	 *         bounds.
146
	 */
147
	public boolean isObservingVisibility() {
148
		return isObservingVisibility;
149
	}
150

    
151
	/**
152
	 * Removes the given figure from this LayoutManager's list of figures.
153
	 * 
154
	 * @param child
155
	 *            The figure to remove
156
	 */
157
	public void remove(IFigure child) {
158
		invalidate();
159
	}
160

    
161
	/**
162
	 * Sets the constraint for the given figure.
163
	 * 
164
	 * @param child
165
	 *            the child
166
	 * @param constraint
167
	 *            the child's new constraint
168
	 */
169
	public void setConstraint(IFigure child, Object constraint) {
170
		invalidate(child);
171
	}
172

    
173
	/**
174
	 * Sets isObservingVisibility to the given value.
175
	 * 
176
	 * @param newValue
177
	 *            <code>true</code> if visibility should be observed
178
	 */
179
	public void setObserveVisibility(boolean newValue) {
180
		if (isObservingVisibility == newValue)
181
			return;
182
		isObservingVisibility = newValue;
183
	}
184

    
185
}
(8-8/171)