org.opensourcephysics.tools
Class LibraryResource

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

public class LibraryResource
extends java.lang.Object
implements java.lang.Comparable<LibraryResource>

This represents a library resource.

Version:
1.0
Author:
Douglas Brown

Nested Class Summary
protected static class LibraryResource.Metadata
          A Comparable class for metadata key-value pairs.
 
Field Summary
protected static java.util.List<java.lang.String> allResourceTypes
           
static java.lang.String COLLECTION_TYPE
           
protected  java.lang.String collectionPath
           
protected  java.lang.String displayName
           
static java.lang.String EJS_TYPE
           
protected static javax.swing.Icon ejsIcon
           
static java.lang.String HTML_TYPE
           
protected static javax.swing.Icon htmlIcon
           
static java.lang.String IMAGE_TYPE
           
protected static javax.swing.filechooser.FileFilter[] imageFilters
           
protected static javax.swing.Icon imageIcon
           
protected static java.text.DecimalFormat megabyteFormat
           
static java.lang.String META_AUTHOR
           
static java.lang.String META_CONTACT
           
static java.lang.String META_KEYWORDS
           
static java.lang.String[] META_TYPES
           
protected  LibraryCollection parent
           
static java.lang.String PDF_TYPE
           
protected static javax.swing.Icon pdfIcon
           
protected static java.lang.String[] RESOURCE_TYPES
           
protected  java.lang.String target
           
static java.lang.String TRACKER_TYPE
           
protected static javax.swing.Icon trackerIcon
           
protected  java.util.List<java.lang.String> treePath
           
static java.lang.String UNKNOWN_TYPE
           
protected static javax.swing.Icon unknownIcon
           
static java.lang.String VIDEO_TYPE
           
protected static javax.swing.Icon videoIcon
           
 
Constructor Summary
LibraryResource(java.lang.String name)
          Constructor.
 
Method Summary
 void addMetadata(LibraryResource.Metadata data)
          Adds a Metadata object to the metadata.
 int compareTo(LibraryResource resource)
          Compares this to the specified resource.
 boolean equals(java.lang.Object obj)
           
 java.lang.String getBasePath()
          Gets the base path.
protected static java.lang.String getBodyStyle()
          Returns the body style for a stylesheet.
 LibraryResource getClone()
          Gets a clone of this resource.
 java.lang.String getCollectionPath()
          Gets the collection path for this resource.
 java.lang.String getDescription()
          Gets the description, which must be in html code.
protected static java.lang.String getH1Style()
          Returns the H1 heading style for a stylesheet.
protected static java.lang.String getH2Style()
          Returns the H2 heading style for a stylesheet.
protected static java.lang.String getHTMLBody(java.lang.String title, java.lang.String resourceType, java.lang.String thumbnailPath, java.lang.String description, java.lang.String authors, java.lang.String contact, java.lang.String moreInfoURL, java.lang.String[] attachment)
          Gets html code for a resource with specified properties.
static java.lang.String getHTMLCode(java.lang.String title, java.lang.String resourceType, java.lang.String thumbnailPath, java.lang.String description, java.lang.String authors, java.lang.String contact, java.lang.String moreInfoURL, java.lang.String[] attachment, java.util.Map<java.lang.String,java.lang.String> data)
          Gets the html code for a resource with specified properties.
 java.lang.String getHTMLPath()
          Gets the path to the html page displayed in the browser.
 javax.swing.Icon getIcon()
          Gets the icon for the tree node associated with this resource.
protected  java.lang.String getInheritedBasePath()
          Returns the first base path found in this or its ancestors.
static XML.ObjectLoader getLoader()
          Returns an ObjectLoader to save and load data for this class.
 java.util.TreeSet<LibraryResource.Metadata> getMetadata()
          Gets the metadata.
 LibraryResource.Metadata getMetadata(java.lang.String key)
          Gets the first metadata of a specified type.
 java.lang.String getName()
          Gets the name of this resource (never null).
 java.lang.String getProperty(java.lang.String name)
          Gets a property value.
 java.util.Set<java.lang.String> getPropertyNames()
          Returns the names of all defined properties.
