Skip to content

Commit 4b38172

Browse files
committed
Simplify creation of PopupHelper LWS when Draw2D autoscaling is enabled
When the auto-scaling property is set, a ScalableLayeredPane is injected between the root figure and its contents. The issue with this approach is that the contents is also stored as a local variable of the LightweightSystem class, which is no longer updated and therefore always null. This pane is now embedded in a custom RootFigure subclass.
1 parent 3d6f654 commit 4b38172

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

org.eclipse.draw2d/src/org/eclipse/draw2d/PopUpHelper.java

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -222,43 +222,57 @@ protected void show() {
222222

223223
private class PopupHelperLightweightSystem extends LightweightSystem {
224224

225-
/**
226-
* The scalable pane that is injected between the root figure and the contents
227-
* of this viewport.
228-
*/
229-
private final ScalableLayeredPane scalablePane;
230-
231-
private PopupHelperLightweightSystem() {
232-
scalablePane = new ScalableLayeredPane(true);
233-
scalablePane.setLayoutManager(new StackLayout());
234-
getRootFigure().add(scalablePane);
235-
}
236-
237-
/**
238-
* Updates the scale factor of the scalable pane to the given value.
239-
*
240-
* @param scale The new scale factor.
241-
*/
242-
private void setScale(double scale) {
243-
scalablePane.setScale(scale);
244-
}
245-
246225
@Override
247226
public void setControl(Canvas c) {
248227
if (c == null) {
249228
return;
250229
}
251230

252-
InternalDraw2dUtils.configureForAutoscalingMode(c, this::setScale);
231+
InternalDraw2dUtils.configureForAutoscalingMode(c, getRootFigure()::setScale);
253232

254233
super.setControl(c);
255234
}
256235

257236
@Override
258-
public void setContents(IFigure figure) {
259-
scalablePane.removeAll();
260-
if (figure != null) {
261-
scalablePane.add(figure);
237+
protected RootFigure createRootFigure() {
238+
RootFigure f = new ScalableRootFigure();
239+
f.addNotify();
240+
f.setOpaque(true);
241+
f.setLayoutManager(new StackLayout());
242+
return f;
243+
}
244+
245+
@Override
246+
public ScalableFigure getRootFigure() {
247+
return (ScalableFigure) super.getRootFigure();
248+
}
249+
250+
private class ScalableRootFigure extends RootFigure implements ScalableFigure {
251+
/**
252+
* The scalable pane that is injected between the root figure and the contents
253+
* of this viewport.
254+
*/
255+
private final ScalableLayeredPane scalablePane;
256+
257+
private ScalableRootFigure() {
258+
scalablePane = new ScalableLayeredPane(true);
259+
scalablePane.setLayoutManager(new StackLayout());
260+
super.add(scalablePane, null, 0);
261+
}
262+
263+
@Override
264+
public void add(IFigure figure, Object constraint, int index) {
265+
scalablePane.add(figure, constraint, index);
266+
}
267+
268+
@Override
269+
public double getScale() {
270+
return scalablePane.getScale();
271+
}
272+
273+
@Override
274+
public void setScale(double scale) {
275+
scalablePane.setScale(scale);
262276
}
263277
}
264278
}

0 commit comments

Comments
 (0)