Package org.opensourcephysics.tools
Class LibraryResource
java.lang.Object
org.opensourcephysics.tools.LibraryResource
- All Implemented Interfaces:
Comparable<LibraryResource>
- Direct Known Subclasses:
LibraryCollection
This represents a library resource.
- Version:
- 1.0
- Author:
- Douglas Brown
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
A Comparable class for metadata key-value pairs. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Font
static final String
protected static ResizableIcon
protected String
static final String
protected static ResizableIcon
protected String
static final String
protected static ResizableIcon
protected static Font
protected static Font
protected static Font
static final String
protected static ResizableIcon
static final String
protected static ResizableIcon
protected String[][]
protected static DecimalFormat
static final String
static final String
static final String
static final String[]
protected LibraryCollection
static final String
protected static ResizableIcon
protected static final String[]
protected String
static final String
protected static ResizableIcon
static final String
protected static ResizableIcon
static final String
protected static ResizableIcon
static final String
protected static ResizableIcon
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a Metadata object to the metadata.int
compareTo
(LibraryResource resource) Compares this to the specified resource.boolean
Gets the absolute path to the target.Gets the base path.protected static String
Returns the body style for a stylesheet.getClone()
Gets a clone of this resource.Gets the collection path for this resource.Gets the description, which must be in html code.protected static String
Returns the H1 heading style for a stylesheet.protected static String
Returns the H2 heading style for a stylesheet.protected static String
Returns the H3 heading style for a stylesheet.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.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.Gets the path to the html page displayed in the browser.protected static String
Returns all HTML styles for a stylesheet.getIcon()
Gets the icon for the tree node associated with this resource.protected String
Returns the first base path found in this or its ancestors.static XML.ObjectLoader
Returns an ObjectLoader to save and load data for this class.Gets the metadata.getMetadata
(String key) Gets the first metadata of a specified type.getName()
Gets the name of this resource (never null).getProperty
(String name) Gets a property value.Returns the names of all defined properties.protected static String
Returns the P heading style for a stylesheet.protected static String
Returns the H2 heading style for a stylesheet.Gets the target of this resource (file name or comPADRE command).Gets the thumbnail of this resource, if any.Gets a title for tabs.getTreePath
(List<String> pathComponents) Gets the tree path for this node.getType()
Gets the type of resource.protected static String
insertLineBreaks
(String text) Inserts HTML line breaks where new lines occur in text.boolean
Removes a Metadata object from the metadata.boolean
setBasePath
(String path) Sets the base path of this resource.boolean
setDescription
(String desc) Sets the description of this resource.boolean
setHTMLPath
(String path) Sets the html path of this resource.void
Sets the metadata.boolean
Sets the name of this resource.void
setProperty
(String name, String value) Sets an arbitrary String property.boolean
Sets the target of this resource.void
setThumbnail
(String imagePath) Sets the thumbnail for this resource.boolean
Sets the type of this resource.toString()
-
Field Details
-
META_AUTHOR
- See Also:
-
META_CONTACT
- See Also:
-
META_KEYWORDS
- See Also:
-
META_TYPES
-
UNKNOWN_TYPE
- See Also:
-
COLLECTION_TYPE
- See Also:
-
TRACKER_TYPE
- See Also:
-
EJS_TYPE
- See Also:
-
VIDEO_TYPE
- See Also:
-
IMAGE_TYPE
- See Also:
-
HTML_TYPE
- See Also:
-
PDF_TYPE
- See Also:
-
DATA_TYPE
- See Also:
-
URL_TYPE
- See Also:
-
RESOURCE_TYPES
-
allResourceTypes
-
htmlIcon
-
videoIcon
-
trackerIcon
-
ejsIcon
-
pdfIcon
-
unknownIcon
-
imageIcon
-
dataIcon
-
urlIcon
-
collectionIcon
-
megabyteFormat
-
bodyFont
-
h1Font
-
h2Font
-
h3Font
-
target
-
displayName
-
loaderMetadata
-
parent
-
collectionPath
-
treePath
-
-
Constructor Details
-
LibraryResource
Constructor.- Parameters:
name
- the name of the resource
-
-
Method Details
-
getName
Gets the name of this resource (never null).- Returns:
- the name
-
setName
Sets the name of this resource.- Parameters:
aName
- the name- Returns:
- true if changed
-
getBasePath
Gets the base path.- Returns:
- the base path
-
setBasePath
Sets the base path of this resource.- Parameters:
path
- the base path- Returns:
- true if changed
-
getInheritedBasePath
Returns the first base path found in this or its ancestors.- Returns:
- the base path
-
getTarget
Gets the target of this resource (file name or comPADRE command).- Returns:
- the target
-
getAbsoluteTarget
Gets the absolute path to the target. Note: this is needed for the- Returns:
- the absolute target, or empty String if none
-
setTarget
Sets the target of this resource.- Parameters:
path
- the target path- Returns:
- true if changed
-
getHTMLPath
Gets the path to the html page displayed in the browser.- Returns:
- the html path
-
setHTMLPath
Sets the html path of this resource.- Parameters:
path
- the html path- Returns:
- true if changed
-
getDescription
Gets the description, which must be in html code.- Returns:
- the description
-
setDescription
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
Gets the type of resource.- Returns:
- the one of the static constant types defined in this class
-
setType
Sets the type of this resource. The types are static constants defined in this class.- Parameters:
type
- the type- Returns:
- true if changed
-
getMetadata
Gets the metadata.- Returns:
- the Set of Metadata (may be null)
-
getMetadata
Gets the first metadata of a specified type.- Parameters:
key
- the type- Returns:
- Metadata, or null if none
-
setMetadata
Sets the metadata. This replaces all previously added metadata.- Parameters:
data
- a Set of Metadata (may be null)
-
addMetadata
Adds a Metadata object to the metadata.- Parameters:
data
- the Metadata
-
removeMetadata
Removes a Metadata object from the metadata.- Parameters:
data
- the Metadata- Returns:
- true if removed
-
setProperty
Sets an arbitrary String property.- Parameters:
name
- the name of the propertyvalue
- the value of the property
-
getProperty
Gets a property value. May return null.- Parameters:
name
- the name of the property- Returns:
- the value of the property
-
getPropertyNames
Returns the names of all defined properties.- Returns:
- a set of names
-
getIcon
Gets the icon for the tree node associated with this resource.- Returns:
- the icon
-
getThumbnail
Gets the thumbnail of this resource, if any.- Returns:
- the thumbnail
-
setThumbnail
Sets the thumbnail for this resource.- Parameters:
imagePath
- the path to a thumbnail image
-
getCollectionPath
Gets the collection path for this resource. May return null.- Returns:
- the collection path of this or an ancestor
-
getTitle
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
-
getDisplayString
-
compareTo
Compares this to the specified resource.- Specified by:
compareTo
in interfaceComparable<LibraryResource>
- Parameters:
resource
- the resource to compare- Returns:
- 0 if equal, otherwise alphabetical name order
-
equals
-
getClone
Gets a clone of this resource.- Returns:
- the clone
-
getTreePath
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 resourceresourceType
- one of the LibraryResource defined typesthumbnailPath
- path to the thumbnail image filedescription
- a description of the resourceauthors
- authorscontact
- author contact information or institutionmoreInfoURL
- link to external HTML with more information about the resourceattachment
- 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 resourceresourceType
- one of the LibraryResource defined typesthumbnailPath
- path to the thumbnail image filedescription
- a description of the resourceauthors
- authorscontact
- author contact information or institutionmoreInfoURL
- link to external HTML with more information about the resourceattachment
- (used for ComPADRE)- Returns:
- the html path
-
getBodyStyle
Returns the body style for a stylesheet.- Returns:
- the body style
-
getH1Style
Returns the H1 heading style for a stylesheet.- Returns:
- the H1 heading style
-
getH2Style
Returns the H2 heading style for a stylesheet.- Returns:
- the H2 heading style
-
getH3Style
Returns the H3 heading style for a stylesheet.- Returns:
- the H3 heading style
-
getPStyle
Returns the P heading style for a stylesheet.- Returns:
- the P heading style
-
getHTMLStyles
Returns all HTML styles for a stylesheet.- Returns:
- the styles
-
getStyleSheetCode
Returns the H2 heading style for a stylesheet.- Returns:
- the H2 heading style
-
insertLineBreaks
Inserts HTML line breaks where new lines occur in text.- Parameters:
text
- the text- Returns:
- the text with HTML line breaks
-
getLoader
Returns an ObjectLoader to save and load data for this class.- Returns:
- the object loader
-