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 (-9 / +23 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 float ratio; //legacy
34
	private int left = 300, right = 300;
32
	
35
	
33
	/* Optimize limit checks by calculating minimum 
36
	/* Optimize limit checks by calculating minimum 
34
	 * and maximum ratios once per drag
37
	 * and maximum ratios once per drag
Lines 138-146 Link Here
138
LayoutPartSash getPreLimit() {
141
LayoutPartSash getPreLimit() {
139
	return preLimit;
142
	return preLimit;
140
}
143
}
141
float getRatio() {
144
142
	return ratio;
145
int getLeft() {
146
	return left;
147
}
148
149
int getRight() {
150
	return right;	
143
}
151
}
152
144
boolean isHorizontal() {
153
boolean isHorizontal() {
145
	return ((style & SWT.HORIZONTAL) == SWT.HORIZONTAL);
154
	return ((style & SWT.HORIZONTAL) == SWT.HORIZONTAL);
146
}
155
}
Lines 153-161 Link Here
153
void setPreLimit(LayoutPartSash newPreLimit) {
162
void setPreLimit(LayoutPartSash newPreLimit) {
154
	preLimit = newPreLimit;
163
	preLimit = newPreLimit;
155
}
164
}
156
void setRatio(float newRatio) {
165
157
	if (newRatio < 0.0 || newRatio > 1.0) return;
166
void setSizes(int left, int right) {
158
	ratio = newRatio;
167
	this.left = left;
168
	this.right = right;
159
}
169
}
160
170
161
private void widgetSelected(int x, int y, int width, int height) {
171
private void widgetSelected(int x, int y, int width, int height) {
Lines 163-174 Link Here
163
	LayoutTreeNode node = root.findSash(this);
173
	LayoutTreeNode node = root.findSash(this);
164
	Rectangle nodeBounds = node.getBounds();
174
	Rectangle nodeBounds = node.getBounds();
165
	//Recompute ratio
175
	//Recompute ratio
176
	x -= nodeBounds.x;
177
	y -= nodeBounds.y;
166
	if(style == SWT.VERTICAL) {
178
	if(style == SWT.VERTICAL) {
167
		setRatio((float)(x - nodeBounds.x)/(float)nodeBounds.width);
179
		setSizes(x, nodeBounds.width - x);
180
		//setRatio((float)(x - nodeBounds.x)/(float)nodeBounds.width);
168
	} else {
181
	} else {
169
		setRatio((float)(y - nodeBounds.y)/(float)nodeBounds.height);
182
		setSizes(y, nodeBounds.height - y);
183
		//setRatio((float)(y - nodeBounds.y)/(float)nodeBounds.height);
170
	}
184
	}
171
		
185
	
172
	node.setBounds(nodeBounds);
186
	node.setBounds(nodeBounds);
173
	initDragRatios();
187
	initDragRatios();
174
}
188
}
(-)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 (-79 / +83 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
		bounds = new Rectangle(0,0, 800, 600);
191
	} else {
192
		bounds = getBounds();
193
	}
194
	
195
	int totalSize = measureTree(bounds, node, isHorizontal);
196
		
197
	int left = (int) (totalSize * ratio);
198
	int right = totalSize - left;
188
199
189
	// store info about relative positions
200
	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
}
201
}
202
203
static int measureTree(Rectangle outerBounds, LayoutTree toMeasure, boolean horizontal) {
204
	if (toMeasure == null) {
205
		return Geometry.getDimension(outerBounds, horizontal);
206
	}
207
	
208
	LayoutTreeNode parent = toMeasure.getParent();
209
	if (parent == null) {
210
		return Geometry.getDimension(outerBounds, horizontal);
211
	}
212
213
	if (parent.getSash().isHorizontal() == horizontal) {
214
		return measureTree(outerBounds, parent, horizontal);
215
	}
216
217
	boolean isLeft = parent.isLeftChild(toMeasure);
218
219
	if (parent.getChild(!isLeft).isVisible()) {
220
		int left = parent.getSash().getLeft();
221
		int right = parent.getSash().getRight();
222
		int childSize = isLeft ? left : right;
223
		
224
		return measureTree(outerBounds, parent, horizontal) * childSize / (left + right);
225
	}
226
227
	return measureTree(outerBounds, parent, horizontal);
228
}
229
197
protected void addChild(RelationshipInfo info) {
230
protected void addChild(RelationshipInfo info) {
198
	LayoutPart child = info.part;
231
	LayoutPart child = info.part;
199
	
232
	
Lines 206-212 Link Here
206
		int vertical = (info.relationship == IPageLayout.LEFT || info.relationship == IPageLayout.RIGHT)?SWT.VERTICAL:SWT.HORIZONTAL;
239
		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; 
240
		boolean left = info.relationship == IPageLayout.LEFT || info.relationship == IPageLayout.TOP; 
208
		LayoutPartSash sash = new LayoutPartSash(this,vertical);
241
		LayoutPartSash sash = new LayoutPartSash(this,vertical);
209
		sash.setRatio(info.ratio);
242
		sash.setSizes(info.left, info.right);
210
		if((parent != null) && !(child instanceof PartPlaceholder))
243
		if((parent != null) && !(child instanceof PartPlaceholder))
211
			sash.createControl(parent);
244
			sash.createControl(parent);
212
		root = root.insert(child,left,sash,info.relative);
245
		root = root.insert(child,left,sash,info.relative);
Lines 354-379 Link Here
354
		return null;
387
		return null;
355
	return root.findBottomRight();
388
	return root.findBottomRight();
356
}
389
}
357
/**
358
 * Find a initial position for a new part.
359
 */
360
private void findPosition(RelationshipInfo info) {
361
390
362
	info.ratio = (float)0.5;
363
	info.relationship = IPageLayout.RIGHT;
364
	info.relative = root.findBottomRight();
365
366
	// If no parent go with default.
367
	if (parent == null)
368
		return;
369
		
370
	// If the relative part is too small, place the part on the left of everything.
371
	if (((float)this.getBounds().width / (float)info.relative.getBounds().width > 2) ||
372
		 ((float)this.getBounds().height / (float)info.relative.getBounds().height > 4)) {
373
		info.relative = null;
374
		info.ratio = 0.75f;
375
	}
376
}
377
/**
391
/**
378
 * @see LayoutPart#getBounds
392
 * @see LayoutPart#getBounds
379
 */
393
 */
Lines 449-485 Link Here
449
public boolean isZoomed() {
463
public boolean isZoomed() {
450
	return (unzoomRoot != null);
464
	return (unzoomRoot != null);
451
}
465
}
452
/**
453
 * Move a part to a new position and keep the bounds when possible, ie,
454
 * when the new relative part has the same higth or width as the part
455
 * being move.
456
 */
457
public void move(LayoutPart child, int relationship, LayoutPart relative) {
458
	LayoutTree childTree = root.find(child);
459
	LayoutTree relativeTree = root.find(relative);
460
461
	LayoutTreeNode commonParent = relativeTree.getParent().findCommonParent(child,relative);
462
	boolean isVertical = commonParent.getSash().isVertical();
463
	boolean recomputeRatio = false;
464
	recomputeRatio =
465
		isRelationshipCompatible(relationship,isVertical) &&
466
			commonParent.sameDirection(isVertical,relativeTree.getParent()) && 
467
				commonParent.sameDirection(isVertical,childTree.getParent());
468
466
469
	root = root.remove(child);
470
	int vertical = (relationship == IPageLayout.LEFT || relationship == IPageLayout.RIGHT)?SWT.VERTICAL:SWT.HORIZONTAL;
471
	boolean left = relationship == IPageLayout.LEFT || relationship == IPageLayout.TOP; 
472
	LayoutPartSash sash = new LayoutPartSash(this,vertical);
473
	sash.setRatio(0.5f);
474
	if((parent != null) && !(child instanceof PartPlaceholder))
475
		sash.createControl(parent);
476
	root = root.insert(child,left,sash,relative);
477
	root.updateSashes(parent);
478
	if(recomputeRatio)
479
		root.recomputeRatio();
480
		
481
	resizeSashes(parent.getClientArea());
482
}
483
/**
467
/**
484
 * Remove a part.
468
 * Remove a part.
485
 */ 
469
 */ 
Lines 671-678 Link Here
671
		int cursor = Geometry.getOppositeSide(side);
655
		int cursor = Geometry.getOppositeSide(side);
672
		
656
		
673
		if (pointlessDrop) {
657
		if (pointlessDrop) {
674
			side = SWT.NONE;
658
			side = SWT.NONE;			
675
			//cursor = SWT.CENTER;			
676
		}
659
		}
677
		
660
		
678
		return new SashContainerDropTarget(sourcePart, side, cursor, null);
661
		return new SashContainerDropTarget(sourcePart, side, cursor, null);
Lines 828-833 Link Here
828
		root.describeLayout(buf);
811
		root.describeLayout(buf);
829
		buf.append(")");
812
		buf.append(")");
830
	}
