Package org.opensourcephysics.tools
Class LibraryTreePanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.opensourcephysics.tools.LibraryTreePanel
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA JTextField for editing LibraryTreeNode data.protected static classA JTextPane that displays html pages for LibraryTreeNodes.protected classA tree node renderer to render LibraryTreeNodes.protected classAn editor for Metadata objects.protected classA ComboBoxModel for metadata.protected classA renderer for Metadata objects.protected classAn EntryField for editing Metadata.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Actionprotected JButtonprotected Actionprotected JButtonprotected final Stringprotected Boxprotected LibraryTreePanel.EntryFieldprotected JLabelprotected LibraryTreePanel.EntryFieldprotected JLabelprotected LibraryBrowserprotected static JFileChooserprotected final Stringprotected Stringprotected Boxprotected LibraryTreePanel.EntryFieldprotected JLabelprotected MouseAdapterprotected Actionprotected JButtonprotected Actionprotected JButtonprotected static Colorprotected static Colorprotected JPanelprotected JToolBarprotected Boxprotected LibraryTreePanel.HTMLPaneprotected LibraryResource.Metadataprotected Set<LibraryTreePanel.EntryField>protected Boxprotected static FileFilterprotected LibraryTreePanel.EntryFieldprotected static FileFilterprotected JLabelprotected static HashMap<LibraryTreeNode,LibraryTreePanel.HTMLPane> protected static HashMap<URL,LibraryTreePanel.HTMLPane> protected JScrollPaneprotected static HyperlinkListenerprotected booleanprotected booleanprotected booleanprotected booleanprotected LibraryTreePanel.MetadataEditFieldprotected static intprotected Boxprotected LibraryTreePanel.EntryFieldprotected JLabelprotected static Colorprotected static Colorprotected Actionprotected Boxprotected JButtonprotected JComboBox<LibraryResource.Metadata>protected ActionListenerprotected JLabelprotected org.opensourcephysics.tools.LibraryTreePanel.MetadataLoaderprotected LibraryTreePanel.MetadataComboBoxModelprotected Actionprotected JButtonprotected Actionprotected JButtonprotected LibraryTreePanel.EntryFieldprotected JLabelprotected JButtonprotected JButtonprotected static Iconprotected JButtonprotected final Stringprotected final Stringprotected Actionprotected JButtonprotected XMLControlprotected Stringprotected JPopupMenuprotected XMLControlprotected LibraryTreeNodeprotected LibraryResourceprotected JSplitPaneprotected LibraryTreePanel.EntryFieldprotected JLabelprotected JTreeprotected DefaultTreeModelprotected MouseAdapterprotected LibraryTreePanel.LibraryTreeNodeRendererprotected JScrollPaneprotected TreeSelectionListenerprotected JLabelprotected intprotected JLabelprotected LibraryTreePanel.MetadataEditFieldFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionLibraryTreePanel(LibraryBrowser browser) Constructs an empty LibraryTreePanel. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.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.static voidprotected voidCreates the GUI and listeners.protected voidcreateTree(LibraryTreeNode root) Creates the tree.protected voidprotected voidEnables/disables buttons based on selected node and clipboard state.Gets the collection displayed in the tree.protected static JFileChooserGets a shared file chooser.protected StringgetHTMLBody(String path) Gets the code from an HTML page.protected String[]getNextSplit(String phrase) Returns the phrase before the next AND or OR operator, the operator itself, and the remainder of the phrase.protected String[]getParenthesisSplit(String phrase) Returns the phrase enclosed in parentheses along with the remainder of a phrase.protected JPopupMenugetPopup(LibraryTreeNode node) Returns a popup menu with items appropriate for a given tree node.protected static StringgetRelativePath(Map<String, ZipEntry> files, String baseName) Gets the selected node.protected voidDetermines if the clipboard can be pasted.protected booleaninsertChildAt(LibraryTreeNode child, LibraryTreeNode parent, int index) Inserts a child into a parent node at a specified index.protected booleanDetermines if the resource has been changed since the last save.protected booleanReturns true if the collection is editable.protected booleanGets the editing state.protected voidUsed to refresh the entry fields when the browser closes.protected voidRefreshes the GUI including locale-dependent resource strings.protected voidrefreshGUI(boolean andRebuild) voidprotected voidremoveNode(LibraryTreeNode node) Removes a given tree node.protected voidrevert()Discards collection edits and reverts to the previous state.protected Stringsave()Saves the current resource.protected booleansaveChanges(String name) Gives the user an opportunity to save changes.protected voidscrollToPath(TreePath path, boolean andSelect) protected voidCalled whenever a resource changes due to a user edit.protected voidsetEditing(boolean edit) Sets the editing state.protected voidsetFontLevel(int level) Sets the font level.voidsetRootResource(LibraryResource resource, String path, boolean editable, boolean pathIsXML) Sets the root resource or collection displayed in the tree.protected voidSets the selected node.protected voidsetSelectionPath(List<String> treePath) Sets the selection path.protected static voidshowHTMLDocument(LibraryTreePanel.HTMLPane htmlPane, URL url, String htmlStr) protected voidshowHTMLPane(LibraryTreeNode node) Displays the HTMLPane for a given tree node.protected voidshowInfo(LibraryTreeNode node, String why) Displays the resource data for the specified node.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, updateMethods 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, transferFocusDownCycle, validate, validateTreeMethods 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
AND
- See Also:
-
OR
- See Also:
-
OPENING
- See Also:
-
CLOSING
- See Also:
-
keyFieldWidth
protected static int keyFieldWidth -
lightRed
-
darkRed
-
lightGreen
-
defaultForeground
-
openFileIcon
-
hyperlinkListener
-
chooser
-
htmlFilter
-
folderFilter
-
htmlPanesByURL
-
htmlPanesByNode
-
browser
-
rootResource
-
pathToRoot
-
rootNode
-
treeModel
-
treeNodeRenderer
-
tree
-
treeScroller
-
htmlScroller
-
editorbar
-
cutAction
-
copyAction
-
pasteAction
-
addCollectionAction
-
addResourceAction
-
moveUpAction
-
moveDownAction
-
metadataAction
-
cutButton
-
copyButton
-
pasteButton
-
addCollectionButton
-
addResourceButton
-
moveUpButton
-
moveDownButton
-
metadataButton
-
editorPanel
-
fileBox
-
displayPanel
-
emptyHTMLPane
-
splitPane
-
nameField
-
htmlField
-
basePathField
-
targetField
-
nameLabel
-
htmlLabel
-
basePathLabel
-
targetLabel
-
metadataFieldListener
-
authorField
-
contactField
-
keywordsField
-
authorLabel
-
contactLabel
-
keywordsLabel
-
metadataLabel
-
authorBox
-
contactBox
-
keywordsBox
-
metadataBox
-
metadataModel
-
metadataDropdown
-
keyEditField
-
valueEditField
-
typeLabel
-
typeField
-
openHTMLButton
-
openBasePathButton
-
openFileButton
-
labels
-
popup
-
treeMouseListener
-
convertPathMouseListener
-
treeSelectionListener
-
pasteControl
-
isEditing
protected boolean isEditing -
isChanged
protected boolean isChanged -
isXMLPath
protected boolean isXMLPath -
ignoreChanges
protected boolean ignoreChanges -
revertControl
-
typeFieldWidth
protected int typeFieldWidth -
command
-
emptyMetadata
-
metadataLoader
protected org.opensourcephysics.tools.LibraryTreePanel.MetadataLoader metadataLoader -
entryFields
-
-
Constructor Details
-
LibraryTreePanel
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 resourcepath- the file path to the resource or collectioneditable- true if the collection is user-editablepathIsXML- true if the path points to a DL xml file
-
getCollection
Gets the collection displayed in the tree.- Returns:
- the collection
-
getSelectedNode
Gets the selected node.- Returns:
- the selected node, or null if none
-
setSelectedNode
Sets the selected node.- Parameters:
node- the node to select
-
setSelectionPath
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
Displays the resource data for the specified node.- Parameters:
node- the LibraryTreeNode
-
showHTMLPane
Displays the HTMLPane for a given tree node.- Parameters:
node- the node
-
createGUI
protected void createGUI()Creates the GUI and listeners. -
doMouseClick
-
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
Creates the tree.- Parameters:
root- the root node
-
ifClipboardPastable
Determines if the clipboard can be pasted. -
getPopup
Returns a popup menu with items appropriate for a given tree node.- Parameters:
node- the node- Returns:
- the popup menu
-
insertChildAt
Inserts a child into a parent node at a specified index.- Parameters:
child- the child nodeparent- the parent nodeindex- the index- Returns:
- true if added
-
removeNode
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
Saves the current resource.- Returns:
- the path to the saved file, or null if not saved
-
saveChanges
Gives the user an opportunity to save changes.- Parameters:
name- the name of the collection- Returns:
falseif the user cancels, otherwisetrue
-
getNextSplit
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
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
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
-
showHTMLDocument
-
getFileChooser
Gets a shared file chooser.- Returns:
- the file chooser
-
refreshSelectedNode
public void refreshSelectedNode() -
scrollToPath
-
clearMaps
public static void clearMaps()
-