protected static java.lang.String getStyleSheetCode()
          Returns the H2 heading style for a stylesheet.
 java.lang.String getTarget()
          Gets the target of this resource (file name or comPADRE command).
 java.lang.String getThumbnail()
          Gets the thumbnail of this resource, if any.
 java.lang.String getTitle(java.lang.String path)
          Gets a title for tabs.
protected  java.util.List<java.lang.String> getTreePath(java.util.List<java.lang.String> pathComponents)
          Gets the tree path for this node.
 java.lang.String getType()
          Gets the type of resource.
protected static java.lang.String insertLineBreaks(java.lang.String text)
          Inserts HTML line breaks where new lines occur in text.
 boolean removeMetadata(LibraryResource.Metadata data)
          Removes a Metadata object from the metadata.
 boolean setBasePath(java.lang.String path)
          Sets the base path of this resource.
 boolean setDescription(java.lang.String desc)
          Sets the description of this resource.
 boolean setHTMLPath(java.lang.String path)
          Sets the html path of this resource.
 void setMetadata(java.util.TreeSet<LibraryResource.Metadata> data)
          Sets the metadata.
 boolean setName(java.lang.String aName)
          Sets the name of this resource.
 void setProperty(java.lang.String name, java.lang.String value)
          Sets an arbitrary String property.
 boolean setTarget(java.lang.String path)
          Sets the target of this resource.
 void setThumbnail(java.lang.String imagePath)
          Sets the thumbnail for this resource.
 boolean setType(java.lang.String type)
          Sets the type of this resource.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

META_AUTHOR

public static final java.lang.String META_AUTHOR
See Also:
Constant Field Values

META_CONTACT

public static final java.lang.String META_CONTACT
See Also:
Constant Field Values

META_KEYWORDS

public static final java.lang.String META_KEYWORDS
See Also:
Constant Field Values

META_TYPES

public static final java.lang.String[] META_TYPES

UNKNOWN_TYPE

public static final java.lang.String UNKNOWN_TYPE
See Also:
Constant Field Values

COLLECTION_TYPE

public static final java.lang.String COLLECTION_TYPE
See Also:
Constant Field Values

TRACKER_TYPE

public static final java.lang.String TRACKER_TYPE
See Also:
Constant Field Values

EJS_TYPE

public static final java.lang.String EJS_TYPE
See Also:
Constant Field Values

VIDEO_TYPE

public static final java.lang.String VIDEO_TYPE
See Also:
Constant Field Values

IMAGE_TYPE

public static final java.lang.String IMAGE_TYPE
See Also:
Constant Field Values

HTML_TYPE

public static final java.lang.String HTML_TYPE
See Also:
Constant Field Values

PDF_TYPE

public static final java.lang.String PDF_TYPE
See Also:
Constant Field Values

RESOURCE_TYPES

protected static final java.lang.String[] RESOURCE_TYPES

allResourceTypes

protected static java.util.List<java.lang.String> allResourceTypes

htmlIcon

protected static javax.swing.Icon htmlIcon

videoIcon

protected static javax.swing.Icon videoIcon

trackerIcon

protected static javax.swing.Icon trackerIcon

ejsIcon

protected static javax.swing.Icon ejsIcon

pdfIcon

protected static javax.swing.Icon pdfIcon

unknownIcon

protected static javax.swing.Icon unknownIcon

imageIcon

protected static javax.swing.Icon imageIcon

imageFilters

protected static javax.swing.filechooser.FileFilter[] imageFilters

megabyteFormat

protected static java.text.DecimalFormat megabyteFormat

target

protected java.lang.String target

displayName

protected java.lang.String displayName

parent

protected LibraryCollection parent

collectionPath

protected java.lang.String collectionPath

treePath

protected java.util.List<java.lang.String> treePath
Constructor Detail

LibraryResource

public LibraryResource(java.lang.String name)
Constructor.

Parameters:
name - the name of the resource
Method Detail

getName

public java.lang.String getName()
Gets the name of this resource (never null).

Returns:
the name

setName

public boolean setName(java.lang.String aName)
Sets the name of this resource.

Parameters:
aName - the name
Returns:
true if changed

getBasePath

public java.lang.String getBasePath()
Gets the base path.

Returns:
the base path

setBasePath

public boolean setBasePath(java.lang.String path)
Sets the base path of this resource.

Parameters:
path - the base path
Returns:
true if changed

getInheritedBasePath

