View | Details | Raw Unified | Return to bug 19524 | Differences between
and this patch

Collapse All | Expand All

(-)EditorArea.java (-5 / +26 lines)
Lines 227-236 Link Here
227
		String partID = childMem.getString(IWorkbenchConstants.TAG_PART);
227
		String partID = childMem.getString(IWorkbenchConstants.TAG_PART);
228
		String relativeID = childMem.getString(IWorkbenchConstants.TAG_RELATIVE);
228
		String relativeID = childMem.getString(IWorkbenchConstants.TAG_RELATIVE);
229
		int relationship = 0;
229
		int relationship = 0;
230
		float ratio = 0.0f;
230
		int left = 0, right = 0;
231
		float ratio = 0.5f;
231
		if (relativeID != null) {
232
		if (relativeID != null) {
232
			relationship = childMem.getInteger(IWorkbenchConstants.TAG_RELATIONSHIP).intValue();
233
			relationship = childMem.getInteger(IWorkbenchConstants.TAG_RELATIONSHIP).intValue();
233
			ratio = childMem.getFloat(IWorkbenchConstants.TAG_RATIO).floatValue();
234
			Float Ratio = childMem.getFloat(IWorkbenchConstants.TAG_RATIO);
235
			Integer Left = childMem.getInteger(IWorkbenchConstants.TAG_RATIO_LEFT);
236
			Integer Right = childMem.getInteger(IWorkbenchConstants.TAG_RATIO_RIGHT);
237
			if (Left != null) {
238
				left = Left.intValue();
239
				right = Right.intValue();
240
			} else if (Ratio != null) {
241
				ratio = Ratio.floatValue();
242
			}
234
		}
243
		}
235
244
236
		// Create the part.
245
		// Create the part.
Lines 245-251 Link Here
245
		} else {
254
		} else {
246
			LayoutPart refPart = (LayoutPart)mapIDtoPart.get(relativeID);
255
			LayoutPart refPart = (LayoutPart)mapIDtoPart.get(relativeID);
247
			if (refPart != null) {
256
			if (refPart != null) {
248
				add(workbook, relationship, ratio, refPart);	
257
				//$TODO pass in left and right
258
				if (left == 0 || right == 0)
259
					add(workbook, relationship, ratio, refPart);
260
				else
261
					add(workbook, relationship, left, right, refPart);
249
			} else {
262
			} else {
250
				WorkbenchPlugin.log("Unable to find part for ID: " + relativeID);//$NON-NLS-1$
263
				WorkbenchPlugin.log("Unable to find part for ID: " + relativeID);//$NON-NLS-1$
251
			}
264
			}
Lines 271-277 Link Here
271
		if (info.relative != null) {
284
		if (info.relative != null) {
272
			childMem.putString(IWorkbenchConstants.TAG_RELATIVE, info.relative.getID());
285
			childMem.putString(IWorkbenchConstants.TAG_RELATIVE, info.relative.getID());
273
			childMem.putInteger(IWorkbenchConstants.TAG_RELATIONSHIP, info.relationship);
286
			childMem.putInteger(IWorkbenchConstants.TAG_RELATIONSHIP, info.relationship);
274
			childMem.putFloat(IWorkbenchConstants.TAG_RATIO, info.ratio);
287
			childMem.putInteger(IWorkbenchConstants.TAG_RATIO_LEFT, info.left);
288
			childMem.putInteger(IWorkbenchConstants.TAG_RATIO_RIGHT, info.right);
289
			//childMem.putFloat(IWorkbenchConstants.TAG_RATIO, info.ratio);
275
		}
290
		}
276
	}
291
	}
277
	return new Status(IStatus.OK,PlatformUI.PLUGIN_ID,0,"",null); //$NON-NLS-1$
292
	return new Status(IStatus.OK,PlatformUI.PLUGIN_ID,0,"",null); //$NON-NLS-1$
