Class LibraryTreeNode

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

public class LibraryTreeNode extends DefaultMutableTreeNode implements 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:
  • Field Details

  • Constructor Details

    • 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 Details

    • equals

      public boolean equals(Object obj)
      Compares this to the specified object. Return true if both nodes have same name, target and HTML.
      Overrides:
      equals in class 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 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 String getName()
      Returns the name of this node's resource.
      Returns:
      the name
    • getBasePath

      protected String getBasePath()
      Returns the base path of this node's resource.
      Returns:
      the base path
    • getHTMLPath

      protected String getHTMLPath()
      Returns the html path of this node's resource.
      Returns:
      the html path
    • getHTMLURL

      protected 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 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 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 String getAbsoluteTarget()
      Returns the absolute target path of this node's resource.
      Returns:
      the absolute target path
    • getTargetURL

      protected 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 String toString()
      Used by the tree node to get the display name.
      Overrides:
      toString in class DefaultMutableTreeNode
      Returns:
      the display name of the node
    • getDisplayString

      public String 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

      protected void setName(String name)
      Sets the name of this node's resource.
      Parameters:
      name - the name
    • getTreePath

      public TreePath getTreePath()
    • setTarget

      protected boolean setTarget(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(String path)
      Sets the html path of this node's resource.
      Parameters:
      path - the html path
    • setBasePath

      protected void setBasePath(String path)
      Sets the base path of this node's resource.
      Parameters:
      path - the base path
    • setType

      protected void setType(String type)
      Sets the type of this node's resource. The types are static constants defined by LibraryResource.
      Parameters:
      type - the type
    • getChildResources

      protected ArrayList<LibraryResource> getChildResources(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

      public String getToolTip()
      Returns the tooltip for this node.
      Returns:
      tooltip String
    • getMetadataSource

      protected String getMetadataSource()
      Returns a source of metadata. Source is usually HTML code itself but may be path to code
      Returns:
      the metadata source
    • getMetadata

      protected TreeSet<LibraryResource.Metadata> getMetadata()
      Returns the metadata for this node.
      Returns:
      a Set of Metadata entries
    • getMetadataValue

      protected String getMetadataValue(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 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 File createThumbnailFile(BufferedImage image, String path, Dimension maxSize)
      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 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