Package org.opensourcephysics.display
Class OSPRuntime
java.lang.Object
org.opensourcephysics.display.OSPRuntime
This class defines static methods related to the runtime environment.
- Version:
- 1.0
- Author:
- Douglas Brown, Wolfgang Christian, Robert M. Hanson
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
An interface with static methods that track implementing classes, adding them to array to "allocate" them, and running their dispose() method when "deallocation" is requested.static class
static class
static class
A class to compare version strings. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic LaunchNode
static boolean
static boolean
static boolean
static boolean
HighlightDataSet -- Firefox has problems with canvas clip/unclip getting slower and slower and slowerstatic boolean
static boolean
static boolean
True if text components should try and anti-alias text.static JApplet
Static reference to an applet for document/code base access.static boolean
True if running as an applet.protected static boolean
True if users allowed to author internal parameters such as Locale strings.static boolean
static final boolean
static boolean
static boolean
static String
File Chooser starting directory.static final String
static final char
static final char
static final String
static final LookAndFeel
static final boolean
static Locale[]
Array of default OSP Locales.static boolean
Disables drawing for faster start-up and to avoid screen flash in Drawing Panels.static boolean
static boolean
static boolean
static boolean
static boolean
static boolean
static boolean
static FontRenderContext
static final String
static boolean
static boolean
static boolean
static swingjs.api.JSUtilI
static boolean
protected static boolean
Set true if a program is being run within Launcher.static boolean
True if always launching in single vm (applet mode, etc).static boolean
Load Data Tool, if available.static boolean
Load Export Tool, if available.static boolean
Load OSP Log, if available.static boolean
Load Translator Tool, if available.static boolean
Load Video Tool, if available.static boolean
static int
static final String
static final char
Minus sign, may be used instead of default hyphen-minusstatic final String
static final String
static final String
Location of OSP icon.static final String
static final Integer
static boolean
static final String
static final String
static boolean
static boolean
static final String
static final String
static boolean
static String
User home directory.static boolean
static final String
static final int
static final int
static final String
static boolean
True if launched by WebStart.static final String
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
static byte[]
addJSCachedBytes
(Object URLorURIorFile) static void
cacheJSFile
(File file, boolean isAdd) Cache (or clear) J2S._javaFileCache for this file.static void
chooseColor
(Color color, String title, Consumer<Color> whenDone) Displays a JColorChooser and returns the selected color.static String
chooseFilename
(JFileChooser chooser) Uses a JFileChooser to ask for a name.static String
chooseFilename
(JFileChooser chooser, Component parent, boolean toSave) Uses a JFileChooser to ask for a name.static void
copy
(String s, ClipboardOwner owner) static javajs.async.AsyncFileChooser
createChooser
(String description, String[] extensions) Creates a JFileChooser with given description and extensionsstatic javajs.async.AsyncFileChooser
createChooser
(String description, String[] extensions, File homeDir) Creates a JFileChooser with given description and extensionsstatic javajs.async.AsyncFileChooser
createChooser
(String title, String description, String[] extensions) Creates a JFileChooser with given title, description and extensionsstatic void
dispatchEventWait
(Runnable runner) static void
displayURL
(String url) static void
exit()
clean up all pending anythingstatic String
static byte[]
getCachedBytes
(String path) Fetch bytes cached for temporary or DnD files in JavaScript.static javajs.async.AsyncFileChooser
Gets a file chooser.static Clipboard
static char
static DecimalFormatSymbols
Gets DecimalFormatSymbols that use the preferred decimal separator, if any.static Locale[]
Gets Locales for languages that have properties files in the core library.Gets the default search paths, typically used for autoloading.static String
getDisplayLanguage
(Locale locale) Gets the display language for a given Locale.static String
Gets the window.location.href when JavaScript code is running in an html page.static File
Gets the download directory.static Locale[]
Gets Locales for languages that have properties files in the core library.static File
getJavaFile
(String jrePath) Gets the java executable file for a given jre path.static String
getJREPath
(File javaFile) Gets the java VM path for a given Java executable file.static JarFile
Gets the jar from which the progam was launched.static String
Gets the launch jar build date.static String
Gets the launch jar directory, if any.static String
Gets the launch jar name, if any.static String
Gets the launch jar path, if any.static int
Gets the major version number.static String
getManifestAttribute
(JarFile jarFile, String attribute) Gets a manifest attribute.static long[]
Get the used and max from jvaa.lang.management.memoryMXBean.static String
static Object
getPreference
(String name) Gets a named preference object.static File
Gets the preferences XML file if it exists.static String
Gets the preferred decimal separator.static boolean
static Translator
Gets the translator, if any.static void
getURLBytesAsync
(URL url, Function<byte[], Void> whenDone) static String
static String
Gets the user home directory.static int
Gets the bitness of the current Java VM.static boolean
static boolean
Determines if running as an appletstatic boolean
Determines if running in author modestatic boolean
Returns true if newly createdJFrame
s orJDialog
s should have their Window decorations provided by the current look and feel.static boolean
static boolean
Gets the launcherMode property.static boolean
isLinux()
Determines if OS is Linuxstatic boolean
isMac()
Determines if OS is Macstatic boolean
Determines if an InputEvent is a popup trigger.static boolean
isVista()
Determines if OS is Vistastatic boolean
Determines if launched by WebStartstatic boolean
Determines if OS is Windowsstatic String
Pastes from the clipboard and returns the pasted string.static void
Deprecated.static void
Saves the current preference XMLControl by writing to a file.static void
Set the "app" property of the HTML5 applet object, for example, "testApplet.app", to point to the Jalview instance.static void
static void
setAuthorMode
(boolean b) Sets the authorMode property.static void
setDefaultDecimalSeparator
(char c) Sets the default decimal separator.static void
setJSClipboardPasteListener
(Component c, TransferHandler handler) Register a TransferHandler for the onpaste event for this component.static void
setLauncherMode
(boolean b) Sets the launcherMode property to true if applications in this VM are launched by Launcher.static void
setLaunchJarPath
(String path) Sets the launch jar path.static boolean
setLookAndFeel
(boolean useDefaultLnFDecorations, String lookAndFeel) Sets the look and feel of the user interface.static void
SwingJS may not have all UI actions already definedstatic void
setPreference
(String name, Object pref) Sets a named preference object.static void
setPreferredDecimalSeparator
(String separator) Sets the preferred decimal separator.static int
setTimeout
(String name, int msDelay, boolean cancelPending, Runnable r) static void
showAboutDialog
(Component parent) Shows the about dialog.static void
showStatus
(String msg) static Timer
trigger
(int ms, ActionListener a) Create a simple one-time Timer and start it.
-
Field Details
-
VERSION
- See Also:
-
RELEASE_DATE
- See Also:
-
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 allowDatasetClipHighlightDataSet -- 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 loadTranslatorToolLoad 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
-
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
- See Also:
-
disableAllDrawing
public static volatile boolean disableAllDrawingDisables drawing for faster start-up and to avoid screen flash in Drawing Panels. -
loadVideoTool
public static boolean loadVideoToolLoad Video Tool, if available. -
loadExportTool
public static boolean loadExportToolLoad Export Tool, if available. -
loadDataTool
public static boolean loadDataToolLoad Data Tool, if available. -
loadOSPLog
public static boolean loadOSPLogLoad OSP Log, if available. -
defaultLocales
Array of default OSP Locales. -
launcherMode
protected static boolean launcherModeSet true if a program is being run within Launcher. -
antiAliasText
public static boolean antiAliasTextTrue if text components should try and anti-alias text. -
appletMode
public static boolean appletModeTrue if running as an applet. -
applet
Static reference to an applet for document/code base access. -
webStart
public static boolean webStartTrue if launched by WebStart. -
authorMode
protected static boolean authorModeTrue if users allowed to author internal parameters such as Locale strings. -
MINUS
public static final char MINUSMinus sign, may be used instead of default hyphen-minus- See Also:
-
chooserDir
File Chooser starting directory. -
userhomeDir
User home directory. -
OSP_ICON_FILE
Location of OSP icon.- See Also:
-
launchingInSingleVM
public static boolean launchingInSingleVMTrue if always launching in single vm (applet mode, etc). -
CROSS_PLATFORM_LF
- See Also:
-
NIMBUS_LF
- See Also:
-
SYSTEM_LF
- See Also:
-
METAL_LF
- See Also:
-
GTK_LF
- See Also:
-
MOTIF_LF
- See Also:
-
WINDOWS_LF
- See Also:
-
DEFAULT_LF
- See Also:
-
DEFAULT_LOOK_AND_FEEL
-
DEFAULT_LOOK_AND_FEEL_DECORATIONS
public static final boolean DEFAULT_LOOK_AND_FEEL_DECORATIONS -
LOOK_AND_FEEL_TYPES
-
PROPERTY_ERROR_OUTOFMEMORY
- See Also:
-
frc
-
activeNode
-
launcherAllowEJSModel
public static boolean launcherAllowEJSModel -
OUT_OF_MEMORY_ERROR
-
outOfMemory
public static boolean outOfMemory
-
-
Method Details
-
getSkipDisplayOfPDF
public static boolean getSkipDisplayOfPDF() -
getUserAgent
-
getBrowserName
-
setApplet
-
getUserHome
Gets the user home directory.- Returns:
- the user home
-
getDownloadDir
Gets the download directory.- Returns:
- the download directory
-
showAboutDialog
Shows the about dialog.- Parameters:
parent
-
-
setLookAndFeel
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 createdJFrame
s orJDialog
s 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
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
Sets the launch jar path.- Parameters:
path
- the path
-
getLaunchJarName
Gets the launch jar name, if any.- Returns:
- launch jar path, or null if not launched from a jar
-
getLaunchJarPath
Gets the launch jar path, if any.- Returns:
- launch jar path, or null if not launched from a jar
-
getDocbase
Gets the window.location.href when JavaScript code is running in an html page.- Returns:
- window.location.href
-
getLaunchJarDirectory
Gets the launch jar directory, if any.- Returns:
- path to the directory containing the launch jar. May be null.
-
getLaunchJar
Gets the jar from which the progam was launched.- Returns:
- JarFile
-
getManifestAttribute
Gets a manifest attribute.- Returns:
- the String value or "" if not known
-
getLaunchJarBuildDate
Gets the launch jar build date.- Returns:
- the build date, or "" if not launched from a jar or date not known
-
getJavaFile
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
Gets the java VM path for a given Java executable file.- Parameters:
javaFile
- the Java executable file- Returns:
- the VM path
-
getDefaultLocales
Gets Locales for languages that have properties files in the core library.- Returns:
- 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
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
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
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
Gets the preferred decimal separator. May return null.- Returns:
- the separator, if any
-
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
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
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 preferencepref
- the object (may be null)
-
savePreferences
public static void savePreferences()Saves the current preference XMLControl by writing to a file. -
getPreferencesFile
Gets the preferences XML file if it exists.- Returns:
- the file, or null if none exists
-
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
Uses a JFileChooser to ask for a name.- Parameters:
chooser
- JFileChooser- Returns:
- String The absolute pah of the filename. Null if cancelled
-
chooseFilename
Uses a JFileChooser to ask for a name.- Parameters:
chooser
- JFileChooserparent
- Parent component for messagestoSave
- 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 titledescription
- a description stringextensions
- an array of allowed extensions- Returns:
- the JFileChooser
-
createChooser
Creates a JFileChooser with given description and extensions- Parameters:
description
- String A description stringextensions
- 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 stringextensions
- String[] An array of allowed extensionshomeDir
- File The target directory when the user clicks the home icon- Returns:
- JFileChooser
-
cacheJSFile
Cache (or clear) J2S._javaFileCache for this file.- Parameters:
file
-isAdd
-
-
getCachedBytes
Fetch bytes cached for temporary or DnD files in JavaScript.- Parameters:
path
-- Returns:
-
addJSCachedBytes
-
isJSTemp
-
displayURL
- Throws:
IOException
-
showStatus
-
getURLBytesAsync
-
postEvent
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
-
setAppClass
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
-
exit
public static void exit()clean up all pending anything -
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
Pastes from the clipboard and returns the pasted string.- Returns:
- the pasted string, or null if none
-
copy
-
setJSClipboardPasteListener
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
-
getMemory
public static long[] getMemory()Get the used and max from jvaa.lang.management.memoryMXBean.- Returns:
- [ used, max ]
-
getMemoryStr
-
trigger
Create a simple one-time Timer and start it.- Parameters:
ms
-a
-- Returns:
-
chooseColor
Displays a JColorChooser and returns the selected color.- Parameters:
color
- the initial color to selecttitle
- the title for the dialogwhenDone
- TODO
-