Package org.opensourcephysics.tools
Class Launcher
java.lang.Object
org.opensourcephysics.tools.Launcher
- Direct Known Subclasses:
LaunchBuilder
This provides a GUI for launching osp applications and xml files.
- Author:
- Douglas Brown
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA class for displaying html pages in a scrolled textPane.classA unique frame class for Launcher.classA class to save and load a set of launch tabs and Launcher static fields. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JMenuItemprotected JMenuItemprotected JButtonprotected static ResizableIconprotected static ResizableIconprotected JMenuItemprotected static floatprotected static JFileChooserprotected LaunchClassChooserprotected static Stringprotected JMenuItemprotected JMenuItemprotected JPanelprotected static JLabelprotected static Stringprotected static ResizableIconprotected JMenuItemprotected JMenuprotected JMenuprotected intprotected JMenuItemprotected booleanprotected static ResizableIconprotected JMenuItemprotected Collection<?>[]protected static String[]protected JMenuprotected JButtonprotected static ResizableIconprotected static ResizableIconprotected static Timerprotected ButtonGroupprotected static ResizableIconprotected static ResizableIconprotected static ResizableIconprotected JMenuprotected JMenuItemprotected static intprotected static ResizableIconprotected ArrayList<Launcher.HTMLPane>protected JMenuItemprotected Stringprotected JMenuItemprotected JMenuItem[]protected JMenuprotected static ResizableIconprotected static ResizableIconprotected static FileFilterprotected static ResizableIconprotected static ResizableIconprotected HyperlinkListenerprotected JMenuItemprotected Stringprotected JMenuItemprotected JMenuprotected static ResizableIconprotected static Launcherprotected JButtonprotected JToolBarprotected Component[]protected JButtonprotected static ResizableIconprotected booleanprotected static ResizableIconprotected Componentprotected booleanprotected static ResizableIconprotected JMenuprotected JMenuItemprotected Stringprotected JMenuItemprotected JPopupMenubooleanprotected booleanprotected booleanprotected LaunchNodeprotected booleanprotected static ResizableIconprotected static ResizableIconprotected static Stringprotected static Stringprotected booleanprotected LaunchNodeprotected Stringprotected booleanprotected booleanprotected JMenuItemstatic booleanprotected static ResizableIconprotected JMenuItemprotected JMenuItemprotected Launcherprotected ButtonGroupprotected static JDialogprotected static JLabelprotected static Timerprotected static JLabelprotected JMenuItemprotected JTabbedPaneprotected JDialogprotected MouseListenerprotected static Stringprotected Stringprotected JTextPaneprotected JScrollPaneprotected Stringprotected LauncherUndoprotected UndoableEditSupportprotected static ResizableIconprotected static ResizableIconprotected static intprotected static FileFilterprotected JDialogprotected static FileFilterprotected intprotected static ResizableIconprotected static ResizableIcon -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddTab(LaunchNode root) Creates a LaunchPanel with the specified root and adds it to a new tab.voidClears the navigation history.protected voidcreateGUI(boolean splash) Creates the GUI.protected voidexit()Exits this application.protected LaunchClassChooserGets a class chooser for selecting launchable classes from jar files.Gets the content pane.protected static StringGets the name of the jar containing the default launcher xml file, if any.protected static StringgetDisplayName(String fileName) Gets the display name of the specified file name.intGets the divider location.protected ResizableIcongetFileIcon(LaunchNode node) Gets an appropriate File icon for a node (must have non-null filename)getHTMLTab(int i) Gets the html tab at the specified index.intGets the html tab count.protected static JComponentgetModelPane(Class<?> type, String[] args) Gets the modelPane for a specified class.protected Object[]getNodeAndPage(URL html) Gets the node path and page number associated with an html URL.Gets the paths of currently open set and tabs.Gets the root node of the selected launch tree.Gets the selected launch node.Gets the LaunchPanel in the selected tab.getSize()Gets the size.getTab(int i) Gets the launch panel at the specified tab index.intGets the current number of tabs (LaunchPanels)protected static JFileChooserGets a file chooser for selecting xml files.protected static FileFilterGets a file filter that acepts xml files.protected voidhandleHyperLink(URL url) protected voidhandleMousePressed(MouseEvent e, LaunchPanel tab) Handles a mouse pressed event.protected booleanhasEJSModel(LaunchNode node) Determines whether the specified node has an associated EJS model (xml file).static booleanisDisplayable(String path) Check to see if a path is displayable using HTMLEditorKit.protected static booleanisLaunchable(Class<?> type) Determines whether the specified class is launchable.protected booleanisLaunchable(LaunchNode node) Determines whether the specified node is launchable.protected booleanisLink(LaunchNode node) Determines whether the specified node is a link to another xset, tab or node.protected static booleanDetermines whether the specified class is a model.booleanReports visibility of the Launcher frame.static voidLaunches an application with no arguments.static voidLaunches an application with an array of string arguments.static voidlaunch(Class<?> type, String[] args, LaunchNode node) Launches an application associated with a launch node.protected static ResizableIconLoads an icon and substitutes default icon if not found.protected static voidstatic voidMain entry point when used as application.protected Stringopen()Opens an xml file selected with a chooser.Opens an xml document specified by name and displays it in a new tab (or selects the tab if already open).Opens an xml document and selects a tab and/or node specified by name.protected voidRefreshes the GUI.protected voidRefreshes the memory button.voidRefreshes the selected tab.protected voidRefreshes string resources.protected static voidAttempts to relaunch the current jar in a separate VM with specified arguments and memory size.protected booleanRemoves all tabs.booleanRemoves the selected tab.voidsetCanExit(boolean _can) Whether exiting invokes System.exit()voidsetDivider(int loc) Sets the divider location.voidsetEditorEnabled(boolean enabled) Sets the editorEnabled property.voidsetFontLevel(int level) Sets the font level.voidsetHyperlinksEnabled(boolean enabled) Sets the hyperlinksEnabled property for all nodes.voidsetHyperlinksEnabled(LaunchNode node, boolean enabled) Sets the hyperlinksEnabled property for a specified node.static voidsetJarsOnly(boolean onlyJars) Sets the static jarsOnly property.protected voidsetLinksEnabled(JEditorPane textPane, boolean enabled) Enables hyperlinks for the specified JEditorPane.protected LaunchersetLookAndFeel(String lf, boolean always) Sets the look and feel.voidsetNavbarRightEndComponents(Component[] comps) Sets the components to be displayed at the right end of the navigation bar.voidsetNavigationVisible(boolean vis) Sets navigation button visibilitysetSelectedNode(String path) Sets the selected node by path and returns the node, or null if node not found.setSelectedNode(String path, int tabNumber) Sets the selected node by path and returns the node, or null if node not found.setSelectedNode(String path, int tabNumber, URL url) Sets the selected node by path and returns the node, or null if node not found.setSelectedNodeByKey(String keywords, int tabNumber) Sets the selected node by path and returns the node, or null if node not found.setSelectedTab(String path) Sets the selected tab by name and returns its LaunchPanel, or null if tab not found.Sets the selected tab and returns its LaunchPanel, or null if tab not found.voidSets the size.voidsetVisible(boolean visible) Sets the visibility of the Launcher frame.protected voidShows the about dialog.protected voidShows the metadata dialog.protected voidshowButtonView(LaunchNode node) Displays a button view of the specified node.protected voidDisplays the standard tabbed pane view.protected booleanTerminates running apps.static booleanCheck URL for content, being sure to close the stream
-
Field Details
-
defaultIcon
-
mainLauncher
-
defaultFileName
-
resourcesPath
-
classPath
-
tabSetBasePath
-
releaseDate
-
chooser
-
xmlFileFilter
-
xsetFileFilter
-
launcherFileFilter
-
wInit
protected static int wInit -
hInit
protected static int hInit -
splashDialog
-
creditsLabel
-
splashTitleLabel
-
splashPathLabel
-
splashTimer
-
baseMenuFontSize
protected static float baseMenuFontSize -
launchIcon
-
launchedIcon
-
singletonIcon
-
whiteFolderIcon
-
redFileIcon
-
greenFileIcon
-
magentaFileIcon
-
yellowFileIcon
-
whiteFileIcon
-
noFileIcon
-
ghostFileIcon
-
redFolderIcon
-
greenFolderIcon
-
yellowFolderIcon
-
linkIcon
-
htmlIcon
-
launchEmptyIcon
-
ejsIcon
-
backIcon
-
forwardIcon
-
backDisabledIcon
-
forwardDisabledIcon
-
singleAppMode
public static boolean singleAppMode -
frameFinder
-
existingFrames
-
extractExtensions
-
passwords
-
xmlInspector
-
tableInspector
-
divider
protected int divider -
frame
-
popupEnabled
public boolean popupEnabled -
postEdits
protected boolean postEdits -
contentPane
-
tabbedPane
-
backButton
-
forwardButton
-
singleAppItem
-
selectedNode
-
previousNode
-
tabSetName
-
textPane
-
textScroller
-
showText
protected boolean showText -
htmlTabList
-
fileMenu
-
displayMenu
-
helpMenu
-
openItem
-
openFromJarMenu
-
passwordItem
-
closeTabItem
-
closeAllItem
-
editItem
-
exitItem
-
inspectItem
-
hideItem
-
backItem
-
languageMenu
-
sizeUpItem
-
sizeDownItem
-
lookFeelMenu
-
specificLFGroup
-
genericLFGroup
-
javaLFItem
-
systemLFItem
-
defaultLFItem
-
lookFeelItem
-
logItem
-
aboutItem
-
authorInfoItem
-
diagnosticMenu
-
languageItems
-
classChooser
-
popup
-
openPaths
-
spawner
-
previewing
protected boolean previewing -
editorEnabled
protected boolean editorEnabled -
changedFiles
-
tabListener
-
newNodeSelected
protected boolean newNodeSelected -
selfContained
protected boolean selfContained -
jarBasePath
-
title
-
tabs
-
undoManager
-
undoSupport
-
password
-
pwRequiredToLoad
protected boolean pwRequiredToLoad -
linkListener
-
saveState
protected boolean saveState -
lookAndFeel
-
expansions
-
selectedPath
-
memoryButton
-
xsetMemorySize
protected int xsetMemorySize
-
-
Constructor Details
-
Launcher
public Launcher()Constructs a bare Launcher with a splash screen. -
Launcher
public Launcher(boolean splash) Constructs a bare Launcher with or without a splash screen.- Parameters:
splash- true to show the splash screen
-
Launcher
Constructs a Launcher and opens the specified xml file.- Parameters:
fileName- the name of the xml file
-
Launcher
-
Launcher
Constructs a Launcher and opens the specified xml file.- Parameters:
fileName- the name of the xml filesplash- true to show the splash screencontentPane- for frameless externalization of contents
-
-
Method Details
-
setCanExit
public void setCanExit(boolean _can) Whether exiting invokes System.exit()- Parameters:
_can-
-
getContentPane
Gets the content pane.- Returns:
- the content pane
-
getSize
Gets the size.- Returns:
- the size Dimension object
-
setSize
Sets the size.- Parameters:
dim- the size Dimension
-
getDivider
public int getDivider()Gets the divider location.- Returns:
- the divider location
-
setDivider
public void setDivider(int loc) Sets the divider location.- Parameters:
loc- the divider location
-
isVisible
public boolean isVisible()Reports visibility of the Launcher frame.- Returns:
- true if visible
-
setVisible
public void setVisible(boolean visible) Sets the visibility of the Launcher frame.- Parameters:
visible- true to show the frame
-
clearHistory
public void clearHistory()Clears the navigation history. -
setEditorEnabled
public void setEditorEnabled(boolean enabled) Sets the editorEnabled property.- Parameters:
enabled- true to enable editing from within Launcher
-
setHyperlinksEnabled
public void setHyperlinksEnabled(boolean enabled) Sets the hyperlinksEnabled property for all nodes.- Parameters:
enabled- true to enable hyperlinks in html pages
-
setHyperlinksEnabled
Sets the hyperlinksEnabled property for a specified node.- Parameters:
node-enabled- true to enable hyperlinks in node's html pages
-
getSelectedTab
Gets the LaunchPanel in the selected tab. May return null.- Returns:
- the LaunchPanel
-
setSelectedTab
Sets the selected tab by name and returns its LaunchPanel, or null if tab not found. The path passed to this method is one or more node names separated by /.- Parameters:
path- a path starting with the name of the tab's root node- Returns:
- the LaunchPanel containing the root
-
setSelectedTab
Sets the selected tab and returns its LaunchPanel, or null if tab not found.- Parameters:
tab- the tab to select- Returns:
- the LaunchPanel containing the root
-
getSelectedNode
Gets the selected launch node. May return null.- Returns:
- the selected launch node
-
setSelectedNode
Sets the selected node by path and returns the node, or null if node not found. Path is node names separated by / or \- Parameters:
path- the path of the node- Returns:
- the LaunchNode
-
setSelectedNode
Sets the selected node by path and returns the node, or null if node not found. Path is node names separated by / or \- Parameters:
path- the path of the nodetabNumber- the display tab number- Returns:
- the LaunchNode
-
setSelectedNode
Sets the selected node by path and returns the node, or null if node not found. Path is node names separated by / or \- Parameters:
path- the path of the nodetabNumber- the display tab numberurl- the URL to display- Returns:
- the LaunchNode
-
setSelectedNodeByKey
Sets the selected node by path and returns the node, or null if node not found. Path is node names separated by / or \- Parameters:
keywords- the keywords of the nodetabNumber- the tab to display- Returns:
- the LaunchNode
-
getRootNode
Gets the root node of the selected launch tree. May return null.- Returns:
- the root node
-
getTabCount
public int getTabCount()Gets the current number of tabs (LaunchPanels)- Returns:
- the tab count
-
getTab
Gets the launch panel at the specified tab index. May return null.- Parameters:
i- the tab index- Returns:
- the launch panel
-
getHTMLTab
Gets the html tab at the specified index.- Parameters:
i- the tab index- Returns:
- the html tab
-
getHTMLTabCount
public int getHTMLTabCount()Gets the html tab count.- Returns:
- the html tab count
-
open
Opens an xml document and selects a tab and/or node specified by name. args[0] may be a relative path, absolute path, or self-contained xml string. args[1] may be a tab name and/or node path.- Parameters:
args- the arguments- Returns:
- the absolute path, or null if failed or currently open
-
open
Opens an xml document specified by name and displays it in a new tab (or selects the tab if already open). Name may be a relative path, absolute path, or self-contained xml string.- Parameters:
name- the name- Returns:
- the absolute path, or null if failed or currently open
-
addTab
Creates a LaunchPanel with the specified root and adds it to a new tab.- Parameters:
root- the root node- Returns:
- true if tab was added
-
showButtonView
Displays a button view of the specified node.- Parameters:
node- the node
-
showTabbedPaneView
protected void showTabbedPaneView()Displays the standard tabbed pane view. -
open
Opens an xml file selected with a chooser.- Returns:
- the name of the opened file
-
removeSelectedTab
public boolean removeSelectedTab()Removes the selected tab.- Returns:
- true if the tab was removed
-
removeAllTabs
protected boolean removeAllTabs()Removes all tabs.- Returns:
- true if all tabs were removed
-
refreshStringResources
protected void refreshStringResources()Refreshes string resources. -
refreshGUI
protected void refreshGUI()Refreshes the GUI. -
createGUI
protected void createGUI(boolean splash) Creates the GUI.- Parameters:
splash- true to show the splash screen
-
setFontLevel
public void setFontLevel(int level) Sets the font level.- Parameters:
level- the level
-
getOpenPaths
Gets the paths of currently open set and tabs.- Returns:
- the open paths
-
setLookAndFeel
Sets the look and feel.- Parameters:
lf- OSPRuntime name of look and feelalways- true to set LnF even if already set- Returns:
- a new Launcher
-
showAboutDialog
protected void showAboutDialog()Shows the about dialog. -
showAuthorInformation
protected void showAuthorInformation()Shows the metadata dialog. -
isLink
Determines whether the specified node is a link to another xset, tab or node. To be a link, there must be no launch class but one or more arguments.- Parameters:
node- the launch node to verify- Returns:
trueif the node is a link
-
hasEJSModel
Determines whether the specified node has an associated EJS model (xml file).- Parameters:
node- the launch node to check- Returns:
trueif the node has an EJS model
-
isLaunchable
Determines whether the specified node is launchable.- Parameters:
node- the launch node to verify- Returns:
trueif the node is launchable
-
setLinksEnabled
Enables hyperlinks for the specified JEditorPane.- Parameters:
textPane- the editor paneenabled- true to enable hyperlinks
-
handleHyperLink
-
isDisplayable
Check to see if a path is displayable using HTMLEditorKit. This will be the case if the path has a hash-tag reference or does not end in ".pdf", ".doc", or ".txt".- Parameters:
path-- Returns:
- true if displayable using HTMLEditorKit
-
getNodeAndPage
Gets the node path and page number associated with an html URL. May return null.- Parameters:
html- the URL- Returns:
- [0] String node path, [1] Integer pageNumber
-
isLaunchable
Determines whether the specified class is launchable.- Parameters:
type- the launch class to verify- Returns:
trueif the class is launchable
-
isModel
Determines whether the specified class is a model. A model class must define a static getModelPane(String[], Frame) method.- Parameters:
type- the class to verify- Returns:
trueif the class is a model
-
getModelPane
Gets the modelPane for a specified class. May return null.- Parameters:
type-args-- Returns:
- the model pane
-
handleMousePressed
Handles a mouse pressed event.- Parameters:
e- the mouse eventtab- the launch panel receiving the event
-
exit
protected void exit()Exits this application. -
terminateApps
protected boolean terminateApps()Terminates running apps.- Returns:
- false if process is cancelled by the user
-
getFileIcon
Gets an appropriate File icon for a node (must have non-null filename)- Parameters:
node- the launch node- Returns:
- the icon
-
launch
Launches an application with no arguments.- Parameters:
type- the class to be launched
-
launch
Launches an application with an array of string arguments.- Parameters:
type- the class to be launchedargs- the String array of arguments
-
launch
Launches an application associated with a launch node.- Parameters:
type- the class to be launchedargs- the argument array (may be null)node- the launch node (may be null)
-
setJarsOnly
public static void setJarsOnly(boolean onlyJars) Sets the static jarsOnly property.- Parameters:
onlyJars- true to restrict class paths to jar files
-
relaunch
Attempts to relaunch the current jar in a separate VM with specified arguments and memory size. If successful, the current VM exits.- Parameters:
args- the main method argumentsmemorySize- the desired memory size in MBcomp- a component used by JOptionPane (may be null)
-
main
Main entry point when used as application.- Parameters:
args- args[0] may be an xml file name
-
getClassChooser
Gets a class chooser for selecting launchable classes from jar files.- Returns:
- the jar class chooser
-
getXMLFilter
Gets a file filter that acepts xml files.- Returns:
- the xml file filter
-
getXMLChooser
Gets a file chooser for selecting xml files.- Returns:
- the xml chooser
-
refreshSelectedTab
public void refreshSelectedTab()Refreshes the selected tab. -
refreshMemoryButton
protected void refreshMemoryButton()Refreshes the memory button. -
getDisplayName
Gets the display name of the specified file name.- Parameters:
fileName- the file name- Returns:
- the bare name without path or extension
-
getDefaultJar
Gets the name of the jar containing the default launcher xml file, if any.- Returns:
- the jar name
-
loadIcon
Loads an icon and substitutes default icon if not found.- Parameters:
imageName- the name of the image file- Returns:
- the icon
-
log
-
urlExists
Check URL for content, being sure to close the stream- Parameters:
url-- Returns:
- true if content is readable
-