Lines 344-350 Link Here
344
	/* package */ DropTarget getDropTarget() {
359
	/* package */ DropTarget getDropTarget() {
345
		return dropTarget;
360
		return dropTarget;
346
	}
361
	}
347
	
362
	/**
363
	 * @see org.eclipse.ui.internal.LayoutPart#getImportance()
364
	 */
365
	public boolean isCompressible() {
366
		//Added for bug 19524
367
		return true;
368
	}	
348
	/* (non-Javadoc)
369
	/* (non-Javadoc)
349
	 * @see org.eclipse.ui.internal.ILayoutContainer#allowsAutoFocus()
370
	 * @see org.eclipse.ui.internal.ILayoutContainer#allowsAutoFocus()
350
	 */
371
	 */
(-)IWorkbenchConstants.java (+3 lines)
Lines 106-111 Link Here
106
	public static final String TAG_RELATIVE = "relative"; //$NON-NLS-1$
106
	public static final String TAG_RELATIVE = "relative"; //$NON-NLS-1$
107
	public static final String TAG_RELATIONSHIP = "relationship"; //$NON-NLS-1$
107
	public static final String TAG_RELATIONSHIP = "relationship"; //$NON-NLS-1$
108
	public static final String TAG_RATIO = "ratio"; //$NON-NLS-1$
108
	public static final String TAG_RATIO = "ratio"; //$NON-NLS-1$
109
	public static final String TAG_RATIO_LEFT = "ratioLeft"; //$NON-NLS-1$
110
	public static final String TAG_RATIO_RIGHT = "ratioRight"; //$NON-NLS-1$
111
	
109
	public static final String TAG_ACTIVE_PAGE_ID = "activePageID"; //$NON-NLS-1$
112
	public static final String TAG_ACTIVE_PAGE_ID = "activePageID"; //$NON-NLS-1$
110
	public static final String TAG_EXPANDED = "expanded"; //$NON-NLS-1$
113
	public static final String TAG_EXPANDED = "expanded"; //$NON-NLS-1$
111
	public static final String TAG_PAGE = "page"; //$NON-NLS-1$
114
	public static final String TAG_PAGE = "page"; //$NON-NLS-1$
(-)LayoutPart.java (+3 lines)
Lines 115-120 Link Here
115
	public String getID() {
115
	public String getID() {
116
		return id;
116
		return id;
117
	}
117
	}
118
	public boolean isCompressible() {
119
		return false;
120
	}
118
	/**
121
	/**
119
	 * Return the preference store for layout parts.
122
	 * Return the preference store for layout parts.
120
	 */
123
	 */
(-)LayoutPartSash.java (-8 / +27 lines)
Lines 9-14 Link Here
9
 * 
9
 * 
10
 * Contributors: 
10
 * Contributors: 
11
 *    IBM Corporation - initial API and implementation 
11
 *    IBM Corporation - initial API and implementation 
12
 *    Randy Hudson <hudsonr@us.ibm.com> 
13
 *      - Fix for bug 19524 - Resizing WorkbenchWindow resizes Views
12
 *    Cagatay Kavukcuoglu <cagatayk@acm.org>
14
 *    Cagatay Kavukcuoglu <cagatayk@acm.org>
13
 *      - Fix for bug 10025 - Resizing views should not use height ratios
15
 *      - Fix for bug 10025 - Resizing views should not use height ratios
14
**********************************************************************/
16
**********************************************************************/
Lines 28-34 Link Here
28
	private LayoutPartSash postLimit;
30
	private LayoutPartSash postLimit;
29
31
30
	SelectionListener selectionListener;
32
	SelectionListener selectionListener;
31
	private float ratio = 0.5f;
33
	private int left = 300, right = 300;
32
	
34
	
