Skip to content

Commit 469cdba

Browse files
Replace usages of new Image(device, width, height) (#2116)
Replacing it with imageGcDrawer
1 parent ff7036c commit 469cdba

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameLinkedMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ void doRename(boolean showPreview) {
387387
Point size;
388388
try {
389389
size= composite.getSize();
390-
image= new Image(gc.getDevice(), size.x, size.y);
390+
image= new Image(gc.getDevice(), (iGc, width, height) -> {}, size.x, size.y) ;
391391
gc.copyArea(image, 0, 0);
392392
} finally {
393393
gc.dispose();

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/breadcrumb/BreadcrumbItemDropDown.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.eclipse.swt.graphics.Image;
3232
import org.eclipse.swt.graphics.ImageData;
3333
import org.eclipse.swt.graphics.ImageDataProvider;
34+
import org.eclipse.swt.graphics.ImageGcDrawer;
3435
import org.eclipse.swt.graphics.Point;
3536
import org.eclipse.swt.graphics.RGB;
3637
import org.eclipse.swt.graphics.Rectangle;
@@ -104,16 +105,22 @@ protected void drawCompositeImage(int width, int height) {
104105
Display display= fParentComposite.getDisplay();
105106

106107
ImageDataProvider imageProvider= zoom -> {
107-
Image image= new Image(display, ARROW_SIZE, ARROW_SIZE * 2);
108-
109-
GC gc= new GC(image, fLTR ? SWT.LEFT_TO_RIGHT : SWT.RIGHT_TO_LEFT);
110-
gc.setAntialias(SWT.ON);
111-
112-
Color triangleColor= createColor(SWT.COLOR_LIST_FOREGROUND, SWT.COLOR_LIST_BACKGROUND, 20, display);
113-
gc.setBackground(triangleColor);
114-
gc.fillPolygon(new int[] { 0, 0, ARROW_SIZE, ARROW_SIZE, 0, ARROW_SIZE * 2 });
115-
gc.dispose();
116-
triangleColor.dispose();
108+
ImageGcDrawer drawer = new ImageGcDrawer() {
109+
@Override
110+
public void drawOn(GC gc, int iWidth, int iHeight) {
111+
gc.setAntialias(SWT.ON);
112+
Color triangleColor= createColor(SWT.COLOR_LIST_FOREGROUND, SWT.COLOR_LIST_BACKGROUND, 20, display);
113+
gc.setBackground(triangleColor);
114+
gc.fillPolygon(new int[] { 0, 0, ARROW_SIZE, ARROW_SIZE, 0, ARROW_SIZE * 2 });
115+
triangleColor.dispose();
116+
}
117+
118+
@Override
119+
public int getGcStyle() {
120+
return fLTR ? SWT.LEFT_TO_RIGHT : SWT.RIGHT_TO_LEFT;
121+
}
122+
};
123+
Image image= new Image(display, drawer, ARROW_SIZE, ARROW_SIZE * 2);
117124

118125
ImageData imageData= image.getImageData(zoom);
119126
image.dispose();

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/javadoc/SignatureStylingColorPreferenceMenuItem.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
import org.eclipse.swt.SWT;
2121
import org.eclipse.swt.graphics.Color;
22-
import org.eclipse.swt.graphics.GC;
2322
import org.eclipse.swt.graphics.Image;
2423
import org.eclipse.swt.graphics.ImageData;
2524
import org.eclipse.swt.graphics.ImageDataProvider;
25+
import org.eclipse.swt.graphics.ImageGcDrawer;
2626
import org.eclipse.swt.graphics.RGB;
2727
import org.eclipse.swt.widgets.ColorDialog;
2828
import org.eclipse.swt.widgets.Shell;
@@ -54,16 +54,14 @@ class SignatureStylingColorPreferenceMenuItem extends Action implements ImageDat
5454

5555
@Override
5656
public ImageData getImageData(int zoom) {
57-
Image image= new Image(shell.getDisplay(), 16, 16);
58-
GC gc= new GC(image);
59-
60-
gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BORDER));
61-
gc.setBackground(new Color(shell.getDisplay(), getCurrentColor()));
62-
gc.fillRectangle(image.getBounds());
63-
gc.setLineWidth(2);
64-
gc.drawRectangle(image.getBounds());
65-
gc.dispose();
66-
57+
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
58+
gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BORDER));
59+
gc.setBackground(new Color(shell.getDisplay(), getCurrentColor()));
60+
gc.fillRectangle(0, 0, width, height);
61+
gc.setLineWidth(2);
62+
gc.drawRectangle(0, 0, width, height);
63+
};
64+
Image image= new Image(shell.getDisplay(), imageGcDrawer, 16, 16);
6765
ImageData data= image.getImageData(zoom);
6866
image.dispose();
6967
return data;

0 commit comments

Comments
 (0)