diff --git a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug121220_AlphaTransparencyWithPatterns.java b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug121220_AlphaTransparencyWithPatterns.java index 04d60504032..13731af174f 100644 --- a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug121220_AlphaTransparencyWithPatterns.java +++ b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug121220_AlphaTransparencyWithPatterns.java @@ -2,8 +2,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageGcDrawer; import org.eclipse.swt.graphics.Pattern; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -16,16 +16,15 @@ public static void main(String[] args) { Shell shell = new Shell(disp); shell.setSize(400, 300); shell.setText("Pattern with alpha"); - Image image = new Image(disp, 50, 50); - { - GC gc = new GC(image); + final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { gc.setForeground(new Color(null, 255, 0, 0)); gc.drawLine(0, 0, 49, 49); gc.drawLine(0, 49, 49, 0); gc.setForeground(new Color(null, 0, 0, 200)); gc.drawString("Pat", 5, 5); - gc.dispose(); - } + }; + Image image = new Image(disp, imageGcDrawer, 50, 50); + final Pattern pat = new Pattern(disp, image); shell.addPaintListener(e -> { diff --git a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug536008_DarkDisabledLabel.java b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug536008_DarkDisabledLabel.java index a3337ec550d..3180e07b690 100644 --- a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug536008_DarkDisabledLabel.java +++ b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug536008_DarkDisabledLabel.java @@ -13,15 +13,24 @@ *******************************************************************************/ package org.eclipse.swt.tests.win32.snippets; +import java.util.function.Consumer; + import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.*; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageGcDrawer; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.*; - -import java.util.function.Consumer; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; public class Bug536008_DarkDisabledLabel { static void moveControl(Control control, Point point) { @@ -73,17 +82,13 @@ public static void main (String [] args) { int cx = 60; int cy = 60; int nRow = 0; - - Image image = new Image(display, cx / 2, cy / 2); - { - GC gc = new GC(image); + final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { gc.setBackground(backColor); gc.setForeground(foreColor); - - Rectangle imageBounds = image.getBounds(); - gc.fillRectangle(imageBounds); - gc.drawOval(imageBounds.x, imageBounds.y, imageBounds.width - 1, imageBounds.height - 1); - } + gc.fillRectangle(0, 0, width, height); + gc.drawOval(0, 0, width - 1, height - 1); + }; + Image image = new Image(display, imageGcDrawer, cx / 2, cy / 2); FillLayout fillLayout = new FillLayout(); fillLayout.marginWidth = 10; diff --git a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560358_DarkMenuBar.java b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560358_DarkMenuBar.java index 22b18eef607..3745aa1c5b3 100644 --- a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560358_DarkMenuBar.java +++ b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560358_DarkMenuBar.java @@ -14,22 +14,28 @@ package org.eclipse.swt.tests.win32.snippets; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.*; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Device; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageGcDrawer; import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.*; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; public class Bug560358_DarkMenuBar { static Image createMenuImage(Device a_Device) { - Image result = new Image(a_Device, 16, 16); - GC gc = new GC(result); + final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { + gc.setBackground(a_Device.getSystemColor(SWT.COLOR_BLUE)); + gc.fillRectangle(0, 0, width, height); - gc.setBackground(a_Device.getSystemColor(SWT.COLOR_BLUE)); - gc.fillRectangle(0, 0, 16, 16); + gc.setForeground(a_Device.getSystemColor(SWT.COLOR_RED)); + gc.drawOval(4, 4, 8, 8); + }; + Image result = new Image(a_Device, imageGcDrawer, 16, 16); - gc.setForeground(a_Device.getSystemColor(SWT.COLOR_RED)); - gc.drawOval(4, 4, 8, 8); - - gc.dispose(); return result; } diff --git a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560546_GC_drawString_vs_GC_drawText.java b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560546_GC_drawString_vs_GC_drawText.java index 4929496f617..02404f86868 100644 --- a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560546_GC_drawString_vs_GC_drawText.java +++ b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560546_GC_drawString_vs_GC_drawText.java @@ -13,9 +13,16 @@ *******************************************************************************/ package org.eclipse.swt.tests.win32.snippets; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageGcDrawer; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; public class Bug560546_GC_drawString_vs_GC_drawText { static Font fontSegoeUI; @@ -73,38 +80,40 @@ void function(GC gc, int x, int y, String string) { static void testSpeeds(Shell shell) { final int finalIterations = 20 * 1000; - String report = ""; - - Image image = new Image(shell.getDisplay(), 2000, 100); - GC gc = new GC(image); - for (int isFinalCalc = 0; isFinalCalc < 2; isFinalCalc++) { - for (int iTestString = 0; iTestString < testStrings.length; iTestString++) { - for (int iTestFunction = 0; iTestFunction < testFunctions.length; iTestFunction++) { - TestString testString = testStrings[iTestString]; - TestFunction testFunction = testFunctions[iTestFunction]; - - // Warm up before measuring - final int iterations = (isFinalCalc != 0) ? finalIterations : 10; - - final long time1 = System.nanoTime(); - for (int iIteration = 0; iIteration < iterations; iIteration++) { - testFunction.function(gc, 0, 0, testString.string); - } - final long time2 = System.nanoTime(); - - if (isFinalCalc != 0) { - final double elapsed = (time2 - time1) / 1000000000.0; - report += String.format("%s, %s - %.3f sec\n", testString.caption, testFunction.caption, elapsed); + final StringBuilder[] reportHolder = new StringBuilder[] { new StringBuilder() }; + + ImageGcDrawer gcDrawer = (gc, width, height) -> { + StringBuilder report = new StringBuilder(); + for (int isFinalCalc = 0; isFinalCalc < 2; isFinalCalc++) { + for (int iTestString = 0; iTestString < testStrings.length; iTestString++) { + for (int iTestFunction = 0; iTestFunction < testFunctions.length; iTestFunction++) { + TestString testString = testStrings[iTestString]; + TestFunction testFunction = testFunctions[iTestFunction]; + + // Warm up before measuring + final int iterations = (isFinalCalc != 0) ? finalIterations : 10; + + final long time1 = System.nanoTime(); + for (int iIteration = 0; iIteration < iterations; iIteration++) { + testFunction.function(gc, 0, 0, testString.string); + } + final long time2 = System.nanoTime(); + + if (isFinalCalc != 0) { + final double elapsed = (time2 - time1) / 1000000000.0; + report.append(String.format("%s, %s - %.3f sec\n", testString.caption, testFunction.caption, elapsed)); + } } } } - } - - gc.dispose(); + reportHolder[0] = report; + }; + Image image = new Image(shell.getDisplay(), gcDrawer, 2000, 100); + image.getImageData(); image.dispose(); MessageBox messageBox = new MessageBox(shell); - messageBox.setMessage(report); + messageBox.setMessage(reportHolder[0].toString()); messageBox.open(); } diff --git a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug563475_DarkDisabledTable.java b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug563475_DarkDisabledTable.java index 64c5e223e59..877ad0b32ae 100644 --- a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug563475_DarkDisabledTable.java +++ b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug563475_DarkDisabledTable.java @@ -15,9 +15,9 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.ImageGcDrawer; import org.eclipse.swt.internal.win32.OS; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -52,14 +52,13 @@ static void setColors(Control control, Color backColor, Color foreColor) { static Image createImage(Display display) { Color transparentColor = display.getSystemColor(SWT.COLOR_BLACK); - Image image = new Image(display, 16, 16); - - GC gc = new GC(image); - gc.setBackground(transparentColor); - gc.fillRectangle(image.getBounds()); - gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); - gc.fillRectangle(6, 6, 4, 4); - gc.dispose(); + final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { + gc.setBackground(transparentColor); + gc.fillRectangle(0, 0, width, height); + gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); + gc.fillRectangle(6, 6, 4, 4); + }; + Image image = new Image(display, imageGcDrawer, 16, 16); return image; } @@ -67,7 +66,7 @@ static Image createImage(Display display) { static Image createItemImage(Display display) { Image image = createImage(display); ImageData imageData = image.getImageData(); - imageData.transparentPixel = imageData.getPixel(0, 0); + imageData.transparentPixel = display.getSystemColor(SWT.COLOR_BLACK).getAlpha(); Image result = new Image(display, imageData); image.dispose(); diff --git a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug205199_Label_Image_vs_Text.java b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug205199_Label_Image_vs_Text.java index a8205aeea23..1c5a3da1ddd 100644 --- a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug205199_Label_Image_vs_Text.java +++ b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug205199_Label_Image_vs_Text.java @@ -15,8 +15,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageGcDrawer; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; @@ -55,12 +55,12 @@ public static void main(String[] args) { Composite container = new Composite(shell, SWT.NONE); container.setLayout(new RowLayout(SWT.HORIZONTAL)); - Image image = new Image(display, 32, 32); - Color color = display.getSystemColor(SWT.COLOR_DARK_GREEN); - GC gc = new GC(image); - gc.setBackground(color); - gc.fillRectangle(image.getBounds()); - gc.dispose(); + final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { + Color color = display.getSystemColor(SWT.COLOR_DARK_GREEN); + gc.setBackground(color); + gc.fillRectangle(0, 0, width, height); + }; + Image image = new Image(display, imageGcDrawer, 32, 32); Label labelText = new Label(container, SWT.NONE); Label labelImage = new Label(container, SWT.NONE); diff --git a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug529534_CTabFolder_topRight_wrapped.java b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug529534_CTabFolder_topRight_wrapped.java index dedb750fca2..fd960d91fe5 100644 --- a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug529534_CTabFolder_topRight_wrapped.java +++ b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug529534_CTabFolder_topRight_wrapped.java @@ -17,8 +17,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; -import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageGcDrawer; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.RowLayout; @@ -96,13 +96,13 @@ public static void main(String[] args) { private static Image image(Display display, int shapeColor) { Rectangle bounds = new Rectangle(0, 0, 16, 16); - Image image = new Image(display, bounds.width, bounds.height); - GC gc = new GC(image); - gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); - gc.fillRectangle(bounds); - gc.setBackground(display.getSystemColor(shapeColor)); - gc.fillOval(bounds.x, bounds.y, bounds.width, bounds.height); - gc.dispose(); + final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { + gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); + gc.fillRectangle(bounds); + gc.setBackground(display.getSystemColor(shapeColor)); + gc.fillOval(bounds.x, bounds.y, bounds.width, bounds.height); + }; + Image image = new Image(display, imageGcDrawer, bounds.width, bounds.height); return image; } } diff --git a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug562233_DisposeExceptions.java b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug562233_DisposeExceptions.java index becc590d9f5..303e2ccd77e 100644 --- a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug562233_DisposeExceptions.java +++ b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug562233_DisposeExceptions.java @@ -16,8 +16,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageGcDrawer; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -249,11 +249,11 @@ public static void main(String[] args) { ); // Make a small image - Image image = new Image (display, 16, 16); - GC gc = new GC(image); - gc.setBackground (display.getSystemColor (SWT.COLOR_BLUE)); - gc.fillRectangle (0, 0, 16, 16); - gc.dispose (); + final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { + gc.setBackground (display.getSystemColor (SWT.COLOR_BLUE)); + gc.fillRectangle (0, 0, width, height); + }; + Image image = new Image (display, imageGcDrawer, 16, 16); // And a Table to use it Table table = new Table(shell, 0); diff --git a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug577878_GTK_TreeTable_NoDragImageWithPaintItem.java b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug577878_GTK_TreeTable_NoDragImageWithPaintItem.java index 028e5c5cb6e..b5abbf858e5 100644 --- a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug577878_GTK_TreeTable_NoDragImageWithPaintItem.java +++ b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug577878_GTK_TreeTable_NoDragImageWithPaintItem.java @@ -14,11 +14,29 @@ package org.eclipse.swt.tests.manual; -import org.eclipse.swt.*; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSource; +import org.eclipse.swt.dnd.DragSourceAdapter; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Device; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageGcDrawer; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.swt.widgets.TreeItem; public final class Bug577878_GTK_TreeTable_NoDragImageWithPaintItem { static final int NUM_ROWS = 100; @@ -31,17 +49,15 @@ static String makeItemText(int iRow, int iCol) { } static Image makeItemImage(Device device, int iRow) { - Image image = new Image(device, IMG_CX, IMG_CY); - GC gc = new GC(image); - gc.setBackground(new Color(100,255,100)); - gc.fillRectangle(0, 0, IMG_CX-1, IMG_CY-1); - gc.drawRectangle(0, 0, IMG_CX-1, IMG_CY-1); - String text = Integer.toString(iRow); - Point textSize = gc.stringExtent(text); - gc.drawText(text, (IMG_CX - textSize.x) / 2, (IMG_CY - textSize.y) / 2); - - gc.dispose(); + final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { + gc.setBackground(new Color(100,255,100)); + gc.fillRectangle(0, 0, width-1, height-1); + gc.drawRectangle(0, 0, width-1, height-1); + Point textSize = gc.stringExtent(text); + gc.drawText(text, (IMG_CX - textSize.x) / 2, (IMG_CY - textSize.y) / 2); + }; + Image image = new Image(device, imageGcDrawer, IMG_CX, IMG_CY); return image; } diff --git a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0021_HdcLeak_ImageCreateGdipImage.java b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0021_HdcLeak_ImageCreateGdipImage.java index a3144523bcf..ab1546f0119 100644 --- a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0021_HdcLeak_ImageCreateGdipImage.java +++ b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0021_HdcLeak_ImageCreateGdipImage.java @@ -21,17 +21,15 @@ public class Issue0021_HdcLeak_ImageCreateGdipImage { static Image makeTrasparentImage(Display display) { - Image image = new Image(display, 40, 40); - GC gc = new GC(image); - Rectangle bounds = image.getBounds(); Color transparent = new Color(display, 0x00, 0x00, 0x00); Color contents = new Color(display, 0x00, 0x80, 0x00); - gc.setBackground(transparent); - gc.fillRectangle(bounds); - gc.setBackground(contents); - gc.fillOval(bounds.x, bounds.y, bounds.width, bounds.height); - gc.dispose(); - + final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { + gc.setBackground(transparent); + gc.fillRectangle(0, 0, width, height); + gc.setBackground(contents); + gc.fillOval(0, 0, width, height); + }; + Image image = new Image(display, imageGcDrawer, 40, 40); ImageData imageData = image.getImageData(); imageData.transparentPixel = 0; image.dispose(); diff --git a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0146_CopyImageToClipBoard.java b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0146_CopyImageToClipBoard.java index b5466defa7f..a399a014c14 100644 --- a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0146_CopyImageToClipBoard.java +++ b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0146_CopyImageToClipBoard.java @@ -19,8 +19,8 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageGcDrawer; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; @@ -37,14 +37,14 @@ public static void main(String[] args) { int size = 200; // Create a simple image - Image image = new Image(display, size, size); - GC gc = new GC(image); - gc.setBackground(new Color(128, 255, 128)); - gc.setForeground(new Color(0, 0, 0)); - gc.fillRectangle(0, 0, size - 1, size - 1); - gc.drawRectangle(0, 0, size - 1, size - 1); - gc.drawText("Hello World", 10, 10); - gc.dispose(); + final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { + gc.setBackground(new Color(128, 255, 128)); + gc.setForeground(new Color(0, 0, 0)); + gc.fillRectangle(0, 0, size - 1, size - 1); + gc.drawRectangle(0, 0, size - 1, size - 1); + gc.drawText("Hello World", 10, 10); + }; + Image image = new Image(display, imageGcDrawer, size, size); // Press the button to copy the image data to the clipboard Button button = new Button(shell, SWT.PUSH); diff --git a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0603_WrongTaskBarOverlays.java b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0603_WrongTaskBarOverlays.java index af54efd05ce..98fda0a3f9f 100644 --- a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0603_WrongTaskBarOverlays.java +++ b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue0603_WrongTaskBarOverlays.java @@ -14,11 +14,15 @@ package org.eclipse.swt.tests.manual; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; +import org.eclipse.swt.graphics.ImageGcDrawer; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TaskItem; public final class Issue0603_WrongTaskBarOverlays { public static void main(String[] args) { @@ -78,14 +82,12 @@ public static void main(String[] args) { } }); - Image image = new Image(display, 16, 16); - { - GC gc = new GC(image); + final ImageGcDrawer imageGcDrawer = (gc, width, height) -> { gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); - gc.fillRectangle(0, 0, 16, 16); - gc.dispose(); - } + gc.fillRectangle(0, 0, width, height); + }; + Image image = new Image(display, imageGcDrawer, 16, 16); Button chkImage = new Button(shell, SWT.CHECK); chkImage.setText("Set Image overlay for me");