org.opensourcephysics.tools
Class LibraryTreePanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.opensourcephysics.tools.LibraryTreePanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class LibraryTreePanel
extends javax.swing.JPanel

This is a JPanel that displays an OSP LibraryCollection in a tree.

Author:
Douglas Brown
See Also:
Serialized Form

Nested Class Summary
protected static class LibraryTreePanel.EntryField
          A JTextField for editing LibraryTreeNode data.
protected static class LibraryTreePanel.HTMLPane
          A JTextPane that displays html pages for LibraryTreeNodes.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  javax.swing.Action addCollectionAction
           
protected  javax.swing.JButton addCollectionButton
           
protected  javax.swing.Action addResourceAction
           
protected  javax.swing.JButton addResourceButton
           
protected  javax.swing.JTextField basePathField
           
protected  javax.swing.JLabel basePathLabel
           
protected  LibraryBrowser browser
           
protected static javax.swing.JFileChooser chooser
           
protected  LibraryCollection collection
           
protected  java.lang.String command
           
protected  java.awt.event.MouseAdapter convertPathMouseListener
           
protected  javax.swing.Action copyAction
           
protected  javax.swing.JButton copyButton
           
protected  javax.swing.Action cutAction
           
protected  javax.swing.JButton cutButton
           
protected static java.awt.Color darkRed
           
protected static java.awt.Color defaultForeground
           
protected  javax.swing.JPanel displayPanel
           
protected  boolean editing
           
protected  javax.swing.JToolBar editorbar
           
protected  javax.swing.Box editorPanel
           
protected  LibraryTreePanel.HTMLPane emptyHTMLPane
           
protected  javax.swing.Box fileBox
           
protected static javax.swing.filechooser.FileFilter folderFilter
           
protected  javax.swing.JTextField htmlField
           
protected static javax.swing.filechooser.FileFilter htmlFilter
           
protected  javax.swing.JLabel htmlLabel
           
protected static java.util.HashMap<LibraryTreeNode,LibraryTreePanel.HTMLPane> htmlPanesByNode
           
protected static java.util.HashMap<java.net.URL,LibraryTreePanel.HTMLPane> htmlPanesByURL
           
protected  javax.swing.JScrollPane htmlScroller
           
protected static javax.swing.event.HyperlinkListener hyperlinkListener
           
protected  boolean isCollectionChanged
           
protected  java.util.ArrayList<javax.swing.JLabel> labels
           
protected static java.awt.Color lightGreen
           
protected static java.awt.Color lightRed
           
protected  javax.swing.Action moveDownAction
           
protected  javax.swing.JButton moveDownButton
           
protected  javax.swing.Action moveUpAction
           
protected  javax.swing.JButton moveUpButton
           
protected  javax.swing.JTextField nameField
           
protected  javax.swing.JLabel nameLabel
           
protected  javax.swing.JButton openBasePathButton
           
protected  javax.swing.JButton openFileButton
           
protected static javax.swing.Icon openFileIcon
           
protected  javax.swing.JButton openHTMLButton
           
protected  javax.swing.Action pasteAction
           
protected  javax.swing.JButton pasteButton
           
protected  XMLControl pasteControl
           
protected  java.lang.String pathToCollection
           
protected  javax.swing.JPopupMenu popup
           
protected  XMLControl revertControl
           
protected  LibraryTreeNode rootNode
           
protected  javax.swing.JSplitPane splitPane
           
protected  javax.swing.JTextField targetField
           
protected  javax.swing.JLabel targetLabel
           
protected  javax.swing.JTree tree
           
protected  javax.swing.tree.DefaultTreeModel treeModel
           
protected  java.awt.event.MouseAdapter treeMouseListener
           
protected  javax.swing.JScrollPane treeScroller
           
protected  javax.swing.event.TreeSelectionListener treeSelectionListener
           
protected  javax.swing.JLabel typeField
           
protected  int typeFieldWidth
           
