Skip to content
Snippets Groups Projects
Commit db7c92f8 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

bugfix: layout utils reuse old objects if possible

refs 820
parent cc30ea9e
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ import org.fortiss.tooling.base.model.layout.ILayoutedModelElement; ...@@ -29,7 +29,7 @@ import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating GREEN Hash: 5C92A83202006734362EED9438B3A2D8 * @ConQAT.Rating YELLOW Hash: 5BDF0EA81728D59FBC5E27E00904D085
*/ */
public final class DimensionUtils { public final class DimensionUtils {
...@@ -42,11 +42,10 @@ public final class DimensionUtils { ...@@ -42,11 +42,10 @@ public final class DimensionUtils {
* the layout key * the layout key
* @return the dimension of the element * @return the dimension of the element
*/ */
public static Dimension getDimension(ILayoutedModelElement layouted, public static Dimension getDimension(ILayoutedModelElement layouted, String key) {
String key) { for(ILayoutData ld : layouted.getLayoutDataList()) {
for (ILayoutData ld : layouted.getLayoutDataList()) { if(ld.getKey().equals(key) && ld instanceof Dimension) {
if (ld.getKey().equals(key) && ld instanceof Dimension) { return (Dimension)ld;
return (Dimension) ld;
} }
} }
return null; return null;
...@@ -64,13 +63,13 @@ public final class DimensionUtils { ...@@ -64,13 +63,13 @@ public final class DimensionUtils {
* @param h * @param h
* the height * the height
*/ */
public static void setDimension(ILayoutedModelElement layouted, String key, public static void setDimension(ILayoutedModelElement layouted, String key, int w, int h) {
int w, int h) {
Dimension old = getDimension(layouted, key); Dimension old = getDimension(layouted, key);
if (old != null) { if(old != null) {
layouted.getLayoutDataList().remove(old); old.setWidth(w);
old.setHeight(h);
} else {
layouted.getLayoutDataList().add(createDimension(w, h, key));
} }
Dimension d = createDimension(w, h, key);
layouted.getLayoutDataList().add(d);
} }
} }
...@@ -32,7 +32,7 @@ import org.fortiss.tooling.base.model.layout.Point; ...@@ -32,7 +32,7 @@ import org.fortiss.tooling.base.model.layout.Point;
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating GREEN Hash: C4401B596767E967B83634EA26A60EC4 * @ConQAT.Rating YELLOW Hash: 497062A726321ADDE1E6991D61DE481F
*/ */
public final class PointUtils { public final class PointUtils {
...@@ -48,10 +48,10 @@ public final class PointUtils { ...@@ -48,10 +48,10 @@ public final class PointUtils {
public static Point getPosition(ILayoutedModelElement layouted, String key) { public static Point getPosition(ILayoutedModelElement layouted, String key) {
Point point = getPoint(layouted, key); Point point = getPoint(layouted, key);
if (point == null) { if(point == null) {
int index = 0; int index = 0;
EObject container = layouted.eContainer(); EObject container = layouted.eContainer();
if (container != null) { if(container != null) {
index = 1 + container.eContents().indexOf(layouted); index = 1 + container.eContents().indexOf(layouted);
} }
Point p = createPoint(index * 20, index * 20, key); Point p = createPoint(index * 20, index * 20, key);
...@@ -62,9 +62,9 @@ public final class PointUtils { ...@@ -62,9 +62,9 @@ public final class PointUtils {
/** Returns a {@link Point} layout data object with the given key or null. */ /** Returns a {@link Point} layout data object with the given key or null. */
private static Point getPoint(ILayoutedModelElement layouted, String key) { private static Point getPoint(ILayoutedModelElement layouted, String key) {
for (ILayoutData ld : layouted.getLayoutDataList()) { for(ILayoutData ld : layouted.getLayoutDataList()) {
if (ld.getKey().equals(key) && ld instanceof Point) { if(ld.getKey().equals(key) && ld instanceof Point) {
return (Point) ld; return (Point)ld;
} }
} }
return null; return null;
...@@ -82,13 +82,13 @@ public final class PointUtils { ...@@ -82,13 +82,13 @@ public final class PointUtils {
* @param y * @param y
* the y coordinate value * the y coordinate value
*/ */
public static void setPoint(ILayoutedModelElement layouted, String key, public static void setPoint(ILayoutedModelElement layouted, String key, int x, int y) {
int x, int y) {
Point old = getPoint(layouted, key); Point old = getPoint(layouted, key);
if (old != null) { if(old != null) {
layouted.getLayoutDataList().remove(old); old.setX(x);
old.setY(y);
} else {
layouted.getLayoutDataList().add(createPoint(x, y, key));
} }
Point p = createPoint(x, y, key);
layouted.getLayoutDataList().add(p);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment