From 3cda47085dac2c14a3d3f66f632da764d3ac1801 Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Mon, 30 Jun 2025 19:19:10 +0200 Subject: [PATCH] [GEF] Remove excessive getFigureCanvas() method from Figure The canvas is only needed to calculate the position of the text field for the Label widget. However, the coordinates can also be calculated by using translateToAbsolute(). --- .../src-draw2d/org/eclipse/wb/draw2d/Figure.java | 15 --------------- .../org/eclipse/wb/draw2d/FigureUtils.java | 13 ------------- .../eclipse/wb/internal/draw2d/FigureCanvas.java | 2 +- .../eclipse/wb/internal/draw2d/RootFigure.java | 11 ++--------- .../graphical/policies/DirectTextEditPolicy.java | 12 +++++------- .../internal/gef/graphical/GraphicalViewer.java | 2 +- 6 files changed, 9 insertions(+), 46 deletions(-) diff --git a/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/draw2d/Figure.java b/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/draw2d/Figure.java index 7bf5cbf5f..0c92ff342 100644 --- a/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/draw2d/Figure.java +++ b/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/draw2d/Figure.java @@ -12,7 +12,6 @@ *******************************************************************************/ package org.eclipse.wb.draw2d; -import org.eclipse.wb.internal.draw2d.FigureCanvas; import org.eclipse.wb.internal.draw2d.FigureVisitor; import org.eclipse.draw2d.Graphics; @@ -74,20 +73,6 @@ public final void accept(FigureVisitor visitor, boolean forward) { } } - //////////////////////////////////////////////////////////////////////////// - // - // Parent/Children - // - //////////////////////////////////////////////////////////////////////////// - - /** - * @return the {@link FigureCanvas} that contains this {@link Figure}. - * @noreference @nooverride - */ - public FigureCanvas getFigureCanvas() { - return ((Figure) getParent()).getFigureCanvas(); - } - //////////////////////////////////////////////////////////////////////////// // // Figure diff --git a/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/draw2d/FigureUtils.java b/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/draw2d/FigureUtils.java index a1c250417..4740db4bc 100644 --- a/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/draw2d/FigureUtils.java +++ b/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/draw2d/FigureUtils.java @@ -12,7 +12,6 @@ *******************************************************************************/ package org.eclipse.wb.draw2d; -import org.eclipse.wb.internal.draw2d.FigureCanvas; import org.eclipse.wb.internal.draw2d.RootFigure; import org.eclipse.draw2d.IFigure; @@ -92,18 +91,6 @@ public static final void translateFigureToAbsolute2(IFigure figure, Translatable } } - /** - * Translates given {@link Translatable} from this {@link Figure} local coordinates to absolute ( - * {@link RootFigure} relative) coordinates. - */ - public static final void translateFigureToCanvas(Figure figure, Translatable translatable) { - translateFigureToAbsolute2(figure, translatable); - FigureCanvas figureCanvas = figure.getFigureCanvas(); - translatable.performTranslate( - -figureCanvas.getViewport().getHorizontalRangeModel().getValue(), - -figureCanvas.getViewport().getVerticalRangeModel().getValue()); - } - /** * Translates given {@link Translatable} from this absolute ({@link RootFigure} * relative) coordinates to bounds {@link IFigure} coordinates. diff --git a/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/internal/draw2d/FigureCanvas.java b/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/internal/draw2d/FigureCanvas.java index 1ad4675fd..5c1edde09 100644 --- a/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/internal/draw2d/FigureCanvas.java +++ b/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/internal/draw2d/FigureCanvas.java @@ -68,7 +68,7 @@ private static LightweightSystem createLightweightSystem() { } protected void setDefaultEventManager() { - m_rootFigure.getFigureCanvas().getLightweightSystem().setEventDispatcher(new EventManager(this)); + getLightweightSystem().setEventDispatcher(new EventManager(this)); } protected void setDefaultUpdateManager() { diff --git a/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/internal/draw2d/RootFigure.java b/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/internal/draw2d/RootFigure.java index bb50a0d4e..061a410c3 100644 --- a/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/internal/draw2d/RootFigure.java +++ b/org.eclipse.wb.core/src-draw2d/org/eclipse/wb/internal/draw2d/RootFigure.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2025 Google, Inc. 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 @@ -69,17 +69,10 @@ public EventDispatcher internalGetEventDispatcher() { // RootFigure // //////////////////////////////////////////////////////////////////////////// - /** - * @noreference @nooverride - */ - @Override - public FigureCanvas getFigureCanvas() { - return m_figureCanvas; - } @Override public UpdateManager getUpdateManager() { - return getFigureCanvas().getLightweightSystem().getUpdateManager(); + return m_figureCanvas.getLightweightSystem().getUpdateManager(); } /** diff --git a/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/graphical/policies/DirectTextEditPolicy.java b/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/graphical/policies/DirectTextEditPolicy.java index cbeeb99f8..6e90e78b9 100644 --- a/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/graphical/policies/DirectTextEditPolicy.java +++ b/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/graphical/policies/DirectTextEditPolicy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2025 Google, Inc. 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 @@ -12,9 +12,7 @@ *******************************************************************************/ package org.eclipse.wb.gef.graphical.policies; -import org.eclipse.wb.draw2d.Figure; -import org.eclipse.wb.draw2d.FigureUtils; - +import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; @@ -156,14 +154,14 @@ private boolean isEditing() { } /** - * Updates location of {@link Text} widget in host {@link Figure}. + * Updates location of {@link Text} widget in host {@link IFigure}. */ private void relocateTextWidget() { // prepare absolute bounds of host figure Rectangle hostBounds; { hostBounds = getHostFigure().getBounds().getCopy(); - FigureUtils.translateFigureToCanvas((Figure) getHostFigure().getParent(), hostBounds); + getHostFigure().translateToAbsolute(hostBounds); } // prepare text size org.eclipse.swt.graphics.Point textSize; @@ -191,7 +189,7 @@ private void relocateTextWidget() { /** * @param hostBounds - * the absolute bounds of host {@link Figure}. + * the absolute bounds of host {@link IFigure}. * @param textSize * the size of {@link Text} widget. * diff --git a/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/graphical/GraphicalViewer.java b/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/graphical/GraphicalViewer.java index d17c643c5..c43b266b8 100644 --- a/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/graphical/GraphicalViewer.java +++ b/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/graphical/GraphicalViewer.java @@ -129,7 +129,7 @@ protected final RootFigure getRootFigureInternal() { public void setEditDomain(EditDomain domain) { super.setEditDomain(domain); m_eventManager = new EditEventManager(m_canvas, domain, this); - getRootFigureInternal().getFigureCanvas().getLightweightSystem().setEventDispatcher(m_eventManager); + m_canvas.getLightweightSystem().setEventDispatcher(m_eventManager); } /**