org.opensourcephysics.tools
Class LibraryBrowser

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.opensourcephysics.tools.LibraryBrowser
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class LibraryBrowser
extends javax.swing.JPanel

A GUI for browsing OSP digital library collections.

Author:
Douglas Brown
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  javax.swing.JMenuItem aboutItem
           
protected static java.lang.String AND
           
protected static javax.swing.border.Border buttonBorder
           
protected  javax.swing.JMenuItem cacheItem
           
protected  javax.swing.JMenuItem closeAllItem
           
protected  javax.swing.JMenuItem closeItem
           
protected static java.lang.String CLOSING
           
protected  javax.swing.JMenuItem collectionsItem
           
protected  javax.swing.JMenu collectionsMenu
           
protected  javax.swing.Action commandAction
           
protected  javax.swing.JButton commandButton
           
protected  javax.swing.JTextField commandField
           
protected  javax.swing.JLabel commandLabel
           
protected static javax.swing.Icon contractIcon
           
protected  javax.swing.JMenuItem deleteItem
           
protected  java.io.FileFilter dlFileFilter
           
protected  javax.swing.JButton editButton
           
protected  javax.swing.JMenuItem exitItem
           
protected  boolean exitOnClose
           
protected static javax.swing.Icon expandIcon
           
protected static javax.swing.JDialog externalDialog
           
protected  javax.swing.JMenu fileMenu
           
protected static javax.swing.filechooser.FileFilter filesAndFoldersFilter
           
static boolean fireHelpEvent
           
protected static javax.swing.JFrame frame
           
protected static javax.swing.Icon heavyContractIcon
           
protected static javax.swing.Icon heavyExpandIcon
           
protected  TextFrame helpFrame
           
protected  javax.swing.JMenuItem helpItem
           
protected  javax.swing.JMenu helpMenu
           
protected  javax.swing.JEditorPane htmlAboutPane
           
protected  javax.swing.JScrollPane htmlScroller
           
protected  boolean isRecentPathXML
           
protected  boolean keyPressed
           
protected  Library library
           
protected static java.lang.String LIBRARY_HELP_BASE
           
protected static java.lang.String LIBRARY_HELP_NAME
           
protected  LibraryManager libraryManager
           
protected  java.lang.String libraryPath
           
protected  java.awt.event.ActionListener loadCollectionAction
           
protected  javax.swing.JMenuItem logItem
           
protected  javax.swing.JMenu manageMenu
           
protected static javax.swing.JMenuBar menubar
           
protected static java.lang.String MY_COLLECTION_NAME
           
protected static java.lang.String MY_LIBRARY_NAME
           
protected  javax.swing.JMenuItem newItem
           
protected static java.lang.String OPENING
           
protected  javax.swing.JMenuItem openItem
           
protected  javax.swing.Action openRecentAction
           
protected static java.lang.String OR
           
protected static java.lang.String OSP_DIRECTORY
           
protected  javax.swing.JMenu recentMenu
           
protected  javax.swing.JButton refreshButton
           
protected static javax.swing.Icon refreshIcon
           
protected  javax.swing.JMenuItem saveAsItem
           
protected  javax.swing.JMenuItem saveItem
           
protected  javax.swing.Action searchAction
           
protected  javax.swing.JTextField searchField
           
protected  javax.swing.JMenuItem searchItem
           
protected  javax.swing.JLabel searchLabel
           
static java.lang.String SHARED_LIBRARY
           
protected  javax.swing.JTabbedPane tabbedPane
           
protected  boolean textChanged
           
protected  javax.swing.JToolBar toolbar
           
protected static java.io.FileFilter TRACKER_FILTER
           
static java.lang.String TRACKER_LIBRARY
           
protected  java.beans.PropertyChangeListener treePanelListener
           
protected static boolean webConnected
           
protected static java.lang.String WINDOWS_OSP_DIRECTORY
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Method Summary
 void addComPADRECollection(java.lang.String path)
          Adds a ComPADRE collection with a specified path.
 void addOSPLibrary(java.lang.String path)
          Adds an OSP-sponsored library with a specified path.