33
	/* Optimize limit checks by calculating minimum 
35
	/* Optimize limit checks by calculating minimum 
34
	 * and maximum ratios once per drag
36
	 * and maximum ratios once per drag
Lines 138-146 Link Here
138
LayoutPartSash getPreLimit() {
140
LayoutPartSash getPreLimit() {
139
	return preLimit;
141
	return preLimit;
140
}
142
}
141
float getRatio() {
143
142
	return ratio;
144
int getLeft() {
145
	return left;
146
}
147
148
int getRight() {
149
	return right;	
143
}
150
}
151
144
boolean isHorizontal() {
152
boolean isHorizontal() {
145
	return ((style & SWT.HORIZONTAL) == SWT.HORIZONTAL);
153
	return ((style & SWT.HORIZONTAL) == SWT.HORIZONTAL);
146
}
154
}
Lines 153-161 Link Here
153
void setPreLimit(LayoutPartSash newPreLimit) {
161
void setPreLimit(LayoutPartSash newPreLimit) {
154
	preLimit = newPreLimit;
162
	preLimit = newPreLimit;
155
}
163
}
164
156
void setRatio(float newRatio) {
165
void setRatio(float newRatio) {
157
	if (newRatio < 0.0 || newRatio > 1.0) return;
166
	int total = left + right;
158
	ratio = newRatio;
167
	left = (int) (total * newRatio);
168
	right = total - left;
169
}
170
171
void setSizes(int left, int right) {
172
	this.left = left;
173
	this.right = right;
159
}
174
}
160
175
161
private void widgetSelected(int x, int y, int width, int height) {
176
private void widgetSelected(int x, int y, int width, int height) {
Lines 163-174 Link Here
163
	LayoutTreeNode node = root.findSash(this);
178
	LayoutTreeNode node = root.findSash(this);
164
	Rectangle nodeBounds = node.getBounds();
179
	Rectangle nodeBounds = node.getBounds();
165
	//Recompute ratio
180
	//Recompute ratio
181
	x -= nodeBounds.x;
182
	y -= nodeBounds.y;
166
	if(style == SWT.VERTICAL) {
183
	if(style == SWT.VERTICAL) {
167
		setRatio((float)(x - nodeBounds.x)/(float)nodeBounds.width);
184
		setSizes(x, nodeBounds.width - x);
185
		//setRatio((float)(x - nodeBounds.x)/(float)nodeBounds.width);
168
	} else {
186
	} else {
169
		setRatio((float)(y - nodeBounds.y)/(float)nodeBounds.height);
187
		setSizes(y, nodeBounds.height - y);
188
		//setRatio((float)(y - nodeBounds.y)/(float)nodeBounds.height);
170
	}
189
	}
171
		
190
	
172
	node.setBounds(nodeBounds);
191
	node.setBounds(nodeBounds);
173
	initDragRatios();
192
	initDragRatios();
174
}
193
}
(-)LayoutTree.java (+10 lines)
Lines 9-14 Link Here
9
 * 
9
 * 
10
 * Contributors: 
10
 * Contributors: 
11
 *     IBM Corporation - initial API and implementation
11
 *     IBM Corporation - initial API and implementation
12
 *    Randy Hudson <hudsonr@us.ibm.com> 
13
 *      - Fix for bug 19524 - Resizing WorkbenchWindow resizes Views
12
 *     Cagatay Kavukcuoglu <cagatayk@acm.org>
14
 *     Cagatay Kavukcuoglu <cagatayk@acm.org>
13
 *       - Fix for bug 10025 - Resizing views should not use height ratios
15
 *       - Fix for bug 10025 - Resizing views should not use height ratios
14
**********************************************************************/
16
**********************************************************************/
Lines 141-146 Link Here
141
		oldParent.replaceChild(relativeChild,node);
143
		oldParent.replaceChild(relativeChild,node);
142
		return this;
144
		return this;
143
	}
145
	}
146
}
147
/**
148
 * Returns true if this tree can be compressed and expanded.
149
 * @return true if springy
150
 */
