2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.Toolkit;
24 import java.awt.event.MouseEvent;
27 import javax.swing.SwingUtilities;
30 * System platform information used by Applet and Application
37 private static boolean isJS = /** @j2sNative true || */false;
39 private static Boolean isNoJSMac = null, isNoJSWin = null,
40 isMac = null, isWin = null;
42 private static Boolean isHeadless = null;
45 * added to group mouse events into Windows and nonWindows (mac, unix, linux)
48 public static boolean isMac()
50 return (isMac == null ? (isMac = (System.getProperty("os.name").indexOf("Mac") >= 0)) : isMac);
54 * added to group mouse events into Windows and nonWindows (mac, unix, linux)
57 public static boolean isWin()
59 return (isWin == null ? (isWin = (System.getProperty("os.name").indexOf("Win") >= 0)) : isWin);
63 * Answers true if Jalview is running as Javascript, else false. The value is
64 * set at compile time.
68 public static boolean isJS()
70 return /** @j2sNative true || */ false;
74 * sorry folks - Macs really are different
76 * BH: disabled for SwingJS -- will need to check key-press issues
78 * @return true if we do things in a special way.
80 public static boolean isAMacAndNotJS()
82 return (isNoJSMac == null ? (isNoJSMac = !isJS && isMac()) : isNoJSMac);
86 * Check if we are on a Microsoft plaform...
88 * @return true if we have to cope with another platform variation
90 public static boolean isWindowsAndNotJS()
92 return (isNoJSWin == null ? (isNoJSWin = !isJS && isWin()) : isNoJSWin);
97 * @return true if we are running in non-interactive no UI mode
99 public static boolean isHeadless()
101 if (isHeadless == null)
103 isHeadless = "true".equals(System.getProperty("java.awt.headless"));
110 * @return nominal maximum command line length for this platform
112 public static int getMaxCommandLineLength()
114 // TODO: determine nominal limits for most platforms.
115 return 2046; // this is the max length for a windows NT system.
119 * escape a string according to the local platform's escape character
122 * @return escaped file
124 public static String escapeString(String file)
126 StringBuffer f = new StringBuffer();
127 int p = 0, lastp = 0;
128 while ((p = file.indexOf('\\', lastp)) > -1)
130 f.append(file.subSequence(lastp, p));
134 f.append(file.substring(lastp));
139 * Answers true if the mouse event has Meta-down (Command key on Mac) or
140 * Ctrl-down (on other o/s). Note this answers _false_ if the Ctrl key is
141 * pressed instead of the Meta/Cmd key on Mac. To test for Ctrl-pressed on Mac,
142 * you can use e.isPopupTrigger().
147 public static boolean isControlDown(MouseEvent e)
149 return isControlDown(e, isMac());
153 * Overloaded version of method (to allow unit testing)
159 protected static boolean isControlDown(MouseEvent e, boolean aMac)
162 return e.isControlDown();
164 // answer false for right mouse button
165 // shortcut key will be META for a Mac
166 return !e.isPopupTrigger()
167 && (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() & e.getModifiers()) != 0;
168 // could we use e.isMetaDown() here?
172 * Windows (not Mac, Linux, or Unix) and right button
173 * to test for the right-mouse pressed event in Windows
174 * that would have opened a menu or a Mac.
179 public static boolean isWinRightButton(MouseEvent e)
181 // was !isAMac(), but that is true also for Linux and Unix and JS,
183 return isWin() && SwingUtilities.isRightMouseButton(e);
188 * Windows (not Mac, Linux, or Unix) and middle button -- for mouse wheeling
189 * without pressing the button.
194 public static boolean isWinMiddleButton(MouseEvent e)
196 // was !isAMac(), but that is true also for Linux and Unix and JS
197 return isWin() && SwingUtilities.isMiddleMouseButton(e);
200 public static boolean allowMnemonics()
205 public final static int TIME_RESET = 0;
206 public final static int TIME_MARK = 1;
208 public static long time, mark;
210 public static void timeCheck(String msg, int mode) {
213 time = mark = System.currentTimeMillis();
214 System.err.println("Platform: timer reset\t\t\t" + msg);
217 long t = System.currentTimeMillis();
220 System.err.println("Platform: timer mark\t" + ((t - time)/1000f) + "\t" + ((t - mark)/1000f) + "\t" + msg);
226 public static void cacheFileData(String path, byte[] data) {
232 * swingjs.JSUtil.cacheFileData$S$O(path, data);
237 public static byte[] getFileBytes(File f) {
238 return /** @j2sNative f && f._bytes || */null;
241 public static byte[] getFileAsBytes(String fileStr) {
242 // BH 2018 hack for no support for access-origin
243 return /** @j2sNative swingjs.JSUtil.getFileAsBytes$O(fileStr) || */ null;
246 public static String getFileAsString(String data) {
247 return /** @j2sNative swingjs.JSUtil.getFileAsString$S(data) || */ null;
250 public static boolean setFileBytes(File f, String urlstring) {
253 @SuppressWarnings("unused")
254 byte[] bytes = getFileAsBytes(urlstring);
262 public static void addJ2SBinaryType(String ext)
264 ext = "." + ext + "?";
269 * J2S._binaryTypes.push(ext);
274 public static String encodeURI(String value) {
277 * return encodeURIComponent(value);
282 public static boolean openURL(String url) {