Bug 421383 - [Graphics] Scaling issues on high DPI displays
improved Snippet367
diff --git a/examples/org.eclipse.swt.snippets/collapseall.png b/examples/org.eclipse.swt.snippets/collapseall.png
deleted file mode 100644
index 0ac25a9..0000000
--- a/examples/org.eclipse.swt.snippets/collapseall.png
+++ /dev/null
Binary files differ
diff --git a/examples/org.eclipse.swt.snippets/collapseall@1.5x.png b/examples/org.eclipse.swt.snippets/collapseall@1.5x.png
deleted file mode 100644
index 24dd563..0000000
--- a/examples/org.eclipse.swt.snippets/collapseall@1.5x.png
+++ /dev/null
Binary files differ
diff --git a/examples/org.eclipse.swt.snippets/collapseall@2x.png b/examples/org.eclipse.swt.snippets/collapseall@2x.png
deleted file mode 100644
index 9fecefb..0000000
--- a/examples/org.eclipse.swt.snippets/collapseall@2x.png
+++ /dev/null
Binary files differ
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java
index 5836cca..afec8ee 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java
@@ -10,69 +10,81 @@
*******************************************************************************/
package org.eclipse.swt.snippets;
-/*
- * Snippet to demonstrate the use of the DPI aware Image constructors.
- */
import org.eclipse.swt.*;
-import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
+/**
+ * Snippet to demonstrate the use of the DPI-aware Image constructors.
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
public class Snippet367 {
+ private static final String IMAGE_100 = "eclipse16.png";
+ private static final String IMAGE_150 = "eclipse24.png";
+ private static final String IMAGE_200 = "eclipse32.png";
+ private static final String IMAGES_ROOT = "bin/org/eclipse/swt/snippets/";
+
+ private static final String IMAGE_PATH_100 = IMAGES_ROOT + IMAGE_100;
+ private static final String IMAGE_PATH_150 = IMAGES_ROOT + IMAGE_150;
+ private static final String IMAGE_PATH_200 = IMAGES_ROOT + IMAGE_200;
+
public static void main (String [] args) {
- final Display display = new Display ();
final ImageFileNameProvider filenameProvider = new ImageFileNameProvider () {
@Override
public String getImagePath (int zoom) {
switch (zoom) {
- case 100:
- return "collapseall.png";
case 150:
- return "collapseall@1.5x.png";
+ return IMAGE_PATH_150;
case 200:
- return "collapseall@2x.png";
+ return IMAGE_PATH_200;
+ default:
+ return IMAGE_PATH_100;
}
- return null;
}
};
final ImageDataProvider imageDataProvider = new ImageDataProvider () {
@Override
public ImageData getImageData (int zoom) {
switch (zoom) {
- case 100:
- return new ImageData ("collapseall.png");
case 150:
- return new ImageData ("collapseall@1.5x.png");
+ return new ImageData (IMAGE_PATH_150);
case 200:
- return new ImageData ("collapseall@2x.png");
+ return new ImageData (IMAGE_PATH_200);
+ default:
+ return new ImageData (IMAGE_PATH_100);
}
- return null;
}
};
- final Image image_even = new Image (display, filenameProvider);
- final Image image_odd = new Image (display, imageDataProvider);
+
+ final Display display = new Display ();
final Shell shell = new Shell (display);
- shell.setLayout (new GridLayout ());
- final CTabFolder folder = new CTabFolder (shell, SWT.BORDER);
- folder.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, false));
- folder.setSimple (false);
- folder.setUnselectedImageVisible (false);
- for (int i = 0; i < 8; i++) {
- CTabItem item = new CTabItem (folder, SWT.NONE);
- item.setText ("Item "+i);
- item.setImage ((i % 2 == 0) ? image_even : image_odd);
- Text text = new Text (folder, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
- text.setText ("Switch\nTabs:\n Image\nZooms...\n");
- item.setControl (text);
- }
- shell.setSize (300, 300);
+ shell.setLayout (new GridLayout (2, false));
+
+ new Label (shell, SWT.NONE).setText (IMAGE_200 + ":");
+ new Label (shell, SWT.NONE).setImage (new Image(display, IMAGE_PATH_200));
+
+ new Label (shell, SWT.NONE).setText (IMAGE_150 + ":");
+ new Label (shell, SWT.NONE).setImage (new Image(display, IMAGE_PATH_150));
+
+ new Label (shell, SWT.NONE).setText (IMAGE_100 + ":");
+ new Label (shell, SWT.NONE).setImage (new Image(display, IMAGE_PATH_100));
+
+ new Label (shell, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, false, 2, 1));
+
+ new Label (shell, SWT.NONE).setText ("ImageFileNameProvider:");
+ new Label (shell, SWT.NONE).setImage (new Image (display, filenameProvider));
+
+ new Label (shell, SWT.NONE).setText ("ImageDataProvider:");
+ new Label (shell, SWT.NONE).setImage (new Image (display, imageDataProvider));
+
+ shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
- image_even.dispose ();
- image_odd.dispose();
display.dispose ();
}
}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/eclipse16.png b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/eclipse16.png
new file mode 100644
index 0000000..7fc6951
--- /dev/null
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/eclipse16.png
Binary files differ
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/eclipse24.png b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/eclipse24.png
new file mode 100644
index 0000000..fbddd3c
--- /dev/null
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/eclipse24.png
Binary files differ
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/eclipse32.png b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/eclipse32.png
new file mode 100644
index 0000000..bf85680
--- /dev/null
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/eclipse32.png
Binary files differ