813
	}
814
}
815
816
void add(LayoutPart child, int relationship, int left, int right, LayoutPart relative) {
817
	if (isZoomed())
818
		zoomOut();
819
820
	if (child == null)
821
		return;
822
	if (relative != null && !isChild(relative))
823
		return;
824
	if (relationship < IPageLayout.LEFT || relationship > IPageLayout.BOTTOM)
825
		relationship = IPageLayout.LEFT;
826
827
	// store info about relative positions
828
	RelationshipInfo info = new RelationshipInfo();
829
	info.part = child;
830
	info.relationship = relationship;
831
	info.left = left;
832
	info.right = right;
833
	info.relative = relative;
834
	addChild(info);
831
}
835
}
832
836
833
}
837
}
(-)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)
(-)WorkbenchPage.java (-115 / +113 lines)
Lines 20-26 Link Here
20
import java.util.Iterator;
20
import java.util.Iterator;
21
import java.util.List;
21
import java.util.List;
22
import java.util.Set;
22
import java.util.Set;
23
24
import org.eclipse.core.runtime.IAdaptable;
23
import org.eclipse.core.runtime.IAdaptable;
25
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.IStatus;
Lines 45-51 Link Here
45
import org.eclipse.swt.events.ControlAdapter;
44
import org.eclipse.swt.events.ControlAdapter;
46
import org.eclipse.swt.events.ControlEvent;
45
import org.eclipse.swt.events.ControlEvent;
47
import org.eclipse.swt.events.ControlListener;
46
import org.eclipse.swt.events.ControlListener;
48
import org.eclipse.swt.graphics.Rectangle;
49
import org.eclipse.swt.widgets.Composite;
47
import org.eclipse.swt.widgets.Composite;
50
import org.eclipse.swt.widgets.Control;
48
import org.eclipse.swt.widgets.Control;
51
import org.eclipse.swt.widgets.Display;
49
import org.eclipse.swt.widgets.Display;
Lines 3471-3587 Link Here
3471
		