protected  org.opensourcephysics.tools.LibraryBrowser.TabLoader addTab(java.lang.String path, java.util.List<java.lang.String> treePath)
          Adds a tab displaying a library resource with a given path.
protected  void addToCollections(java.lang.String path)
          Adds a collection to this browser's library after prompting the user to assign it a name.
protected  java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> applyAND(java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> results1, java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> results2)
          Returns the resources that are contained in the keysets of both of two input maps.
protected  java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> applyOR(java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> results1, java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> results2)
          Returns the resources that are contained in the keysets of either of two input maps.
protected  boolean closeTab(int index)
          Closes a tab.
protected  LibraryCollection createCollection(java.io.File targetDir, java.io.File base, java.io.FileFilter filter)
          Creates a LibraryCollection containing all DL resources in a target directory.
protected  void createGUI()
          Creates the visible components of this panel.
protected  LibraryTreePanel createLibraryTreePanel()
          Creates a new empty LibraryTreePanel.
protected  java.lang.String createNewCollection()
          Creates a new LibraryCollection file.
protected  LibraryResource createResource(java.io.File targetFile, java.io.File baseDir, java.io.FileFilter filter)
          Creates a LibraryResource that describes and targets a file.
 boolean exit()
          Exits this browser.
protected  java.lang.String getAboutLibraryBrowserText()
          Returns html code that describes this browser.
static LibraryBrowser getBrowser()
          Gets the shared singleton browser.
static LibraryBrowser getBrowser(javax.swing.JDialog dialog)
          Gets the shared singleton browser in a JDialog or, if none, in a shared JFrame.
protected  java.lang.String getChooserSavePath(java.lang.String chooserTitle)
          Uses a file chooser to define a path to which a library or resource file (xml) can be saved.
 java.io.FileFilter getDLFileFilter()
          Gets the fileFilter used to determine which files are DL resources.
protected  LibraryManager getManager()
          Gets the library manager for this browser.
protected  java.lang.String[] getNextSplit(java.lang.String phrase)
          Returns the phrase before the next AND or OR operator, the operator itself, and the remainder of the phrase.
protected  java.lang.String[] getParenthesisSplit(java.lang.String phrase)
          Returns the phrase enclosed in parentheses along with the remainder of a phrase.
protected static java.lang.String getRedirectFromHTMLCode(java.lang.String code)
          Returns the redirect URL path, if any, of an HTML page.
protected  java.util.Set<LibraryResource> getSearchCacheTargets()
          Returns the set of all searchable cache resources.
protected  LibraryTreePanel getSelectedTreePanel()
          Gets the selected LibraryTreePanel, if any.
protected  int getTabIndexFromPath(java.lang.String path)
          Gets the index of the tab associated with a given path.
protected  int getTabIndexFromTitle(java.lang.String title)
          Gets the index of the tab associated with a given title.
protected  java.lang.String getTabTitle(int index)
          Gets the title of the tab at a given index.
protected  java.lang.String getTabTitle(java.lang.String path)
          Gets the title of the tab associated with a given path.
protected  LibraryTreePanel getTreePanel(int index)
          Gets the LibraryTreePanel at a specified tab index.
protected  java.lang.String getUniqueName(java.lang.String proposed, java.lang.String nameToIgnore)
          Returns a name that is not a duplicate of an existing name.
 void importLibrary(java.lang.String path)
          Imports a library with a specified path.
protected  boolean isDuplicateName(java.lang.String name, java.lang.String nameToIgnore)
          Determines if a name duplicates an existing name.
protected static boolean isWebConnected()
          Returns true if connected to the web.
protected  LibraryResource loadResource(java.lang.String path)
          Loads a library resource from a given path.
protected  void loadTab(java.lang.String path, java.util.List<java.lang.String> treePath)
          Loads a tab from a given path.
static void main(java.lang.String[] args)
          Entry point when run as an independent application.
protected  void open()
          Opens a file using a file chooser.
protected  void open(java.lang.String path)
          Opens a file with a specified path.
 void refreshCollectionsMenu()
          Refreshes the Collections menu.