protected java.lang.String getInheritedBasePath()
Returns the first base path found in this or its ancestors.

Returns:
the base path

getTarget

public java.lang.String getTarget()
Gets the target of this resource (file name or comPADRE command).

Returns:
the target

setTarget

public boolean setTarget(java.lang.String path)
Sets the target of this resource.

Parameters:
path - the target path
Returns:
true if changed

getHTMLPath

public java.lang.String getHTMLPath()
Gets the path to the html page displayed in the browser.

Returns:
the html path

setHTMLPath

public boolean setHTMLPath(java.lang.String path)
Sets the html path of this resource.

Parameters:
path - the html path
Returns:
true if changed

getDescription

public java.lang.String getDescription()
Gets the description, which must be in html code.

Returns:
the description

setDescription

public boolean setDescription(java.lang.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 java.lang.String getType()
Gets the type of resource.

Returns:
the one of the static constant types defined in this class

setType

public boolean setType(java.lang.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 java.util.TreeSet<LibraryResource.Metadata> getMetadata()
Gets the metadata.

Returns:
the Set of Metadata (may be null)

getMetadata

public LibraryResource.Metadata getMetadata(java.lang.String key)
Gets the first metadata of a specified type.

Parameters:
key - the type
Returns:
Metadata, or null if none

setMetadata

public void setMetadata(java.util.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(java.lang.String name,
                        java.lang.String value)
Sets an arbitrary String property.

Parameters:
name - the name of the property
value - the value of the property

getProperty

public java.lang.String getProperty(java.lang.String name)
Gets a property value. May return null.

Parameters:
name - the name of the property
Returns:
the value of the property

getPropertyNames

public java.util.Set<java.lang.String> getPropertyNames()
Returns the names of all defined properties.

Returns:
a set of names

getIcon

public javax.swing.Icon getIcon()
Gets the icon for the tree node associated with this resource.

Returns:
the icon

getThumbnail

public java.lang.String getThumbnail()
Gets the thumbnail of this resource, if any.

Returns:
the thumbnail

setThumbnail

public void setThumbnail(java.lang.String imagePath)
Sets the thumbnail for this resource.

Parameters:
imagePath - the path to a thumbnail image

getCollectionPath

public java.lang.String getCollectionPath()
Gets the collection path for this resource. May return null.

Returns:
the collection path of this or an ancestor

getTitle

public java.lang.String getTitle(java.lang.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 java.lang.String toString()
Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(LibraryResource resource)
Compares this to the specified resource.

Specified by:
compareTo in interface java.lang.Comparable<LibraryResource>
Parameters:
resource - the resource to compare
Returns:
0 if equal, otherwise alphabetical name order

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

getClone

public LibraryResource getClone()
Gets a clone of this resource.

Returns:
the clone

getTreePath

protected java.util.List<java.lang.String> getTreePath(java.util.List<java.lang.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 java.lang.String getHTMLCode(java.lang.String title,
                                           java.lang.String resourceType,
                                           java.lang.String thumbnailPath,
                                           java.lang.String description,
                                           java.lang.String authors,
                                           java.lang.String contact,
                                           java.lang.String moreInfoURL,
                                           java.lang.String[] attachment,
                                           java.util.Map<java.lang.String,java.lang.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 java.lang.String getHTMLBody(java.lang.String title,
                                              java.lang.String resourceType,
                                              java.lang.String thumbnailPath,
                                              java.lang.String description,
                                              java.lang.String authors,
                                              java.lang.String contact,
                                              java.lang.String moreInfoURL,
                                              java.lang.String[] 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 - String[] {downloadURL, filename, sizeInBytes} (used for ComPADRE)
Returns:
the html path

getBodyStyle

protected static java.lang.String getBodyStyle()
Returns the body style for a stylesheet.

Returns:
the body style

getH1Style

protected static java.lang.String getH1Style()
Returns the H1 heading style for a stylesheet.

Returns:
the H1 heading style

getH2Style

protected static java.lang.String getH2Style()
Returns the H2 heading style for a stylesheet.

Returns:
the H2 heading style

getStyleSheetCode

protected static java.lang.String getStyleSheetCode()
Returns the H2 heading style for a stylesheet.

Returns:
the H2 heading style

insertLineBreaks

protected static java.lang.String insertLineBreaks(java.lang.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