org.opensourcephysics.tools
Class Launcher

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

public class Launcher
extends java.lang.Object

This provides a GUI for launching osp applications and xml files.


Nested Class Summary
 class Launcher.LaunchSet
          A class to save and load a set of launch tabs and Launcher static fields.
protected  class Launcher.LinkEdit
          A class to undo/redo a link, open or new tabset action.
 
Field Summary
protected  javax.swing.JMenuItem aboutItem
           
static LaunchNode activeNode
           
protected  javax.swing.JMenuItem backItem
           
protected static float baseMenuFontSize
           
protected  java.util.Set changedFiles
           
protected static javax.swing.JFileChooser chooser
           
protected  LaunchClassChooser classChooser
           
protected static java.lang.String classPath
           
protected  javax.swing.JMenuItem closeAllItem
           
protected  javax.swing.JMenuItem closeTabItem
           
protected  javax.swing.JPanel contentPane
           
protected static java.lang.String defaultFileName
           
protected  javax.swing.JMenu diagnosticMenu
           
protected  javax.swing.JMenu displayMenu
           
protected  int divider
           
protected  javax.swing.JMenuItem editItem
           
protected  boolean editorEnabled
           
protected static java.util.ArrayList existingFrames
           
protected  javax.swing.JMenuItem exitItem
           
protected  javax.swing.JMenu fileMenu
           
 javax.swing.JFrame frame
           
protected static javax.swing.Timer frameFinder
           
protected static javax.swing.Icon ghostFileIcon
           
protected static javax.swing.Icon greenFileIcon
           
protected static javax.swing.Icon greenFolderIcon
           
protected  javax.swing.JMenu helpMenu
           
protected  javax.swing.JMenuItem hideItem
           
protected static int hInit
           
protected static javax.swing.Icon htmlIcon
           
protected  javax.swing.JMenuItem inspectItem
           
protected  javax.swing.JDialog inspector
           
protected static boolean isWebStart
           
protected  java.lang.String jarBasePath
           
protected  javax.swing.JMenuItem[] languageItems
           
protected  javax.swing.JMenu languageMenu
           
protected static javax.swing.Icon launchedIcon
           
protected static javax.swing.Icon launchEmptyIcon
           
protected static javax.swing.filechooser.FileFilter launcherFileFilter
           
protected static javax.swing.Icon launchIcon
           
protected static javax.swing.Icon linkIcon
           
protected  javax.swing.JMenuItem logItem
           
protected  javax.swing.JMenuItem lookFeelItem
           
protected static javax.swing.Icon magentaFileIcon
           
protected  boolean newNodeSelected
           
protected static javax.swing.Icon noFileIcon
           
protected  javax.swing.JMenu openFromJarMenu
           
protected  javax.swing.JMenuItem openItem
           
protected  java.util.Set openPaths
           
protected  java.lang.String password
           
protected  javax.swing.JPopupMenu popup
           
protected  boolean previewing
           
protected  LaunchNode previousNode
           
protected  boolean pwRequiredToLoad
           
protected static javax.swing.Icon redFileIcon
           
protected static javax.swing.Icon redFolderIcon
           
protected static java.lang.String releaseDate
           
protected static java.lang.String resourcesPath
           
protected  LaunchNode selectedNode
           
protected  boolean selfContained
           
protected  boolean showText
           
protected  javax.swing.JMenuItem singleAppItem
           
static boolean singleAppMode
           
protected static javax.swing.Icon singletonIcon
           
static boolean singletonMode
           
protected  javax.swing.JMenuItem sizeDownItem
           
protected  javax.swing.JMenuItem sizeUpItem
           
protected  Launcher spawner
           
protected static javax.swing.JDialog splashDialog
           
protected static javax.swing.JLabel splashPathLabel
           
protected static javax.swing.Timer splashTimer
           
protected static javax.swing.JLabel splashTitleLabel
           
protected  javax.swing.JTabbedPane tabbedPane
           
protected  java.awt.event.MouseListener tabListener
           
protected  java.util.ArrayList tabs
           
protected static java.lang.String tabSetBasePath
           
protected  java.lang.String tabSetName
           
protected  javax.swing.JEditorPane textPane
           
protected  javax.swing.JScrollPane textScroller
           
protected  java.lang.String title
           
protected  Launcher.LinkEdit undoEdit
           
