Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiraj Modi2015-03-04 05:04:40 -0500
committerNiraj Modi2015-03-04 05:04:40 -0500
commit8826217ea22800d62831857ec0d0597d717c1c9f (patch)
tree757fce1d84786d3bc16fe67d46d5ec884c016689
parent616ae7e023e5caa7916df827dc7611e51381bb63 (diff)
downloadeclipse.platform.swt-slakkimsetti/hiDpiWork.tar.gz
eclipse.platform.swt-slakkimsetti/hiDpiWork.tar.xz
eclipse.platform.swt-slakkimsetti/hiDpiWork.zip
Bug 421383 - [Graphics] Scaling issues on high DPI displaysslakkimsetti/hiDpiWork
- Added a DpiUtil class for common constants & utility methods. Change-Id: I7086f4221ab951accb2ce5c9161b85192a6172e4 Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DpiUtil.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DpiUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DpiUtil.java
new file mode 100644
index 0000000000..4b5f86a66e
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DpiUtil.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.graphics;
+
+/**
+ * This class hold common constants and utility functions w.r.t. to SWT high DPI
+ * functionality.
+ *
+ * @since 3.104
+ */
+public class DpiUtil {
+ public static final char FILE_EXTENSION_SEPARATOR = '.';
+ public static final String FILE_ONE_HALF_IDENTIFIER = "@1.5x";
+ public static final String FILE_DOUBLE_IDENTIFIER = "@2x";
+ public static final int SIZE = 3;
+
+ /**
+ * Prepare an array of Image filenames for various DPI levels.
+ *
+ * @return String[] image filenames
+ */
+ public static String[] getImageNames (String fileName) {
+ if (fileName == null || fileName.trim().length() == 0)
+ return new String[0];
+
+ String[] fileNames = new String[SIZE];
+ int separatorLoc = fileName.lastIndexOf (FILE_EXTENSION_SEPARATOR);
+ if (separatorLoc != -1) {
+ fileNames[0] = fileName;
+ fileNames[1] = fileName.substring (0, separatorLoc) + FILE_ONE_HALF_IDENTIFIER + FILE_EXTENSION_SEPARATOR
+ + fileName.substring(separatorLoc + 1);
+ fileNames[2] = fileName.substring (0, separatorLoc) + FILE_DOUBLE_IDENTIFIER + FILE_EXTENSION_SEPARATOR
+ + fileName.substring (separatorLoc + 1);
+ }
+ return fileNames;
+ }
+
+ /**
+ * Compute the imageSelector index based on the DPI value.
+ *
+ * @return imageSelector index
+ */
+ public static int mapDpiToImageSelectorIndex (int dpi) {
+ int imageSelectorIndex;
+ if (dpi >= 192) {
+ imageSelectorIndex = 2;
+ } else if (dpi >= 144) {
+ imageSelectorIndex = 1;
+ } else {
+ imageSelectorIndex = 0;
+ }
+ return imageSelectorIndex;
+ }
+
+ /**
+ * Compute the imageSelector index based on the zoom value.
+ *
+ * @return imageSelector index
+ */
+ public static int mapZoomToImageSelectorIndex (int zoom) {
+ int imageSelectorIndex = 0;
+ switch (zoom) {
+ case 200:
+ imageSelectorIndex = 2;
+ break;
+ case 150:
+ imageSelectorIndex = 1;
+ break;
+ case 100:
+ default:
+ imageSelectorIndex = 0;
+ break;
+ }
+ return imageSelectorIndex;
+ }
+}

Back to the top