151
public boolean isCompressible() {
152
	//Added for bug 19524
153
	return part.isCompressible();
144
}
154
}
145
/**
155
/**
146
 * Returns true if this tree has visible parts otherwise returns false.
156
 * Returns true if this tree has visible parts otherwise returns false.
(-)LayoutTreeNode.java (-37 / +71 lines)
Lines 9-21 Link Here
9
 * 
9
 * 
10
 * Contributors: 
10
 * Contributors: 
11
 *    IBM Corporation - initial API and implementation 
11
 *    IBM Corporation - initial API and implementation 
12
 *    Randy Hudson <hudsonr@us.ibm.com> 
13
 *       - Fix for bug 19524 - Resizing WorkbenchWindow resizes Views
12
 *    Cagatay Kavukcuoglu <cagatayk@acm.org>
14
 *    Cagatay Kavukcuoglu <cagatayk@acm.org>
13
 *       - Fix for bug 10025 - Resizing views should not use height ratios
15
 *       - Fix for bug 10025 - Resizing views should not use height ratios
14
**********************************************************************/
16
**********************************************************************/
15
17
16
import java.util.ArrayList;
18
import java.util.ArrayList;
17
19
18
import org.eclipse.jface.util.Geometry;
19
import org.eclipse.swt.graphics.Point;
20
import org.eclipse.swt.graphics.Point;
20
import org.eclipse.swt.graphics.Rectangle;
21
import org.eclipse.swt.graphics.Rectangle;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Composite;
Lines 61-67 Link Here
61
	
62
	
62
	Rectangle bounds = sash.getBounds();
63
	Rectangle bounds = sash.getBounds();
63
	
64
	
64
	int relativePos = Geometry.getRelativePosition(bounds, toFind);
65
	//int relativePos = Geometry.getRelativePosition(bounds, toFind);
65
	
66
	