3469
		
3472
		return new IViewPart [] {part};
3470
		return new IViewPart [] {part};
3473
	}
3471
	}
3474
	/**
3472
//	/**
3475
	 * Allow for programmatically resizing a part.
3473
//	 * Allow for programmatically resizing a part.
3476
	 * <p>
3474
//	 * <p>
3477
	 * <em>EXPERIMENTAL</em>
3475
//	 * <em>EXPERIMENTAL</em>
3478
	 * </p>
3476
//	 * </p>
3479
	 * <p>
3477
//	 * <p>
3480
	 * Known limitations:
3478
//	 * Known limitations:
3481
	 * <ul>
3479
//	 * <ul>
3482
	 * <li>currently applies only to views</li>
3480
//	 * <li>currently applies only to views</li>
3483
	 * <li>has no effect when view is zoomed</li>
3481
//	 * <li>has no effect when view is zoomed</li>
3484
	 * </ul> 
3482
//	 * </ul> 
3485
	 */
3483
//	 */
3486
	public void resizeView(IViewPart part, int width, int height) {
3484
//	public void resizeView(IViewPart part, int width, int height) {
3487
		SashInfo sashInfo = new SashInfo();
3485
//		SashInfo sashInfo = new SashInfo();
3488
		PartPane pane = ((PartSite)part.getSite()).getPane();
3486
//		PartPane pane = ((PartSite)part.getSite()).getPane();
3489
		ILayoutContainer container = pane.getContainer();
3487
//		ILayoutContainer container = pane.getContainer();
3490
		LayoutTree tree = getPerspectivePresentation().getLayout().root.find(((PartTabFolder)container));
3488
//		LayoutTree tree = getPerspectivePresentation().getLayout().root.find(((PartTabFolder)container));
3491
		
3489
//		
3492
		// retrieve our layout sashes from the layout tree
3490
//		// retrieve our layout sashes from the layout tree
3493
		findSashParts(tree, pane.findSashes(), sashInfo);
3491
//		findSashParts(tree, pane.findSashes(), sashInfo);
3494
		
3492
//		
3495
		// first set the width
3493
//		// first set the width
3496
		float deltaWidth = width - pane.getBounds().width;
3494
//		float deltaWidth = width - pane.getBounds().width;
3497
		if (sashInfo.right != null) {
3495
//		if (sashInfo.right != null) {
3498
			Rectangle rightBounds = sashInfo.rightNode.getBounds();
3496
//			Rectangle rightBounds = sashInfo.rightNode.getBounds();
3499
			// set the new ratio 
3497
//			// set the new ratio 
3500
			sashInfo.right.setRatio(
3498
//			sashInfo.right.setRatio(
3501
				((float) ((deltaWidth + sashInfo.right.getBounds().x) - rightBounds.x))
3499
//				((float) ((deltaWidth + sashInfo.right.getBounds().x) - rightBounds.x))
3502
					/ ((float) rightBounds.width));		
3500
//					/ ((float) rightBounds.width));		
3503
			// complete the resize
3501
//			// complete the resize
3504
			sashInfo.rightNode.setBounds(rightBounds);	
3502
//			sashInfo.rightNode.setBounds(rightBounds);	
3505
		}
3503
//		}
3506
		else if (sashInfo.left != null) {
3504
//		else if (sashInfo.left != null) {
3507
			Rectangle leftBounds = sashInfo.leftNode.getBounds();
3505
//			Rectangle leftBounds = sashInfo.leftNode.getBounds();
3508
			// set the ratio
3506
//			// set the ratio
3509
			sashInfo.left.setRatio(
3507
//			sashInfo.left.setRatio(
3510
				(float) ((sashInfo.left.getBounds().x - deltaWidth) - leftBounds.x)
3508
//				(float) ((sashInfo.left.getBounds().x - deltaWidth) - leftBounds.x)
3511
					/ ((float) leftBounds.width));			
3509
//					/ ((float) leftBounds.width));			
3512
			// complete the resize
3510
//			// complete the resize
3513
			sashInfo.leftNode.setBounds(sashInfo.leftNode.getBounds());
3511
//			sashInfo.leftNode.setBounds(sashInfo.leftNode.getBounds());
3514
		}
3512
//		}
3515
3513
//
3516
		// next set the height
3514
//		// next set the height
3517
		float deltaHeight = height - pane.getBounds().height;
3515
//		float deltaHeight = height - pane.getBounds().height;
3518
		if (sashInfo.bottom != null) {
3516
//		if (sashInfo.bottom != null) {
3519
			Rectangle bottomBounds = sashInfo.bottomNode.getBounds();
3517
//			Rectangle bottomBounds = sashInfo.bottomNode.getBounds();
3520
			// set the new ratio 
3518
//			// set the new ratio 
3521
			sashInfo.bottom.setRatio(
3519
//			sashInfo.bottom.setRatio(
3522
				((float) ((deltaHeight + sashInfo.bottom.getBounds().y) - bottomBounds.y))
3520
//				((float) ((deltaHeight + sashInfo.bottom.getBounds().y) - bottomBounds.y))
3523
					/ ((float) bottomBounds.height));		
3521
//					/ ((float) bottomBounds.height));		
3524
			// complete the resize
3522
//			// complete the resize
3525
			sashInfo.bottomNode.setBounds(bottomBounds);	
3523
//			sashInfo.bottomNode.setBounds(bottomBounds);	
3526
		}
3524
//		}
3527
		else if (sashInfo.top != null) {
3525
//		else if (sashInfo.top != null) {
3528
			Rectangle topBounds = sashInfo.topNode.getBounds();
3526
//			Rectangle topBounds = sashInfo.topNode.getBounds();
3529
			// set the ratio
3527
//			// set the ratio
3530
			sashInfo.top.setRatio(
3528
//			sashInfo.top.setRatio(
3531
				(float) ((sashInfo.top.getBounds().y - deltaHeight) - topBounds.y)
3529
//				(float) ((sashInfo.top.getBounds().y - deltaHeight) - topBounds.y)
3532
					/ ((float) topBounds.height));			
3530
//					/ ((float) topBounds.height));			
3533
			// complete the resize
3531
//			// complete the resize
3534
			sashInfo.topNode.setBounds(topBounds);
3532
//			sashInfo.topNode.setBounds(topBounds);
3535
		}	
3533
//		}	
3536
3534
//
3537
	}
