Skip to content

Commit fed7869

Browse files
Replace usages of new Image(device, width, height)
Replacing it with imageGcDrawer
1 parent f720f49 commit fed7869

File tree

2 files changed

+22
-25
lines changed
  • bundles
    • org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom
    • org.eclipse.swt.tools.spies/src/org/eclipse/swt/tools/internal

2 files changed

+22
-25
lines changed

bundles/org.eclipse.swt.tools.spies/src/org/eclipse/swt/tools/internal/Sleak.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,11 @@ private void saveToFile(boolean prompt) {
359359
if (saveImages) {
360360
String suffix = String.format("%05d.png", i++);
361361
String pngName = String.format("%s_%s", fileName, suffix);
362-
Image image = new Image(saveAs.getDisplay(), 100, 100);
362+
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
363+
draw(gc, object);
364+
};
365+
Image image = new Image(saveAs.getDisplay(), imageGcDrawer, 100, 100);
363366
try {
364-
GC gc = new GC(image);
365-
try {
366-
draw(gc, object);
367-
} finally {
368-
gc.dispose();
369-
}
370367
ImageLoader loader = new ImageLoader();
371368
loader.data = new ImageData[] { image.getImageData() };
372369
loader.save(pngName, SWT.IMAGE_PNG);

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -1593,31 +1593,31 @@ void createCaretBitmaps() {
15931593
leftCaretBitmap.dispose();
15941594
}
15951595
int lineHeight = renderer.getLineHeight();
1596-
leftCaretBitmap = new Image(display, caretWidth, lineHeight);
1597-
GC gc = new GC (leftCaretBitmap);
1598-
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
1599-
gc.fillRectangle(0, 0, caretWidth, lineHeight);
1600-
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
1601-
gc.drawLine(0,0,0,lineHeight);
1602-
gc.drawLine(0,0,caretWidth-1,0);
1603-
gc.drawLine(0,1,1,1);
1604-
gc.dispose();
1596+
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
1597+
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
1598+
gc.fillRectangle(0, 0, width, height);
1599+
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
1600+
gc.drawLine(0,0,0,height);
1601+
gc.drawLine(0,0,width-1,0);
1602+
gc.drawLine(0,1,1,1);
1603+
};
1604+
leftCaretBitmap = new Image(display, imageGcDrawer, caretWidth, lineHeight);
16051605

16061606
if (rightCaretBitmap != null) {
16071607
if (defaultCaret != null && rightCaretBitmap.equals(defaultCaret.getImage())) {
16081608
defaultCaret.setImage(null);
16091609
}
16101610
rightCaretBitmap.dispose();
16111611
}
1612-
rightCaretBitmap = new Image(display, caretWidth, lineHeight);
1613-
gc = new GC (rightCaretBitmap);
1614-
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
1615-
gc.fillRectangle(0, 0, caretWidth, lineHeight);
1616-
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
1617-
gc.drawLine(caretWidth-1,0,caretWidth-1,lineHeight);
1618-
gc.drawLine(0,0,caretWidth-1,0);
1619-
gc.drawLine(caretWidth-1,1,1,1);
1620-
gc.dispose();
1612+
final ImageGcDrawer imageGcDrawer1 = (gc, width, height) -> {
1613+
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
1614+
gc.fillRectangle(0, 0, width, height);
1615+
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
1616+
gc.drawLine(width-1,0,width-1,height);
1617+
gc.drawLine(0,0,width-1,0);
1618+
gc.drawLine(width-1,1,1,1);
1619+
};
1620+
rightCaretBitmap = new Image(display, imageGcDrawer1, caretWidth, lineHeight);
16211621
}
16221622
/**
16231623
* Moves the selected text to the clipboard. The text will be put in the

0 commit comments

Comments
 (0)