Class LibraryTreePanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class LibraryTreePanel extends JPanel
This is a JPanel that displays an OSP LibraryResource at the root of a tree. If the resource is a LibraryCollection, the tree is populated with its child resources.
Author:
Douglas Brown
See Also:
  • Field Details

  • Constructor Details

    • LibraryTreePanel

      public LibraryTreePanel(LibraryBrowser browser)
      Constructs an empty LibraryTreePanel.
      Parameters:
      browser - the LibraryBrowser that will display this panel
  • Method Details

    • setRootResource

      public void setRootResource(LibraryResource resource, String path, boolean editable, boolean pathIsXML)
      Sets the root resource or collection displayed in the tree.
      Parameters:
      resource - the resource
      path - the file path to the resource or collection
      editable - true if the collection is user-editable
      pathIsXML - true if the path points to a DL xml file
    • getCollection

      public LibraryResource getCollection()
      Gets the collection displayed in the tree.
      Returns:
      the collection
    • getSelectedNode

      public LibraryTreeNode getSelectedNode()
      Gets the selected node.
      Returns:
      the selected node, or null if none
    • setSelectedNode

      protected void setSelectedNode(LibraryTreeNode node)
      Sets the selected node.
      Parameters:
      node - the node to select
    • setSelectionPath

      protected void setSelectionPath(List<String> treePath)
      Sets the selection path.
      Parameters:
      treePath - tree path to select in root-first order (may be null)
    • setFontLevel

      protected void setFontLevel(int level)
      Sets the font level.
      Parameters:
      level - the desired font level
    • setEditing

      protected void setEditing(boolean edit)
      Sets the editing state.
      Parameters:
      edit - true to start editing, false to stop
    • isEditable

      protected boolean isEditable()
      Returns true if the collection is editable.
      Returns:
      true if editable
    • isEditing

      protected boolean isEditing()
      Gets the editing state.
      Returns:
      true if editing
    • showInfo

      protected void showInfo(LibraryTreeNode node, String why)
      Displays the resource data for the specified node.
      Parameters:
      node - the LibraryTreeNode
    • showHTMLPane

      protected void showHTMLPane(LibraryTreeNode node)
      Displays the HTMLPane for a given tree node.
      Parameters:
      node - the node
    • createGUI

      protected void createGUI()
      Creates the GUI and listeners.
    • doMouseClick

      protected void doMouseClick(MouseEvent e)
    • refreshGUI

      protected void refreshGUI()
      Refreshes the GUI including locale-dependent resource strings.
    • refreshGUI

      protected void refreshGUI(boolean andRebuild)
    • enableButtons

      protected void enableButtons()
      Enables/disables buttons based on selected node and clipboard state.
    • revert

      protected void revert()
      Discards collection edits and reverts to the previous state.
    • createTree

      protected void createTree(LibraryTreeNode root)
      Creates the tree.
      Parameters:
      root - the root node
    • ifClipboardPastable

      protected void ifClipboardPastable(Runnable r)
      Determines if the clipboard can be pasted.
    • getPopup

      protected JPopupMenu getPopup(LibraryTreeNode node)
      Returns a popup menu with items appropriate for a given tree node.
      Parameters:
      node - the node
      Returns:
      the popup menu
    • insertChildAt

      protected boolean insertChildAt(LibraryTreeNode child, LibraryTreeNode parent, int index)
      Inserts a child into a parent node at a specified index.
      Parameters:
      child - the child node
      parent - the parent node
      index - the index
      Returns:
      true if added
    • removeNode

      protected void removeNode(LibraryTreeNode node)
      Removes a given tree node.
      Parameters:
      node - the node
    • setChanged

      protected void setChanged()
      Called whenever a resource changes due to a user edit.
    • isChanged

      protected boolean isChanged()
      Determines if the resource has been changed since the last save.
      Returns:
      true if changed
    • save

      protected String save()
      Saves the current resource.
      Returns:
      the path to the saved file, or null if not saved
    • saveChanges

      protected boolean saveChanges(String name)
      Gives the user an opportunity to save changes.
      Parameters:
      name - the name of the collection
      Returns:
      false if the user cancels, otherwise true
    • getNextSplit

      protected String[] getNextSplit(String phrase)
      Returns the phrase before the next AND or OR operator, the operator itself, and the remainder of the phrase.
      Parameters:
      phrase - a search phrase
      Returns:
      String[]
    • getParenthesisSplit

      protected String[] getParenthesisSplit(String phrase)
      Returns the phrase enclosed in parentheses along with the remainder of a phrase.
      Parameters:
      phrase - a phrase that starts immediately AFTER an opening parenthesis
      Returns:
      String[] {the enclosed phrase, the remainder}
    • applyAND

      protected Map<LibraryTreeNode,List<String[]>> applyAND(Map<LibraryTreeNode,List<String[]>> results1, Map<LibraryTreeNode,List<String[]>> results2)
      Returns the nodes that are contained in the keysets of both of two input maps.
      Parameters:
      results1 -
      results2 -
      Returns:
      map of nodes found in both keysets
    • applyOR

      protected Map<LibraryTreeNode,List<String[]>> applyOR(Map<LibraryTreeNode,List<String[]>> results1, Map<LibraryTreeNode,List<String[]>> results2)
      Returns the nodes that are contained in the keysets of either of two input maps.
      Parameters:
      results1 -
      results2 -
      Returns:
      map of nodes found in either keyset
    • getHTMLBody

      protected String getHTMLBody(String path)
      Gets the code from an HTML page.
      Parameters:
      path - the HTML path
      Returns:
      the body of the HTML
    • refreshEntryFields

      protected void refreshEntryFields()
      Used to refresh the entry fields when the browser closes.
    • getRelativePath

      protected static String getRelativePath(Map<String,ZipEntry> files, String baseName)
    • showHTMLDocument

      protected static void showHTMLDocument(LibraryTreePanel.HTMLPane htmlPane, URL url, String htmlStr)
    • getFileChooser

      protected static JFileChooser getFileChooser()
      Gets a shared file chooser.
      Returns:
      the file chooser
    • refreshSelectedNode

      public void refreshSelectedNode()
    • scrollToPath

      protected void scrollToPath(TreePath path, boolean andSelect)
    • clearMaps

      public static void clearMaps()