Class OSPRuntime

java.lang.Object
org.opensourcephysics.display.OSPRuntime

public class OSPRuntime extends Object
This class defines static methods related to the runtime environment.
Version:
1.0
Author:
Douglas Brown, Wolfgang Christian, Robert M. Hanson
  • Field Details

    • VERSION

      public static final String VERSION
      See Also:
    • RELEASE_DATE

      public static final String RELEASE_DATE
      See Also:
    • OSP_PROPERTY_LOCALE

      public static final String OSP_PROPERTY_LOCALE
      See Also:
    • macOffset

      public static int macOffset
    • isJS

      public static boolean isJS
    • jsutil

      public static swingjs.api.JSUtilI jsutil
    • DECIMAL_SEPARATOR_COMMA

      public static final char DECIMAL_SEPARATOR_COMMA
      See Also:
    • DECIMAL_SEPARATOR_PERIOD

      public static final char DECIMAL_SEPARATOR_PERIOD
      See Also:
    • isApplet

      public static boolean isApplet
    • isBHTest

      public static boolean isBHTest
    • dontLog

      public static boolean dontLog
    • allowBackgroundNodeLoading

      public static boolean allowBackgroundNodeLoading
    • allowAutopaste

      public static boolean allowAutopaste
    • allowDatasetClip

      public static boolean allowDatasetClip
      HighlightDataSet -- Firefox has problems with canvas clip/unclip getting slower and slower and slower
    • allowLibClipboardPasteCheck

      public static boolean allowLibClipboardPasteCheck
    • allowSetFonts

      public static boolean allowSetFonts
    • allowAsyncURL

      public static boolean allowAsyncURL
    • loadTranslatorTool

      public static boolean loadTranslatorTool
      Load Translator Tool, if available.
    • autoAddLibrary

      public static boolean autoAddLibrary
    • checkImages

      public static final boolean checkImages
      See Also:
    • checkTempDirCache

      public static boolean checkTempDirCache
    • checkZipLoaders

      public static boolean checkZipLoaders
    • doCacheThumbnail

      public static boolean doCacheThumbnail
    • doCacheLibaryRecord

      public static boolean doCacheLibaryRecord
    • doCacheZipContents

      public static boolean doCacheZipContents
    • doScrollToPath

      public static boolean doScrollToPath
    • drawDontFillAxes

      public static boolean drawDontFillAxes
    • logToJ2SMonitor

      public static boolean logToJ2SMonitor
    • resCacheEnabled

      public static boolean resCacheEnabled
    • setRenderingHints

      public static boolean setRenderingHints
    • embedVideoAsObject

      public static boolean embedVideoAsObject
    • useZipAssets

      public static boolean useZipAssets
    • unzipFiles

      public static boolean unzipFiles
    • tempDir

      public static final String tempDir
    • WEB_CONNECTED_TEST_JAVA_TIMEOUT_MS

      public static final int WEB_CONNECTED_TEST_JAVA_TIMEOUT_MS
      See Also:
    • WEB_CONNECTED_TEST_JS_TIMEOUT_MS

      public static final int WEB_CONNECTED_TEST_JS_TIMEOUT_MS
      See Also:
    • WEB_CONNECTED_TEST_URL

      public static final String WEB_CONNECTED_TEST_URL
      See Also:
    • disableAllDrawing

      public static volatile boolean disableAllDrawing
      Disables drawing for faster start-up and to avoid screen flash in Drawing Panels.
    • loadVideoTool

      public static boolean loadVideoTool
      Load Video Tool, if available.
    • loadExportTool

      public static boolean loadExportTool
      Load Export Tool, if available.
    • loadDataTool

      public static boolean loadDataTool
      Load Data Tool, if available.
    • loadOSPLog

      public static boolean loadOSPLog
      Load OSP Log, if available.
    • defaultLocales

      public static Locale[] defaultLocales
      Array of default OSP Locales.
    • launcherMode

      protected static boolean launcherMode
      Set true if a program is being run within Launcher.
    • antiAliasText

      public static boolean antiAliasText
      True if text components should try and anti-alias text.
    • appletMode

      public static boolean appletMode
      True if running as an applet.
    • applet

      public static JApplet applet
      Static reference to an applet for document/code base access.
    • webStart

      public static boolean webStart
      True if launched by WebStart.
    • authorMode

      protected static boolean authorMode
      True if users allowed to author internal parameters such as Locale strings.
    • MINUS

      public static final char MINUS
      Minus sign, may be used instead of default hyphen-minus
      See Also:
    • chooserDir

      public static String chooserDir
      File Chooser starting directory.
    • userhomeDir

      public static String userhomeDir
      User home directory.
    • OSP_ICON_FILE

      public static final String OSP_ICON_FILE
      Location of OSP icon.
      See Also:
    • launchingInSingleVM

      public static boolean launchingInSingleVM
      True if always launching in single vm (applet mode, etc).
    • CROSS_PLATFORM_LF

      public static final String CROSS_PLATFORM_LF
      See Also:
    • NIMBUS_LF

      public static final String NIMBUS_LF
      See Also:
    • SYSTEM_LF

      public static final String SYSTEM_LF
      See Also:
    • METAL_LF

      public static final String METAL_LF
      See Also:
    • GTK_LF

      public static final String GTK_LF
      See Also:
    • MOTIF_LF

      public static final String MOTIF_LF
      See Also:
    • WINDOWS_LF

      public static final String WINDOWS_LF
      See Also:
    • DEFAULT_LF

      public static final String DEFAULT_LF
      See Also:
    • DEFAULT_LOOK_AND_FEEL

      public static final LookAndFeel DEFAULT_LOOK_AND_FEEL
    • DEFAULT_LOOK_AND_FEEL_DECORATIONS

      public static final boolean DEFAULT_LOOK_AND_FEEL_DECORATIONS
    • LOOK_AND_FEEL_TYPES

      public static final HashMap<String,String> LOOK_AND_FEEL_TYPES
    • PROPERTY_ERROR_OUTOFMEMORY

      public static final String PROPERTY_ERROR_OUTOFMEMORY
      See Also:
    • frc

      public static FontRenderContext frc
    • activeNode

      public static LaunchNode activeNode
    • launcherAllowEJSModel

      public static boolean launcherAllowEJSModel
    • OUT_OF_MEMORY_ERROR

      public static final Integer OUT_OF_MEMORY_ERROR
    • outOfMemory

      public static boolean outOfMemory
  • Method Details

    • getSkipDisplayOfPDF

      public static boolean getSkipDisplayOfPDF()
    • getUserAgent

      public static String getUserAgent()
    • getBrowserName

      public static String getBrowserName()
    • setApplet

      public static void setApplet(JApplet a)
    • getUserHome

      public static String getUserHome()
      Gets the user home directory.
      Returns:
      the user home
    • getDownloadDir

      public static File getDownloadDir()
      Gets the download directory.
      Returns:
      the download directory
    • showAboutDialog

      public static void showAboutDialog(Component parent)
      Shows the about dialog.
      Parameters:
      parent -
    • setLookAndFeel

      public static boolean setLookAndFeel(boolean useDefaultLnFDecorations, String lookAndFeel)
      Sets the look and feel of the user interface. Look and feel user interfaces are: NIMBUS_LF: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel METAL_LF: javax.swing.plaf.metal.MetalLookAndFeel GTK_LF: com.sun.java.swing.plaf.gtk.GTKLookAndFeel MOTIF_LF: com.sun.java.swing.plaf.motif.MotifLookAndFeel WINDOWS_LF: com.sun.java.swing.plaf.windows.WindowsLookAndFeel DEFAULT_LF: the default look and feel in effect when this class was loaded CROSS_PLATFORM_LF: the cross platform look and feel; usually METAL_LF SYSTEM_LF: the operating system look and feel
      Parameters:
      useDefaultLnFDecorations -
      lookAndFeel -
      Returns:
      true if successful
    • isDefaultLookAndFeelDecorated

      public static boolean isDefaultLookAndFeelDecorated()
      Returns true if newly created JFrames or JDialogs should have their Window decorations provided by the current look and feel. This is only a hint, as certain look and feels may not support this feature.
      Returns:
      true if look and feel should provide Window decorations.
      Since:
      1.4
    • isWindows

      public static boolean isWindows()
      Determines if OS is Windows
      Returns:
      true if Windows
    • isMac

      public static boolean isMac()
      Determines if OS is Mac
      Returns:
      true if Mac
    • isLinux

      public static boolean isLinux()
      Determines if OS is Linux
      Returns:
      true if Linux
    • isVista

      public static boolean isVista()
      Determines if OS is Vista
      Returns:
      true if Vista
    • hasJava3D

      public static boolean hasJava3D()
    • isPopupTrigger

      public static boolean isPopupTrigger(InputEvent e)
      Determines if an InputEvent is a popup trigger.
      Parameters:
      e - the input event
      Returns:
      true if event is a popup trigger
    • isWebStart

      public static boolean isWebStart()
      Determines if launched by WebStart
      Returns:
      true if launched by WebStart
    • isAppletMode

      public static boolean isAppletMode()
      Determines if running as an applet
      Returns:
      true if running as an applet
    • isAuthorMode

      public static boolean isAuthorMode()
      Determines if running in author mode
      Returns:
      true if running in author mode
    • setAuthorMode

      public static void setAuthorMode(boolean b)
      Sets the authorMode property. AuthorMode allows users to author internal parameters such as Locale strings.
      Parameters:
      b - boolean
    • setLauncherMode

      public static void setLauncherMode(boolean b)
      Sets the launcherMode property to true if applications in this VM are launched by Launcher. LauncherMode disables access to properties, such as Locale, that affect the VM.
      Parameters:
      b - boolean
    • isLauncherMode

      public static boolean isLauncherMode()
      Gets the launcherMode property. Returns true if applications in this VM are launched by Launcher. LauncherMode disables access to properties, such as Locale, that affect the VM.
      Returns:
      boolean
    • setLaunchJarPath

      public static void setLaunchJarPath(String path)
      Sets the launch jar path.
      Parameters:
      path - the path
    • getLaunchJarName

      public static String getLaunchJarName()
      Gets the launch jar name, if any.
      Returns:
      launch jar path, or null if not launched from a jar
    • getLaunchJarPath

      public static String getLaunchJarPath()
      Gets the launch jar path, if any.
      Returns:
      launch jar path, or null if not launched from a jar
    • getDocbase

      public static String getDocbase()
      Gets the window.location.href when JavaScript code is running in an html page.
      Returns:
      window.location.href
    • getLaunchJarDirectory

      public static String getLaunchJarDirectory()
      Gets the launch jar directory, if any.
      Returns:
      path to the directory containing the launch jar. May be null.
    • getLaunchJar

      public static JarFile getLaunchJar()
      Gets the jar from which the progam was launched.
      Returns:
      JarFile
    • getManifestAttribute

      public static String getManifestAttribute(JarFile jarFile, String attribute)
      Gets a manifest attribute.
      Returns:
      the String value or "" if not known
    • getLaunchJarBuildDate

      public static String getLaunchJarBuildDate()
      Gets the launch jar build date.
      Returns:
      the build date, or "" if not launched from a jar or date not known
    • getJavaFile

      public static File getJavaFile(String jrePath)
      Gets the java executable file for a given jre path. May return null.
      Parameters:
      jrePath - the path to a java jre or jdk VM
      Returns:
      the Java executable
    • getMajorVersion

      public static int getMajorVersion()
      Gets the major version number. For VERSION 6.0.1, the major is 6.
      Returns:
      the major version, or 0 if fails
    • getVMBitness

      public static int getVMBitness()
      Gets the bitness of the current Java VM. Note this identifies only 32- and 64-bit VMs as of Jan 2011.
      Returns:
      64 if 64-bit VM, otherwise 32
    • getJREPath

      public static String getJREPath(File javaFile)
      Gets the java VM path for a given Java executable file.
      Parameters:
      javaFile - the Java executable file
      Returns:
      the VM path
    • getDefaultLocales

      public static Locale[] getDefaultLocales()
      Gets Locales for languages that have properties files in the core library.
      Returns:
      Locale[]
    • getInstalledLocales

      public static Locale[] getInstalledLocales()
      Gets Locales for languages that have properties files in the core library. Locales are returned with English first, then in alphabetical order.
      Returns:
      Locale[]
    • getDisplayLanguage

      public static String getDisplayLanguage(Locale locale)
      Gets the display language for a given Locale. This returns the language name in the locale's own language, but substitutes the equivalent of SIMPLIFIED_CHINESE and TRADITIONAL_CHINESE for those locales.
      Parameters:
      locale - the Locale
      Returns:
      the display language
    • getDecimalFormatSymbols

      public static DecimalFormatSymbols getDecimalFormatSymbols()
      Gets DecimalFormatSymbols that use the preferred decimal separator, if any. If no preference, the default separator for the current locale is used.
      Returns:
      the DecimalFormatSymbols
    • setDefaultDecimalSeparator

      public static void setDefaultDecimalSeparator(char c)
      Sets the default decimal separator. Sets the current DecimalFormatSymbols value to the given value as long as there is no preferred decimal separator.
      Parameters:
      c - a decimal separator
    • setPreferredDecimalSeparator

      public static void setPreferredDecimalSeparator(String separator)
      Sets the preferred decimal separator. Must be DECIMAL_SEPARATOR_PERIOD or DECIMAL_SEPARATOR_COMMA.
      Parameters:
      separator - If non-null, assigns the given value to the current DecimalFormatSymbols value; if null, resets the DecimalFormatSymbols value to the default value.
    • getCurrentDecimalSeparator

      public static char getCurrentDecimalSeparator()
    • getPreferredDecimalSeparator

      public static String getPreferredDecimalSeparator()
      Gets the preferred decimal separator. May return null.
      Returns:
      the separator, if any
    • getDefaultSearchPaths

      public static ArrayList<String> getDefaultSearchPaths()
      Gets the default search paths, typically used for autoloading. Search paths are platform-specific "appdata", user home and code base, in that order.
      Returns:
      the default search paths
    • getPreference

      public static Object getPreference(String name)
      Gets a named preference object. The object must be cast to the correct type by the user.
      Parameters:
      name - the name of the preference
      Returns:
      the object (may be null)
    • setPreference

      public static void setPreference(String name, Object pref)
      Sets a named preference object. The object can be anything storable in an XMLControl--eg, String, Collection, OSP object, Boolean, Double, Integer
      Parameters:
      name - the name of the preference
      pref - the object (may be null)
    • savePreferences

      public static void savePreferences()
      Saves the current preference XMLControl by writing to a file.
    • getPreferencesFile

      public static File getPreferencesFile()
      Gets the preferences XML file if it exists.
      Returns:
      the file, or null if none exists
    • getTranslator

      public static Translator getTranslator()
      Gets the translator, if any.
      Returns:
      translator, or null if none available
    • getChooser

      public static javajs.async.AsyncFileChooser getChooser()
      Gets a file chooser. The choose is static and will therefore be the same for all OSPFrames.
      Returns:
      the chooser
    • chooseFilename

      public static String chooseFilename(JFileChooser chooser)
      Uses a JFileChooser to ask for a name.
      Parameters:
      chooser - JFileChooser
      Returns:
      String The absolute pah of the filename. Null if cancelled
    • chooseFilename

      public static String chooseFilename(JFileChooser chooser, Component parent, boolean toSave)
      Uses a JFileChooser to ask for a name.
      Parameters:
      chooser - JFileChooser
      parent - Parent component for messages
      toSave - true if we will save to the chosen file, false if we will read from it
      Returns:
      String The absolute pah of the filename. Null if cancelled
    • createChooser

      public static javajs.async.AsyncFileChooser createChooser(String title, String description, String[] extensions)
      Creates a JFileChooser with given title, description and extensions
      Parameters:
      title - the title
      description - a description string
      extensions - an array of allowed extensions
      Returns:
      the JFileChooser
    • createChooser

      public static javajs.async.AsyncFileChooser createChooser(String description, String[] extensions)
      Creates a JFileChooser with given description and extensions
      Parameters:
      description - String A description string
      extensions - String[] An array of allowed extensions
      Returns:
      JFileChooser
    • createChooser

      public static javajs.async.AsyncFileChooser createChooser(String description, String[] extensions, File homeDir)
      Creates a JFileChooser with given description and extensions
      Parameters:
      description - String A description string
      extensions - String[] An array of allowed extensions
      homeDir - File The target directory when the user clicks the home icon
      Returns:
      JFileChooser
    • cacheJSFile

      public static void cacheJSFile(File file, boolean isAdd)
      Cache (or clear) J2S._javaFileCache for this file.
      Parameters:
      file -
      isAdd -
    • getCachedBytes

      public static byte[] getCachedBytes(String path)
      Fetch bytes cached for temporary or DnD files in JavaScript.
      Parameters:
      path -
      Returns:
    • addJSCachedBytes

      public static byte[] addJSCachedBytes(Object URLorURIorFile)
    • isJSTemp

      public static boolean isJSTemp(String path)
    • displayURL

      public static void displayURL(String url) throws IOException
      Throws:
      IOException
    • showStatus

      public static void showStatus(String msg)
    • getURLBytesAsync

      public static void getURLBytesAsync(URL url, Function<byte[],Void> whenDone)
    • postEvent

      @Deprecated public static void postEvent(Runnable runner)
      Deprecated.
      BH created this to consolidate all the isEventDispatchThread calls, but those were all using runner.run() directly, and he has had no issues with other programs. It is Swing, after all....
      Parameters:
      runner -
    • dispatchEventWait

      public static void dispatchEventWait(Runnable runner)
    • setAppClass

      public static void setAppClass(Object j)
      Set the "app" property of the HTML5 applet object, for example, "testApplet.app", to point to the Jalview instance. This will be the object that page developers use that is similar to the original Java applet object that was accessed via LiveConnect.
      Parameters:
      j -
    • setTimeout

      public static int setTimeout(String name, int msDelay, boolean cancelPending, Runnable r)
    • exit

      public static void exit()
      clean up all pending anything
    • getClipboard

      public static Clipboard getClipboard()
    • setOSPAction

      public static void setOSPAction(InputMap im, KeyStroke ks, String actionKey, ActionMap am, Action pasteAction)
      SwingJS may not have all UI actions already defined
      Parameters:
      im -
      ks -
      actionKey -
      am -
      pasteAction -
    • paste

      public static String paste(Consumer<String> whenDone)
      Pastes from the clipboard and returns the pasted string.
      Returns:
      the pasted string, or null if none
    • copy

      public static void copy(String s, ClipboardOwner owner)
    • setJSClipboardPasteListener

      public static void setJSClipboardPasteListener(Component c, TransferHandler handler)
      Register a TransferHandler for the onpaste event for this component. This registration will consume the jQuery paste event. The returned MimeType is text/plain and will match DataFlavor.plainTextFlavor
      Parameters:
      c -
      handler -
    • addAssets

      public static void addAssets(String name, String zipPath, String path)
    • getMemory

      public static long[] getMemory()
      Get the used and max from jvaa.lang.management.memoryMXBean.
      Returns:
      [ used, max ]
    • getMemoryStr

      public static String getMemoryStr()
    • trigger

      public static Timer trigger(int ms, ActionListener a)
      Create a simple one-time Timer and start it.
      Parameters:
      ms -
      a -
      Returns:
    • chooseColor

      public static void chooseColor(Color color, String title, Consumer<Color> whenDone)
      Displays a JColorChooser and returns the selected color.
      Parameters:
      color - the initial color to select
      title - the title for the dialog
      whenDone - TODO