1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2008, 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.gef.internal.ui.palette.editparts;
|
12
|
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.eclipse.draw2d.FlowLayout;
|
16
|
import org.eclipse.draw2d.IFigure;
|
17
|
import org.eclipse.draw2d.geometry.Dimension;
|
18
|
import org.eclipse.draw2d.geometry.Rectangle;
|
19
|
|
20
|
/**
|
21
|
* Extends <code>FlowLayout</code> to allow the pane of a pinnable stack in icon
|
22
|
* mode to occupy the row following the row in which the icon of the palette
|
23
|
* stack header appears.
|
24
|
*
|
25
|
* @author crevells
|
26
|
* @since 3.4
|
27
|
*/
|
28
|
public class PaletteContainerFlowLayout extends FlowLayout {
|
29
|
|
30
|
/**
|
31
|
* Constructs a PaletteContainerFlowLayout with horizontal orientation.
|
32
|
*/
|
33
|
public PaletteContainerFlowLayout() {
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* Constructs a PaletteContainerFlowLayout whose orientation is given in the
|
38
|
* input.
|
39
|
*
|
40
|
* @param isHorizontal
|
41
|
* <code>true</code> if the layout should be horizontal
|
42
|
*/
|
43
|
public PaletteContainerFlowLayout(boolean isHorizontal) {
|
44
|
setHorizontal(isHorizontal);
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* Overridden to include the size of the expanded pane of an expanded
|
49
|
* pinnable palette stack.
|
50
|
*
|
51
|
* @see org.eclipse.draw2d.AbstractLayout#calculatePreferredSize(IFigure,
|
52
|
* int, int)
|
53
|
*/
|
54
|
protected Dimension calculatePreferredSize(IFigure container, int wHint,
|
55
|
int hHint) {
|
56
|
|
57
|
Dimension prefSize = super.calculatePreferredSize(container, wHint,
|
58
|
hHint);
|
59
|
|
60
|
List children = container.getChildren();
|
61
|
IFigure child;
|
62
|
|
63
|
// Build the sizes for each row, and update prefSize accordingly
|
64
|
Dimension expandedPaneSize = null;
|
65
|
for (int i = 0; i < children.size(); i++) {
|
66
|
child = (IFigure) children.get(i);
|
67
|
|
68
|
if (child instanceof PinnablePaletteStackFigure
|
69
|
&& ((PinnablePaletteStackFigure) child).isExpanded()) {
|
70
|
|
71
|
// Subtract out the insets from the hints
|
72
|
if (wHint > -1)
|
73
|
wHint = Math.max(0, wHint
|
74
|
- container.getInsets().getWidth());
|
75
|
if (hHint > -1)
|
76
|
hHint = Math.max(0, hHint
|
77
|
- container.getInsets().getHeight());
|
78
|
|
79
|
// Figure out the new hint that we are interested in based on
|
80
|
// the
|
81
|
// orientation. Ignore the other hint (by setting it to -1).
|
82
|
// NOTE:
|
83
|
// The children of the parent figure will then be asked to
|
84
|
// ignore
|
85
|
// that hint as well.
|
86
|
if (isHorizontal()) {
|
87
|
hHint = -1;
|
88
|
} else {
|
89
|
wHint = -1;
|
90
|
}
|
91
|
|
92
|
expandedPaneSize = ((PinnablePaletteStackFigure) child)
|
93
|
.getExpandedContainerPreferredSize(wHint, hHint);
|
94
|
|
95
|
break; // there can only be one expanded stack
|
96
|
}
|
97
|
}
|
98
|
|
99
|
if (expandedPaneSize != null) {
|
100
|
// increment height to account for expanded stack
|
101
|
prefSize.height += transposer.t(expandedPaneSize).height;
|
102
|
prefSize.union(getBorderPreferredSize(container));
|
103
|
}
|
104
|
|
105
|
return prefSize;
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* Overridden to handle <code>PinnablePaletteStackFigure</code>.
|
110
|
*
|
111
|
* @see FlowLayout#getChildSize(IFigure, int, int)
|
112
|
*/
|
113
|
protected Dimension getChildSize(IFigure child, int wHint, int hHint) {
|
114
|
if (child instanceof PinnablePaletteStackFigure) {
|
115
|
return ((PinnablePaletteStackFigure) child).getHeaderPreferredSize(
|
116
|
wHint, hHint);
|
117
|
} else {
|
118
|
return child.getPreferredSize(wHint, hHint);
|
119
|
}
|
120
|
}
|
121
|
|
122
|
/**
|
123
|
* Overridden to include the size of the expanded pane of an expanded
|
124
|
* pinnable palette stack during the layout.
|
125
|
*
|
126
|
* @see FlowLayout#layoutRow(IFigure)
|
127
|
*/
|
128
|
protected void layoutRow(IFigure parent) {
|
129
|
int majorAdjustment = 0;
|
130
|
int minorAdjustment = 0;
|
131
|
int correctMajorAlignment = majorAlignment;
|
132
|
int correctMinorAlignment = minorAlignment;
|
133
|
|
134
|
majorAdjustment = data.area.width - data.rowWidth + getMinorSpacing();
|
135
|
|
136
|
switch (correctMajorAlignment) {
|
137
|
case ALIGN_LEFTTOP:
|
138
|
majorAdjustment = 0;
|
139
|
break;
|
140
|
case ALIGN_CENTER:
|
141
|
majorAdjustment /= 2;
|
142
|
break;
|
143
|
case ALIGN_RIGHTBOTTOM:
|
144
|
break;
|
145
|
}
|
146
|
|
147
|
int expandedPaneHeight = 0;
|
148
|
for (int j = 0; j < data.rowCount; j++) {
|
149
|
if (fill) {
|
150
|
data.bounds[j].height = data.rowHeight;
|
151
|
} else {
|
152
|
minorAdjustment = data.rowHeight - data.bounds[j].height;
|
153
|
switch (correctMinorAlignment) {
|
154
|
case ALIGN_LEFTTOP:
|
155
|
minorAdjustment = 0;
|
156
|
break;
|
157
|
case ALIGN_CENTER:
|
158
|
minorAdjustment /= 2;
|
159
|
break;
|
160
|
case ALIGN_RIGHTBOTTOM:
|
161
|
break;
|
162
|
}
|
163
|
data.bounds[j].y += minorAdjustment;
|
164
|
}
|
165
|
data.bounds[j].x += majorAdjustment;
|
166
|
|
167
|
IFigure child = data.row[j];
|
168
|
setBoundsOfChild(parent, data.row[j], transposer.t(data.bounds[j]));
|
169
|
|
170
|
if (child instanceof PinnablePaletteStackFigure
|
171
|
&& ((PinnablePaletteStackFigure) child).isExpanded()) {
|
172
|
|
173
|
int wHint = -1;
|
174
|
int hHint = -1;
|
175
|
if (isHorizontal())
|
176
|
wHint = parent.getClientArea().width;
|
177
|
else
|
178
|
hHint = parent.getClientArea().height;
|
179
|
|
180
|
expandedPaneHeight = ((PinnablePaletteStackFigure) child)
|
181
|
.getExpandedContainerPreferredSize(wHint, hHint).height;
|
182
|
child.setBounds(new Rectangle(data.area.x, data.area.y
|
183
|
+ data.rowY, data.area.width, data.rowHeight
|
184
|
+ expandedPaneHeight));
|
185
|
}
|
186
|
}
|
187
|
data.rowY += getMajorSpacing() + data.rowHeight + expandedPaneHeight;
|
188
|
initRow();
|
189
|
}
|
190
|
|
191
|
/**
|
192
|
* Overridden to set the bounds for <code>PinnablePaletteStackFigures</code>
|
193
|
* .
|
194
|
*
|
195
|
* @see FlowLayout#setBoundsOfChild(IFigure, IFigure, Rectangle)
|
196
|
*/
|
197
|
protected void setBoundsOfChild(IFigure parent, IFigure child,
|
198
|
Rectangle bounds) {
|
199
|
|
200
|
if (child instanceof PinnablePaletteStackFigure
|
201
|
&& ((PinnablePaletteStackFigure) child).isExpanded()) {
|
202
|
parent.getClientArea(Rectangle.SINGLETON);
|
203
|
bounds.translate(Rectangle.SINGLETON.x, Rectangle.SINGLETON.y);
|
204
|
((PinnablePaletteStackFigure) child)
|
205
|
.setHeaderBoundsLayoutHint(bounds);
|
206
|
} else {
|
207
|
super.setBoundsOfChild(parent, child, bounds);
|
208
|
}
|
209
|
}
|
210
|
|
211
|
}
|