Class LibraryBrowser

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class LibraryBrowser extends JPanel
A GUI for browsing OSP digital library collections.
Author:
Douglas Brown
See Also:
  • Field Details

    • TRACKER_LIBRARY

      public static final String TRACKER_LIBRARY
      See Also:
    • SHARED_LIBRARY

      public static final String SHARED_LIBRARY
      See Also:
    • AND

      protected static final String AND
      See Also:
    • OR

      protected static final String OR
      See Also:
    • OPENING

      protected static final String OPENING
      See Also:
    • CLOSING

      protected static final String CLOSING
      See Also:
    • MY_LIBRARY_NAME

      protected static final String MY_LIBRARY_NAME
      See Also:
    • MY_COLLECTION_NAME

      protected static final String MY_COLLECTION_NAME
      See Also:
    • RECENT_COLLECTION_NAME

      protected static final String RECENT_COLLECTION_NAME
      See Also:
    • LIBRARY_HELP_NAME

      protected static final String LIBRARY_HELP_NAME
      See Also:
    • LIBRARY_HELP_BASE

      protected static final String LIBRARY_HELP_BASE
      See Also:
    • WINDOWS_OSP_DIRECTORY

      protected static final String WINDOWS_OSP_DIRECTORY
      See Also:
    • OSP_DIRECTORY

      protected static final String OSP_DIRECTORY
      See Also:
    • WEB_SEARCH_BASE_PATH

      protected static final String WEB_SEARCH_BASE_PATH
      See Also:
    • WEB_EJS

      protected static final String WEB_EJS
      See Also:
    • TRACKER_ONLINE

      protected static final String TRACKER_ONLINE
      See Also:
    • DATATOOL_ONLINE

      protected static final String DATATOOL_ONLINE
      See Also:
    • HINT_LOAD_RESOURCE

      public static final String HINT_LOAD_RESOURCE
      See Also:
    • HINT_DOWNLOAD_RESOURCE

      public static final String HINT_DOWNLOAD_RESOURCE
      See Also:
    • PROPERTY_LIBRARY_TARGET

      public static final String PROPERTY_LIBRARY_TARGET
      See Also:
    • PROPERTY_LIBRARY_EDITED

      public static final String PROPERTY_LIBRARY_EDITED
      See Also:
    • buttonBorder

      protected static Border buttonBorder
    • frame

      protected static JFrame frame
    • externalDialog

      protected static JDialog externalDialog
    • expandIcon

      protected static ResizableIcon expandIcon
    • contractIcon

      protected static ResizableIcon contractIcon
    • heavyExpandIcon

      protected static ResizableIcon heavyExpandIcon
    • heavyContractIcon

      protected static ResizableIcon heavyContractIcon
    • refreshIcon

      protected static ResizableIcon refreshIcon
    • downloadIcon

      protected static ResizableIcon downloadIcon
    • downloadDisabledIcon

      protected static ResizableIcon downloadDisabledIcon
    • searchTargetIcon

      protected static ResizableIcon searchTargetIcon
    • TRACKER_FILTER

      protected static final org.opensourcephysics.tools.LibraryBrowser.TrackerDLFilter TRACKER_FILTER
    • filesAndFoldersFilter

      protected static FileFilter filesAndFoldersFilter
    • searchTimer

      protected static Timer searchTimer
    • fireHelpEvent

      public static boolean fireHelpEvent
    • maxRecentCollectionSize

      public static int maxRecentCollectionSize
    • useOnlineOnly

      protected static boolean useOnlineOnly
    • webConnected

      protected boolean webConnected
    • localLibraryLoaded

      protected boolean localLibraryLoaded
    • library

      protected Library library
    • libraryPath

      protected String libraryPath
    • toolbar

      protected JToolBar toolbar
    • messageButton

      protected JButton messageButton
    • commandAction

      protected Action commandAction
    • searchAction

      protected Action searchAction
    • openRecentAction

      protected Action openRecentAction
    • downloadAction

      protected Action downloadAction
    • commandLabel

      protected JLabel commandLabel
    • searchLabel

      protected JLabel searchLabel
    • commandField

      protected JTextField commandField
    • searchField

      protected JTextField searchField
    • fileMenu

      protected JMenu fileMenu
    • recentMenu

      protected JMenu recentMenu
    • collectionsMenu

      protected JMenu collectionsMenu
    • manageMenu

      protected JMenu manageMenu
    • helpMenu

      protected JMenu helpMenu
    • newItem

      protected JMenuItem newItem
    • openItem

      protected JMenuItem openItem
    • saveItem

      protected JMenuItem saveItem
    • saveAsItem

      protected JMenuItem saveAsItem
    • closeItem

      protected JMenuItem closeItem
    • closeAllItem

      protected JMenuItem closeAllItem
    • exitItem

      protected JMenuItem exitItem
    • deleteItem

      protected JMenuItem deleteItem
    • collectionsItem

      protected JMenuItem collectionsItem
    • searchItem

      protected JMenuItem searchItem
    • cacheItem

      protected JMenuItem cacheItem
    • aboutItem

      protected JMenuItem aboutItem
    • logItem

      protected JMenuItem logItem
    • helpItem

      protected JMenuItem helpItem
    • commandButton

      protected JButton commandButton
    • editButton

      protected JButton editButton
    • refreshButton

      protected JButton refreshButton
    • downloadButton

      protected JButton downloadButton
    • searchTargetButton

      protected JButton searchTargetButton
    • loadCollectionAction

      protected ActionListener loadCollectionAction
    • exitOnClose

      protected boolean exitOnClose
    • tabbedPane

      protected JTabbedPane tabbedPane
    • htmlScroller

      protected JScrollPane htmlScroller
    • treePanelListener

      protected PropertyChangeListener treePanelListener
    • metadataLoaderListener

      protected PropertyChangeListener metadataLoaderListener
    • keyPressed

      protected boolean keyPressed
    • textChanged

      protected boolean textChanged
    • helpFrame

      protected TextFrame helpFrame
    • htmlAboutPane

      protected JEditorPane htmlAboutPane
    • dlFileFilter

      protected org.opensourcephysics.tools.LibraryBrowser.TrackerDLFilter dlFileFilter
    • isResourcePathXML

      protected boolean isResourcePathXML
    • libraryManager

      protected LibraryManager libraryManager
    • searchTargetChooser

      protected ListChooser searchTargetChooser
    • searchResultsTreePanel

      protected LibraryTreePanel searchResultsTreePanel
    • searchPathMap

      protected TreeMap<String,String> searchPathMap
  • Method Details

    • getBrowser

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

      public static LibraryBrowser getBrowser(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
    • isPopulatedCollection

      public static boolean isPopulatedCollection(LibraryTreeNode node)
    • setAlwaysOnTop

      public void setAlwaysOnTop(boolean alwaysOnTop)
    • setFontLevel

      public void setFontLevel(int level)
      Sets the font level.
      Parameters:
      level - the desired font level
    • importLibrary

      public void importLibrary(String path)
      Imports a library with a specified path. (no references to this method?)
      Parameters:
      path - the path to the Library xml file
    • addOSPLibrary

      public void addOSPLibrary(String path)
      Adds an OSP-sponsored library with a specified path.
      Parameters:
      path - the path to the Library xml file
    • addComPADRECollection

      public void addComPADRECollection(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(String title)
      Sets the title of this DL browser.
      Parameters:
      title - the title
    • getDLFileFilter

      public FileFilter getDLFileFilter()
      Gets the fileFilter used to determine which files are DL resources.
      Returns:
      the file filter
    • setVisible

      public void setVisible(boolean vis)
      Sets the visibility of this browser
      Overrides:
      setVisible in class 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
    • cancelLoading

      public void cancelLoading()
    • doneLoading

      public void doneLoading()
    • getManager

      protected LibraryManager getManager()
      Gets the library manager for this browser.
      Returns:
      the collections manager
    • getSelectedTreePanel

      public 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 String getTabTitle(String path)
      Gets the title of the tab associated with a given path.
      Parameters:
      path - the collection path
      Returns:
      the tab title
    • getTabTitle

      protected 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(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(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(String path, List<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)
    • loadTabAndListen

      protected boolean loadTabAndListen(String path, List<String> treePath, String mode)
    • getRecentCollection

      public LibraryCollection getRecentCollection()
      Gets the recent collection.
      Returns:
      the collection, or null if failed
    • loadResourceAsync

      protected void loadResourceAsync(String path, Function<LibraryResource,Void> whenDone)
    • loadResource

      protected LibraryResource loadResource(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(File targetFile, File baseDir, 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
    • addTabAndExecute

      protected boolean addTabAndExecute(String path, List<String> treePath, PropertyChangeListener listener)
      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)
      listener -
      Returns:
      true if successful
    • refreshTabTitle

      protected void refreshTabTitle(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
    • loadTabAsync

      protected void loadTabAsync(String path, int index, List<String> treePath, PropertyChangeListener listener)
    • createGUI

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

      public void setMessage(String message, Color color)
      Sets a message in the message label.
      Parameters:
      message - the message. Will be truncated if too long.
      color - the background color
    • processTargetCollection

      protected void processTargetCollection(LibraryTreeNode node)
    • processTargetSelection

      protected void processTargetSelection(LibraryResource record, Object hint)
    • doSearch

      protected void doSearch()
    • doDownload

      protected void doDownload()
    • doCommand

      protected void doCommand()
    • setComandButtonEnabled

      public void setComandButtonEnabled(boolean enabled)
      Enables/disables the command button.
      Parameters:
      enabled - true if enabled
    • refreshGUI

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

      protected void refreshGUI(boolean andRebuild)
      Refreshes the GUI, including locale-dependent resources strings.
      Parameters:
      andRebuild - true to refresh strings and rebuild file menu
    • refreshRecentMenu

      public void refreshRecentMenu()
      Refreshes the open recent files menu.
      Parameters:
      menu - the menu to refresh
    • open

      protected void open()
      Opens a file using an AsyncFileChooser.
    • open

      public void open(String path)
      Opens a file with a specified path.
      Parameters:
      path - the path to the file
    • closeTab

      public boolean closeTab(int index)
      Closes a tab.
      Parameters:
      index - the tab number
      Returns:
      true unless cancelled by user
    • getTabCount

      public int getTabCount()
      Gets the current tab count.
      Returns:
      tab count
    • save

      protected String save()
      Saves the selected LibraryTreePanel collection.
      Returns:
      the path to the saved file, or null if not saved
    • saveAs

      protected 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 String getChooserSavePath(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
    • addSearchResource

      protected static void addSearchResource(LibraryResource resource)
      Adds a searchable collection to the search resource map.
    • existsOnWeb

      public static boolean existsOnWeb(String URLPath)
    • getSearchPathMap

      protected TreeMap<String,String> getSearchPathMap()
    • loadSearchPathMap

      protected void loadSearchPathMap()
      Loads all searchable paths into the search path map.
    • getSearchTargets

      protected Set<LibraryResource> getSearchTargets()
      Returns the set of searchable resources.
      Returns:
      a set of searchable resources
    • searchFor

      protected LibraryTreeNode searchFor(String searchPhrase, 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 LibraryTreeNode with the search results, or null if no matches found
    • searchCollectionFor

      protected Map<LibraryResource,List<String[]>> searchCollectionFor(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 List<String[]> searchResourceFor(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 String[] getNextSplit(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 String[] getParenthesisSplit(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 Map<LibraryResource,List<String[]>> applyAND(Map<LibraryResource,List<String[]>> results1, Map<LibraryResource,List<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 Map<LibraryResource,List<String[]>> applyOR(Map<LibraryResource,List<String[]>> results1, Map<LibraryResource,List<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(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 String createNewCollection()
      Creates a new LibraryCollection file.
      Returns:
      the path to the new collection
    • getUniqueName

      protected String getUniqueName(String proposed, 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(String name, 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 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(String[] args)
      Entry point when run as an independent application.
      Parameters:
      args - String[] ignored
    • warnNotLoaded

      public void warnNotLoaded(String path)
    • isWebConnected

      protected boolean isWebConnected(boolean[] isDialogShown)
      Returns true if connected to the web OR if JavaScript.
      Returns:
      true if web connected
    • getRedirectFromHTMLCode

      protected static String getRedirectFromHTMLCode(String code)
      Returns the redirect URL path, if any, of an HTML page.
      Parameters:
      code - the HTML code
      Returns:
      the redirect path
    • getMetadataFromHTML

      public static ArrayList<String[]> getMetadataFromHTML(String htmlCode)
      Returns the metadata, if any, defined in HTML code
      Parameters:
      htmlCode - the HTML code
      Returns:
      a list of String[] {name, value}
    • addMetadataLoaderListener

      public void addMetadataLoaderListener(PropertyChangeListener listener)
      Adds a listener to be notified whenever a LibraryTreePanel.MetadataLoader finishes. This is used only for refreshing metadata for Tracker JS.
      Parameters:
      listener - the listener
    • getOSPPath

      protected static String getOSPPath()
      Gets the path to the local OSP folder.
      Returns:
      the path
    • clearCache

      public static void clearCache()