Lines 55-61
Link Here
|
55 |
protected LayoutPart part; |
55 |
protected LayoutPart part; |
56 |
protected LayoutPart relative; |
56 |
protected LayoutPart relative; |
57 |
protected int relationship; |
57 |
protected int relationship; |
58 |
protected float ratio; |
58 |
|
|
|
59 |
/** |
60 |
* Preferred size for the left child (this would be the size, in pixels of the child |
61 |
* at the time the sash was last moved) |
62 |
*/ |
63 |
protected int left; |
64 |
|
65 |
/** |
66 |
* Preferred size for the right child (this would be the size, in pixels of the child |
67 |
* at the time the sash was last moved) |
68 |
*/ |
69 |
protected int right; |
59 |
} |
70 |
} |
60 |
|
71 |
|
61 |
private class SashContainerDropTarget extends AbstractDropTarget { |
72 |
private class SashContainerDropTarget extends AbstractDropTarget { |
Lines 122-140
Link Here
|
122 |
/** |
133 |
/** |
123 |
* Add a part. |
134 |
* Add a part. |
124 |
*/ |
135 |
*/ |
125 |
public void add(LayoutPart child) { |
136 |
public void add(LayoutPart child) { |
126 |
if (isZoomed()) |
|
|
127 |
zoomOut(); |
128 |
|
129 |
if (child == null) |
137 |
if (child == null) |
130 |
return; |
138 |
return; |
131 |
|
139 |
|
132 |
RelationshipInfo info = new RelationshipInfo(); |
140 |
addEnhanced(child, SWT.RIGHT, 0.5f, findBottomRight()); |
133 |
info.part = child; |
|
|
134 |
if(root != null) { |
135 |
findPosition(info); |
136 |
} |
137 |
addChild(info); |
138 |
} |
141 |
} |
139 |
|
142 |
|
140 |
/** |
143 |
/** |
Lines 173-199
Link Here
|
173 |
* @param relationship one of PageLayout.TOP, PageLayout.BOTTOM, PageLayout.LEFT, or PageLayout.RIGHT |
176 |
* @param relationship one of PageLayout.TOP, PageLayout.BOTTOM, PageLayout.LEFT, or PageLayout.RIGHT |
174 |
* @param ratio a value between 0.0 and 1.0, indicating how much space will be allocated to the UPPER-LEFT pane |
177 |
* @param ratio a value between 0.0 and 1.0, indicating how much space will be allocated to the UPPER-LEFT pane |
175 |
* @param relative part where the new part will be attached |
178 |
* @param relative part where the new part will be attached |
176 |
* |
|
|
177 |
*/ |
179 |
*/ |
178 |
public void add(LayoutPart child, int relationship, float ratio, LayoutPart relative) { |
180 |
public void add(LayoutPart child, int relationship, float ratio, LayoutPart relative) { |
179 |
if (isZoomed()) |
181 |
boolean isHorizontal = (relationship == IPageLayout.LEFT || relationship == IPageLayout.RIGHT); |
180 |
zoomOut(); |
|
|
181 |
|
182 |
|
182 |
if (child == null) |
183 |
LayoutTree node = null; |
183 |
return; |
184 |
if (root != null && relative != null) { |
184 |
if (relative != null && !isChild(relative)) |
185 |
node = root.find(relative); |
185 |
return; |
186 |
} |
186 |
if (relationship < IPageLayout.LEFT || relationship > IPageLayout.BOTTOM) |
187 |
|
187 |
relationship = IPageLayout.LEFT; |
188 |
Rectangle bounds; |
|
|
189 |
if (getParent() == null) { |
190 |
Control control = getPage().getClientComposite(); |
191 |
if (control != null && !control.isDisposed()) { |
192 |
bounds = control.getBounds(); |
193 |
} else { |
194 |
bounds = new Rectangle(0,0,800,600); |
195 |
} |
196 |
bounds.x = 0; |
197 |
bounds.y = 0; |
198 |
} else { |
199 |
bounds = getBounds(); |
200 |
} |
201 |
|
202 |
int totalSize = measureTree(bounds, node, isHorizontal); |
203 |
|
204 |
int left = (int) (totalSize * ratio); |
205 |
int right = totalSize - left; |
188 |
|
206 |
|
189 |
// store info about relative positions |
207 |
add(child, relationship, left, right, relative); |
190 |
RelationshipInfo info = new RelationshipInfo(); |
|
|
191 |
info.part = child; |
192 |
info.relationship = relationship; |
193 |
info.ratio = ratio; |
194 |
info.relative = relative; |
195 |
addChild(info); |
196 |
} |
208 |
} |
|
|
209 |
|
210 |
static int measureTree(Rectangle outerBounds, LayoutTree toMeasure, boolean horizontal) { |
211 |
if (toMeasure == null) { |
212 |
return Geometry.getDimension(outerBounds, horizontal); |
213 |
} |
214 |
|
215 |
LayoutTreeNode parent = toMeasure.getParent(); |
216 |
if (parent == null) { |
217 |
return Geometry.getDimension(outerBounds, horizontal); |
218 |
} |
219 |
|
220 |
if (parent.getSash().isHorizontal() == horizontal) { |
221 |
return measureTree(outerBounds, parent, horizontal); |
222 |
} |
223 |
|
224 |
boolean isLeft = parent.isLeftChild(toMeasure); |
225 |
|
226 |
LayoutTree otherChild = parent.getChild(!isLeft); |
227 |
if (otherChild.isVisible()) { |
228 |
int left = parent.getSash().getLeft(); |
229 |
int right = parent.getSash().getRight(); |
230 |
int childSize = isLeft ? left : right; |
231 |
|
232 |
int bias = parent.getCompressionBias(); |
233 |
|
234 |
// Normalize bias: 1 = we're fixed, -1 = other child is fixed |
235 |
if (isLeft) { |
236 |
bias = -bias; |
237 |
} |
238 |
|
239 |
if (bias == 1) { |
240 |
// If we're fixed, return the fixed size |
241 |
return childSize; |
242 |
} else if (bias == -1) { |
243 |
|
244 |
// If the other child is fixed, return the size of the parent minus the fixed size of the |
245 |
// other child |
246 |
return measureTree(outerBounds, parent, horizontal) - (left + right - childSize); |
247 |
} |
248 |
|
249 |
// Else return the size of the parent, scaled appropriately |
250 |
return measureTree(outerBounds, parent, horizontal) * childSize / (left + right); |
251 |
} |
252 |
|
253 |
return measureTree(outerBounds, parent, horizontal); |
254 |
} |
255 |
|
197 |
protected void addChild(RelationshipInfo info) { |
256 |
protected void addChild(RelationshipInfo info) { |
198 |
LayoutPart child = info.part; |
257 |
LayoutPart child = info.part; |
199 |
|
258 |
|
Lines 206-212
Link Here
|
206 |
int vertical = (info.relationship == IPageLayout.LEFT || info.relationship == IPageLayout.RIGHT)?SWT.VERTICAL:SWT.HORIZONTAL; |
265 |
int vertical = (info.relationship == IPageLayout.LEFT || info.relationship == IPageLayout.RIGHT)?SWT.VERTICAL:SWT.HORIZONTAL; |
207 |
boolean left = info.relationship == IPageLayout.LEFT || info.relationship == IPageLayout.TOP; |
266 |
boolean left = info.relationship == IPageLayout.LEFT || info.relationship == IPageLayout.TOP; |
208 |
LayoutPartSash sash = new LayoutPartSash(this,vertical); |
267 |
LayoutPartSash sash = new LayoutPartSash(this,vertical); |
209 |
sash.setRatio(info.ratio); |
268 |
sash.setSizes(info.left, info.right); |
210 |
if((parent != null) && !(child instanceof PartPlaceholder)) |
269 |
if((parent != null) && !(child instanceof PartPlaceholder)) |
211 |
sash.createControl(parent); |
270 |
sash.createControl(parent); |
212 |
root = root.insert(child,left,sash,info.relative); |
271 |
root = root.insert(child,left,sash,info.relative); |
Lines 222-227
Link Here
|
222 |
} |
281 |
} |
223 |
|
282 |
|
224 |
} |
283 |
} |
|
|
284 |
|
225 |
/** |
285 |
/** |
226 |
* Adds the child using ratio and position attributes |
286 |
* Adds the child using ratio and position attributes |
227 |
* from the specified placeholder without replacing |
287 |
* from the specified placeholder without replacing |
Lines 235-241
Link Here
|
235 |
RelationshipInfo newRelationshipInfo = new RelationshipInfo(); |
295 |
RelationshipInfo newRelationshipInfo = new RelationshipInfo(); |
236 |
newRelationshipInfo.part = child; |
296 |
newRelationshipInfo.part = child; |
237 |
if(root != null) { |
297 |
if(root != null) { |
238 |
findPosition(newRelationshipInfo); |
298 |
newRelationshipInfo.relationship = IPageLayout.RIGHT; |
|
|
299 |
newRelationshipInfo.relative = root.findBottomRight(); |
300 |
newRelationshipInfo.left = 200; |
301 |
newRelationshipInfo.right = 200; |
239 |
} |
302 |
} |
240 |
|
303 |
|
241 |
// find the relationship info for the placeholder |
304 |
// find the relationship info for the placeholder |
Lines 243-249
Link Here
|
243 |
for (int i = 0; i < relationships.length; i ++) { |
306 |
for (int i = 0; i < relationships.length; i ++) { |
244 |
RelationshipInfo info = relationships[i]; |
307 |
RelationshipInfo info = relationships[i]; |
245 |
if (info.part == placeholder) { |
308 |
if (info.part == placeholder) { |
246 |
newRelationshipInfo.ratio = info.ratio; |
309 |
newRelationshipInfo.left = info.left; |
|
|
310 |
newRelationshipInfo.right = info.right; |
247 |
newRelationshipInfo.relationship = info.relationship; |
311 |
newRelationshipInfo.relationship = info.relationship; |
248 |
newRelationshipInfo.relative = info.relative; |
312 |
newRelationshipInfo.relative = info.relative; |
249 |
} |
313 |
} |
Lines 373-398
Link Here
|
373 |
return null; |
437 |
return null; |
374 |
return root.findBottomRight(); |
438 |
return root.findBottomRight(); |
375 |
} |
439 |
} |
376 |
/** |
|
|
377 |
* Find a initial position for a new part. |
378 |
*/ |
379 |
private void findPosition(RelationshipInfo info) { |
380 |
|
381 |
info.ratio = (float)0.5; |
382 |
info.relationship = IPageLayout.RIGHT; |
383 |
info.relative = root.findBottomRight(); |
384 |
|
440 |
|
385 |
// If no parent go with default. |
|
|
386 |
if (parent == null) |
387 |
return; |
388 |
|
389 |
// If the relative part is too small, place the part on the left of everything. |
390 |
if (((float)this.getBounds().width / (float)info.relative.getBounds().width > 2) || |
391 |
((float)this.getBounds().height / (float)info.relative.getBounds().height > 4)) { |
392 |
info.relative = null; |
393 |
info.ratio = 0.75f; |
394 |
} |
395 |
} |
396 |
/** |
441 |
/** |
397 |
* @see LayoutPart#getBounds |
442 |
* @see LayoutPart#getBounds |
398 |
*/ |
443 |
*/ |
Lines 468-504
Link Here
|
468 |
public boolean isZoomed() { |
513 |
public boolean isZoomed() { |
469 |
return (unzoomRoot != null); |
514 |
return (unzoomRoot != null); |
470 |
} |
515 |
} |
471 |
/** |
|
|
472 |
* Move a part to a new position and keep the bounds when possible, ie, |
473 |
* when the new relative part has the same higth or width as the part |
474 |
* being move. |
475 |
*/ |
476 |
public void move(LayoutPart child, int relationship, LayoutPart relative) { |
477 |
LayoutTree childTree = root.find(child); |
478 |
LayoutTree relativeTree = root.find(relative); |
479 |
|
480 |
LayoutTreeNode commonParent = relativeTree.getParent().findCommonParent(child,relative); |
481 |
boolean isVertical = commonParent.getSash().isVertical(); |
482 |
boolean recomputeRatio = false; |
483 |
recomputeRatio = |
484 |
isRelationshipCompatible(relationship,isVertical) && |
485 |
commonParent.sameDirection(isVertical,relativeTree.getParent()) && |
486 |
commonParent.sameDirection(isVertical,childTree.getParent()); |
487 |
|
516 |
|
488 |
root = root.remove(child); |
|
|
489 |
int vertical = (relationship == IPageLayout.LEFT || relationship == IPageLayout.RIGHT)?SWT.VERTICAL:SWT.HORIZONTAL; |
490 |
boolean left = relationship == IPageLayout.LEFT || relationship == IPageLayout.TOP; |
491 |
LayoutPartSash sash = new LayoutPartSash(this,vertical); |
492 |
sash.setRatio(0.5f); |
493 |
if((parent != null) && !(child instanceof PartPlaceholder)) |
494 |
sash.createControl(parent); |
495 |
root = root.insert(child,left,sash,relative); |
496 |
root.updateSashes(parent); |
497 |
if(recomputeRatio) |
498 |
root.recomputeRatio(); |
499 |
|
500 |
resizeSashes(parent.getClientArea()); |
501 |
} |
502 |
/** |
517 |
/** |
503 |
* Remove a part. |
518 |
* Remove a part. |
504 |
*/ |
519 |
*/ |
Lines 690-697
Link Here
|
690 |
int cursor = Geometry.getOppositeSide(side); |
705 |
int cursor = Geometry.getOppositeSide(side); |
691 |
|
706 |
|
692 |
if (pointlessDrop) { |
707 |
if (pointlessDrop) { |
693 |
side = SWT.NONE; |
708 |
side = SWT.NONE; |
694 |
//cursor = SWT.CENTER; |
|
|
695 |
} |
709 |
} |
696 |
|
710 |
|
697 |
return new SashContainerDropTarget(sourcePart, side, cursor, null); |
711 |
return new SashContainerDropTarget(sourcePart, side, cursor, null); |
Lines 847-852
Link Here
|
847 |
root.describeLayout(buf); |
861 |
root.describeLayout(buf); |
848 |
buf.append(")"); |
862 |
buf.append(")"); |
849 |
} |
863 |
} |
|
|
864 |
} |
865 |
|
866 |
void add(LayoutPart child, int relationship, int left, int right, LayoutPart relative) { |
867 |
if (isZoomed()) |
868 |
zoomOut(); |
869 |
|
870 |
if (child == null) |
871 |
return; |
872 |
if (relative != null && !isChild(relative)) |
873 |
return; |
874 |
if (relationship < IPageLayout.LEFT || relationship > IPageLayout.BOTTOM) |
875 |
relationship = IPageLayout.LEFT; |
876 |
|
877 |
// store info about relative positions |
878 |
RelationshipInfo info = new RelationshipInfo(); |
879 |
info.part = child; |
880 |
info.relationship = relationship; |
881 |
info.left = left; |
882 |
info.right = right; |
883 |
info.relative = relative; |
884 |
addChild(info); |
850 |
} |
885 |
} |
851 |
|
886 |
|
852 |
} |
887 |
} |