|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 10-30
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.draw2d; |
11 |
package org.eclipse.draw2d; |
| 12 |
|
12 |
|
|
|
13 |
import java.util.ListIterator; |
| 14 |
|
| 13 |
import org.eclipse.draw2d.geometry.Point; |
15 |
import org.eclipse.draw2d.geometry.Point; |
|
|
16 |
import org.eclipse.draw2d.geometry.Rectangle; |
| 14 |
|
17 |
|
| 15 |
/** |
18 |
/** |
| 16 |
* A layout for {@link org.eclipse.draw2d.FreeformFigure FreeformFigures}. |
19 |
* A layout for {@link org.eclipse.draw2d.FreeformFigure FreeformFigures}. |
|
|
20 |
* Supports option to set only positive (x,y) coordinates for children figures. |
| 17 |
*/ |
21 |
*/ |
| 18 |
public class FreeformLayout |
22 |
public class FreeformLayout |
| 19 |
extends XYLayout |
23 |
extends XYLayout |
| 20 |
{ |
24 |
{ |
| 21 |
|
25 |
|
| 22 |
/** |
26 |
/** |
|
|
27 |
* Option that forces only positive coordinates to children figures by |
| 28 |
* setting the layout origin appropriately |
| 29 |
*/ |
| 30 |
private static final int FLAG__POSITIVE_COORDINATES = 1; |
| 31 |
|
| 32 |
/** |
| 33 |
* Option flags |
| 34 |
*/ |
| 35 |
private int flags; |
| 36 |
|
| 37 |
/** |
| 38 |
* Layout origin point |
| 39 |
*/ |
| 40 |
private Point origin = null; |
| 41 |
|
| 42 |
/** |
| 23 |
* Returns the point (0,0) as the origin. |
43 |
* Returns the point (0,0) as the origin. |
| 24 |
* @see XYLayout#getOrigin(IFigure) |
44 |
* @see XYLayout#getOrigin(IFigure) |
| 25 |
*/ |
45 |
*/ |
| 26 |
public Point getOrigin(IFigure figure) { |
46 |
public Point getOrigin(IFigure figure) { |
| 27 |
return new Point(); |
47 |
if (origin == null) { |
|
|
48 |
origin = new Point(); |
| 49 |
if (isPositiveCoordinates()) { |
| 50 |
ListIterator children = figure.getChildren().listIterator(); |
| 51 |
while (children.hasNext()) { |
| 52 |
IFigure f = (IFigure) children.next(); |
| 53 |
Rectangle constraint = (Rectangle)getConstraint(f); |
| 54 |
if (constraint != null) { |
| 55 |
origin.x = Math.min(origin.x, constraint.x); |
| 56 |
origin.y = Math.min(origin.y, constraint.y); |
| 57 |
} |
| 58 |
} |
| 59 |
origin.negate(); |
| 60 |
} |
| 61 |
} |
| 62 |
return origin; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Checks whether the positive coordinates flag is on, e.g positive |
| 67 |
* coordinates for children are inforced by the layout |
| 68 |
* |
| 69 |
* @return <code>boolean</code> |
| 70 |
* @since 3.2 |
| 71 |
*/ |
| 72 |
public boolean isPositiveCoordinates() { |
| 73 |
return (flags & FLAG__POSITIVE_COORDINATES) != 0; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Sets/unsets the positive coordinates flag for true/false parameters |
| 78 |
* respectively. If option is set to on then layout calculates positive |
| 79 |
* coordinates for children figures by adjusting the layout origin |
| 80 |
* accordingly. |
| 81 |
* |
| 82 |
* @param positiveCoordinates |
| 83 |
* @since 3.2 |
| 84 |
*/ |
| 85 |
public void setPositiveCoordinates(boolean positiveCoordinates) { |
| 86 |
if (positiveCoordinates != isPositiveCoordinates()) { |
| 87 |
if (positiveCoordinates) { |
| 88 |
flags |= FLAG__POSITIVE_COORDINATES; |
| 89 |
} else { |
| 90 |
flags &= ~FLAG__POSITIVE_COORDINATES; |
| 91 |
} |
| 92 |
invalidate(); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* @see org.eclipse.draw2d.AbstractLayout#invalidate() |
| 98 |
*/ |
| 99 |
public void invalidate() { |
| 100 |
origin = null; |
| 101 |
super.invalidate(); |
| 28 |
} |
102 |
} |
| 29 |
|
103 |
|
| 30 |
} |
104 |
} |