protected  javax.swing.JLabel typeLabel
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
LibraryTreePanel(LibraryBrowser browser)
          Constructs an empty LibraryTreePanel.
 
Method Summary
protected  void collectionChanged()
          Called whenever the collection changes due to a user edit.
protected  void createGUI()
          Creates the GUI and listeners.
protected  void createTree(LibraryTreeNode root)
          Creates the tree.
protected  void enableButtons()
          Enables/disables buttons based on selected node and clipboard state.
 LibraryCollection getCollection()
          Gets the collection displayed in the tree.
protected static javax.swing.JFileChooser getFileChooser()
          Gets a shared file chooser.
protected  LibraryTreePanel.HTMLPane getHTMLPane(LibraryTreeNode node)
          Gets the HTMLPane that describes a given tree node.
protected  javax.swing.JPopupMenu getPopup(LibraryTreeNode node)
          Returns a popup menu with items appropriate for a given tree node.
protected  LibraryTreeNode getSelectedNode()
          Gets the selected node.
protected  boolean insertChildAt(LibraryTreeNode child, LibraryTreeNode parent, int index)
          Inserts a child into a parent node at a specified index.
protected  boolean isClipboardPastable()
          Determines if the clipboard can be pasted.
protected  boolean isCollectionChanged()
          Called whenever the collection changes due to a user edit.
protected  boolean isEditable()
          Returns true if the collection is editable.
protected  boolean isEditing()
          Gets the editing state.
protected  void refreshGUI()
          Refreshes the GUI including locale-dependent resource strings.
protected  void removeNode(LibraryTreeNode node)
          Removes a given tree node.
protected  void revert()
          Discards collection edits and reverts to the previous state.
protected  void save()
          Saves the current collection.
protected  boolean saveChanges(java.lang.String name)
          Gives the user an opportunity to save changes.
 void setCollection(LibraryCollection collection, java.lang.String path, boolean editable)
          Sets the collection displayed in the tree.
protected  void setEditing(boolean edit)
          Sets the editing state.
protected  void setSelectedNode(LibraryTreeNode node)
          Sets the selected node.
protected  void showInfo(LibraryTreeNode node)
          Displays the resource data for the specified node.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lightRed

protected static java.awt.Color lightRed

darkRed

protected static java.awt.Color darkRed

lightGreen

protected static java.awt.Color lightGreen

defaultForeground

protected static java.awt.Color defaultForeground

openFileIcon

protected static javax.swing.Icon openFileIcon

hyperlinkListener

protected static javax.swing.event.HyperlinkListener hyperlinkListener

chooser

protected static javax.swing.JFileChooser chooser

htmlFilter

protected static javax.swing.filechooser.FileFilter htmlFilter

folderFilter

protected static javax.swing.filechooser.FileFilter folderFilter

htmlPanesByURL

protected static java.util.HashMap<java.net.URL,LibraryTreePanel.HTMLPane> htmlPanesByURL

htmlPanesByNode

protected static java.util.HashMap<LibraryTreeNode,LibraryTreePanel.HTMLPane> htmlPanesByNode

browser

protected LibraryBrowser browser

collection

protected LibraryCollection collection

pathToCollection

protected java.lang.String pathToCollection

rootNode

protected LibraryTreeNode rootNode

treeModel

protected javax.swing.tree.DefaultTreeModel treeModel

tree

protected javax.swing.JTree tree

treeScroller

protected javax.swing.JScrollPane treeScroller

htmlScroller

protected javax.swing.JScrollPane htmlScroller

editorbar

protected javax.swing.JToolBar editorbar

cutButton

protected javax.swing.JButton cutButton

copyButton

protected javax.swing.JButton copyButton

pasteButton

protected javax.swing.JButton pasteButton

addCollectionButton

protected javax.swing.JButton addCollectionButton

addResourceButton

protected javax.swing.JButton addResourceButton

moveUpButton

protected javax.swing.JButton moveUpButton

moveDownButton

protected javax.swing.JButton moveDownButton

editorPanel

protected javax.swing.Box editorPanel

