X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FPlatform.java;h=4ecf6372d866be55007bbd117f19ada9e29d8624;hb=5e17ddc59003daff5f9933cf5710889bcdb9e856;hp=44d93b72291212fa34d50e57039dd4ef6fe88fe8;hpb=25aa5cbe7f7d3d98f236cab3fb93197866b3bba4;p=jalview.git diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index 44d93b7..4ecf637 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -20,8 +20,6 @@ */ package jalview.util; -import jalview.javascript.json.JSON; - import java.awt.Toolkit; import java.awt.event.MouseEvent; import java.io.BufferedReader; @@ -40,6 +38,8 @@ import javax.swing.SwingUtilities; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; +import jalview.javascript.json.JSON; + /** * System platform information used by Applet and Application * @@ -52,10 +52,31 @@ public class Platform false; private static Boolean isNoJSMac = null, isNoJSWin = null, isMac = null, - isWin = null; + isWin = null, isLinux = null; private static Boolean isHeadless = null; + // If launched from CLI with launcher script then -DCOLUMNWIDTH is set + private static final int CONSOLEWIDTH; + + private static final String CONSOLEWIDTHPROPERTY = "CONSOLEWIDTH"; + + static + { + int cw = 80; + if (System.getProperty(CONSOLEWIDTHPROPERTY) != null + && System.getProperty(CONSOLEWIDTHPROPERTY).length() > 0) + { + try + { + cw = Integer.parseInt(System.getProperty(CONSOLEWIDTHPROPERTY)); + } catch (NumberFormatException e) + { + } + } + CONSOLEWIDTH = cw; + } + /** * added to group mouse events into Windows and nonWindows (mac, unix, linux) * @@ -81,6 +102,19 @@ public class Platform } /** + * added to check LaF for Linux + * + * @return + */ + public static boolean isLinux() + { + return (isLinux == null + ? (isLinux = (System.getProperty("os.name") + .indexOf("Linux") >= 0)) + : isLinux); + } + + /** * * @return true if HTML5 JavaScript */ @@ -275,7 +309,7 @@ public class Platform time = mark = t; if (msg != null) { - System.err.println("Platform: timer reset\t\t\t" + msg); + jalview.bin.Console.errPrintln("Platform: timer reset\t\t\t" + msg); } break; case TIME_MARK: @@ -291,7 +325,7 @@ public class Platform } if (msg != null) { - System.err.println("Platform: timer mark\t" + ((t - time) / 1000f) + jalview.bin.Console.errPrintln("Platform: timer mark\t" + ((t - time) / 1000f) + "\t" + ((t - mark) / 1000f) + "\t" + msg); } mark = t; @@ -303,7 +337,7 @@ public class Platform case TIME_GET: if (msg != null) { - System.err.println("Platform: timer dur\t" + ((t - time) / 1000f) + jalview.bin.Console.errPrintln("Platform: timer dur\t" + ((t - time) / 1000f) + "\t" + ((duration) / 1000f) + "\t" + msg); } set = 0; @@ -337,9 +371,7 @@ public class Platform public static byte[] getFileBytes(File f) { - // TODO temporary doubling of 秘bytes and _bytes; - // just remove _bytes when new transpiler has been installed - return /** @j2sNative f && (f.\u79d8bytes || f._bytes) || */ + return /** @j2sNative f && swingjs.JSUtil.getFileAsBytes$O(f) || */ null; } @@ -432,10 +464,8 @@ public class Platform public static String getUniqueAppletID() { - @SuppressWarnings("unused") - ThreadGroup g = Thread.currentThread().getThreadGroup(); /** - * @j2sNative return g.\u79d8html5Applet._uniqueId; + * @j2sNative return swingjs.JSUtil.getApplet$()._uniqueId; * */ return null; @@ -456,16 +486,15 @@ public class Platform { return; } - @SuppressWarnings("unused") - ThreadGroup g = Thread.currentThread().getThreadGroup(); String id = getUniqueAppletID(); String key = "", value = ""; /** - * @j2sNative var info = g.\u79d8html5Applet.__Info || {}; for (var key in info) { - * if (key.indexOf(prefix) == 0) { value = "" + info[key]; + * @j2sNative var info = swingjs.JSUtil.getApplet$().__Info || {}; for (var + * key in info) { if (key.indexOf(prefix) == 0) { value = "" + + * info[key]; */ - System.out.println( + jalview.bin.Console.outPrintln( "Platform id=" + id + " reading Info." + key + " = " + value); p.put(id + "_" + key, value); @@ -515,8 +544,7 @@ public class Platform public static Object parseJSON(String json) throws ParseException { - return (isJS() ? JSON.parse(json) - : new JSONParser().parse(json)); + return (isJS() ? JSON.parse(json) : new JSONParser().parse(json)); } public static Object parseJSON(Reader r) @@ -554,17 +582,16 @@ public class Platform public static void streamToFile(InputStream is, File outFile) throws IOException { + if (isJS() && /** + * @j2sNative outFile.setBytes$O && outFile.setBytes$O(is) && + */ + true) + { + return; + } FileOutputStream fio = new FileOutputStream(outFile); try { - if (isJS() - && /** - * @j2sNative outFile.setBytes$O && outFile.setBytes$O(is) && - */ - true) - { - return; - } byte[] bb = new byte[32 * 1024]; int l; while ((l = is.read(bb)) > 0) @@ -593,9 +620,9 @@ public class Platform if (isJS()) { - System.out.println( - "Platform adding known access-control-allow-origin * for domain " - + domain); + jalview.bin.Console.outPrintln( + "Platform adding known access-control-allow-origin * for domain " + + domain); /** * @j2sNative * @@ -607,23 +634,31 @@ public class Platform public static void getURLCommandArguments() { - - /** - * Retrieve the first query field as command arguments to Jalview. Include - * only if prior to "?j2s" or "&j2s" or "#". Assign the applet's __Info.args - * element to this value. - * - * @j2sNative var a = - * decodeURI((document.location.href.replace("&","?").split("?j2s")[0] - * + "?").split("?")[1].split("#")[0]); a && - * (J2S.thisApplet.__Info.args = a.split(" ")); - */ - + try + { + /** + * Retrieve the first query field as command arguments to Jalview. Include + * only if prior to "?j2s" or "&j2s" or "#". Assign the applet's + * __Info.args element to this value. + * + * @j2sNative var a = + * decodeURI((document.location.href.replace("&","?").split("?j2s")[0] + * + "?").split("?")[1].split("#")[0]); a && + * (jalview.bin.Console.outPrintln("URL arguments detected were "+a)) && + * (J2S.thisApplet.__Info.urlargs = a.split(" ")); + * (!J2S.thisApplet.__Info.args || J2S.thisApplet.__Info.args + * == "" || J2S.thisApplet.__Info.args == "??") && + * (J2S.thisApplet.__Info.args = a) && (jalview.bin.Console.outPrintln("URL + * arguments were passed to J2S main.")); + */ + } catch (Throwable t) + { + } } /** - * A (case sensitive) file path comparator that ignores the difference between / - * and \ + * A (case sensitive) file path comparator that ignores the difference between + * / and \ * * @param path1 * @param path2 @@ -643,4 +678,12 @@ public class Platform String p2 = path2.replace('\\', '/'); return p1.equals(p2); } + + /** + * If started on command line using launch script, return the console width + */ + public static int consoleWidth() + { + return CONSOLEWIDTH; + } }