Bug 578987 - [GTK] Snippet 246 needs clarity improvements
With this patch this snippet becomes a lot more clear as to what it
does.
Makes the generated image twice the size as previous one is too tiny on
newer high res monitors.
Change-Id: I71a02c3beef800e45250d192300d259aeacdc21f
Signed-off-by: Joel Majano <jmajano@redhat.com>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/191265
Tested-by: Alexander Kurtakov <akurtako@redhat.com>
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet246.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet246.java
index a8eb744..331228d 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet246.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet246.java
@@ -21,32 +21,51 @@
*/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class Snippet246 {
+ static Display display;
public static void main(String[] args) {
- Display display = new Display();
- Font font = new Font(display, "Comic Sans MS", 24, SWT.BOLD);
- Image image = new Image(display, 87, 48);
+ display = new Display();
+ Shell shell = new Shell(display);
+ shell.setText("Snippet 246");
+ GridLayout layout = new GridLayout(2, false);
+ shell.setLayout(layout);
+ createImage();
+
+ String executionPath = System.getProperty("user.dir");
+ Label label = new Label(shell, SWT.WRAP);
+ label.setText("File created as: " + executionPath.replace("\\", "/")+"/swt.png");
+ shell.pack();
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+
+ private static void createImage() {
+ Font font = new Font(display, "Comic Sans MS", 48, SWT.BOLD);
+ Image image = new Image(display, 174, 96);
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
gc.fillRectangle(image.getBounds());
gc.setFont(font);
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
- gc.drawString("S", 3, 0);
+ gc.drawString("S", 3, 10);
gc.setForeground(display.getSystemColor(SWT.COLOR_GREEN));
- gc.drawString("W", 25, 0);
+ gc.drawString("W", 50, 10);
gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
- gc.drawString("T", 62, 0);
+ gc.drawString("T", 124, 10);
gc.dispose();
ImageLoader loader = new ImageLoader();
- loader.data = new ImageData[] {image.getImageData()};
+ loader.data = new ImageData[] { image.getImageData() };
loader.save("swt.png", SWT.IMAGE_PNG);
-
image.dispose();
font.dispose();
- display.dispose();
}
}