Class LibraryResource

java.lang.Object
org.opensourcephysics.tools.LibraryResource
All Implemented Interfaces:
Comparable<LibraryResource>
Direct Known Subclasses:
LibraryCollection

public class LibraryResource extends Object implements Comparable<LibraryResource>
This represents a library resource.
Version:
1.0
Author:
Douglas Brown
  • Field Details

  • Constructor Details

    • LibraryResource

      public LibraryResource(String name)
      Constructor.
      Parameters:
      name - the name of the resource
  • Method Details

    • getName

      public String getName()
      Gets the name of this resource (never null).
      Returns:
      the name
    • setName

      public boolean setName(String aName)
      Sets the name of this resource.
      Parameters:
      aName - the name
      Returns:
      true if changed
    • getBasePath

      public String getBasePath()
      Gets the base path.
      Returns:
      the base path
    • setBasePath

      public boolean setBasePath(String path)
      Sets the base path of this resource.
      Parameters:
      path - the base path
      Returns:
      true if changed
    • getInheritedBasePath

      protected String getInheritedBasePath()
      Returns the first base path found in this or its ancestors.
      Returns:
      the base path
    • getTarget

      public String getTarget()
      Gets the target of this resource (file name or comPADRE command).
      Returns:
      the target
    • getAbsoluteTarget

      public String getAbsoluteTarget()
      Gets the absolute path to the target. Note: this is needed for the
      Returns:
      the absolute target, or empty String if none
    • setTarget

      public boolean setTarget(String path)
      Sets the target of this resource.
      Parameters:
      path - the target path
      Returns:
      true if changed
    • getHTMLPath

      public String getHTMLPath()
      Gets the path to the html page displayed in the browser.
      Returns:
      the html path
    • setHTMLPath

      public boolean setHTMLPath(String path)
      Sets the html path of this resource.
      Parameters:
      path - the html path
      Returns:
      true if changed
    • getDescription

      public String getDescription()
      Gets the description, which must be in html code.
      Returns:
      the description
    • setDescription

      public boolean setDescription(String desc)
      Sets the description of this resource. Note: the description must be in html code, since it is displayed in the html pane of the LibraryTreePanel if the html path is empty.
      Parameters:
      desc - the description in HTML code
      Returns:
      true if changed
    • getType

      public String getType()
      Gets the type of resource.
      Returns:
      the one of the static constant types defined in this class
    • setType

      public boolean setType(String type)
      Sets the type of this resource. The types are static constants defined in this class.
      Parameters:
      type - the type
      Returns:
      true if changed
    • getMetadata

      public TreeSet<LibraryResource.Metadata> getMetadata()
      Gets the metadata.
      Returns:
      the Set of Metadata (may be null)
    • getMetadata

      public LibraryResource.Metadata getMetadata(String key)
      Gets the first metadata of a specified type.
      Parameters:
      key - the type
      Returns:
      Metadata, or null if none
    • setMetadata

      public void setMetadata(TreeSet<LibraryResource.Metadata> data)
      Sets the metadata. This replaces all previously added metadata.
      Parameters:
      data - a Set of Metadata (may be null)
    • addMetadata

      public void addMetadata(LibraryResource.Metadata data)
      Adds a Metadata object to the metadata.
      Parameters:
      data - the Metadata
    • removeMetadata

      public boolean removeMetadata(LibraryResource.Metadata data)
      Removes a Metadata object from the metadata.
      Parameters:
      data - the Metadata
      Returns:
      true if removed
    • setProperty

      public void setProperty(String name, String value)
      Sets an arbitrary String property.
      Parameters:
      name - the name of the property
      value - the value of the property
    • getProperty

      public String getProperty(String name)
      Gets a property value. May return null.
      Parameters:
      name - the name of the property
      Returns:
      the value of the property
    • getPropertyNames

      public Set<String> getPropertyNames()
      Returns the names of all defined properties.
      Returns:
      a set of names
    • getIcon

      public Icon getIcon()
      Gets the icon for the tree node associated with this resource.
      Returns:
      the icon
    • getThumbnail

      public String getThumbnail()
      Gets the thumbnail of this resource, if any.
      Returns:
      the thumbnail
    • setThumbnail

      public void setThumbnail(String imagePath)
      Sets the thumbnail for this resource.
      Parameters:
      imagePath - the path to a thumbnail image
    • getCollectionPath

      public String getCollectionPath()
      Gets the collection path for this resource. May return null.
      Returns:
      the collection path of this or an ancestor
    • getTitle

      public String getTitle(String path)
      Gets a title for tabs. May return null.
      Parameters:
      path - the path to the xml file associated with this resource (may be null)
      Returns:
      the title
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getDisplayString

      public String getDisplayString()
    • compareTo

      public int compareTo(LibraryResource resource)
      Compares this to the specified resource.
      Specified by:
      compareTo in interface Comparable<LibraryResource>
      Parameters:
      resource - the resource to compare
      Returns:
      0 if equal, otherwise alphabetical name order
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getClone

      public LibraryResource getClone()
      Gets a clone of this resource.
      Returns:
      the clone
    • getTreePath

      protected List<String> getTreePath(List<String> pathComponents)
      Gets the tree path for this node.
      Parameters:
      pathComponents - a List of Strings in root-to-leaf order that represent this path
      Returns:
      the tree path
    • getHTMLCode

      public static String getHTMLCode(String title, String resourceType, String thumbnailPath, String description, String authors, String contact, String moreInfoURL, org.opensourcephysics.tools.LibraryResource.Attachment attachment, Map<String,String> data)
      Gets the html code for a resource with specified properties. Note this code is for display in the LibraryBrowser, and has no stylesheet of its own.
      Parameters:
      title - the name of the resource
      resourceType - one of the LibraryResource defined types
      thumbnailPath - path to the thumbnail image file
      description - a description of the resource
      authors - authors
      contact - author contact information or institution
      moreInfoURL - link to external HTML with more information about the resource
      attachment - String[] {downloadURL, filename, sizeInBytes} (used for ComPADRE)
      data - Map of metadata names to values
      Returns:
      the html code
    • getHTMLBody

      protected static String getHTMLBody(String title, String resourceType, String thumbnailPath, String description, String authors, String contact, String moreInfoURL, org.opensourcephysics.tools.LibraryResource.Attachment attachment)
      Gets html code for a resource with specified properties.
      Parameters:
      title - the name of the resource
      resourceType - one of the LibraryResource defined types
      thumbnailPath - path to the thumbnail image file
      description - a description of the resource
      authors - authors
      contact - author contact information or institution
      moreInfoURL - link to external HTML with more information about the resource
      attachment - (used for ComPADRE)
      Returns:
      the html path
    • getBodyStyle

      protected static String getBodyStyle()
      Returns the body style for a stylesheet.
      Returns:
      the body style
    • getH1Style

      protected static String getH1Style()
      Returns the H1 heading style for a stylesheet.
      Returns:
      the H1 heading style
    • getH2Style

      protected static String getH2Style()
      Returns the H2 heading style for a stylesheet.
      Returns:
      the H2 heading style
    • getH3Style

      protected static String getH3Style()
      Returns the H3 heading style for a stylesheet.
      Returns:
      the H3 heading style
    • getPStyle

      protected static String getPStyle()
      Returns the P heading style for a stylesheet.
      Returns:
      the P heading style
    • getHTMLStyles

      protected static String getHTMLStyles()
      Returns all HTML styles for a stylesheet.
      Returns:
      the styles
    • getStyleSheetCode

      protected static String getStyleSheetCode()
      Returns the H2 heading style for a stylesheet.
      Returns:
      the H2 heading style
    • insertLineBreaks

      protected static String insertLineBreaks(String text)
      Inserts HTML line breaks where new lines occur in text.
      Parameters:
      text - the text
      Returns:
      the text with HTML line breaks
    • getLoader

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