*/
package jalview.util;
-import jalview.javascript.json.JSON;
-
import java.awt.Component;
import java.awt.Dimension;
+import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
+import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.Properties;
import java.util.logging.ConsoleHandler;
import com.stevesoft.pat.Regex;
+import jalview.javascript.json.JSON;
import swingjs.api.JSUtilI;
/**
*
* @author Jim Procter
*/
+
public class Platform
{
isWin = null;
private static Boolean isHeadless = null;
-
+
private static swingjs.api.JSUtilI jsutil;
+
- static {
- if (isJS) {
+ static
+ {
+ if (isJS)
+ {
try
{
jsutil = ((JSUtilI) Class.forName("swingjs.JSUtil").newInstance());
{
e.printStackTrace();
}
- }
+ }
}
// private static Boolean isHeadless = null;
: isMac);
}
+ public static int SHIFT_DOWN_MASK = KeyEvent.SHIFT_DOWN_MASK;
+
+ public static int ALT_DOWN_MASK = KeyEvent.ALT_DOWN_MASK;
+
+ public static int SHORTCUT_KEY_MASK = (Platform.isMac() ? KeyEvent.META_DOWN_MASK : KeyEvent.CTRL_DOWN_MASK);
+
+ static
+ {
+ if (!GraphicsEnvironment.isHeadless())
+ {
+ try
+ {
+
+ Class<? extends Toolkit> tk = Toolkit.getDefaultToolkit().getClass();
+ Method method = tk.getMethod("getMenuShortcutKeyMaskEx");
+ if (method == null)
+ method = tk.getMethod("getMenuShortcutKeyMask");
+ SHORTCUT_KEY_MASK = ((int) method.invoke(tk, new Object[0]));
+ if (SHORTCUT_KEY_MASK <= 0xF)
+ {
+ // shift this into the extended region (was Java 8)
+ SHORTCUT_KEY_MASK = SHORTCUT_KEY_MASK << 6;
+ }
+ } catch (Exception e)
+ {
+ }
+ }
+ }
+
/**
* added to group mouse events into Windows and nonWindows (mac, unix, linux)
*
return (isNoJSWin == null ? (isNoJSWin = !isJS && isWin()) : isNoJSWin);
}
- /**
- *
- * @return true if we are running in non-interactive no UI mode
- */
- public static boolean isHeadless()
- {
- if (isHeadless == null)
- {
- isHeadless = "true".equals(System.getProperty("java.awt.headless"));
- }
- return isHeadless;
- }
+ /**
+ *
+ * @return true if we are running in non-interactive no UI mode
+ */
+ public static boolean isHeadless()
+ {
+ if (isHeadless == null)
+ {
+ isHeadless = "true".equals(System.getProperty("java.awt.headless"));
+ }
+ return isHeadless;
+ }
/**
*
{
return s == null ? null : s.replace("\\", "\\\\");
}
-
+
/**
* Answers true if the mouse event has Meta-down (Command key on Mac) or
* Ctrl-down (on other o/s). Note this answers _false_ if the Ctrl key is
*/
protected static boolean isControlDown(MouseEvent e, boolean aMac)
{
- if (!aMac)
- {
- return e.isControlDown();
-
- // Jalview 2.11 code below: above is as amended for JalviewJS
- // /*
- // * answer false for right mouse button
- // */
- // if (e.isPopupTrigger())
- // {
- // return false;
- // }
- // return
- // (jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx() //
- // .getMenuShortcutKeyMaskEx()
- // & jalview.util.ShortcutKeyMaskExWrapper
- // .getModifiersEx(e)) != 0; // getModifiers()) != 0;
+
+ System.out.println(e.isPopupTrigger()
+ + " " + ((SHORTCUT_KEY_MASK & e.getModifiersEx()) != 0)
+ + " " + e.isControlDown());
+ return (aMac ? !e.isPopupTrigger()
+ && (SHORTCUT_KEY_MASK & e.getModifiersEx()) != 0
+ : e.isControlDown());
}
- // answer false for right mouse button
- // shortcut key will be META for a Mac
- return !e.isPopupTrigger()
- && (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
- & e.getModifiers()) != 0;
- // could we use e.isMetaDown() here?
- }
// BH: I don't know about that previous method. Here is what SwingJS uses.
// Notice the distinction in mouse events. (BUTTON3_MASK == META)
}
}
-
public static void cacheFileData(File file)
{
if (isJS)
}
return null;
}
-
+
public static String getFileAsString(String url)
{
if (isJS && url != null)
return false;
}
-
public static void addJ2SBinaryType(String ext)
{
if (isJS)
jsutil.addBinaryFileType(ext);
}
}
-
+
/**
* Encode the URI using JavaScript encodeURIComponent
*
return (isJS ? (String) jsutil.getAppletAttribute("_uniqueId") : null);
}
-
/**
* Read the Info block for this applet.
*
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)
* @param is
* @param outFile
* @throws IOException
- * if the file cannot be created or there is a problem
- * reading the input stream.
+ * if the file cannot be created or there is a problem reading the
+ * input stream.
*/
public static void streamToFile(InputStream is, File outFile)
throws IOException
jsutil.addDirectDatabaseCall(domain);
System.out.println(
- "Platform adding known access-control-allow-origin * for domain "
- + domain);
+ "Platform adding known access-control-allow-origin * for domain "
+ + domain);
}
}
}
/**
- * 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
return p1.equals(p2);
}
+ ///////////// JAL-3253 Applet additions //////////////
-
-///////////// JAL-3253 Applet additions //////////////
-
-
/**
* Retrieve the object's embedded size from a div's style on a page if
* embedded in SwingJS.
}
}
-
/**
* load a resource -- probably a core file -- if and only if a particular
* class has not been instantialized. We use a String here because if we used
return (isJS ? jsutil.getCodeBase() : null);
}
-
}