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 interfaceAn 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 classstatic classstatic classA class to compare version strings. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic LaunchNodestatic booleanstatic booleanstatic booleanstatic booleanHighlightDataSet -- Firefox has problems with canvas clip/unclip getting slower and slower and slowerstatic booleanstatic booleanstatic booleanTrue if text components should try and anti-alias text.static JAppletStatic reference to an applet for document/code base access.static booleanTrue if running as an applet.protected static booleanTrue if users allowed to author internal parameters such as Locale strings.static booleanstatic final booleanstatic booleanstatic booleanstatic StringFile Chooser starting directory.static final Stringstatic final charstatic final charstatic final Stringstatic final LookAndFeelstatic final booleanstatic Locale[]Array of default OSP Locales.static booleanDisables drawing for faster start-up and to avoid screen flash in Drawing Panels.static booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic FontRenderContextstatic final Stringstatic booleanstatic booleanstatic booleanstatic swingjs.api.JSUtilIstatic booleanprotected static booleanSet true if a program is being run within Launcher.static booleanTrue if always launching in single vm (applet mode, etc).static booleanLoad Data Tool, if available.static booleanLoad Export Tool, if available.static booleanLoad OSP Log, if available.static booleanLoad Translator Tool, if available.static booleanLoad Video Tool, if available.static booleanstatic intstatic final Stringstatic final charMinus sign, may be used instead of default hyphen-minusstatic final Stringstatic final Stringstatic final StringLocation of OSP icon.static final Stringstatic final Integerstatic booleanstatic final Stringstatic final Stringstatic booleanstatic booleanstatic final Stringstatic final Stringstatic booleanstatic StringUser home directory.static booleanstatic final Stringstatic final intstatic final intstatic final Stringstatic booleanTrue if launched by WebStart.static final String -
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic byte[]addJSCachedBytes(Object URLorURIorFile) static voidcacheJSFile(File file, boolean isAdd) Cache (or clear) J2S._javaFileCache for this file.static voidchooseColor(Color color, String title, Consumer<Color> whenDone) Displays a JColorChooser and returns the selected color.static StringchooseFilename(JFileChooser chooser) Uses a JFileChooser to ask for a name.static StringchooseFilename(JFileChooser chooser, Component parent, boolean toSave) Uses a JFileChooser to ask for a name.static voidcopy(String s, ClipboardOwner owner) static javajs.async.AsyncFileChoosercreateChooser(String description, String[] extensions) Creates a JFileChooser with given description and extensionsstatic javajs.async.AsyncFileChoosercreateChooser(String description, String[] extensions, File homeDir) Creates a JFileChooser with given description and extensionsstatic javajs.async.AsyncFileChoosercreateChooser(String title, String description, String[] extensions) Creates a JFileChooser with given title, description and extensionsstatic voiddispatchEventWait(Runnable runner) static voiddisplayURL(String url) static voidexit()clean up all pending anythingstatic Stringstatic byte[]getCachedBytes(String path) Fetch bytes cached for temporary or DnD files in JavaScript.static javajs.async.AsyncFileChooserGets a file chooser.static Clipboardstatic charstatic DecimalFormatSymbolsGets 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 StringgetDisplayLanguage(Locale locale) Gets the display language for a given Locale.static StringGets the window.location.href when JavaScript code is running in an html page.static FileGets the download directory.static Locale[]Gets Locales for languages that have properties files in the core library.static FilegetJavaFile(String jrePath) Gets the java executable file for a given jre path.static StringgetJREPath(File javaFile) Gets the java VM path for a given Java executable file.static JarFileGets the jar from which the progam was launched.static StringGets the launch jar build date.static StringGets the launch jar directory, if any.static StringGets the launch jar name, if any.static StringGets the launch jar path, if any.static intGets the major version number.static StringgetManifestAttribute(JarFile jarFile, String attribute) Gets a manifest attribute.static long[]Get the used and max from jvaa.lang.management.memoryMXBean.static Stringstatic ObjectgetPreference(String name) Gets a named preference object.static FileGets the preferences XML file if it exists.static StringGets the preferred decimal separator.static booleanstatic TranslatorGets the translator, if any.static voidgetURLBytesAsync(URL url, Function<byte[], Void> whenDone) static Stringstatic StringGets the user home directory.static intGets the bitness of the current Java VM.static booleanstatic booleanDetermines if running as an appletstatic booleanDetermines if running in author modestatic booleanReturns true if newly createdJFrames orJDialogs should have their Window decorations provided by the current look and feel.static booleanstatic booleanGets the launcherMode property.static booleanisLinux()Determines if OS is Linuxstatic booleanisMac()Determines if OS is Macstatic booleanDetermines if an InputEvent is a popup trigger.static booleanisVista()Determines if OS is Vistastatic booleanDetermines if launched by WebStartstatic booleanDetermines if OS is Windowsstatic StringPastes from the clipboard and returns the pasted string.static voidDeprecated.static voidSaves the current preference XMLControl by writing to a file.static voidSet the "app" property of the HTML5 applet object, for example, "testApplet.app", to point to the Jalview instance.static voidstatic voidsetAuthorMode(boolean b) Sets the authorMode property.static voidsetDefaultDecimalSeparator(char c) Sets the default decimal separator.static voidsetJSClipboardPasteListener(Component c, TransferHandler handler) Register a TransferHandler for the onpaste event for this component.static voidsetLauncherMode(boolean b) Sets the launcherMode property to true if applications in this VM are launched by Launcher.static voidsetLaunchJarPath(String path) Sets the launch jar path.static booleansetLookAndFeel(boolean useDefaultLnFDecorations, String lookAndFeel) Sets the look and feel of the user interface.static voidSwingJS may not have all UI actions already definedstatic voidsetPreference(String name, Object pref) Sets a named preference object.static voidsetPreferredDecimalSeparator(String separator) Sets the preferred decimal separator.static intsetTimeout(String name, int msDelay, boolean cancelPending, Runnable r) static voidshowAboutDialog(Component parent) Shows the about dialog.static voidshowStatus(String msg) static Timertrigger(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 createdJFrames orJDialogs 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
-