66
	if(sash.isVertical()) {
67
	if(sash.isVertical()) {
67
		if (toFind.x < bounds.x + (bounds.width / 2)) {
68
		if (toFind.x < bounds.x + (bounds.width / 2)) {
Lines 90-96 Link Here
90
	PartSashContainer.RelationshipInfo r = new PartSashContainer.RelationshipInfo();
91
	PartSashContainer.RelationshipInfo r = new PartSashContainer.RelationshipInfo();
91
	r.relative = children[0].computeRelation(relations);
92
	r.relative = children[0].computeRelation(relations);
92
	r.part = children[1].computeRelation(relations);
93
	r.part = children[1].computeRelation(relations);
93
	r.ratio = getSash().getRatio();
94
	r.left = getSash().getLeft();
95
	r.right = getSash().getRight();
94
	r.relationship = getSash().isVertical()?IPageLayout.RIGHT:IPageLayout.BOTTOM;
96
	r.relationship = getSash().isVertical()?IPageLayout.RIGHT:IPageLayout.BOTTOM;
95
	relations.add(0,r);
97
	relations.add(0,r);
96
	return r.relative;
98
	return r.relative;
Lines 227-255 Link Here
227
public boolean isVisible() {
229
public boolean isVisible() {
228
	return children[0].isVisible() || children[1].isVisible();
230
	return children[0].isVisible() || children[1].isVisible();
229
}
231
}
230
/**
232
231
 * Recompute the ratios in this tree. The ratio for a node is the width
232
 * (or height if the sash is horizontal) of the left child's bounds 
233
 * divided by the width or height of node's bounds. Sash width <em>is</em> 
234
 * considered in ratio computation.
235
 */
236
public void recomputeRatio() {
237
	children[0].recomputeRatio();
238
	children[1].recomputeRatio();
239
240
	if(children[0].isVisible() && children[1].isVisible()) {
241
		if(getSash().isVertical()) {
242
			float left = children[0].getBounds().width;
243
			float right = children[1].getBounds().width;
244
			getSash().setRatio(left/(right+left+SASH_WIDTH));
245
		} else {
246
			float left = children[0].getBounds().height;
247
			float right = children[1].getBounds().height;
248
			getSash().setRatio(left/(right+left+SASH_WIDTH));
249
		}
250
	}
251
		
252
}
253
/**
233
/**
254
 * Remove the child and this node from the tree
234
 * Remove the child and this node from the tree
255
 */
235
 */
Lines 307-312 Link Here
307
 * Resize the parts on this tree to fit in <code>bounds</code>.
287
 * Resize the parts on this tree to fit in <code>bounds</code>.
308
 */
288
 */
309
public void setBounds(Rectangle bounds) {
289
public void setBounds(Rectangle bounds) {
290
//	if (bounds.isEmpty())
291
//		return;
310
	if(!children[0].isVisible()) {
292
	if(!children[0].isVisible()) {
311
		children[1].setBounds(bounds);
293
		children[1].setBounds(bounds);
312
		return;
294
		return;
Lines 320-331 Link Here
320
	Rectangle rightBounds = new Rectangle(bounds.x,bounds.y,bounds.width,bounds.height);
302
	Rectangle rightBounds = new Rectangle(bounds.x,bounds.y,bounds.width,bounds.height);
321
	Rectangle sashBounds = new Rectangle(bounds.x,bounds.y,bounds.width,bounds.height);
303
	Rectangle sashBounds = new Rectangle(bounds.x,bounds.y,bounds.width,bounds.height);
322
	
304
	
323
	float ratio = getSash().getRatio();
305
	int left = getSash().getLeft();
306
	int right = getSash().getRight();
307
	int total = left+right;
308
	
309
	//At first I was going to have a more elaborate weighting system, but all-or-non is
310
	// sufficient
311
	double wLeft = left, wRight = right;
312
	switch (getCompressionBias()) {
313
		case -1:
314
			wLeft = 0.0;
315
			break;
316
		case 1:
317
			wRight = 0.0;
318
			break;
319
		default:
320
			break;
321
	}
322
	double wTotal = wLeft + wRight;
324
	
323
	
325
	if(getSash().isVertical()) {
324
	if(getSash().isVertical()) {
326
		
325
		
327
		//Work on x and width
326
		//Work on x and width
328
		leftBounds.width = (int)(ratio * bounds.width);
327
		leftBounds.width = left;
328
		rightBounds.width = right;
329
		
330
		int redistribute = bounds.width - SASH_WIDTH - total;
331
332
		leftBounds.x = bounds.x;
333
		leftBounds.width += Math.round(redistribute * wLeft / wTotal);
334
		
329
		sashBounds.x = leftBounds.x + leftBounds.width;
335
		sashBounds.x = leftBounds.x + leftBounds.width;
330
		sashBounds.width = SASH_WIDTH;
336
		sashBounds.width = SASH_WIDTH;
331
		
337
		
Lines 334-340 Link Here
334
		}
340
		}
335
		
341
		
336
		rightBounds.x = sashBounds.x + sashBounds.width;
342
		rightBounds.x = sashBounds.x + sashBounds.width;
337
		rightBounds.width = bounds.width - leftBounds.width - sashBounds.width;
343
		rightBounds.width = bounds.x + bounds.width - rightBounds.x;
338
		
344
		
339
		if (children[1].fixedHeight()) {
345
		if (children[1].fixedHeight()) {
340
			rightBounds.height = children[1].getBounds().height;
346
			rightBounds.height = children[1].getBounds().height;
Lines 343-357 Link Here
343
		adjustWidths(bounds, leftBounds, rightBounds, sashBounds);
349
		adjustWidths(bounds, leftBounds, rightBounds, sashBounds);
344
	} else {
350
	} else {
345
		//Work on y and height
351
		//Work on y and height
352
		int redistribute = bounds.height - SASH_WIDTH - total;
353
346
		if (children[0].fixedHeight()) {
354
		if (children[0].fixedHeight()) {
347
			leftBounds.height = children[0].getBounds().height;
355
			leftBounds.height = children[0].getBounds().height;
356
		} else if (children[1].fixedHeight()) {
357
			leftBounds.height = bounds.height - children[1].getBounds().height - SASH_WIDTH;
348
		} else {
358
		} else {
349
			
359
			leftBounds.height = left + (int)Math.round(redistribute * wLeft / wTotal);
350
			if (children[1].fixedHeight()) {
351
				leftBounds.height = bounds.height - children[1].getBounds().height - SASH_WIDTH;
352
			} else {
353
				leftBounds.height = (int)(ratio * bounds.height);
354
			}
355
		}
360
		}
356
		sashBounds.y = leftBounds.y + leftBounds.height;
361
		sashBounds.y = leftBounds.y + leftBounds.height;
357
		sashBounds.height = SASH_WIDTH;
362
		sashBounds.height = SASH_WIDTH;
Lines 360-366 Link Here
360
		if (children[1].fixedHeight()) {
365
		if (children[1].fixedHeight()) {
361
			rightBounds.height = children[1].getBounds().height;
366
			rightBounds.height = children[1].getBounds().height;
362
		} else {
367
		} else {
363
			rightBounds.height = bounds.height - leftBounds.height - sashBounds.height;
368
			rightBounds.height = bounds.y + bounds.height - rightBounds.y;
364
		}
369
		}
365
		adjustHeights(bounds, leftBounds, rightBounds, sashBounds);
370
		adjustHeights(bounds, leftBounds, rightBounds, sashBounds);
366
	}
371
	}
Lines 471-477 Link Here
471
	return (part != 0 ) ? part / whole : IPageLayout.RATIO_MIN;
476
	return (part != 0 ) ? part / whole : IPageLayout.RATIO_MIN;
472
}
477
}
473
478
474
// getMaximumRatioFor added by cagatayk@acm.org 
479
480
//Added by hudsonr@us.ibm.com - bug 19524
481
482
public boolean isCompressible() {
483
	return children[0].isCompressible() || children[1].isCompressible();
484
}
485
486
/**
487
 * Returns 0 if there is no bias. Returns -1 if the first child should be of
488
 * fixed size, and the second child should be compressed. Returns 1 if the
489
 * second child should be of fixed size.
490
 * @return the bias
491
 */
492
public int getCompressionBias() {
493
	boolean left = children[0].isCompressible();
494
	boolean right = children[1].isCompressible();
495
	if (left == right)
496
		return 0;
497
	if (right)
498
		return -1;
499
	return 1;
500
}// getMaximumRatioFor added by cagatayk@acm.org 
475
/**
501
/**
476
 * Obtain the maximum ratio required to display the control on the "right"
502
 * Obtain the maximum ratio required to display the control on the "right"
477
 * using its minimum dimensions.
503
 * using its minimum dimensions.
Lines 538-543 Link Here
538
	return minimum;
564
	return minimum;
539
}
565
}
540
566
567
boolean isLeftChild(LayoutTree toTest) {
568
	return children[0] == toTest;
569
}
570
571
LayoutTree getChild(boolean left) {
572
	int index = left?0:1;
573
	return (children[index]);
574
}
541
575
542
/**
576
/**
543
 * Sets a child in this node
577
 * Sets a child in this node
(-)PartSashContainer.java (-81 / +116 lines)
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
}
(-)RootLayoutContainer.java (-11 / +15 lines)
Lines 96-104 Link Here
96
		String relativeID = childMem.getString(IWorkbenchConstants.TAG_RELATIVE);
96
		String relativeID = childMem.getString(IWorkbenchConstants.TAG_RELATIVE);
97
		int relationship = 0;
97
		int relationship = 0;
98
		float ratio = 0.0f;
98
		float ratio = 0.0f;
99
		int left = 0, right = 0;
99
		if (relativeID != null) {
100
		if (relativeID != null) {
100
			relationship = childMem.getInteger(IWorkbenchConstants.TAG_RELATIONSHIP).intValue();
101
			relationship = childMem.getInteger(IWorkbenchConstants.TAG_RELATIONSHIP).intValue();
101
			ratio = childMem.getFloat(IWorkbenchConstants.TAG_RATIO).floatValue();
102
			Float Ratio = childMem.getFloat(IWorkbenchConstants.TAG_RATIO);
103
			if (Ratio == null) {
104
				left = childMem.getInteger(IWorkbenchConstants.TAG_RATIO_LEFT).intValue();
105
				right = childMem.getInteger(IWorkbenchConstants.TAG_RATIO_RIGHT).intValue();
106
			} else {
107
				ratio = Ratio.floatValue();
108
			}
102
		}
109
		}
103
		String strFolder = childMem.getString(IWorkbenchConstants.TAG_FOLDER);
110
		String strFolder = childMem.getString(IWorkbenchConstants.TAG_FOLDER);
104
111
Lines 123-129 Link Here
123
		} else {
130
		} else {
124
			LayoutPart refPart = (LayoutPart)mapIDtoPart.get(relativeID);
131
			LayoutPart refPart = (LayoutPart)mapIDtoPart.get(relativeID);
125
			if (refPart != null) {
132
			if (refPart != null) {
126
				add(part, relationship, ratio, refPart);	
133
				if (left != 0)
134
					add(part, relationship, left, right, refPart);
135
				else
136
					add(part, relationship, ratio, refPart);
127
			} else {
137
			} else {
128
				WorkbenchPlugin.log("Unable to find part for ID: " + relativeID);//$NON-NLS-1$
138
				WorkbenchPlugin.log("Unable to find part for ID: " + relativeID);//$NON-NLS-1$
129
			}
139
			}
Lines 155-161 Link Here
155
		if (info.relative != null) {
165
		if (info.relative != null) {
156
			childMem.putString(IWorkbenchConstants.TAG_RELATIVE, info.relative.getID());
166
			childMem.putString(IWorkbenchConstants.TAG_RELATIVE, info.relative.getID());
157
			childMem.putInteger(IWorkbenchConstants.TAG_RELATIONSHIP, info.relationship);
167
			childMem.putInteger(IWorkbenchConstants.TAG_RELATIONSHIP, info.relationship);
158
			childMem.putFloat(IWorkbenchConstants.TAG_RATIO, info.ratio);
168
			childMem.putInteger(IWorkbenchConstants.TAG_RATIO_LEFT, info.left);
169
			childMem.putInteger(IWorkbenchConstants.TAG_RATIO_RIGHT, info.right);
170
			//childMem.putFloat(IWorkbenchConstants.TAG_RATIO, info.ratio);
159
		}
171
		}
160
172
161
		// Is this part a folder or a placeholder for one?
173
		// Is this part a folder or a placeholder for one?
Lines 183-196 Link Here
183
public boolean allowsAutoFocus() {
195
public boolean allowsAutoFocus() {
184
	return true;
196
	return true;
185
}
197
}
186
187
/* (non-Javadoc)
188
 * @see org.eclipse.ui.internal.PartSashContainer#dropObject(org.eclipse.ui.internal.LayoutPart, org.eclipse.ui.internal.LayoutPart, int)
189
 */
190
protected void dropObject(LayoutPart sourcePart, LayoutPart targetPart, int side) {
191
	super.dropObject(sourcePart, targetPart, side);
192
}
193
194
198
195
/* (non-Javadoc)
199
/* (non-Javadoc)
196
 * @see org.eclipse.ui.internal.PartSashContainer#getDockingRatio(org.eclipse.ui.internal.LayoutPart, org.eclipse.ui.internal.LayoutPart)
200
 * @see org.eclipse.ui.internal.PartSashContainer#getDockingRatio(org.eclipse.ui.internal.LayoutPart, org.eclipse.ui.internal.LayoutPart)

Return to bug 19524