fileBox

protected javax.swing.Box fileBox

displayPanel

protected javax.swing.JPanel displayPanel

emptyHTMLPane

protected LibraryTreePanel.HTMLPane emptyHTMLPane

splitPane

protected javax.swing.JSplitPane splitPane

nameField

protected javax.swing.JTextField nameField

htmlField

protected javax.swing.JTextField htmlField

basePathField

protected javax.swing.JTextField basePathField

targetField

protected javax.swing.JTextField targetField

nameLabel

protected javax.swing.JLabel nameLabel

htmlLabel

protected javax.swing.JLabel htmlLabel

basePathLabel

protected javax.swing.JLabel basePathLabel

targetLabel

protected javax.swing.JLabel targetLabel

typeLabel

protected javax.swing.JLabel typeLabel

typeField

protected javax.swing.JLabel typeField

openHTMLButton

protected javax.swing.JButton openHTMLButton

openBasePathButton

protected javax.swing.JButton openBasePathButton

openFileButton

protected javax.swing.JButton openFileButton

labels

protected java.util.ArrayList<javax.swing.JLabel> labels

popup

protected javax.swing.JPopupMenu popup

treeMouseListener

protected java.awt.event.MouseAdapter treeMouseListener

convertPathMouseListener

protected java.awt.event.MouseAdapter convertPathMouseListener

treeSelectionListener

protected javax.swing.event.TreeSelectionListener treeSelectionListener

cutAction

protected javax.swing.Action cutAction

copyAction

protected javax.swing.Action copyAction

pasteAction

protected javax.swing.Action pasteAction

addCollectionAction

protected javax.swing.Action addCollectionAction

addResourceAction

protected javax.swing.Action addResourceAction

moveUpAction

protected javax.swing.Action moveUpAction

moveDownAction

protected javax.swing.Action moveDownAction

pasteControl

protected XMLControl pasteControl

editing

protected boolean editing

isCollectionChanged

protected boolean isCollectionChanged

revertControl

protected XMLControl revertControl

typeFieldWidth

protected int typeFieldWidth

command

protected java.lang.String command
Constructor Detail

LibraryTreePanel

public LibraryTreePanel(LibraryBrowser browser)
Constructs an empty LibraryTreePanel.

Parameters:
browser - the LibraryBrowser that will display this panel
Method Detail

setCollection

public void setCollection(LibraryCollection collection,
                          java.lang.String path,
                          boolean editable)
Sets the collection displayed in the tree.

Parameters:
collection - the collection
path - the collection xml file path
editable - true if the collection is user-editable

getCollection

public LibraryCollection getCollection()
Gets the collection displayed in the tree.

Returns:
the collection

getSelectedNode

protected 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

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)
Displays the resource data for the specified node.

Parameters:
node - the LibraryTreeNode

getHTMLPane

protected LibraryTreePanel.HTMLPane getHTMLPane(LibraryTreeNode node)
Gets the HTMLPane that describes a given tree node.

Parameters:
node - the node
Returns:
the HTMLPane

createGUI

protected void createGUI()
Creates the GUI and listeners.


refreshGUI

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


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

isClipboardPastable

protected boolean isClipboardPastable()
Determines if the clipboard can be pasted.

Returns:
true if the clipboard contains a LibraryTreeNode XMLControl string

getPopup

protected javax.swing.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

removeNode

protected void removeNode(LibraryTreeNode node)
Removes a given tree node.

Parameters:
node - the node

collectionChanged

protected void collectionChanged()
Called whenever the collection changes due to a user edit.


isCollectionChanged

protected boolean isCollectionChanged()
Called whenever the collection changes due to a user edit.


save

protected void save()
Saves the current collection.


saveChanges

protected boolean saveChanges(java.lang.String name)
Gives the user an opportunity to save changes.

Returns:
false if the user cancels, otherwise true

getFileChooser

protected static javax.swing.JFileChooser getFileChooser()
Gets a shared file chooser.

Returns:
the file chooser