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;
26 import javax.swing.SwingUtilities;
29 * System platform information used by Applet and Application
36 private static boolean isJS = /** @j2sNative true || */false;
38 private static Boolean isNoJSMac = null, isNoJSWin = null,
39 isMac = null, isWin = null;
41 private static Boolean isHeadless = null;
44 * added to group mouse events into Windows and nonWindows (mac, unix, linux)
47 public static boolean isMac()
49 return (isMac == null ? (isMac = (System.getProperty("os.name").indexOf("Mac") >= 0)) : isMac);
53 * added to group mouse events into Windows and nonWindows (mac, unix, linux)
56 public static boolean isWin()
58 return (isWin == null ? (isWin = (System.getProperty("os.name").indexOf("Win") >= 0)) : isWin);
63 * @return true if HTML5 JavaScript
65 public static boolean isJS()
71 * sorry folks - Macs really are different
73 * BH: disabled for SwingJS -- will need to check key-press issues
75 * @return true if we do things in a special way.
77 public static boolean isAMacAndNotJS()
79 return (isNoJSMac == null ? (isNoJSMac = !isJS && isMac()) : isNoJSMac);
83 * Check if we are on a Microsoft plaform...
85 * @return true if we have to cope with another platform variation
87 public static boolean isWindowsAndNotJS()
89 return (isNoJSWin == null ? (isNoJSWin = !isJS && isWin()) : isNoJSWin);
94 * @return true if we are running in non-interactive no UI mode
96 public static boolean isHeadless()
98 if (isHeadless == null)
100 isHeadless = "true".equals(System.getProperty("java.awt.headless"));
107 * @return nominal maximum command line length for this platform
109 public static int getMaxCommandLineLength()
111 // TODO: determine nominal limits for most platforms.
112 return 2046; // this is the max length for a windows NT system.
116 * escape a string according to the local platform's escape character
119 * @return escaped file
121 public static String escapeString(String file)
123 StringBuffer f = new StringBuffer();
124 int p = 0, lastp = 0;
125 while ((p = file.indexOf('\\', lastp)) > -1)
127 f.append(file.subSequence(lastp, p));
131 f.append(file.substring(lastp));
136 * Answers true if the mouse event has Meta-down (Command key on Mac) or
137 * Ctrl-down (on other o/s). Note this answers _false_ if the Ctrl key is
138 * pressed instead of the Meta/Cmd key on Mac. To test for Ctrl-pressed on Mac,
139 * you can use e.isPopupTrigger().
144 public static boolean isControlDown(MouseEvent e)
146 return isControlDown(e, isMac());
150 * Overloaded version of method (to allow unit testing)
156 protected static boolean isControlDown(MouseEvent e, boolean aMac)
159 return e.isControlDown();
161 // answer false for right mouse button
162 // shortcut key will be META for a Mac
163 return !e.isPopupTrigger()
164 && (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() & e.getModifiers()) != 0;
165 // could we use e.isMetaDown() here?
169 * Windows (not Mac, Linux, or Unix) and right button
170 * to test for the right-mouse pressed event in Windows
171 * that would have opened a menu or a Mac.
176 public static boolean isWinRightButton(MouseEvent e)
178 // was !isAMac(), but that is true also for Linux and Unix and JS,
180 return isWin() && SwingUtilities.isRightMouseButton(e);
185 * Windows (not Mac, Linux, or Unix) and middle button -- for mouse wheeling
186 * without pressing the button.
191 public static boolean isWinMiddleButton(MouseEvent e)
193 // was !isAMac(), but that is true also for Linux and Unix and JS
194 return isWin() && SwingUtilities.isMiddleMouseButton(e);
197 public static boolean allowMnemonics()
202 public final static int TIME_RESET = 0;
203 public final static int TIME_MARK = 1;
204 public static final int TIME_SET = 2;
205 public static final int TIME_GET = 3;
207 public static long time, mark, set, duration;
209 public static void timeCheck(String msg, int mode) {
210 long t = System.currentTimeMillis();
215 System.err.println("Platform: timer reset\t\t\t" + msg);
219 duration += (t - set);
224 System.err.println("Platform: timer mark\t" + ((t - time)/1000f) + "\t" + ((t - mark)/1000f) + "\t" + msg);
233 System.err.println("Platform: timer dur\t" + ((t - time)/1000f) + "\t" + ((duration)/1000f) + "\t" + msg);