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 its own collections and provides access to collections from comPADRE, OSP and imported libraries.

Author:
Douglas Brown

Field Summary
protected  java.lang.String chooserDir
           
protected  org.opensourcephysics.tools.Library.Manager manager
           
protected  java.lang.String[] openTabPaths
           
 
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  boolean containsPath(java.lang.String path, boolean allLists)
          Returns true if this library contains a collection path.
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  org.opensourcephysics.tools.Library.Manager getManager(LibraryBrowser browser)
          Gets the collections manager for this library.
protected  java.lang.String getName()
          Gets the name of this library.
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 rebuildCollectionsMenu(LibraryBrowser browser)
          Rebuilds the Collections menu.
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 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

openTabPaths

protected java.lang.String[] openTabPaths

manager

protected org.opensourcephysics.tools.Library.Manager manager

chooserDir

protected java.lang.String chooserDir
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

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

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
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

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

getManager

protected org.opensourcephysics.tools.Library.Manager getManager(LibraryBrowser browser)
Gets the collections manager for this library.

Parameters:
browser - a LibraryBrowser
Returns:
the collections manager

rebuildCollectionsMenu

protected void rebuildCollectionsMenu(LibraryBrowser browser)
Rebuilds the Collections menu.

Parameters:
browser - the LibraryBrowser that will display the menu

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

getLoader

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

Returns:
the object loader