diff --git a/org.eclipse.gef/.settings/.api_filters b/org.eclipse.gef/.settings/.api_filters index 1dc315cd6..0a5af5ac5 100644 --- a/org.eclipse.gef/.settings/.api_filters +++ b/org.eclipse.gef/.settings/.api_filters @@ -72,6 +72,22 @@ + + + + + + + + + + + + + + + + diff --git a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/BendpointEditPolicy.java b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/BendpointEditPolicy.java index 87d7a5b56..267fb1300 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/BendpointEditPolicy.java +++ b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/BendpointEditPolicy.java @@ -120,7 +120,7 @@ private List createHandlesForUserBendpoints() { * @see SelectionHandlesEditPolicy#createSelectionHandles() */ @Override - protected List createSelectionHandles() { + protected List createSelectionHandles() { if (isAutomaticallyBending()) { return createHandlesForAutomaticBendpoints(); } diff --git a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ConnectionEndpointEditPolicy.java b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ConnectionEndpointEditPolicy.java index 5cdbc8e4f..6f58e41fc 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ConnectionEndpointEditPolicy.java +++ b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ConnectionEndpointEditPolicy.java @@ -108,7 +108,7 @@ public void validate() { * @see org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#createSelectionHandles() */ @Override - protected List createSelectionHandles() { + protected List createSelectionHandles() { List list = new ArrayList<>(); list.add(new ConnectionEndpointHandle((ConnectionEditPart) getHost(), ConnectionLocator.SOURCE)); list.add(new ConnectionEndpointHandle((ConnectionEditPart) getHost(), ConnectionLocator.TARGET)); diff --git a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/NonResizableEditPolicy.java b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/NonResizableEditPolicy.java index 2671ece59..c5fea738b 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/NonResizableEditPolicy.java +++ b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/NonResizableEditPolicy.java @@ -30,7 +30,6 @@ import org.eclipse.gef.Handle; import org.eclipse.gef.Request; import org.eclipse.gef.RequestConstants; -import org.eclipse.gef.SharedCursors; import org.eclipse.gef.commands.Command; import org.eclipse.gef.handles.AbstractHandle; import org.eclipse.gef.handles.HandleBounds; @@ -82,7 +81,7 @@ protected IFigure createDragSourceFeedbackFigure() { * @see org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#createSelectionHandles() */ @Override - protected List createSelectionHandles() { + protected List createSelectionHandles() { List list = new ArrayList<>(); createMoveHandle(list); createDragHandle(list, PositionConstants.NORTH_EAST); @@ -102,14 +101,14 @@ protected List createSelectionHandles() { * handle for * @since 3.7 */ - protected void createDragHandle(List handles, int direction) { + protected void createDragHandle(List handles, int direction) { if (isDragAllowed()) { // display 'resize' handles to allow dragging (drag tracker) - NonResizableHandleKit.addHandle(getHost(), handles, direction, getDragTracker(), SharedCursors.SIZEALL); + NonResizableHandleKit.addHandle(getHost(), handles, direction, getDragTracker(), Cursors.SIZEALL); } else { // display 'resize' handles to indicate selection only (selection // tracker) - NonResizableHandleKit.addHandle(getHost(), handles, direction, getSelectTracker(), SharedCursors.ARROW); + NonResizableHandleKit.addHandle(getHost(), handles, direction, getSelectTracker(), Cursors.ARROW); } } @@ -141,13 +140,13 @@ protected DragEditPartsTracker getDragTracker() { * @param handles The list of handles to add the move handle to. * @since 3.7 */ - protected void createMoveHandle(List handles) { + protected void createMoveHandle(List handles) { if (isDragAllowed()) { // display 'move' handle to allow dragging ResizableHandleKit.addMoveHandle(getHost(), handles, getDragTracker(), Cursors.SIZEALL); } else { // display 'move' handle only to indicate selection - ResizableHandleKit.addMoveHandle(getHost(), handles, getSelectTracker(), SharedCursors.ARROW); + ResizableHandleKit.addMoveHandle(getHost(), handles, getSelectTracker(), Cursors.ARROW); } } @@ -278,6 +277,7 @@ protected Command getMoveCommand(ChangeBoundsRequest request) { * @param req the orphan request * @return null by default */ + @SuppressWarnings("static-method") protected Command getOrphanCommand(Request req) { return null; } @@ -324,16 +324,16 @@ public void setDragAllowed(boolean isDragAllowed) { * @param request the request */ protected void showChangeBoundsFeedback(ChangeBoundsRequest request) { - IFigure feedback = getDragSourceFeedbackFigure(); + IFigure dsFeedbackFigure = getDragSourceFeedbackFigure(); PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); getHostFigure().translateToAbsolute(rect); rect.translate(request.getMoveDelta()); rect.resize(request.getSizeDelta()); - feedback.translateToRelative(rect); - feedback.setBounds(rect); - feedback.validate(); + dsFeedbackFigure.translateToRelative(rect); + dsFeedbackFigure.setBounds(rect); + dsFeedbackFigure.validate(); } /** diff --git a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ResizableEditPolicy.java b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ResizableEditPolicy.java index c581166fd..ef5297519 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ResizableEditPolicy.java +++ b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ResizableEditPolicy.java @@ -44,19 +44,11 @@ public class ResizableEditPolicy extends NonResizableEditPolicy { private int resizeDirections = PositionConstants.NSEW; - /** - * Constructs a new {@link ResizableEditPolicy}. - * - * @since 3.7 - */ - public ResizableEditPolicy() { - } - /** * @see org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#createSelectionHandles() */ @Override - protected List createSelectionHandles() { + protected List createSelectionHandles() { if (resizeDirections == PositionConstants.NONE) { // non resizable, so delegate to super implementation return super.createSelectionHandles(); @@ -87,7 +79,7 @@ protected List createSelectionHandles() { * handle for * @since 3.7 */ - protected void createResizeHandle(List handles, int direction) { + protected void createResizeHandle(List handles, int direction) { if ((resizeDirections & direction) == direction) { ResizableHandleKit.addHandle(getHost(), handles, direction, getResizeTracker(direction), Cursors.getDirectionalCursor(direction, getHostFigure().isMirrored())); @@ -195,8 +187,8 @@ public void showSourceFeedback(Request request) { public boolean understandsRequest(Request request) { if (REQ_RESIZE.equals(request.getType())) { // check all resize directions of the request are supported - int resizeDirections = ((ChangeBoundsRequest) request).getResizeDirection(); - return (resizeDirections & getResizeDirections()) == resizeDirections; + int reqResizeDirection = ((ChangeBoundsRequest) request).getResizeDirection(); + return (reqResizeDirection & getResizeDirections()) == reqResizeDirection; } return super.understandsRequest(request); } diff --git a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/SelectionHandlesEditPolicy.java b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/SelectionHandlesEditPolicy.java index c9aaac224..e4afc7142 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/SelectionHandlesEditPolicy.java +++ b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/SelectionHandlesEditPolicy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2024 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 @@ -42,7 +42,7 @@ public abstract class SelectionHandlesEditPolicy extends SelectionEditPolicy imp /** * the List of handles */ - protected List handles; + protected List handles; /** * Adds the handles to the handle layer. @@ -51,9 +51,7 @@ protected void addSelectionHandles() { removeSelectionHandles(); IFigure layer = getLayer(LayerConstants.HANDLE_LAYER); handles = createSelectionHandles(); - for (Object handle : handles) { - layer.add((IFigure) handle); - } + handles.stream().filter(IFigure.class::isInstance).map(IFigure.class::cast).forEach(layer::add); } /** @@ -61,7 +59,7 @@ protected void addSelectionHandles() { * * @return List of handles; cannot be null */ - protected abstract List createSelectionHandles(); + protected abstract List createSelectionHandles(); /** * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) @@ -69,20 +67,17 @@ protected void addSelectionHandles() { @Override public T getAdapter(final Class key) { if (key == AccessibleHandleProvider.class) { - return key.cast(new AccessibleHandleProvider() { - @Override - public List getAccessibleHandleLocations() { - List result = new ArrayList<>(); - if (handles != null) { - for (Object handle : handles) { - Point p = ((Handle) handle).getAccessibleLocation(); - if (p != null) { - result.add(p); - } + return key.cast((AccessibleHandleProvider) () -> { + List result = new ArrayList<>(); + if (handles != null) { + for (Handle handle : handles) { + Point p = handle.getAccessibleLocation(); + if (p != null) { + result.add(p); } } - return result; } + return result; }); } return null; @@ -106,9 +101,7 @@ protected void removeSelectionHandles() { return; } IFigure layer = getLayer(LayerConstants.HANDLE_LAYER); - for (Object handle : handles) { - layer.remove((IFigure) handle); - } + handles.stream().filter(IFigure.class::isInstance).map(IFigure.class::cast).forEach(layer::remove); handles = null; } diff --git a/org.eclipse.gef/src/org/eclipse/gef/handles/NonResizableHandleKit.java b/org.eclipse.gef/src/org/eclipse/gef/handles/NonResizableHandleKit.java index 1eef49570..38a5e93f2 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/handles/NonResizableHandleKit.java +++ b/org.eclipse.gef/src/org/eclipse/gef/handles/NonResizableHandleKit.java @@ -16,12 +16,12 @@ import org.eclipse.swt.graphics.Cursor; +import org.eclipse.draw2d.Cursors; import org.eclipse.draw2d.PositionConstants; import org.eclipse.gef.DragTracker; import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gef.Handle; -import org.eclipse.gef.SharedCursors; import org.eclipse.gef.tools.DragEditPartsTracker; /** @@ -39,7 +39,8 @@ public class NonResizableHandleKit { * @param tracker the handles' DragTracker * @param cursor the handles' Cursor */ - public static void addCornerHandles(GraphicalEditPart part, List handles, DragTracker tracker, Cursor cursor) { + public static void addCornerHandles(GraphicalEditPart part, List handles, DragTracker tracker, + Cursor cursor) { handles.add(createHandle(part, PositionConstants.SOUTH_EAST, tracker, cursor)); handles.add(createHandle(part, PositionConstants.SOUTH_WEST, tracker, cursor)); handles.add(createHandle(part, PositionConstants.NORTH_WEST, tracker, cursor)); @@ -52,7 +53,7 @@ public static void addCornerHandles(GraphicalEditPart part, List handles, DragTr * @param part the handles' GraphicalEditPart * @param handles the List to add the four corner handles to */ - public static void addCornerHandles(GraphicalEditPart part, List handles) { + public static void addCornerHandles(GraphicalEditPart part, List handles) { handles.add(createHandle(part, PositionConstants.SOUTH_EAST)); handles.add(createHandle(part, PositionConstants.SOUTH_WEST)); handles.add(createHandle(part, PositionConstants.NORTH_WEST)); @@ -67,7 +68,7 @@ public static void addCornerHandles(GraphicalEditPart part, List handles) { * @param direction the integer constant from PositionConstants that refers to * the handle direction */ - public static void addHandle(GraphicalEditPart part, List handles, int direction) { + public static void addHandle(GraphicalEditPart part, List handles, int direction) { handles.add(createHandle(part, direction)); } @@ -81,7 +82,7 @@ public static void addHandle(GraphicalEditPart part, List handles, int direction * the handle direction * @param cursor the Cursor to use when hovering over this handle */ - public static void addHandle(GraphicalEditPart part, List handles, int direction, DragTracker tracker, + public static void addHandle(GraphicalEditPart part, List handles, int direction, DragTracker tracker, Cursor cursor) { handles.add(createHandle(part, direction, tracker, cursor)); } @@ -93,7 +94,8 @@ public static void addHandle(GraphicalEditPart part, List handles, int direction * @param handles the List to add the handles to * @deprecated */ - public static void addHandles(GraphicalEditPart part, List handles) { + @Deprecated + public static void addHandles(GraphicalEditPart part, List handles) { addMoveHandle(part, handles); addCornerHandles(part, handles); } @@ -107,7 +109,8 @@ public static void addHandles(GraphicalEditPart part, List handles) { * @param cursor the handles' Cursor * @deprecated */ - public static void addHandles(GraphicalEditPart part, List handles, DragTracker tracker, Cursor cursor) { + @Deprecated + public static void addHandles(GraphicalEditPart part, List handles, DragTracker tracker, Cursor cursor) { addMoveHandle(part, handles, tracker, cursor); addCornerHandles(part, handles, tracker, cursor); } @@ -118,7 +121,7 @@ public static void addHandles(GraphicalEditPart part, List handles, DragTracker * @param f the handles' GraphicalEditPart * @param handles the List to add the handles to */ - public static void addMoveHandle(GraphicalEditPart f, List handles) { + public static void addMoveHandle(GraphicalEditPart f, List handles) { handles.add(moveHandle(f)); } @@ -130,13 +133,13 @@ public static void addMoveHandle(GraphicalEditPart f, List handles) { * @param handles the List to add the handles to * @param cursor the Cursor to use when hovering over this handle */ - public static void addMoveHandle(GraphicalEditPart f, List handles, DragTracker tracker, Cursor cursor) { + public static void addMoveHandle(GraphicalEditPart f, List handles, DragTracker tracker, Cursor cursor) { handles.add(moveHandle(f, tracker, cursor)); } static Handle createHandle(GraphicalEditPart owner, int direction) { ResizeHandle handle = new ResizeHandle(owner, direction); - handle.setCursor(SharedCursors.SIZEALL); + handle.setCursor(Cursors.SIZEALL); handle.setDragTracker(new DragEditPartsTracker(owner)); return handle; } @@ -173,4 +176,8 @@ public static Handle moveHandle(GraphicalEditPart owner, DragTracker tracker, Cu return moveHandle; } + private NonResizableHandleKit() { + throw new UnsupportedOperationException("Helper class should not be instantiated!"); //$NON-NLS-1$ + } + } diff --git a/org.eclipse.gef/src/org/eclipse/gef/handles/ResizableHandleKit.java b/org.eclipse.gef/src/org/eclipse/gef/handles/ResizableHandleKit.java index cd95d6750..a6250d5b5 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/handles/ResizableHandleKit.java +++ b/org.eclipse.gef/src/org/eclipse/gef/handles/ResizableHandleKit.java @@ -38,7 +38,7 @@ public class ResizableHandleKit { * @param direction the integer constant from PositionConstants that refers to * the handle direction */ - public static void addHandle(GraphicalEditPart part, List handles, int direction) { + public static void addHandle(GraphicalEditPart part, List handles, int direction) { handles.add(createHandle(part, direction)); } @@ -53,7 +53,7 @@ public static void addHandle(GraphicalEditPart part, List handles, int direction * the handle direction * @param cursor the Cursor to use when hovering over this handle */ - public static void addHandle(GraphicalEditPart part, List handles, int direction, DragTracker tracker, + public static void addHandle(GraphicalEditPart part, List handles, int direction, DragTracker tracker, Cursor cursor) { handles.add(createHandle(part, direction, tracker, cursor)); } @@ -66,7 +66,8 @@ public static void addHandle(GraphicalEditPart part, List handles, int direction * @param handles the List to add the handles to * @deprecated */ - public static void addHandles(GraphicalEditPart part, List handles) { + @Deprecated + public static void addHandles(GraphicalEditPart part, List handles) { addMoveHandle(part, handles); addCornerAndSideHandles(part, handles); } @@ -78,7 +79,7 @@ public static void addHandles(GraphicalEditPart part, List handles) { * @param handles the List to add the four corner handles to * @since 3.7 */ - public static void addCornerAndSideHandles(GraphicalEditPart part, List handles) { + public static void addCornerAndSideHandles(GraphicalEditPart part, List handles) { handles.add(createHandle(part, PositionConstants.EAST)); handles.add(createHandle(part, PositionConstants.SOUTH_EAST)); handles.add(createHandle(part, PositionConstants.SOUTH)); @@ -98,7 +99,7 @@ public static void addCornerAndSideHandles(GraphicalEditPart part, List handles) * @param cursor the handles' Cursor * @since 3.7 */ - public static void addCornerAndSideHandles(GraphicalEditPart part, List handles, DragTracker tracker, + public static void addCornerAndSideHandles(GraphicalEditPart part, List handles, DragTracker tracker, Cursor cursor) { handles.add(createHandle(part, PositionConstants.EAST, tracker, cursor)); handles.add(createHandle(part, PositionConstants.SOUTH_EAST, tracker, cursor)); @@ -116,7 +117,7 @@ public static void addCornerAndSideHandles(GraphicalEditPart part, List handles, * @param f the GraphicalEditPart that is the owner of the handles * @param handles the List to add the handles to */ - public static void addMoveHandle(GraphicalEditPart f, List handles) { + public static void addMoveHandle(GraphicalEditPart f, List handles) { handles.add(moveHandle(f)); } @@ -129,7 +130,7 @@ public static void addMoveHandle(GraphicalEditPart f, List handles) { * @param handles the List to add the handles to * @param cursor the Cursor to use when hovering over this handle */ - public static void addMoveHandle(GraphicalEditPart f, List handles, DragTracker tracker, Cursor cursor) { + public static void addMoveHandle(GraphicalEditPart f, List handles, DragTracker tracker, Cursor cursor) { handles.add(moveHandle(f, tracker, cursor)); } @@ -169,4 +170,8 @@ public static Handle moveHandle(GraphicalEditPart owner, DragTracker tracker, Cu return moveHandle; } + private ResizableHandleKit() { + throw new UnsupportedOperationException("Helper class should not be instantiated!"); //$NON-NLS-1$ + } + }