protected  javax.swing.undo.UndoManager undoManager
           
protected  javax.swing.undo.UndoableEditSupport undoSupport
           
protected static java.lang.String version
           
protected static javax.swing.Icon whiteFileIcon
           
protected static javax.swing.Icon whiteFolderIcon
           
protected static int wInit
           
protected static javax.swing.filechooser.FileFilter xmlFileFilter
           
protected static javax.swing.filechooser.FileFilter xsetFileFilter
           
protected static javax.swing.Icon yellowFileIcon
           
protected static javax.swing.Icon yellowFolderIcon
           
 
Constructor Summary
Launcher()
          Constructs a bare Launcher with a splash screen.
Launcher(boolean splash)
          Constructs a bare Launcher with or without a splash screen.
Launcher(java.lang.String fileName)
          Constructs a Launcher and opens the specified xml file.
Launcher(java.lang.String fileName, boolean splash)
          Constructs a Launcher and opens the specified xml file.
 
Method Summary
protected  boolean addTab(LaunchNode root)
          Creates a LaunchPanel with the specified root and adds it to a new tab.
protected  void createGUI(boolean splash)
          Creates the GUI.
protected  void exit()
          Exits this application.
protected  LaunchClassChooser getClassChooser()
          Gets a class chooser for selecting launchable classes from jar files.
 java.awt.Container getContentPane()
          Gets the content pane.
protected static java.lang.String getDefaultJar()
          Gets the name of the jar containing the default launcher xml file, if any.
protected static java.lang.String getDisplayName(java.lang.String fileName)
          Gets the display name of the specified file name.
 int getDivider()
          Gets the divider location.
protected  javax.swing.Icon getFileIcon(LaunchNode node)
          Gets an appropriate File icon for a node (must have non-null filename)
protected  java.util.Set getOpenPaths()
          Gets the paths of currently open set and tabs.
 LaunchNode getRootNode()
          Gets the root node of the selected launch tree.
 LaunchNode getSelectedNode()
          Gets the selected launch node.
 LaunchPanel getSelectedTab()
          Gets the LaunchPanel in the selected tab.
 java.awt.Dimension getSize()
          Gets the size.
 LaunchPanel getTab(int i)
          Gets the launch tree at the specified tab index.
protected static javax.swing.JFileChooser getXMLChooser()
          Gets a file chooser for selecting xml files.
protected  void handleMousePressed(java.awt.event.MouseEvent e, LaunchPanel tab)
          Handles a mouse pressed event.
