Skip to content

Commit

Permalink
Pull getLocation() method from Figure to IFigure interface.
Browse files Browse the repository at this point in the history
If a method only works on the IFigure interface, it currently has to
either cast the object to a Figure, in order to be able to call
getLocation() or instead go via getBounds().getLocation().

To avoid this issue, this method has been pulled to the implemented
interface. A default implementation is used to for backwards
compatibility. The implementation inside the Figure is not removed, in
order to keep the 'final' modifier, but internally only calls the
default implementation.

The interface already has a setter method for the location. Also
providing a getter only seems natural.
  • Loading branch information
ptziegler authored and azoitl committed Aug 27, 2023
1 parent 196bee5 commit 45ca0c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion org.eclipse.draw2d/src/org/eclipse/draw2d/Figure.java
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,9 @@ public Color getLocalForegroundColor() {
* @return The top-left corner of this Figure's bounds
* @since 2.0
*/
@Override
public final Point getLocation() {
return getBounds().getLocation();
return IFigure.super.getLocation();
}

/**
Expand Down
12 changes: 11 additions & 1 deletion org.eclipse.draw2d/src/org/eclipse/draw2d/IFigure.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -374,6 +374,16 @@ public boolean isEmpty() {
*/
Color getLocalForegroundColor();

/**
* Returns the top-left corner of this Figure's bounds.
*
* @return The top-left corner of this Figure's bounds
* @since 3.14
*/
default Point getLocation() {
return getBounds().getLocation();
}

/**
* Returns a hint indicating the largest desireable size for the IFigure.
* Returned Dimension is by value.
Expand Down

0 comments on commit 45ca0c7

Please sign in to comment.