3535
//	}
3538
	// provides sash information for the given pane
3536
//	// provides sash information for the given pane
3539
	private class SashInfo {
3537
//	private class SashInfo {
3540
		private LayoutPartSash right;
3538
//		private LayoutPartSash right;
3541
		private LayoutPartSash left;
3539
//		private LayoutPartSash left;
3542
		private LayoutPartSash top;
3540
//		private LayoutPartSash top;
3543
		private LayoutPartSash bottom;
3541
//		private LayoutPartSash bottom;
3544
		private LayoutTreeNode rightNode;
3542
//		private LayoutTreeNode rightNode;
3545
		private LayoutTreeNode leftNode;
3543
//		private LayoutTreeNode leftNode;
3546
		private LayoutTreeNode topNode;
3544
//		private LayoutTreeNode topNode;
3547
		private LayoutTreeNode bottomNode;
3545
//		private LayoutTreeNode bottomNode;
3548
	}
3546
//	}
3549
	private void findSashParts(LayoutTree tree, PartPane.Sashes sashes, SashInfo info) {
3547
//	private void findSashParts(LayoutTree tree, PartPane.Sashes sashes, SashInfo info) {
3550
		LayoutTree parent = tree.getParent();
3548
//		LayoutTree parent = tree.getParent();
3551
		if (parent == null)
3549
//		if (parent == null)
3552
			return;
3550
//			return;
3553
3551
//
3554
		if (parent.part instanceof LayoutPartSash) {
3552
//		if (parent.part instanceof LayoutPartSash) {
3555
			// get the layout part sash from this tree node
3553
//			// get the layout part sash from this tree node
3556
			LayoutPartSash sash = (LayoutPartSash) parent.part;			
3554
//			LayoutPartSash sash = (LayoutPartSash) parent.part;			
3557
			// make sure it has a sash control
3555
//			// make sure it has a sash control
3558
			Control control = sash.getControl();
3556
//			Control control = sash.getControl();
3559
			if (control != null) {
3557
//			if (control != null) {
3560
				// check for a vertical sash
3558
//				// check for a vertical sash
3561
				if (sash.isVertical()) {
3559
//				if (sash.isVertical()) {
3562
					if (sashes.left == control) {
3560
//					if (sashes.left == control) {
3563
						info.left = sash;
3561
//						info.left = sash;
3564
						info.leftNode = parent.findSash(sash);
3562
//						info.leftNode = parent.findSash(sash);
3565
					}
3563
//					}
3566
					else if (sashes.right == control) {
3564
//					else if (sashes.right == control) {
3567
						info.right = sash;
3565
//						info.right = sash;
3568
						info.rightNode = parent.findSash(sash);
3566
//						info.rightNode = parent.findSash(sash);
3569
					}
3567
//					}
3570
				}				
3568
//				}				
3571
				// check for a horizontal sash
3569
//				// check for a horizontal sash
3572
				else {
3570
//				else {
3573
					if (sashes.top == control) {
3571
//					if (sashes.top == control) {
3574
						info.top = sash;
3572
//						info.top = sash;
3575
						info.topNode = parent.findSash(sash);	
3573
//						info.topNode = parent.findSash(sash);	
3576
					}
3574
//					}
3577
					else if (sashes.bottom == control) {
3575
//					else if (sashes.bottom == control) {
3578
						info.bottom = sash;
3576
//						info.bottom = sash;
3579
						info.bottomNode = parent.findSash(sash);
3577
//						info.bottomNode = parent.findSash(sash);
3580
					}
3578
//					}
3581
				}
3579
//				}
3582
			}
3580
//			}
3583
		}
3581
//		}
3584
		// recursive call to continue up the tree
3582
//		// recursive call to continue up the tree
3585
		findSashParts(parent, sashes, info);		
3583
//		findSashParts(parent, sashes, info);		
3586
	}
3584
//	}
3587
}
3585
}

Return to bug 19524