Class Launcher

java.lang.Object
org.opensourcephysics.tools.Launcher
Direct Known Subclasses:
LaunchBuilder

public class Launcher extends Object
This provides a GUI for launching osp applications and xml files.
Author:
Douglas Brown
  • Field Details

    • defaultIcon

      protected static ResizableIcon defaultIcon
    • mainLauncher

      protected static Launcher mainLauncher
    • defaultFileName

      protected static String defaultFileName
    • resourcesPath

      protected static String resourcesPath
    • classPath

      protected static String classPath
    • tabSetBasePath

      protected static String tabSetBasePath
    • releaseDate

      protected static String releaseDate
    • chooser

      protected static JFileChooser chooser
    • xmlFileFilter

      protected static FileFilter xmlFileFilter
    • xsetFileFilter

      protected static FileFilter xsetFileFilter
    • launcherFileFilter

      protected static FileFilter launcherFileFilter
    • wInit

      protected static int wInit
    • hInit

      protected static int hInit
    • splashDialog

      protected static JDialog splashDialog
    • creditsLabel

      protected static JLabel creditsLabel
    • splashTitleLabel

      protected static JLabel splashTitleLabel
    • splashPathLabel

      protected static JLabel splashPathLabel
    • splashTimer

      protected static Timer splashTimer
    • baseMenuFontSize

      protected static float baseMenuFontSize
    • launchIcon

      protected static ResizableIcon launchIcon
    • launchedIcon

      protected static ResizableIcon launchedIcon
    • singletonIcon

      protected static ResizableIcon singletonIcon
    • whiteFolderIcon

      protected static ResizableIcon whiteFolderIcon
    • redFileIcon

      protected static ResizableIcon redFileIcon
    • greenFileIcon

      protected static ResizableIcon greenFileIcon
    • magentaFileIcon

      protected static ResizableIcon magentaFileIcon
    • yellowFileIcon

      protected static ResizableIcon yellowFileIcon
    • whiteFileIcon

      protected static ResizableIcon whiteFileIcon
    • noFileIcon

      protected static ResizableIcon noFileIcon
    • ghostFileIcon

      protected static ResizableIcon ghostFileIcon
    • redFolderIcon

      protected static ResizableIcon redFolderIcon
    • greenFolderIcon

      protected static ResizableIcon greenFolderIcon
    • yellowFolderIcon

      protected static ResizableIcon yellowFolderIcon
    • linkIcon

      protected static ResizableIcon linkIcon
    • htmlIcon

      protected static ResizableIcon htmlIcon
    • launchEmptyIcon

      protected static ResizableIcon launchEmptyIcon
    • ejsIcon

      protected static ResizableIcon ejsIcon
    • backIcon

      protected static ResizableIcon backIcon
    • forwardIcon

      protected static ResizableIcon forwardIcon
    • backDisabledIcon

      protected static ResizableIcon backDisabledIcon
    • forwardDisabledIcon

      protected static ResizableIcon forwardDisabledIcon
    • singleAppMode

      public static boolean singleAppMode
    • frameFinder

      protected static Timer frameFinder
    • existingFrames

      protected static ArrayList<Frame> existingFrames
    • extractExtensions

      protected static String[] extractExtensions
    • passwords

      protected static Set<String> passwords
    • xmlInspector

      protected JDialog xmlInspector
    • tableInspector

      protected JDialog tableInspector
    • divider

      protected int divider
    • frame

      public Launcher.LauncherFrame frame
    • popupEnabled

      public boolean popupEnabled
    • postEdits

      protected boolean postEdits
    • contentPane

      protected JPanel contentPane
    • tabbedPane

      protected JTabbedPane tabbedPane
    • backButton

      protected JButton backButton
    • forwardButton

      protected JButton forwardButton
    • singleAppItem

      protected JMenuItem singleAppItem
    • selectedNode

      protected LaunchNode selectedNode
    • previousNode

      protected LaunchNode previousNode
    • tabSetName

      protected String tabSetName
    • textPane

      protected JTextPane textPane
    • textScroller

      protected JScrollPane textScroller
    • showText

      protected boolean showText
    • htmlTabList

      protected ArrayList<Launcher.HTMLPane> htmlTabList
    • fileMenu

      protected JMenu fileMenu
    • displayMenu

      protected JMenu displayMenu
    • helpMenu

      protected JMenu helpMenu
    • openItem

      protected JMenuItem openItem
    • openFromJarMenu

      protected JMenu openFromJarMenu
    • passwordItem

      protected JMenuItem passwordItem
    • closeTabItem

      protected JMenuItem closeTabItem
    • closeAllItem

      protected JMenuItem closeAllItem
    • editItem

      protected JMenuItem editItem
    • exitItem

      protected JMenuItem exitItem
    • inspectItem

      protected JMenuItem inspectItem
    • hideItem

      protected JMenuItem hideItem
    • backItem

      protected JMenuItem backItem
    • languageMenu

      protected JMenu languageMenu
    • sizeUpItem

      protected JMenuItem sizeUpItem
    • sizeDownItem

      protected JMenuItem sizeDownItem
    • lookFeelMenu

      protected JMenu lookFeelMenu
    • specificLFGroup

      protected ButtonGroup specificLFGroup
    • genericLFGroup

      protected ButtonGroup genericLFGroup
    • javaLFItem

      protected JMenuItem javaLFItem
    • systemLFItem

      protected JMenuItem systemLFItem
    • defaultLFItem

      protected JMenuItem defaultLFItem
    • lookFeelItem

      protected JMenuItem lookFeelItem
    • logItem

      protected JMenuItem logItem
    • aboutItem

      protected JMenuItem aboutItem
    • authorInfoItem

      protected JMenuItem authorInfoItem
    • diagnosticMenu

      protected JMenu diagnosticMenu
    • languageItems

      protected JMenuItem[] languageItems
    • classChooser

      protected LaunchClassChooser classChooser
    • openPaths

      protected Set<String> openPaths
    • spawner

      protected Launcher spawner
    • previewing

      protected boolean previewing
    • editorEnabled

      protected boolean editorEnabled
    • changedFiles

      protected Set<String> changedFiles
    • tabListener

      protected MouseListener tabListener
    • newNodeSelected

      protected boolean newNodeSelected
    • selfContained

      protected boolean selfContained
    • jarBasePath

      protected String jarBasePath
    • title

      protected String title
    • tabs

      protected ArrayList<Component> tabs
    • undoManager

      protected LauncherUndo undoManager
    • undoSupport

      protected UndoableEditSupport undoSupport
    • password

      protected String password
    • pwRequiredToLoad

      protected boolean pwRequiredToLoad
    • linkListener

      protected HyperlinkListener linkListener
    • saveState

      protected boolean saveState
    • lookAndFeel

      protected String lookAndFeel
    • expansions

      protected Collection<?>[] expansions
    • selectedPath

      protected String selectedPath
    • memoryButton

      protected JButton 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

      public Launcher(String fileName)
      Constructs a Launcher and opens the specified xml file.
      Parameters:
      fileName - the name of the xml file
    • Launcher

      public Launcher(String help_path, boolean splash)
    • Launcher

      public Launcher(String fileName, boolean splash, JPanel contentPane)
      Constructs a Launcher and opens the specified xml file.
      Parameters:
      fileName - the name of the xml file
      splash - true to show the splash screen
      contentPane - for frameless externalization of contents
  • Method Details

    • setCanExit

      public void setCanExit(boolean _can)
      Whether exiting invokes System.exit()
      Parameters:
      _can -
    • getContentPane

      public Container getContentPane()
      Gets the content pane.
      Returns:
      the content pane
    • getSize

      public Dimension getSize()
      Gets the size.
      Returns:
      the size Dimension object
    • setSize

      public void setSize(Dimension dim)
      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
    • setNavigationVisible

      public void setNavigationVisible(boolean vis)
      Sets navigation button visibility
      Parameters:
      vis - true to show navigation buttons
    • 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

      public void setHyperlinksEnabled(LaunchNode node, boolean enabled)
      Sets the hyperlinksEnabled property for a specified node.
      Parameters:
      node -
      enabled - true to enable hyperlinks in node's html pages
    • getSelectedTab

      public LaunchPanel getSelectedTab()
      Gets the LaunchPanel in the selected tab. May return null.
      Returns:
      the LaunchPanel
    • setSelectedTab

      public LaunchPanel setSelectedTab(String path)
      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

      public LaunchPanel setSelectedTab(LaunchPanel tab)
      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

      public LaunchNode getSelectedNode()
      Gets the selected launch node. May return null.
      Returns:
      the selected launch node
    • setSelectedNode

      public LaunchNode setSelectedNode(String path)
      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

      public LaunchNode setSelectedNode(String path, int tabNumber)
      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
      tabNumber - the display tab number
      Returns:
      the LaunchNode
    • setSelectedNode

      public LaunchNode setSelectedNode(String path, int tabNumber, URL url)
      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
      tabNumber - the display tab number
      url - the URL to display
      Returns:
      the LaunchNode
    • setSelectedNodeByKey

      public LaunchNode setSelectedNodeByKey(String keywords, int tabNumber)
      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 node
      tabNumber - the tab to display
      Returns:
      the LaunchNode
    • getRootNode

      public 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

      public LaunchPanel getTab(int i)
      Gets the launch panel at the specified tab index. May return null.
      Parameters:
      i - the tab index
      Returns:
      the launch panel
    • getHTMLTab

      public Launcher.HTMLPane getHTMLTab(int i)
      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

      public String open(String[] args)
      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

      public String open(String name)
      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
    • setNavbarRightEndComponents

      public void setNavbarRightEndComponents(Component[] comps)
      Sets the components to be displayed at the right end of the navigation bar.
      Parameters:
      comps - the components
    • addTab

      public boolean addTab(LaunchNode root)
      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

      protected void showButtonView(LaunchNode node)
      Displays a button view of the specified node.
      Parameters:
      node - the node
    • showTabbedPaneView

      protected void showTabbedPaneView()
      Displays the standard tabbed pane view.
    • open

      protected String 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

      protected Set<String> getOpenPaths()
      Gets the paths of currently open set and tabs.
      Returns:
      the open paths
    • setLookAndFeel

      protected Launcher setLookAndFeel(String lf, boolean always)
      Sets the look and feel.
      Parameters:
      lf - OSPRuntime name of look and feel
      always - 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

      protected boolean isLink(LaunchNode node)
      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

      protected boolean hasEJSModel(LaunchNode node)
      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

      protected boolean isLaunchable(LaunchNode node)
      Determines whether the specified node is launchable.
      Parameters:
      node - the launch node to verify
      Returns:
      true if the node is launchable
    • setLinksEnabled

      protected void setLinksEnabled(JEditorPane textPane, boolean enabled)
      Enables hyperlinks for the specified JEditorPane.
      Parameters:
      textPane - the editor pane
      enabled - true to enable hyperlinks
    • handleHyperLink

      protected void handleHyperLink(URL url)
    • isDisplayable

      public static boolean isDisplayable(String path)
      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

      protected Object[] getNodeAndPage(URL html)
      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

      protected static boolean isLaunchable(Class<?> type)
      Determines whether the specified class is launchable.
      Parameters:
      type - the launch class to verify
      Returns:
      true if the class is launchable
    • isModel

      protected static boolean isModel(Class<?> type)
      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

      protected static JComponent getModelPane(Class<?> type, String[] args)
      Gets the modelPane for a specified class. May return null.
      Parameters:
      type -
      args -
      Returns:
      the model pane
    • handleMousePressed

      protected void handleMousePressed(MouseEvent e, LaunchPanel tab)
      Handles a mouse pressed event.
      Parameters:
      e - the mouse event
      tab - 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

      protected ResizableIcon getFileIcon(LaunchNode node)
      Gets an appropriate File icon for a node (must have non-null filename)
      Parameters:
      node - the launch node
      Returns:
      the icon
    • launch

      public static void launch(Class<?> type)
      Launches an application with no arguments.
      Parameters:
      type - the class to be launched
    • launch

      public static void launch(Class<?> type, String[] args)
      Launches an application with an array of string arguments.
      Parameters:
      type - the class to be launched
      args - the String array of arguments
    • launch

      public static void launch(Class<?> type, String[] args, LaunchNode node)
      Launches an application associated with a launch node.
      Parameters:
      type - the class to be launched
      args - 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

      protected static void relaunch(String[] args, long memorySize, Component comp)
      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 arguments
      memorySize - the desired memory size in MB
      comp - a component used by JOptionPane (may be null)
    • main

      public static void main(String[] args)
      Main entry point when used as application.
      Parameters:
      args - args[0] may be an xml file name
    • getClassChooser

      protected LaunchClassChooser getClassChooser()
      Gets a class chooser for selecting launchable classes from jar files.
      Returns:
      the jar class chooser
    • getXMLFilter

      protected static FileFilter getXMLFilter()
      Gets a file filter that acepts xml files.
      Returns:
      the xml file filter
    • getXMLChooser

      protected static JFileChooser 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

      protected static String getDisplayName(String fileName)
      Gets the display name of the specified file name.
      Parameters:
      fileName - the file name
      Returns:
      the bare name without path or extension
    • getDefaultJar

      protected static String getDefaultJar()
      Gets the name of the jar containing the default launcher xml file, if any.
      Returns:
      the jar name
    • loadIcon

      protected static ResizableIcon loadIcon(String imageName)
      Loads an icon and substitutes default icon if not found.
      Parameters:
      imageName - the name of the image file
      Returns:
      the icon
    • log

      protected static void log(String key)
    • urlExists

      public static boolean urlExists(URL url)
      Check URL for content, being sure to close the stream
      Parameters:
      url -
      Returns:
      true if content is readable