protected  void refreshGUI()
          Refreshes the GUI, including locale-dependent resources strings.
 void refreshRecentMenu()
          Refreshes the open recent files menu.
protected  void refreshTabTitle(java.lang.String path, LibraryResource collection)
          Refreshes the title of a tab based on the properties of a LibraryCollection and the path associated with that collection.
protected  java.lang.String save()
          Saves the selected LibraryTreePanel collection.
protected  java.lang.String saveAs()
          Saves the current root resource as a new xml file.
protected  java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> searchCollectionFor(java.lang.String searchPhrase, LibraryCollection collection)
          Searches a LibraryCollection for matches to a search phrase.
protected  LibraryTreePanel searchFor(java.lang.String searchPhrase, java.util.Set<LibraryResource> searchTargets)
          Searches a set of LibraryResources for resources matching a search phrase.
protected  java.util.List<java.lang.String[]> searchResourceFor(java.lang.String searchPhrase, LibraryResource record)
          Searches a LibraryResource for matches to a search phrase.
 void setDLFileFilter(java.io.FileFilter filter)
          Sets the fileFilter used to determine which files are DL resources.
 void setTitle(java.lang.String title)
          Sets the title of this DL browser.
 void setVisible(boolean vis)
          Sets the visibility of this browser
protected  void showAboutDialog()
          Shows the about dialog.
protected  void showHelp()
          Shows the help frame and displays a help HTML page.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRACKER_LIBRARY

public static final java.lang.String TRACKER_LIBRARY
See Also:
Constant Field Values

SHARED_LIBRARY

public static final java.lang.String SHARED_LIBRARY
See Also:
Constant Field Values

AND

protected static final java.lang.String AND
See Also:
Constant Field Values

OR

protected static final java.lang.String OR
See Also:
Constant Field Values

OPENING

protected static final java.lang.String OPENING
See Also:
Constant Field Values

CLOSING

protected static final java.lang.String CLOSING
See Also:
Constant Field Values

MY_LIBRARY_NAME

protected static final java.lang.String MY_LIBRARY_NAME
See Also:
Constant Field Values

MY_COLLECTION_NAME

protected static final java.lang.String MY_COLLECTION_NAME
See Also:
Constant Field Values

LIBRARY_HELP_NAME

protected static final java.lang.String LIBRARY_HELP_NAME
See Also:
Constant Field Values

LIBRARY_HELP_BASE

protected static final java.lang.String LIBRARY_HELP_BASE
See Also:
Constant Field Values

WINDOWS_OSP_DIRECTORY

protected static final java.lang.String WINDOWS_OSP_DIRECTORY
See Also:
Constant Field Values

OSP_DIRECTORY

protected static final java.lang.String OSP_DIRECTORY
See Also:
Constant Field Values

buttonBorder

protected static javax.swing.border.Border buttonBorder

webConnected

protected static boolean webConnected

frame

protected static javax.swing.JFrame frame

externalDialog

protected static javax.swing.JDialog externalDialog

menubar

protected static javax.swing.JMenuBar menubar

expandIcon

protected static javax.swing.Icon expandIcon

contractIcon

protected static javax.swing.Icon contractIcon

heavyExpandIcon

protected static javax.swing.Icon heavyExpandIcon

heavyContractIcon

protected static javax.swing.Icon heavyContractIcon

refreshIcon

protected static javax.swing.Icon refreshIcon

TRACKER_FILTER

protected static final java.io.FileFilter TRACKER_FILTER

filesAndFoldersFilter

protected static javax.swing.filechooser.FileFilter filesAndFoldersFilter

fireHelpEvent

public static boolean fireHelpEvent

library

protected Library library

libraryPath

protected java.lang.String libraryPath

toolbar

protected javax.swing.JToolBar toolbar

commandAction

protected javax.swing.Action commandAction

searchAction

protected javax.swing.Action searchAction

openRecentAction

protected javax.swing.Action openRecentAction

commandLabel

protected javax.swing.JLabel commandLabel

searchLabel

protected javax.swing.JLabel searchLabel

commandField

protected javax.swing.JTextField commandField

searchField

protected javax.swing.JTextField searchField

fileMenu

