org.opensourcephysics.tools
Class LibraryTreeNode

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by org.opensourcephysics.tools.LibraryTreeNode
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<LibraryTreeNode>, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode

public class LibraryTreeNode
extends javax.swing.tree.DefaultMutableTreeNode
implements java.lang.Comparable<LibraryTreeNode>

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:
Serialized Form

Field Summary
protected static java.awt.Dimension defaultThumbnailDimension
           
protected  boolean editable
           
protected static java.util.HashMap<java.lang.String,java.net.URL> htmlURLs
           
protected  java.lang.String metadataSource
           
protected  LibraryResource record
           
protected  java.util.ArrayList<LibraryResource> resources
           
protected  LibraryResource.Metadata selectedMetadata
           
protected static java.util.HashMap<java.lang.String,java.net.URL> targetURLs
           
protected  java.lang.String tooltip
           
protected  LibraryTreePanel treePanel
           
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
protected LibraryTreeNode(LibraryResource resource, LibraryTreePanel treePanel)
          Constructs a node with a LibraryResource.
 
Method Summary
 int compareTo(LibraryTreeNode node)
          Compares this to the specified node.
protected  boolean createChildNodes()
          Creates the child nodes of this node if this is a collection node.
protected  java.io.File createThumbnailFile(java.awt.image.BufferedImage image, java.lang.String path, java.awt.Dimension maxSize)
          Creates a thumbnail image and writes it to a specified path.
 boolean equals(java.lang.Object obj)
          Compares this to the specified object.
protected  java.lang.String getAbsoluteTarget()
          Returns the absolute target path of this node's resource.
protected  java.lang.String getBasePath()
          Returns the base path of this node's resource.
protected  java.util.ArrayList<LibraryResource> getChildResources(java.lang.String[] types)
          Returns this node's child resources, if any, of a given set of types.
protected  java.lang.String getHTMLPath()
          Returns the html path of this node's resource.
protected  java.lang.String getHTMLString()
          Returns an HTML string that describes this node's resource.
protected  java.net.URL getHTMLURL()
          Returns the html URL for this node, or null if html path is empty or invalid.
protected  java.util.TreeSet<LibraryResource.Metadata> getMetadata()
          Returns the metadata for this node.
protected  java.lang.String getMetadataSourcePath()
          Returns the path to a source of metadata (usually HTML path)
protected  java.lang.String getMetadataValue(java.lang.String key)
          Returns the metadata value of a specified type.
protected  java.lang.String getName()
          Returns the name of this node's resource.
protected  java.lang.String getTarget()
          Returns the target of this node's resource.
protected  java.net.URL getTargetURL()
          Returns the target URL for this node, or null if target is empty or invalid.
protected  java.io.File getThumbnailFile()
          Returns a File that points to the cached thumbnail, if any, for this node.
protected  java.lang.String getToolTip()
          Returns the (multiline) tooltip for this node.
protected  boolean isEditable()
          Determines if this node is editable.
protected  void setBasePath(java.lang.String path)
          Sets the base path of this node's resource.
protected  void setEditable(boolean edit)
          Sets the editable property for this node.
protected  void setHTMLPath(java.lang.String path)
          Sets the html path of this node's resource.
protected  void setName(java.lang.String name)
          Sets the name of this node's resource.
protected  boolean setTarget(java.lang.String path)
          Sets the target of this node's resource.
protected  void setType(java.lang.String type)
          Sets the type of this node's resource.
 java.lang.String 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
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

htmlURLs

protected static java.util.HashMap<java.lang.String,java.net.URL> htmlURLs

targetURLs

protected static java.util.HashMap<java.lang.String,java.net.URL> targetURLs

defaultThumbnailDimension

protected static java.awt.Dimension defaultThumbnailDimension

record

protected LibraryResource record

editable

protected boolean editable

treePanel

protected LibraryTreePanel treePanel

resources

protected java.util.ArrayList<LibraryResource> resources

tooltip

protected java.lang.String tooltip

selectedMetadata

protected LibraryResource.Metadata selectedMetadata

metadataSource

protected java.lang.String metadataSource
Constructor Detail

LibraryTreeNode

protected LibraryTreeNode(LibraryResource resource,
                          LibraryTreePanel treePanel)
Constructs a node with a LibraryResource.

Parameters:
resource - the resource
treePanel - the LibraryTreePanel that will use the node
Method Detail

equals

public boolean equals(java.lang.Object obj)
Compares this to the specified object. Return true if both nodes have same name, target and HTML.

Overrides:
equals in class java.lang.Object
Parameters:
object - the object
Returns:
true if this equals the specified object

compareTo

public int compareTo(LibraryTreeNode node)
Compares this to the specified node.

Specified by:
compareTo in interface java.lang.Comparable<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

protected java.lang.String getName()
Returns the name of this node's resource.

Returns:
the name

getBasePath

protected java.lang.String getBasePath()
Returns the base path of this node's resource.

Returns:
the base path

getHTMLPath

protected java.lang.String getHTMLPath()
Returns the html path of this node's resource.

Returns:
the html path

getHTMLURL

protected java.net.URL 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

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

protected java.lang.String getTarget()
Returns the target of this node's resource. The target may be absolute or relative to base path.

Returns:
the target

getAbsoluteTarget

protected java.lang.String getAbsoluteTarget()
Returns the absolute target path of this node's resource.

Returns:
the absolute target path

getTargetURL

protected java.net.URL 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

public java.lang.String toString()
Used by the tree node to get the display name.

Overrides:
toString in class javax.swing.tree.DefaultMutableTreeNode
Returns:
the display name of the node

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

protected void setName(java.lang.String name)
Sets the name of this node's resource.

Parameters:
name - the name

setTarget

protected boolean setTarget(java.lang.String path)
Sets the target of this node's resource. May be absolute or relative path.

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

setHTMLPath

protected void setHTMLPath(java.lang.String path)
Sets the html path of this node's resource.

Parameters:
path - the html path

setBasePath

protected void setBasePath(java.lang.String path)
Sets the base path of this node's resource.

Parameters:
path - the base path

setType

protected void setType(java.lang.String type)
Sets the type of this node's resource. The types are static constants defined by LibraryResource.

Parameters:
type - the type

getChildResources

protected java.util.ArrayList<LibraryResource> getChildResources(java.lang.String[] types)
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

protected java.lang.String getToolTip()
Returns the (multiline) tooltip for this node.

Returns:
tooltip String

getMetadataSourcePath

protected java.lang.String getMetadataSourcePath()
Returns the path to a source of metadata (usually HTML path)

Returns:
the metadata path

getMetadata

protected java.util.TreeSet<LibraryResource.Metadata> getMetadata()
Returns the metadata for this node.

Returns:
a Set of Metadata entries

getMetadataValue

protected java.lang.String getMetadataValue(java.lang.String key)
Returns the metadata value of a specified type.

Parameters:
key - the type of the metadata
Returns:
the value, or null if none

getThumbnailFile

protected java.io.File 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

protected java.io.File createThumbnailFile(java.awt.image.BufferedImage image,
                                           java.lang.String path,
                                           java.awt.Dimension maxSize)
Creates a thumbnail image and writes it to a specified path.

Parameters:
image - the full-size image from which to create the thumbnail
path - the path for the thumbnail image file
maxSize - the maximum size of the thumbnail image
Returns:
the thumbnail File, or null if failed