1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2003, 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.rulers;
|
12
|
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.eclipse.draw2d.IFigure;
|
16
|
import org.eclipse.draw2d.XYLayout;
|
17
|
import org.eclipse.draw2d.geometry.Dimension;
|
18
|
import org.eclipse.draw2d.geometry.Rectangle;
|
19
|
|
20
|
/**
|
21
|
* A custom layout manager for rulers. It is not meant to be used externally or
|
22
|
* with any figure other than a
|
23
|
* {@link org.eclipse.gef.internal.ui.rulers.RulerFigure ruler}.
|
24
|
*
|
25
|
* @author Pratik Shah
|
26
|
* @since 3.0
|
27
|
*/
|
28
|
public class RulerLayout extends XYLayout {
|
29
|
|
30
|
/**
|
31
|
* @see org.eclipse.draw2d.AbstractLayout#calculatePreferredSize(org.eclipse.draw2d.IFigure,
|
32
|
* int, int)
|
33
|
*/
|
34
|
protected Dimension calculatePreferredSize(IFigure container, int wHint,
|
35
|
int hHint) {
|
36
|
return new Dimension(1, 1);
|
37
|
}
|
38
|
|
39
|
/**
|
40
|
* @see org.eclipse.draw2d.AbstractLayout#getConstraint(org.eclipse.draw2d.IFigure)
|
41
|
*/
|
42
|
public Object getConstraint(IFigure child) {
|
43
|
return constraints.get(child);
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure)
|
48
|
*/
|
49
|
public void layout(IFigure container) {
|
50
|
List children = container.getChildren();
|
51
|
Rectangle rulerSize = container.getClientArea();
|
52
|
for (int i = 0; i < children.size(); i++) {
|
53
|
IFigure child = (IFigure) children.get(i);
|
54
|
Dimension childSize = child.getPreferredSize();
|
55
|
int position = ((Integer) getConstraint(child)).intValue();
|
56
|
if (((RulerFigure) container).isHorizontal()) {
|
57
|
childSize.height = rulerSize.height - 1;
|
58
|
Rectangle.SINGLETON.setLocation(position
|
59
|
- (childSize.width / 2), rulerSize.y);
|
60
|
} else {
|
61
|
childSize.width = rulerSize.width - 1;
|
62
|
Rectangle.SINGLETON.setLocation(rulerSize.x, position
|
63
|
- (childSize.height / 2));
|
64
|
}
|
65
|
Rectangle.SINGLETON.setSize(childSize);
|
66
|
child.setBounds(Rectangle.SINGLETON);
|
67
|
}
|
68
|
}
|
69
|
|
70
|
}
|