protected static boolean isLaunchable(java.lang.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.
 boolean isVisible()
          Reports visibility of the Launcher frame.
static void launch(java.lang.Class type)
          Launches an application with no arguments.
static void launch(java.lang.Class type, java.lang.String[] args)
          Launches an application with an array of string arguments.
static void launch(java.lang.Class type, java.lang.String[] args, LaunchNode node)
          Launches an application asociated with a launch node.
static void main(java.lang.String[] args)
          Main entry point when used as application.
protected  java.lang.String open()
          Opens an xml file selected with a chooser.
 java.lang.String open(java.lang.String name)
          Opens an xml document specified by name and displays it in a new tab (or selects the tab if already open).
 java.lang.String open(java.lang.String[] args)
          Opens an xml document and selects a tab and/or node specified by name.
protected  void refreshGUI()
          Refreshes the GUI.
protected  void refreshStringResources()
          Refreshes string resources.
protected  boolean removeAllTabs()
          Removes all tabs.
protected  boolean removeSelectedTab()
          Removes the selected tab.
 void setDivider(int loc)
          Sets the divider location.
protected  void setFontLevel(int level)
          Sets the font level.
protected  void setLookAndFeel(boolean defaultLF)
          Sets the look and feel.
 LaunchNode setSelectedNode(java.lang.String path)
          Sets the selected node by path and returns the node, or null if node not found.
 LaunchPanel setSelectedTab(java.lang.String path)
          Sets the selected tab by name and returns its LaunchPanel, or null if tab not found.
 void setSize(java.awt.Dimension dim)
          Sets the size.
 void setSize(int width, int height)
          Sets the size.
 void setVisible(boolean visible)
          Sets the visibility of the Launcher frame.
protected  void showAboutDialog()
          Shows the about dialog.
protected  void showButtonView(LaunchNode node)
          Displays a button view of the specified node.
protected  void showTabbedPaneView()
          Displays the standard tabbed pane view.
protected  boolean terminateApps()
          Terminates running apps.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultFileName

protected static java.lang.String defaultFileName

resourcesPath

protected static java.lang.String resourcesPath

classPath

protected static java.lang.String classPath

tabSetBasePath

protected static java.lang.String tabSetBasePath

version

protected static java.lang.String version

releaseDate

protected static java.lang.String releaseDate

chooser

protected static javax.swing.JFileChooser chooser

xmlFileFilter

protected static javax.swing.filechooser.FileFilter xmlFileFilter

xsetFileFilter

protected static javax.swing.filechooser.FileFilter xsetFileFilter

launcherFileFilter

protected static javax.swing.filechooser.FileFilter launcherFileFilter

wInit

protected static int wInit

hInit

protected static int hInit

splashDialog

protected static javax.swing.JDialog splashDialog

splashTitleLabel

protected static javax.swing.JLabel splashTitleLabel

splashPathLabel

protected static javax.swing.JLabel splashPathLabel

splashTimer

protected static javax.swing.Timer splashTimer

isWebStart

protected static boolean isWebStart

baseMenuFontSize

protected static float baseMenuFontSize

launchIcon

protected static javax.swing.Icon launchIcon

launchedIcon

protected static javax.swing.Icon launchedIcon

singletonIcon

protected static javax.swing.Icon singletonIcon

whiteFolderIcon

protected static javax.swing.Icon whiteFolderIcon

redFileIcon

protected static javax.swing.Icon redFileIcon

greenFileIcon

protected static javax.swing.Icon greenFileIcon

magentaFileIcon

protected static javax.swing.Icon magentaFileIcon

yellowFileIcon

protected static javax.swing.Icon yellowFileIcon

whiteFileIcon

protected static javax.swing.Icon whiteFileIcon

noFileIcon

protected static javax.swing.Icon noFileIcon

ghostFileIcon

protected static javax.swing.Icon ghostFileIcon

redFolderIcon

protected static javax.swing.Icon redFolderIcon

greenFolderIcon

protected static javax.swing.Icon greenFolderIcon

yellowFolderIcon

protected static javax.swing.Icon yellowFolderIcon

linkIcon

protected static javax.swing.Icon linkIcon

htmlIcon

protected static javax.swing.Icon htmlIcon

launchEmptyIcon

protected static javax.swing.Icon launchEmptyIcon

singleAppMode

public static boolean singleAppMode

singletonMode

public static boolean singletonMode

frameFinder

protected static javax.swing.Timer frameFinder

existingFrames

protected static java.util.ArrayList existingFrames

activeNode

public static LaunchNode activeNode

inspector

protected javax.swing.JDialog inspector

divider

protected int divider

frame

public javax.swing.JFrame frame

contentPane

protected javax.swing.JPanel contentPane

tabbedPane

protected javax.swing.JTabbedPane tabbedPane

singleAppItem

protected javax.swing.JMenuItem singleAppItem

selectedNode

protected LaunchNode selectedNode

previousNode

protected LaunchNode previousNode

tabSetName

protected java.lang.String tabSetName

textPane

protected javax.swing.JEditorPane textPane

textScroller

protected javax.swing.JScrollPane textScroller

showText

protected boolean showText

fileMenu

protected javax.swing.JMenu fileMenu

displayMenu

protected javax.swing.JMenu displayMenu

helpMenu

protected javax.swing.JMenu helpMenu

openItem

protected javax.swing.JMenuItem openItem

openFromJarMenu

protected javax.swing.JMenu openFromJarMenu

closeTabItem

protected javax.swing.JMenuItem closeTabItem

closeAllItem

protected javax.swing.JMenuItem closeAllItem

editItem

protected javax.swing.JMenuItem editItem

exitItem

protected javax.swing.JMenuItem exitItem

inspectItem

protected javax.swing.JMenuItem inspectItem

hideItem

protected javax.swing.JMenuItem hideItem

backItem

protected javax.swing.JMenuItem backItem

languageMenu

protected javax.swing.JMenu languageMenu

sizeUpItem

protected javax.swing.JMenuItem sizeUpItem

sizeDownItem

protected javax.swing.JMenuItem sizeDownItem

lookFeelItem

protected javax.swing.JMenuItem lookFeelItem

logItem

protected javax.swing.JMenuItem logItem

aboutItem

protected javax.swing.JMenuItem aboutItem

diagnosticMenu

protected javax.swing.JMenu diagnosticMenu

languageItems

protected javax.swing.JMenuItem[] languageItems

classChooser

protected LaunchClassChooser classChooser

popup

protected javax.swing.JPopupMenu popup

openPaths

protected java.util.Set openPaths

spawner

protected Launcher spawner

previewing

protected boolean previewing

editorEnabled

protected boolean editorEnabled

changedFiles

protected java.util.Set changedFiles

tabListener

protected java.awt.event.MouseListener tabListener

newNodeSelected

protected boolean newNodeSelected

selfContained

protected boolean selfContained

jarBasePath

protected java.lang.String jarBasePath

title

protected java.lang.String title

tabs

protected java.util.ArrayList tabs

undoManager

protected javax.swing.undo.UndoManager undoManager

undoSupport

protected javax.swing.undo.UndoableEditSupport undoSupport

password

protected java.lang.String password

pwRequiredToLoad

protected boolean pwRequiredToLoad

undoEdit

protected Launcher.LinkEdit undoEdit
Constructor Detail

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(java.lang.String fileName)
Constructs a Launcher and opens the specified xml file.

Parameters:
fileName - the name of the xml file

Launcher

public Launcher(java.lang.String fileName,
                boolean splash)
Constructs a Launcher and opens the specified xml file.

Parameters:
fileName - the name of the xml file
splash - true to show the splash screen
Method Detail

getSize

public java.awt.Dimension getSize()
Gets the size.

Returns:
the size Dimension object

setSize

public void setSize(java.awt.Dimension dim)
Sets the size.

Parameters:
dim - the size Dimension

setSize

public void setSize(int width,
                    int height)
Sets the size.

Parameters:
width - the width
height - the height

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

getSelectedTab

public LaunchPanel getSelectedTab()
Gets the LaunchPanel in the selected tab. May return null.

Returns:
the LaunchPanel

setSelectedTab

public LaunchPanel setSelectedTab(java.lang.String path)
Sets the selected tab by name and returns its LaunchPanel, or null if tab not found.

Parameters:
path - a path that starts with the name of the tab's root node
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(java.lang.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

getRootNode

public LaunchNode getRootNode()
Gets the root node of the selected launch tree. May return null.

Returns:
the root node

getTab

public LaunchPanel getTab(int i)
Gets the launch tree at the specified tab index. May return null.

Parameters:
i - the tab index
Returns:
the launch tree

getContentPane

public java.awt.Container getContentPane()
Gets the content pane.

Returns:
the content pane

open

public java.lang.String open(java.lang.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 java.lang.String open(java.lang.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

addTab

protected 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 java.lang.String open()
Opens an xml file selected with a chooser.

Returns:
the name of the opened file

removeSelectedTab

protected 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

protected void setFontLevel(int level)
Sets the font level.

Parameters:
level - the level

getOpenPaths

protected java.util.Set getOpenPaths()
Gets the paths of currently open set and tabs.

Returns:
the open paths

setLookAndFeel

protected void setLookAndFeel(boolean defaultLF)
Sets the look and feel.

Parameters:
defaultLF - true to use default L&F

showAboutDialog

protected void showAboutDialog()
Shows the about 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

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

isLaunchable

protected static boolean isLaunchable(java.lang.Class type)
Determines whether the specified class is launchable.

Parameters:
type - the launch class to verify
Returns:
true if the class is launchable

handleMousePressed

protected void handleMousePressed(java.awt.event.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 javax.swing.Icon 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(java.lang.Class type)
Launches an application with no arguments.

Parameters:
type - the class to be launched

launch

public static void launch(java.lang.Class type,
                          java.lang.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(java.lang.Class type,
                          java.lang.String[] args,
                          LaunchNode node)
Launches an application asociated 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)

main

public static void main(java.lang.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

getXMLChooser

protected static javax.swing.JFileChooser getXMLChooser()
Gets a file chooser for selecting xml files.

Returns:
the xml chooser

getDisplayName

protected static java.lang.String getDisplayName(java.lang.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 java.lang.String getDefaultJar()
Gets the name of the jar containing the default launcher xml file, if any.

Returns:
the jar name