org.opensourcephysics.tools
Class Library

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

public class Library
extends java.lang.Object

A Library for a LibraryBrowser. Maintains lists of collection paths and imported sub-libraries.

Author:
Douglas Brown

Field Summary
protected  java.util.HashMap<java.lang.String,java.lang.String> allPathsToNameMap
           
protected  LibraryBrowser browser
           
protected  java.lang.String chooserDir
           
protected  java.util.ArrayList<java.lang.String> comPADREPathList
           
protected  java.util.HashMap<java.lang.String,java.lang.String> comPADREPathToNameMap
           
protected  java.util.ArrayList<java.lang.String> importedPathList
           
protected  java.util.HashMap<java.lang.String,Library> importedPathToLibraryMap
           
protected  int maxRecentTabCount
           
protected  java.lang.String name
           
protected  java.util.Set<java.lang.String> noSearchSet
           
protected  java.lang.String[] openTabPaths
           
protected  java.util.ArrayList<java.lang.String> ospPathList
           
protected  java.util.HashMap<java.lang.String,Library> ospPathToLibraryMap
           
protected  java.util.ArrayList<java.lang.String> pathList
           
protected  java.util.HashMap<java.lang.String,java.lang.String> pathToNameMap
           
protected  java.util.ArrayList<java.lang.String> recentTabs
           
protected  java.util.ArrayList<java.lang.String> subPathList
           
protected  java.util.HashMap<java.lang.String,Library> subPathToLibraryMap
           
 
Constructor Summary
Library()
           
 
Method Summary
protected  void addCollection(java.lang.String path, java.lang.String name)
          Adds a collection to this library.
 boolean addComPADRECollection(java.lang.String path, java.lang.String name)
          Adds a comPADRE collection.
 boolean addOSPLibrary(java.lang.String path)
          Adds an OSP-sponsored library.
protected  void addRecent(java.lang.String filename, boolean atEnd)
          Adds a path to the list of recently opened tabs.
 boolean addSubLibrary(java.lang.String path)
          Adds a sublibrary.
protected  boolean containsPath(java.lang.String path, boolean allLists)
          Returns true if this library contains a collection path.
protected  java.util.TreeSet<java.lang.String> getAllPaths()
          Returns all collection paths in this Library and sublibraries.
protected  Library getCloneForExport()
          Gets a clone of this library that is suitable for exporting.
static XML.ObjectLoader getLoader()
          Returns an ObjectLoader to save and load data for this class.
protected  java.lang.String getName()
          Gets the name of this library.
protected  java.util.HashMap<java.lang.String,java.lang.String> getNameMap()
          Returns a Map of path-to-tab name.
protected  java.util.Collection<java.lang.String> getNames()
          Gets the names of all collections maintained by this library.
 boolean importLibrary(java.lang.String path)
          Imports a library.
protected  boolean importLibrary(java.lang.String path, Library library)
          Imports a Library if not already imported.
protected  boolean isEmpty()
          Returns true if this library has no collections.
protected  void load(java.lang.String path)
          Loads this library from an xml file.
protected  void renameCollection(java.lang.String path, java.lang.String newName)
          Renames a collection.
protected  void save(java.lang.String path)
          Saves this library in an xml file.
protected  void setCache(java.lang.String cachePath)
          Sets the cache path.
protected  void setName(java.lang.String name)
          Sets the name of this library.
 java.lang.String toString()
          Returns a string representation of this library.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

pathList

protected java.util.ArrayList<java.lang.String> pathList

pathToNameMap

protected java.util.HashMap<java.lang.String,java.lang.String> pathToNameMap

comPADREPathList

protected java.util.ArrayList<java.lang.String> comPADREPathList

comPADREPathToNameMap

protected java.util.HashMap<java.lang.String,java.lang.String> comPADREPathToNameMap

ospPathList

protected java.util.ArrayList<java.lang.String> ospPathList

ospPathToLibraryMap

protected java.util.HashMap<java.lang.String,Library> ospPathToLibraryMap

importedPathList

protected java.util.ArrayList<java.lang.String> importedPathList

importedPathToLibraryMap

protected java.util.HashMap<java.lang.String,Library> importedPathToLibraryMap

subPathList

protected java.util.ArrayList<java.lang.String> subPathList

subPathToLibraryMap

protected java.util.HashMap<java.lang.String,Library> subPathToLibraryMap

allPathsToNameMap

protected java.util.HashMap<java.lang.String,java.lang.String> allPathsToNameMap

noSearchSet

protected java.util.Set<java.lang.String> noSearchSet

openTabPaths

protected java.lang.String[] openTabPaths

recentTabs

protected java.util.ArrayList<java.lang.String> recentTabs

maxRecentTabCount

protected int maxRecentTabCount

chooserDir

protected java.lang.String chooserDir

browser

protected LibraryBrowser browser
Constructor Detail

Library

public Library()
Method Detail

addOSPLibrary

public boolean addOSPLibrary(java.lang.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(java.lang.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(java.lang.String path,
                                     java.lang.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(java.lang.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 java.lang.String toString()
Returns a string representation of this library.

Overrides:
toString in class java.lang.Object
Returns:
the name of the library

setCache

protected void setCache(java.lang.String cachePath)
Sets the cache path.

Parameters:
cachePath - the cache path

setName

protected void setName(java.lang.String name)
Sets the name of this library.

Parameters:
name - the name

getName

protected java.lang.String getName()
Gets the name of this library.

Returns:
the name

save

protected void save(java.lang.String path)
Saves this library in an xml file.

Parameters:
path - the path to the saved file

load

protected void load(java.lang.String path)
Loads this library from an xml file.

Parameters:
path - the path to the file

getNames

protected java.util.Collection<java.lang.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(java.lang.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

protected void addCollection(java.lang.String path,
                             java.lang.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(java.lang.String path,
                                java.lang.String newName)
Renames a collection.

Parameters:
path - the path to the collection
newName - the new name

getAllPaths

protected java.util.TreeSet<java.lang.String> getAllPaths()
Returns all collection paths in this Library and sublibraries.

Returns:
array of paths

getNameMap

protected java.util.HashMap<java.lang.String,java.lang.String> getNameMap()
Returns a Map of path-to-tab name.

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

getLoader

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

Returns:
the object loader