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 TypeClassDescriptionclass
A class for displaying html pages in a scrolled textPane.class
A unique frame class for Launcher.class
A class to save and load a set of launch tabs and Launcher static fields. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JMenuItem
protected JMenuItem
protected JButton
protected static ResizableIcon
protected static ResizableIcon
protected JMenuItem
protected static float
protected static JFileChooser
protected LaunchClassChooser
protected static String
protected JMenuItem
protected JMenuItem
protected JPanel
protected static JLabel
protected static String
protected static ResizableIcon
protected JMenuItem
protected JMenu
protected JMenu
protected int
protected JMenuItem
protected boolean
protected static ResizableIcon
protected JMenuItem
protected Collection<?>[]
protected static String[]
protected JMenu
protected JButton
protected static ResizableIcon
protected static ResizableIcon
protected static Timer
protected ButtonGroup
protected static ResizableIcon
protected static ResizableIcon
protected static ResizableIcon
protected JMenu
protected JMenuItem
protected static int
protected static ResizableIcon
protected ArrayList<Launcher.HTMLPane>
protected JMenuItem
protected String
protected JMenuItem
protected JMenuItem[]
protected JMenu
protected static ResizableIcon
protected static ResizableIcon
protected static FileFilter
protected static ResizableIcon
protected static ResizableIcon
protected HyperlinkListener
protected JMenuItem
protected String
protected JMenuItem
protected JMenu
protected static ResizableIcon
protected static Launcher
protected JButton
protected JToolBar
protected Component[]
protected JButton
protected static ResizableIcon
protected boolean
protected static ResizableIcon
protected Component
protected boolean
protected static ResizableIcon
protected JMenu
protected JMenuItem
protected String
protected JMenuItem
protected JPopupMenu
boolean
protected boolean
protected boolean
protected LaunchNode
protected boolean
protected static ResizableIcon
protected static ResizableIcon
protected static String
protected static String
protected boolean
protected LaunchNode
protected String
protected boolean
protected boolean
protected JMenuItem
static boolean
protected static ResizableIcon
protected JMenuItem
protected JMenuItem
protected Launcher
protected ButtonGroup
protected static JDialog
protected static JLabel
protected static Timer
protected static JLabel
protected JMenuItem
protected JTabbedPane
protected JDialog
protected MouseListener
protected static String
protected String
protected JTextPane
protected JScrollPane
protected String
protected LauncherUndo
protected UndoableEditSupport
protected static ResizableIcon
protected static ResizableIcon
protected static int
protected static FileFilter
protected JDialog
protected static FileFilter
protected int
protected static ResizableIcon
protected static ResizableIcon
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addTab
(LaunchNode root) Creates a LaunchPanel with the specified root and adds it to a new tab.void
Clears the navigation history.protected void
createGUI
(boolean splash) Creates the GUI.protected void
exit()
Exits this application.protected LaunchClassChooser
Gets a class chooser for selecting launchable classes from jar files.Gets the content pane.protected static String
Gets the name of the jar containing the default launcher xml file, if any.protected static String
getDisplayName
(String fileName) Gets the display name of the specified file name.int
Gets the divider location.protected ResizableIcon
getFileIcon
(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.int
Gets the html tab count.protected static JComponent
getModelPane
(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.int
Gets the current number of tabs (LaunchPanels)protected static JFileChooser
Gets a file chooser for selecting xml files.protected static FileFilter
Gets a file filter that acepts xml files.protected void
handleHyperLink
(URL url) protected void
handleMousePressed
(MouseEvent e, LaunchPanel tab) Handles a mouse pressed event.protected boolean
hasEJSModel
(LaunchNode node) Determines whether the specified node has an associated EJS model (xml file).static boolean
isDisplayable
(String path) Check to see if a path is displayable using HTMLEditorKit.protected static boolean
isLaunchable
(Class<?> type) Determines whether the specified class is launchable.protected boolean
isLaunchable
(LaunchNode node) Determines whether the specified node is launchable.protected boolean
isLink
(LaunchNode node) Determines whether the specified node is a link to another xset, tab or node.protected static boolean
Determines whether the specified class is a model.boolean
Reports visibility of the Launcher frame.static void
Launches an application with no arguments.static void
Launches an application with an array of string arguments.static void
launch
(Class<?> type, String[] args, LaunchNode node) Launches an application associated with a launch node.protected static ResizableIcon
Loads an icon and substitutes default icon if not found.protected static void
static void
Main entry point when used as application.protected String
open()
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 void
Refreshes the GUI.protected void
Refreshes the memory button.void
Refreshes the selected tab.protected void
Refreshes string resources.protected static void
Attempts to relaunch the current jar in a separate VM with specified arguments and memory size.protected boolean
Removes all tabs.boolean
Removes the selected tab.void
setCanExit
(boolean _can) Whether exiting invokes System.exit()void
setDivider
(int loc) Sets the divider location.void
setEditorEnabled
(boolean enabled) Sets the editorEnabled property.void
setFontLevel
(int level) Sets the font level.void
setHyperlinksEnabled
(boolean enabled) Sets the hyperlinksEnabled property for all nodes.void
setHyperlinksEnabled
(LaunchNode node, boolean enabled) Sets the hyperlinksEnabled property for a specified node.static void
setJarsOnly
(boolean onlyJars) Sets the static jarsOnly property.protected void
setLinksEnabled
(JEditorPane textPane, boolean enabled) Enables hyperlinks for the specified JEditorPane.protected Launcher
setLookAndFeel
(String lf, boolean always) Sets the look and feel.void
setNavbarRightEndComponents
(Component[] comps) Sets the components to be displayed at the right end of the navigation bar.void
setNavigationVisible
(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.void
Sets the size.void
setVisible
(boolean visible) Sets the visibility of the Launcher frame.protected void
Shows the about dialog.protected void
Shows the metadata dialog.protected void
showButtonView
(LaunchNode node) Displays a button view of the specified node.protected void
Displays the standard tabbed pane view.protected boolean
Terminates running apps.static boolean
Check 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:
true
if 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:
true
if the node has an EJS model
-
isLaunchable
Determines whether the specified node is launchable.- Parameters:
node
- the launch node to verify- Returns:
true
if 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:
true
if 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:
true
if 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
-