protected javax.swing.JMenu fileMenu

recentMenu

protected javax.swing.JMenu recentMenu

collectionsMenu

protected javax.swing.JMenu collectionsMenu

manageMenu

protected javax.swing.JMenu manageMenu

helpMenu

protected javax.swing.JMenu helpMenu

newItem

protected javax.swing.JMenuItem newItem

openItem

protected javax.swing.JMenuItem openItem

saveItem

protected javax.swing.JMenuItem saveItem

saveAsItem

protected javax.swing.JMenuItem saveAsItem

closeItem

protected javax.swing.JMenuItem closeItem

closeAllItem

protected javax.swing.JMenuItem closeAllItem

exitItem

protected javax.swing.JMenuItem exitItem

deleteItem

protected javax.swing.JMenuItem deleteItem

collectionsItem

protected javax.swing.JMenuItem collectionsItem

searchItem

protected javax.swing.JMenuItem searchItem

cacheItem

protected javax.swing.JMenuItem cacheItem

aboutItem

protected javax.swing.JMenuItem aboutItem

logItem

protected javax.swing.JMenuItem logItem

helpItem

protected javax.swing.JMenuItem helpItem

commandButton

protected javax.swing.JButton commandButton

editButton

protected javax.swing.JButton editButton

refreshButton

protected javax.swing.JButton refreshButton

loadCollectionAction

protected java.awt.event.ActionListener loadCollectionAction

exitOnClose

protected boolean exitOnClose

tabbedPane

protected javax.swing.JTabbedPane tabbedPane

htmlScroller

protected javax.swing.JScrollPane htmlScroller

treePanelListener

protected java.beans.PropertyChangeListener treePanelListener

keyPressed

protected boolean keyPressed

textChanged

protected boolean textChanged

helpFrame

protected TextFrame helpFrame

htmlAboutPane

protected javax.swing.JEditorPane htmlAboutPane

dlFileFilter

protected java.io.FileFilter dlFileFilter

isRecentPathXML

protected boolean isRecentPathXML

libraryManager

protected LibraryManager libraryManager
Method Detail

getBrowser

public static LibraryBrowser getBrowser()
Gets the shared singleton browser.

Returns:
the shared LibraryBrowser

getBrowser

public static LibraryBrowser getBrowser(javax.swing.JDialog dialog)
Gets the shared singleton browser in a JDialog or, if none, in a shared JFrame.

Parameters:
dialog - a JDialog (if null, browser is returned in a JFrame)
Returns:
the shared LibraryBrowser

importLibrary

public void importLibrary(java.lang.String path)
Imports a library with a specified path.

Parameters:
path - the path to the Library xml file

addOSPLibrary

public void addOSPLibrary(java.lang.String path)
Adds an OSP-sponsored library with a specified path.

Parameters:
path - the path to the Library xml file

addComPADRECollection

public void addComPADRECollection(java.lang.String path)
Adds a ComPADRE collection with a specified path.

Parameters:
path - the ComPADRE query

refreshCollectionsMenu

public void refreshCollectionsMenu()
Refreshes the Collections menu.


setTitle

public void setTitle(java.lang.String title)
Sets the title of this DL browser.

Parameters:
title - the title

getDLFileFilter

public java.io.FileFilter getDLFileFilter()
Gets the fileFilter used to determine which files are DL resources.

Returns:
the file filter

setDLFileFilter

public void setDLFileFilter(java.io.FileFilter filter)
Sets the fileFilter used to determine which files are DL resources.

Parameters:
filter - the file filter (may be null)

setVisible

public void setVisible(boolean vis)
Sets the visibility of this browser

Overrides:
setVisible in class javax.swing.JComponent
Parameters:
vis - true to show, false to hide

exit

public boolean exit()
Exits this browser.

Returns:
true if exited, false if cancelled by user

getManager

protected LibraryManager getManager()
Gets the library manager for this browser.

Returns:
the collections manager

getSelectedTreePanel

protected LibraryTreePanel getSelectedTreePanel()
Gets the selected LibraryTreePanel, if any.

Returns:
the selected treePanel, or null if none

getTreePanel

