Skip to content
Snippets Groups Projects
Commit b31c1849 authored by Simon Barner's avatar Simon Barner
Browse files

Unify OS/Platform case distinctions


- Rework SystemUtils and use it everywhere
- FontUtils: Add CODEFONT_11PT for native font used to render code

Issue-Ref: 2243
Signed-off-by: default avatarSimon Barner <barner@fortiss.org>
parent a733e48c
No related branches found
No related tags found
1 merge request!32443 os architecture case distinctions
......@@ -3,7 +3,7 @@ ActionUtils.java f16dd179005f48c747d2c9cf250b05e7225495cf GREEN
ConstraintsBaseUIUtils.java 50c26b90a6ebe6c7f7861092dac5ebc1f3fc0ce3 GREEN
DragAndDropBaseUtils.java 4308b2151a7075adeb4f7e7246859d421150415b GREEN
EllipseLayoutUIUtils.java 271e287f1e5befb03a9d115a98e22453056521e0 GREEN
FontUtils.java fe542b8d8bfebeaf19c09f2b36d7b0f8cfb3b63f GREEN
FontUtils.java a167a05bdaa8da9853705cc5134f30f6d81bc9f2 YELLOW
GCStateManager.java 983973a92376b5c757c1253b32e33d0666ccdf7b GREEN
LayoutDataUIUtils.java 8034bbb9f595092f56807525abcbf23fd5d01428 GREEN
PropertiesViewUtils.java d345b4501c4092228edf1c98e0189317d53aaf22 GREEN
......
......@@ -15,6 +15,10 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.utils;
import static org.fortiss.tooling.base.utils.SystemUtils.isLinuxPlatform;
import static org.fortiss.tooling.base.utils.SystemUtils.isMacOSXPlatform;
import static org.fortiss.tooling.base.utils.SystemUtils.isWindowsPlatform;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
......@@ -38,9 +42,25 @@ public class FontUtils {
public static FontData VERDANA_16PT = new FontData("Verdana", 16, SWT.NORMAL);
/** Verdana 14pt font. */
public static FontData VERDANA_18PT = new FontData("Verdana", 18, SWT.NORMAL);
/** "Code" 11pt font. */
public static FontData CODEFONT_11PT = createCodeFontData(11);
/** Creates a {@link Font} from the given {@link FontData}, which MUST be disposed after use. */
public static Font createFont(FontData fontData) {
return new Font(Display.getCurrent(), fontData);
}
/** Returns the {@link FontData} used to represent code (OS specific). */
private static FontData createCodeFontData(int height) {
String font = "Courier";
if(isMacOSXPlatform()) {
font = "Monaco";
} else if(isWindowsPlatform()) {
font = "Consolas";
} else if(isLinuxPlatform()) {
font = "Monospace";
}
return new FontData(font, height, SWT.NORMAL);
}
}
......@@ -13,6 +13,6 @@ PointUtils.java b21c92cc8e80ece9d87ede8a750f4de314379743 GREEN
PointsUtils.java bad69811c59004948929f6a57edd5a79c0bf8643 GREEN
RectangleLayoutUtils.java cdd61d162761da7f3e1d3512264135b9b0d564ff GREEN
SnapToGridUtils.java 413785d7a8655db31a129b6f821e1d5f859aa726 GREEN
SystemUtils.java b36590c6934413cd2408de1321af5254dc263e11 GREEN
SystemUtils.java 8546c23e43551a58f4aca273015c496546793611 YELLOW
VisualizationModelElementFactory.java 18e67450ee4cf4a03dc88a10becb0fb6ce4c1bad GREEN
ZoomUtils.java a339613fde18281bed3b55b529a053d348545bc7 GREEN
......@@ -18,13 +18,41 @@ package org.fortiss.tooling.base.utils;
/**
* Utility functions that deal with the underlying system.
*
* @author ratiu
* @author ratiu, barner
*/
public class SystemUtils {
/** Returns true if we are in a Windows system. */
public static boolean isWindowsOperatingSystem() {
return System.getProperty("os.name").startsWith("Windows");
/** Predicate if the current platform is Windows. */
public static boolean isWindowsPlatform() {
String osName = System.getProperty("os.name");
return osName != null && osName.contains("Windows");
}
/** Predicate if the current platform is Linux. */
public static boolean isLinuxPlatform() {
String osName = System.getProperty("os.name");
return osName != null && osName.contains("Linux");
}
/** Predicate if the current platform is Mac OS X. */
public static boolean isMacOSXPlatform() {
String osName = System.getProperty("os.name");
return osName != null && osName.contains("Mac OS X.");
}
/** Predicate if the current <b>Java VM</b> architecture is 64 bit. */
public static boolean isVm64BitArch() {
String osArch = System.getProperty("os.arch");
return osArch != null && osArch.contains("64");
}
/** Predicate if the current <b>OS</b> architecture is 64 bit. */
public static boolean isOs64BitArch() {
if(isWindowsPlatform()) {
return System.getenv("ProgramFiles(x86)") != null;
}
return isVm64BitArch();
}
/**
......@@ -32,7 +60,7 @@ public class SystemUtils {
* interpreted, then an empty string is returned.
*/
public static String interpretProcessExitValues(int exitValue) {
if(!isWindowsOperatingSystem()) {
if(!isWindowsPlatform()) {
switch(exitValue) {
case 126:
return "Command not found";
......
ToolingGraphicsGLUIActivator.java 86df10a01835d65709fb655622a1feb2b1a44948 GREEN
ToolingGraphicsGLUIActivator.java 1775f5ee6932438fb7fe6cf15279a7595fdedb53 YELLOW
......@@ -17,6 +17,7 @@ package org.fortiss.tooling.graphicsGL.ui;
import static java.lang.System.mapLibraryName;
import static org.eclipse.core.runtime.FileLocator.toFileURL;
import static org.fortiss.tooling.base.utils.SystemUtils.isOs64BitArch;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
......@@ -46,12 +47,7 @@ public class ToolingGraphicsGLUIActivator extends AbstractUIPlugin {
System.out.println(" Preloading native LWJGL libraries.");
boolean is64bit;
if(System.getProperty("os.name").contains("Windows")) {
is64bit = (System.getenv("ProgramFiles(x86)") != null);
} else {
is64bit = (System.getProperty("os.arch").indexOf("64") != -1);
}
boolean is64bit = isOs64BitArch();
// preload JEMALLOC
String jemallocLibPath = loadPluginLocalLibrary(getBundle(), "jemalloc", is64bit);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment