Skip to content

Commit a750f57

Browse files
committed
Use DrawableTextUtilities for Label and TextFlow figures
This adds a new getTextUtilitie() method to the root figure, which returns a DrawableTextUtilities, rather than a TextUtilities instance.
1 parent 8726ed7 commit a750f57

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

org.eclipse.draw2d/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Plugin.name
44
Bundle-SymbolicName: org.eclipse.draw2d;singleton:=true
5-
Bundle-Version: 3.20.200.qualifier
5+
Bundle-Version: 3.21.0.qualifier
66
Bundle-Vendor: %Plugin.providerName
77
Bundle-Localization: plugin
88
Export-Package: org.eclipse.draw2d,

org.eclipse.draw2d/src/org/eclipse/draw2d/FigureUtilities.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ public static int getTextWidth(String s, Font f) {
178178
return getTextDimension(s, f).x;
179179
}
180180

181+
/**
182+
* @since 3.21
183+
*/
184+
public static TextUtilities getTextUtilities(IFigure figure) {
185+
if (getRoot(figure) instanceof LightweightSystem.RootFigure rootFigure) {
186+
return rootFigure.getTextUtilities();
187+
}
188+
return TextUtilities.INSTANCE;
189+
}
190+
181191
/**
182192
* Returns a Color the same as the passed color in a lighter hue.
183193
*

org.eclipse.draw2d/src/org/eclipse/draw2d/Label.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2010 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
@@ -689,9 +689,8 @@ public void setTextPlacement(int where) {
689689
* @return a <code>TextUtilities</code> instance
690690
* @since 3.4
691691
*/
692-
@SuppressWarnings("static-method")
693692
public TextUtilities getTextUtilities() {
694-
return TextUtilities.INSTANCE;
693+
return FigureUtilities.getTextUtilities(this);
695694
}
696695

697696
/**

org.eclipse.draw2d/src/org/eclipse/draw2d/LightweightSystem.java

Lines changed: 12 additions & 1 deletion
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
@@ -39,6 +39,7 @@
3939
import org.eclipse.swt.widgets.Listener;
4040

4141
import org.eclipse.draw2d.geometry.Rectangle;
42+
import org.eclipse.draw2d.internal.DrawableTextUtilities;
4243

4344
/**
4445
* The LightweightSystem is the link between SWT and Draw2d. It is the component
@@ -55,6 +56,7 @@
5556
*/
5657
public class LightweightSystem {
5758

59+
private DrawableTextUtilities textUtilities;
5860
private Canvas canvas;
5961
IFigure contents;
6062
private IFigure root;
@@ -236,6 +238,8 @@ public void setControl(Canvas c) {
236238
getEventDispatcher().setControl(c);
237239
addListeners();
238240

241+
textUtilities = new DrawableTextUtilities(canvas);
242+
239243
// Size the root figure and contents to the current control's size
240244
Rectangle r = new Rectangle(canvas.getClientArea());
241245
r.setLocation(0, 0);
@@ -351,6 +355,13 @@ public boolean isMirrored() {
351355
public boolean isShowing() {
352356
return true;
353357
}
358+
359+
/* package */ TextUtilities getTextUtilities() {
360+
if (textUtilities == null) {
361+
return TextUtilities.INSTANCE;
362+
}
363+
return textUtilities;
364+
}
354365
}
355366

356367
/**

org.eclipse.draw2d/src/org/eclipse/draw2d/text/TextFlow.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2010 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
@@ -19,6 +19,7 @@
1919
import org.eclipse.swt.graphics.TextLayout;
2020

2121
import org.eclipse.draw2d.ColorConstants;
22+
import org.eclipse.draw2d.FigureUtilities;
2223
import org.eclipse.draw2d.Graphics;
2324
import org.eclipse.draw2d.TextUtilities;
2425
import org.eclipse.draw2d.geometry.Dimension;
@@ -733,9 +734,8 @@ protected FlowUtilities getFlowUtilities() {
733734
* @return a <code>TextUtilities</code> instance
734735
* @since 3.4
735736
*/
736-
@SuppressWarnings("static-method")
737737
protected TextUtilities getTextUtilities() {
738-
return TextUtilities.INSTANCE;
738+
return FigureUtilities.getTextUtilities(this);
739739
}
740740

741741
}

org.eclipse.gef/src/org/eclipse/gef/ui/palette/FlyoutPaletteComposite.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@
8181
import org.eclipse.draw2d.LightweightSystem;
8282
import org.eclipse.draw2d.MarginBorder;
8383
import org.eclipse.draw2d.PositionConstants;
84-
import org.eclipse.draw2d.TextUtilities;
8584
import org.eclipse.draw2d.Triangle;
8685
import org.eclipse.draw2d.geometry.Dimension;
87-
import org.eclipse.draw2d.internal.DrawableTextUtilities;
8886

8987
import org.eclipse.gef.GraphicalViewer;
9088
import org.eclipse.gef.dnd.TemplateTransfer;
@@ -1116,7 +1114,6 @@ protected void updateState() {
11161114
private class TitleLabel extends Label {
11171115
protected static final Border BORDER = new MarginBorder(4, 3, 4, 3);
11181116
protected static final Border TOOL_TIP_BORDER = new MarginBorder(0, 2, 0, 2);
1119-
private TextUtilities textUtilities;
11201117

11211118
public TitleLabel(boolean isHorizontal) {
11221119
super(GEFMessages.Palette_Label, InternalImages.get(InternalImages.IMG_PALETTE));
@@ -1128,14 +1125,6 @@ public TitleLabel(boolean isHorizontal) {
11281125
setForegroundColor(ColorConstants.listForeground);
11291126
}
11301127

1131-
@Override
1132-
public TextUtilities getTextUtilities() {
1133-
if (textUtilities == null) {
1134-
textUtilities = new DrawableTextUtilities(paletteContainer);
1135-
}
1136-
return textUtilities;
1137-
}
1138-
11391128
@Override
11401129
public IFigure getToolTip() {
11411130
if (isTextTruncated()) {

0 commit comments

Comments
 (0)