Class Library

java.lang.Object
org.opensourcephysics.tools.Library

public class Library extends Object
A Library for a LibraryBrowser. Maintains lists of collection paths and imported sub-libraries.
Author:
Douglas Brown
  • Field Details

  • Constructor Details

    • Library

      public Library()
  • Method Details

    • addOSPLibrary

      public boolean addOSPLibrary(String path)
      Adds an OSP-sponsored library. OSP libraries are not under user control.
      Parameters:
      path - the library path
      Returns:
      true if successfully added
    • importLibrary

      public boolean importLibrary(String path)
      Imports a library. Imported libraries are managed by the user.
      Parameters:
      path - the library path
      Returns:
      true if successfully imported
    • addComPADRECollection

      public boolean addComPADRECollection(String path, String name)
      Adds a comPADRE collection. ComPADRE collections are not under user control.
      Parameters:
      path - the comPADRE query
      name - the name of the collection
      Returns:
      true if successfully added
    • addSubLibrary

      public boolean addSubLibrary(String path)
      Adds a sublibrary. Sublibraries are shown as submenus in a Library's Collections menu. Sublibraries are not under user control.
      Parameters:
      path - the path to the sublibrary
      Returns:
      true if successfully added
    • toString

      public String toString()
      Returns a string representation of this library.
      Overrides:
      toString in class Object
      Returns:
      the name of the library
    • setName

      protected void setName(String name)
      Sets the name of this library.
      Parameters:
      name - the name
    • getName

      protected String getName()
      Gets the name of this library.
      Returns:
      the name
    • save

      protected void save(String path)
      Saves this library in an xml file.
      Parameters:
      path - the path to the saved file
    • load

      protected void load(String path)
      Loads this library from an xml file.
      Parameters:
      path - the path to the file
    • getNames

      protected Collection<String> getNames()
      Gets the names of all collections maintained by this library.
      Returns:
      a collection of names
    • isEmpty

      protected boolean isEmpty()
      Returns true if this library has no collections.
      Returns:
      true if empty
    • containsPath

      protected boolean containsPath(String path, boolean allLists)
      Returns true if this library contains a collection path.
      Parameters:
      path - the collection path
      allLists - true to search in all collection lists
      Returns:
      true if this contains the path
    • addCollection

      public void addCollection(String path, String name)
      Adds a collection to this library.
      Parameters:
      path - the path to the collection
      name - the menu item name for the collection
    • renameCollection

      protected void renameCollection(String path, String newName)
      Renames a collection.
      Parameters:
      path - the path to the collection
      newName - the new name
    • getAllPaths

      public TreeSet<String> getAllPaths()
      Returns all collection paths in this Library and sub-libraries.
      Returns:
      array of paths
    • getNameMap

      public HashMap<String,String> getNameMap()
      Returns a Map of path-to-tabname.
      Returns:
      path-to-name map
    • getCloneForExport

      protected Library getCloneForExport()
      Gets a clone of this library that is suitable for exporting. The exported library has no OSP libraries, ComPADRE collections or imported libraries.
      Returns:
      a Library for export
    • importLibrary

      protected boolean importLibrary(String path, Library library)
      Imports a Library if not already imported.
      Parameters:
      path - the path to the library
      library - the library
      Returns:
      true if imported
    • addRecent

      protected void addRecent(String filename, boolean atEnd)
      Adds a path to the list of recently opened tabs.
      Parameters:
      filename - the absolute path to a recently opened or saved file.
      atEnd - true to add at end of the list
    • removeRecent

      protected void removeRecent(String filename)
      Removes a path from the list of recently opened tabs.
      Parameters:
      filename - the path to remove.
    • getLoader

      public static XML.ObjectLoader getLoader()
      Returns an ObjectLoader to save and load data for this class.
      Returns:
      the object loader