Skip to content

Commit

Permalink
[13] Reduce usage of Draw2D/GEF deprecated APIs
Browse files Browse the repository at this point in the history
Bug: #13
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
  • Loading branch information
pcdavid committed May 6, 2023
1 parent 7238cba commit bdee95d
Show file tree
Hide file tree
Showing 23 changed files with 191 additions and 205 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* Copyright (c) 2004, 2023 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -36,7 +36,7 @@ public Insets getInsets(IFigure figure) {
}

public void paint(IFigure figure, Graphics g, Insets in) {
Rectangle r = figure.getBounds().getCropped(in);
Rectangle r = figure.getBounds().getShrinked(in);
IMapMode mm = MapModeUtil.getMapMode(figure);

//Draw the sides of the border
Expand All @@ -51,8 +51,8 @@ public void paint(IFigure figure, Graphics g, Insets in) {
g.drawLine(r.x, r.y + 2, r.x, r.bottom() - 3);
g.drawLine(r.right() - 1, r.bottom() - 3, r.right() - 1, r.y + 2);

r.crop(new Insets(1, 1, 0, 0));
r.shrink(new Insets(1, 1, 0, 0));
r.expand(1, 1);
r.crop(getInsets(figure));
r.shrink(getInsets(figure));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others.
* Copyright (c) 2004, 2023 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -41,7 +41,7 @@ public LogicFlowFigure(Dimension size) {
* @see org.eclipse.gef.handles.HandleBounds#getHandleBounds()
*/
public Rectangle getHandleBounds() {
return getBounds().getCropped(new Insets(2,0,2,0));
return getBounds().getShrinked(new Insets(2,0,2,0));
}

public Dimension getPreferredSize(int w, int h) {
Expand All @@ -55,7 +55,7 @@ public Dimension getPreferredSize(int w, int h) {
*/
protected void paintFigure(Graphics graphics) {
Rectangle rect = getBounds().getCopy();
rect.crop(new Insets(2,0,2,0));
rect.shrink(new Insets(2,0,2,0));
}

public String toString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2003, 2010 IBM Corporation and others.
* Copyright (c) 2003, 2010, 2023 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -78,11 +78,11 @@ public PointList getAnchorBorderPointList() {
if (arcSize == 0) {
// rectangle, no rounded corners
PrecisionPointList ptList = new PrecisionPointList(5);
ptList.addPoint(new PrecisionPoint(rBounds.preciseX, rBounds.preciseY));
ptList.addPoint(new PrecisionPoint(rBounds.preciseX + rBounds.preciseWidth, rBounds.preciseY));
ptList.addPoint(new PrecisionPoint(rBounds.preciseX + rBounds.preciseWidth, rBounds.preciseY + rBounds.preciseHeight));
ptList.addPoint(new PrecisionPoint(rBounds.preciseX, rBounds.preciseY + rBounds.preciseHeight));
ptList.addPoint(new PrecisionPoint(rBounds.preciseX, rBounds.preciseY));
ptList.addPoint(new PrecisionPoint(rBounds.preciseX(), rBounds.preciseY()));
ptList.addPoint(new PrecisionPoint(rBounds.preciseX() + rBounds.preciseWidth(), rBounds.preciseY()));
ptList.addPoint(new PrecisionPoint(rBounds.preciseX() + rBounds.preciseWidth(), rBounds.preciseY() + rBounds.preciseHeight()));
ptList.addPoint(new PrecisionPoint(rBounds.preciseX(), rBounds.preciseY() + rBounds.preciseHeight()));
ptList.addPoint(new PrecisionPoint(rBounds.preciseX(), rBounds.preciseY()));
return ptList;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2002, 2010 IBM Corporation and others.
* Copyright (c) 2002, 2010, 2023 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -991,9 +991,8 @@ private void updateNewSlidingAnchorReferenceRatio(ICommandProxy setAnchorCommand
newRatio = cmd.getNewTargetTerminal() == null ? new PrecisionPoint(0.5, 0.5) : BaseSlidableAnchor.parseTerminalString(cmd.getNewTargetTerminal());
}
if (newRatio != null) {
ratio.preciseX = newRatio.preciseX;
ratio.preciseY = newRatio.preciseY;
ratio.updateInts();
ratio.setPreciseX(newRatio.preciseX());
ratio.setPreciseY(newRatio.preciseY());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2002, 2010, 2022 IBM Corporation and others.
* Copyright (c) 2002, 2010, 2022, 2023 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -713,8 +713,8 @@ public ImageData getImageData() {
mm.LPtoDP(rect);

// Create the graphics and wrap it with the HiMetric graphics object
graphics = setUpGraphics((int) Math.round(rect.preciseWidth),
(int) Math.round(rect.preciseHeight));
graphics = setUpGraphics((int) Math.round(rect.preciseWidth()),
(int) Math.round(rect.preciseHeight()));

RenderedMapModeGraphics mapModeGraphics = new RenderedMapModeGraphics(
graphics, getMapMode());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2002, 2009 IBM Corporation and others.
* Copyright (c) 2002, 2009, 2023 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -143,8 +143,8 @@ public java.awt.Image createAWTImageForParts(List selectedObjects, org.eclipse.s

mm.LPtoDP(rect);

awtImage = new BufferedImage((int) Math.round(rect.preciseWidth),
(int) Math.rint(rect.preciseHeight),
awtImage = new BufferedImage((int) Math.round(rect.preciseWidth()),
(int) Math.rint(rect.preciseHeight()),
BufferedImage.TYPE_4BYTE_ABGR_PRE);

Graphics2D g2d = awtImage.createGraphics();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2009, 2010 IBM Corporation and others.
* Copyright (c) 2009, 2010, 2023 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -76,23 +76,22 @@ public static final Rectangle calculateImageRectangle(
}

PrecisionRectangle rect = new PrecisionRectangle();
rect.preciseWidth = maxX - minX;
rect.preciseHeight = maxY - minY;
rect.setPreciseWidth(maxX - minX);
rect.setPreciseHeight(maxY - minY);

if (defaultSize != null) {
if (rect.preciseHeight <= 0) {
rect.preciseHeight = defaultSize.preciseWidth();
if (rect.preciseHeight() <= 0) {
rect.setPreciseHeight(defaultSize.preciseWidth());
}
if (rect.preciseHeight <= 0) {
rect.preciseHeight = defaultSize.preciseHeight();
if (rect.preciseHeight() <= 0) {
rect.setPreciseHeight(defaultSize.preciseHeight());
}
}

rect.preciseX = minX - frameSize;
rect.preciseY = minY - frameSize;
rect.preciseWidth += 2 * frameSize;
rect.preciseHeight += 2 * frameSize;
rect.updateInts();
rect.setPreciseX(minX - frameSize);
rect.setPreciseY(minY - frameSize);
rect.setPreciseWidth(rect.preciseWidth() + 2 * frameSize);
rect.setPreciseHeight(rect.preciseHeight() + 2 * frameSize);
return rect;
}

Expand Down Expand Up @@ -127,9 +126,9 @@ public static void zOrderSort(List<? extends GraphicalEditPart> editparts, IFigu
if (editparts == null || editparts.size() < 2) {
return;
}
final Map<GraphicalEditPart, List<Integer>> indexMap = new IdentityHashMap<GraphicalEditPart, List<Integer>>(editparts.size());
final Map<GraphicalEditPart, List<Integer>> indexMap = new IdentityHashMap<>(editparts.size());
for (GraphicalEditPart ep : editparts) {
List<Integer> index = new ArrayList<Integer>();
List<Integer> index = new ArrayList<>();
for (IFigure fig = ep.getFigure(); fig != zOrderRoot && fig.getParent() != null; fig = fig.getParent()) {
index.add(fig.getParent().getChildren().indexOf(fig));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2004, 2006 IBM Corporation and others.
* Copyright (c) 2004, 2006, 2023 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -18,6 +18,7 @@
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.GraphicalEditPart;
Expand All @@ -29,7 +30,7 @@
import org.eclipse.gmf.runtime.gef.ui.internal.requests.RotateShapeRequest;

/**
* A rotatable editpolicy for rotating fork and join itparts
* A rotatable editpolicy for rotating fork and join parts
* It rotates the figure if diagonal handlers are dragged and
* resizes the figure otherwise as defined by the superclass
*
Expand Down Expand Up @@ -113,12 +114,12 @@ protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
private PrecisionRectangle rotateRectangle(Rectangle r) {
PrecisionRectangle rect = new PrecisionRectangle(r);
if (isVertical(r)) {
rect.setX(rect.preciseX-rect.preciseHeight/2.0+rect.preciseWidth/2.0);
rect.setY(rect.preciseY+rect.preciseHeight/2.0-rect.preciseWidth/2.0);
rect.setPreciseX(rect.preciseX()-rect.preciseHeight()/2.0+rect.preciseWidth()/2.0);
rect.setPreciseY(rect.preciseY()+rect.preciseHeight()/2.0-rect.preciseWidth()/2.0);
}
else {
rect.setX(rect.preciseX+rect.preciseWidth/2.0-rect.preciseHeight/2.0);
rect.setY(rect.preciseY-rect.preciseWidth/2.0+rect.preciseHeight/2.0);
rect.setPreciseX(rect.preciseX()+rect.preciseWidth()/2.0-rect.preciseHeight()/2.0);
rect.setPreciseY(rect.preciseY()-rect.preciseWidth()/2.0+rect.preciseHeight()/2.0);
}
transposePrecisionRectangleSize(rect);
return rect;
Expand All @@ -139,9 +140,9 @@ private boolean isVertical(Rectangle r) {
* @return PrecisionRectangle with transposed size
*/
private void transposePrecisionRectangleSize(PrecisionRectangle r) {
double height = r.preciseHeight;
r.setHeight(r.preciseWidth);
r.setWidth(height);
double height = r.preciseHeight();
r.setPreciseHeight(r.preciseWidth());
r.setPreciseWidth(height);
}

/*
Expand Down Expand Up @@ -175,7 +176,7 @@ protected Command getResizeCommand(ChangeBoundsRequest request) {
PrecisionRectangle rect = getAbsoluteRotatedBounds();
PrecisionRectangle initFigure = getAbsoluteInitialBounds();
req.setMoveDelta
(new Point(rect.preciseX - initFigure.preciseX, rect.preciseY - initFigure.preciseY));
(new PrecisionPoint(rect.preciseX() - initFigure.preciseX(), rect.preciseY() - initFigure.preciseY()));
req.setSizeDelta
(new Dimension(rect.width - initFigure.width, rect.height - initFigure.height));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2008 IBM Corporation and others.
* Copyright (c) 2008, 2023 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -32,6 +32,7 @@ public CompoundSnapToHelperEx(SnapToHelper[] delegates) {
super(delegates);
}

@Override
public int snapRectangle(Request request, int snapOrientation,
PrecisionRectangle baseRect, PrecisionRectangle result) {

Expand All @@ -46,9 +47,9 @@ public int snapRectangle(Request request, int snapOrientation,
snapOrientation = SnapToHelperUtil.updateSnapLocations(snapOrientation,
restrictedDirections);

SnapToHelper delegates[] = getDelegates();
int snapOrientations[] = new int[delegates.length];
PrecisionRectangle results[] = new PrecisionRectangle[delegates.length];
SnapToHelper[] delegates = getDelegates();
int[] snapOrientations = new int[delegates.length];
PrecisionRectangle[] results = new PrecisionRectangle[delegates.length];

for (int i = 0; i < delegates.length; i++) {
results[i] = new PrecisionRectangle();
Expand All @@ -63,24 +64,23 @@ public int snapRectangle(Request request, int snapOrientation,
if (snapChanged != 0) {
// some snapping occurred
if ((snapChanged & HORIZONTAL) != 0) {
if (result.preciseX == 0
|| Math.abs(results[i].preciseX) < Math
.abs(result.preciseX)) {
result.preciseX = results[i].preciseX;
if (result.preciseX() == 0
|| Math.abs(results[i].preciseX()) < Math
.abs(result.preciseX())) {
result.setPreciseX(results[i].preciseX());
}
snapOrientationToReturn &= ~HORIZONTAL;
}
if ((snapChanged & VERTICAL) != 0) {
if (result.preciseY == 0
|| Math.abs(results[i].preciseY) < Math
.abs(result.preciseY)) {
result.preciseY = results[i].preciseY;
if (result.preciseY() == 0
|| Math.abs(results[i].preciseY()) < Math
.abs(result.preciseY())) {
result.setPreciseY(results[i].preciseY());
}
snapOrientationToReturn &= ~VERTICAL;
}
}
}
result.updateInts();
return snapOrientationToReturn;
}
}
Loading

0 comments on commit bdee95d

Please sign in to comment.