protected LibraryTreePanel getTreePanel(int index)
Gets the LibraryTreePanel at a specified tab index.

Parameters:
index - the tab index
Returns:
the treePanel

getTabTitle

protected java.lang.String getTabTitle(java.lang.String path)
Gets the title of the tab associated with a given path.

Parameters:
path - the collection path
Returns:
the tab title

getTabTitle

protected java.lang.String getTabTitle(int index)
Gets the title of the tab at a given index.

Parameters:
index - the tab index
Returns:
the tab title

getTabIndexFromPath

protected int getTabIndexFromPath(java.lang.String path)
Gets the index of the tab associated with a given path.

Parameters:
path - the collection path
Returns:
the tab index

getTabIndexFromTitle

protected int getTabIndexFromTitle(java.lang.String title)
Gets the index of the tab associated with a given title.

Parameters:
title - the tab title
Returns:
the tab index

loadTab

protected void loadTab(java.lang.String path,
                       java.util.List<java.lang.String> treePath)
Loads a tab from a given path. If the tab is already loaded, this selects it. if not yet loaded, this adds a new tab and selects it. If a treePath is specified, the node it points to will be selected

Parameters:
path - the path
treePath - tree path to select in root-first order (may be null)

loadResource

protected LibraryResource loadResource(java.lang.String path)
Loads a library resource from a given path.

Parameters:
path - the path
Returns:
the resource, or null if failed

createResource

protected LibraryResource createResource(java.io.File targetFile,
                                         java.io.File baseDir,
                                         java.io.FileFilter filter)
Creates a LibraryResource that describes and targets a file.

Parameters:
targetFile - the target file
baseDir - the base directory for relative paths
filter - a FileFilter to determine if the file is a DL library resource
Returns:
a LibraryResource that describes and targets the file

createCollection

protected LibraryCollection createCollection(java.io.File targetDir,
                                             java.io.File base,
                                             java.io.FileFilter filter)
Creates a LibraryCollection containing all DL resources in a target directory.

Parameters:
targetDir - the target directory
base - the base directory for relative paths
filter - a FileFilter to determine which files are DL resources
Returns:
the collection

addTab

protected org.opensourcephysics.tools.LibraryBrowser.TabLoader addTab(java.lang.String path,
                                                                      java.util.List<java.lang.String> treePath)
Adds a tab displaying a library resource with a given path. If a treePath is specified, the node it points to will be selected

Parameters:
path - the path to the resource
treePath - tree path to select in root-first order (may be null)
Returns:
the TabLoader that adds the tab

refreshTabTitle

protected void refreshTabTitle(java.lang.String path,
                               LibraryResource collection)
Refreshes the title of a tab based on the properties of a LibraryCollection and the path associated with that collection.

Parameters:
path - the collection path
collection - the LibraryCollection itself

createGUI

protected void createGUI()
Creates the visible components of this panel.


refreshGUI

protected void refreshGUI()
Refreshes the GUI, including locale-dependent resources strings.


refreshRecentMenu

public void refreshRecentMenu()
Refreshes the open recent files menu.

Parameters:
menu - the menu to refresh

open

protected void open()
Opens a file using a file chooser.


open

protected void open(java.lang.String path)
Opens a file with a specified path.

Parameters:
path - the path to the file

closeTab

protected boolean closeTab(int index)
Closes a tab.

Parameters:
index - the tab number
Returns:
true unless cancelled by user

save

protected java.lang.String save()
Saves the selected LibraryTreePanel collection.

Returns:
the path to the saved file, or null if not saved

saveAs

protected java.lang.String saveAs()
Saves the current root resource as a new xml file.

Returns:
the path to the saved file, or null if not saved

getChooserSavePath

protected java.lang.String getChooserSavePath(java.lang.String chooserTitle)
Uses a file chooser to define a path to which a library or resource file (xml) can be saved. This adds the extension ".xml", if none, and checks for duplicates.

Parameters:
chooserTitle - the title of the file chooser
Returns:
the path, or null if canceled by the user

getSearchCacheTargets

protected java.util.Set<LibraryResource> getSearchCacheTargets()
Returns the set of all searchable cache resources.

