Package org.opensourcephysics.tools
Class LibraryTreeNode
java.lang.Object
javax.swing.tree.DefaultMutableTreeNode
org.opensourcephysics.tools.LibraryTreeNode
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<LibraryTreeNode>,MutableTreeNode,TreeNode
A DefaultMutableTreeNode for a LibraryTreePanel tree, with a LibraryResource
user object. Provides convenience methods for getting, setting and displaying
LibraryResource data.
- Version:
- 1.0
- Author:
- Douglas Brown
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Dimensionprotected booleanprotected Stringprotected LibraryResourceprotected ArrayList<LibraryResource>protected LibraryResource.Metadataprotected Stringprotected LibraryTreePanelFields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLibraryTreeNode(LibraryResource resource, LibraryTreePanel treePanel) Constructs a node with a LibraryResource. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(LibraryTreeNode node) Compares this to the specified node.protected booleanCreates the child nodes of this node if this is a collection node.protected FilecreateThumbnailFile(BufferedImage image, String path, Dimension maxSize) SwingJS note: This does not work in SwingJS because it is being invoked immediately after creating the image.booleanCompares this to the specified object.protected StringReturns the absolute target path of this node's resource.protected StringReturns the base path of this node's resource.protected ArrayList<LibraryResource>getChildResources(String[] types) Returns this node's child resources, if any, of a given set of types.protected StringReturns the html path of this node's resource.protected StringReturns an HTML string that describes this node's resource.protected URLReturns the html URL for this node, or null if html path is empty or invalid.protected TreeSet<LibraryResource.Metadata>Returns the metadata for this node.protected StringReturns a source of metadata.protected StringgetMetadataValue(String key) Returns the metadata value of a specified type.protected StringgetName()Returns the name of this node's resource.protected StringReturns the target of this node's resource.protected URLReturns the target URL for this node, or null if target is empty or invalid.protected FileReturns a File that points to the cached thumbnail, if any, for this node.Returns the tooltip for this node.protected booleanDetermines if this node is editable.protected voidsetBasePath(String path) Sets the base path of this node's resource.protected voidsetEditable(boolean edit) Sets the editable property for this node.protected voidsetHTMLPath(String path) Sets the html path of this node's resource.protected voidSets the name of this node's resource.protected booleanSets the target of this node's resource.protected voidSets the type of this node's resource.toString()Used by the tree node to get the display name.Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject
-
Field Details
-
htmlURLs
-
targetURLs
-
defaultThumbnailDimension
-
record
-
editable
protected boolean editable -
treePanel
-
resources
-
tooltip
-
selectedMetadata
-
metadataSource
-
-
Constructor Details
-
LibraryTreeNode
Constructs a node with a LibraryResource.- Parameters:
resource- the resourcetreePanel- the LibraryTreePanel that will use the node
-
-
Method Details
-
equals
Compares this to the specified object. Return true if both nodes have same name, target and HTML. -
compareTo
Compares this to the specified node.- Specified by:
compareToin interfaceComparable<LibraryTreeNode>- Parameters:
node- the node to compare- Returns:
- 0 if equal, otherwise alphabetical name order
-
createChildNodes
protected boolean createChildNodes()Creates the child nodes of this node if this is a collection node.- Returns:
- true if children were added
-
getName
Returns the name of this node's resource.- Returns:
- the name
-
getBasePath
Returns the base path of this node's resource.- Returns:
- the base path
-
getHTMLPath
Returns the html path of this node's resource.- Returns:
- the html path
-
getHTMLURL
Returns the html URL for this node, or null if html path is empty or invalid. If a cached file exists, this returns its URL instead of the original.- Returns:
- the URL
-
getHTMLString
Returns an HTML string that describes this node's resource. This is displayed if no html URL is available.- Returns:
- the html string
-
getTarget
Returns the target of this node's resource. The target may be absolute or relative to base path.- Returns:
- the target
-
getAbsoluteTarget
Returns the absolute target path of this node's resource.- Returns:
- the absolute target path
-
getTargetURL
Returns the target URL for this node, or null if target is empty or invalid. If a cached file exists, this returns its URL instead of the original.- Returns:
- the URL
-
toString
Used by the tree node to get the display name.- Overrides:
toStringin classDefaultMutableTreeNode- Returns:
- the display name of the node
-
getDisplayString
-
isEditable
protected boolean isEditable()Determines if this node is editable. Note: returns true only if this and its parent are editable.- Returns:
- true of editable
-
setEditable
protected void setEditable(boolean edit) Sets the editable property for this node.- Parameters:
edit- true to make this node editable
-
setName
Sets the name of this node's resource.- Parameters:
name- the name
-
getTreePath
-
setTarget
Sets the target of this node's resource. May be absolute or relative path.- Parameters:
path- the target path- Returns:
- true if changed
-
setHTMLPath
Sets the html path of this node's resource.- Parameters:
path- the html path
-
setBasePath
Sets the base path of this node's resource.- Parameters:
path- the base path
-
setType
Sets the type of this node's resource. The types are static constants defined by LibraryResource.- Parameters:
type- the type
-
getChildResources
Returns this node's child resources, if any, of a given set of types. The types are static constants defined by LibraryResource.- Parameters:
types- an array of resource types- Returns:
- a list of LibraryResources
-
getToolTip
Returns the tooltip for this node.- Returns:
- tooltip String
-
getMetadataSource
Returns a source of metadata. Source is usually HTML code itself but may be path to code- Returns:
- the metadata source
-
getMetadata
Returns the metadata for this node.- Returns:
- a Set of Metadata entries
-
getMetadataValue
Returns the metadata value of a specified type.- Parameters:
key- the type of the metadata- Returns:
- the value, or null if none
-
getThumbnailFile
Returns a File that points to the cached thumbnail, if any, for this node. Note: the thumbnail file may not exist--this just determines where it should be.- Returns:
- the thumbnail File, whether or not it exists
-
createThumbnailFile
SwingJS note: This does not work in SwingJS because it is being invoked immediately after creating the image. Unlike in Java, ImageIO cannot wait for the image creation to complete without a clock tick. But it would seem that we don't need this, anyway. We can just transfer the files. Creates a thumbnail image and writes it to a specified path.- Parameters:
image- the full-size image from which to create the thumbnailpath- the path for the thumbnail image filemaxSize- the maximum size of the thumbnail image- Returns:
- the thumbnail File, or null if failed
-