Returns:
a set of searchable resources

searchFor

protected LibraryTreePanel searchFor(java.lang.String searchPhrase,
                                     java.util.Set<LibraryResource> searchTargets)
Searches a set of LibraryResources for resources matching a search phrase.

Parameters:
searchPhrase - the phrase to match
searchTargets - a set of LibraryResources to search
Returns:
a LibraryTreePanel containing the search results, or null if no nodes found

searchCollectionFor

protected java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> searchCollectionFor(java.lang.String searchPhrase,
                                                                                                LibraryCollection collection)
Searches a LibraryCollection for matches to a search phrase.

Parameters:
searchPhrase - the phrase
collection - the LibraryResource
Returns:
a List of String[] {where match was found, value in which match was found}, or null if no match found

searchResourceFor

protected java.util.List<java.lang.String[]> searchResourceFor(java.lang.String searchPhrase,
                                                               LibraryResource record)
Searches a LibraryResource for matches to a search phrase.

Parameters:
searchPhrase - the phrase
record - the LibraryResource
Returns:
a List of String[] {category where match found, value where match found}, or null if no match found

getNextSplit

protected java.lang.String[] getNextSplit(java.lang.String phrase)
Returns the phrase before the next AND or OR operator, the operator itself, and the remainder of the phrase.

Parameters:
phrase - a search phrase
Returns:
String[]

getParenthesisSplit

protected java.lang.String[] getParenthesisSplit(java.lang.String phrase)
Returns the phrase enclosed in parentheses along with the remainder of a phrase.

Parameters:
phrase - a phrase that starts immediately AFTER an opening parenthesis
Returns:
String[] {the enclosed phrase, the remainder}

applyAND

protected java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> applyAND(java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> results1,
                                                                                     java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> results2)
Returns the resources that are contained in the keysets of both of two input maps.

Parameters:
results1 -
results2 -
Returns:
map of resources found in both keysets

applyOR

protected java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> applyOR(java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> results1,
                                                                                    java.util.Map<LibraryResource,java.util.List<java.lang.String[]>> results2)
Returns the resources that are contained in the keysets of either of two input maps.

Parameters:
results1 -
results2 -
Returns:
map of resources found in either keyset

addToCollections

protected void addToCollections(java.lang.String path)
Adds a collection to this browser's library after prompting the user to assign it a name.

Parameters:
path - the path to the collection

createNewCollection

protected java.lang.String createNewCollection()
Creates a new LibraryCollection file.

Returns:
the path to the new collection

getUniqueName

protected java.lang.String getUniqueName(java.lang.String proposed,
                                         java.lang.String nameToIgnore)
Returns a name that is not a duplicate of an existing name.

Parameters:
proposed - a proposed name
nameToIgnore - a name that is ignored when comparing
Returns:
a unique name that is the proposed name plus a possible suffix

isDuplicateName

protected boolean isDuplicateName(java.lang.String name,
                                  java.lang.String nameToIgnore)
Determines if a name duplicates an existing name.

Parameters:
name - the proposed name
nameToIgnore - a name that is ignored when comparing
Returns:
true if name is a duplicate

createLibraryTreePanel

protected LibraryTreePanel createLibraryTreePanel()
Creates a new empty LibraryTreePanel.

Returns:
the library tree panel

showAboutDialog

protected void showAboutDialog()
Shows the about dialog.


showHelp

protected void showHelp()
Shows the help frame and displays a help HTML page.


getAboutLibraryBrowserText

protected java.lang.String getAboutLibraryBrowserText()
Returns html code that describes this browser. This is displayed when no LibraryTreePanel is loaded.

Returns:
the html code

main

public static void main(java.lang.String[] args)
Entry point when run as an independent application.

Parameters:
args - String[] ignored

isWebConnected

protected static boolean isWebConnected()
Returns true if connected to the web.

Returns:
true if web connected

getRedirectFromHTMLCode

protected static java.lang.String getRedirectFromHTMLCode(java.lang.String code)
Returns the redirect URL path, if any, of an HTML page.

Parameters:
code - the HTML code
Returns:
the redirect path