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 class
A JTextField for editing LibraryTreeNode data.protected static class
A JTextPane that displays html pages for LibraryTreeNodes.protected class
A tree node renderer to render LibraryTreeNodes.protected class
An editor for Metadata objects.protected class
A ComboBoxModel for metadata.protected class
A renderer for Metadata objects.protected class
An EntryField for editing Metadata.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Action
protected JButton
protected Action
protected JButton
protected final String
protected Box
protected LibraryTreePanel.EntryField
protected JLabel
protected LibraryTreePanel.EntryField
protected JLabel
protected LibraryBrowser
protected static JFileChooser
protected final String
protected String
protected Box
protected LibraryTreePanel.EntryField
protected JLabel
protected MouseAdapter
protected Action
protected JButton
protected Action
protected JButton
protected static Color
protected static Color
protected JPanel
protected JToolBar
protected Box
protected LibraryTreePanel.HTMLPane
protected LibraryResource.Metadata
protected Set<LibraryTreePanel.EntryField>
protected Box
protected static FileFilter
protected LibraryTreePanel.EntryField
protected static FileFilter
protected JLabel
protected static HashMap<LibraryTreeNode,
LibraryTreePanel.HTMLPane> protected static HashMap<URL,
LibraryTreePanel.HTMLPane> protected JScrollPane
protected static HyperlinkListener
protected boolean
protected boolean
protected boolean
protected boolean
protected LibraryTreePanel.MetadataEditField
protected static int
protected Box
protected LibraryTreePanel.EntryField
protected JLabel
protected static Color
protected static Color
protected Action
protected Box
protected JButton
protected JComboBox<LibraryResource.Metadata>
protected ActionListener
protected JLabel
protected org.opensourcephysics.tools.LibraryTreePanel.MetadataLoader
protected LibraryTreePanel.MetadataComboBoxModel
protected Action
protected JButton
protected Action
protected JButton
protected LibraryTreePanel.EntryField
protected JLabel
protected JButton
protected JButton
protected static Icon
protected JButton
protected final String
protected final String
protected Action
protected JButton
protected XMLControl
protected String
protected JPopupMenu
protected XMLControl
protected LibraryTreeNode
protected LibraryResource
protected JSplitPane
protected LibraryTreePanel.EntryField
protected JLabel
protected JTree
protected DefaultTreeModel
protected MouseAdapter
protected LibraryTreePanel.LibraryTreeNodeRenderer
protected JScrollPane
protected TreeSelectionListener
protected JLabel
protected int
protected JLabel
protected LibraryTreePanel.MetadataEditField
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
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 void
protected void
Creates the GUI and listeners.protected void
createTree
(LibraryTreeNode root) Creates the tree.protected void
protected void
Enables/disables buttons based on selected node and clipboard state.Gets the collection displayed in the tree.protected static JFileChooser
Gets a shared file chooser.protected String
getHTMLBody
(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 JPopupMenu
getPopup
(LibraryTreeNode node) Returns a popup menu with items appropriate for a given tree node.protected static String
getRelativePath
(Map<String, ZipEntry> files, String baseName) Gets the selected node.protected void
Determines if the clipboard can be pasted.protected boolean
insertChildAt
(LibraryTreeNode child, LibraryTreeNode parent, int index) Inserts a child into a parent node at a specified index.protected boolean
Determines if the resource has been changed since the last save.protected boolean
Returns true if the collection is editable.protected boolean
Gets the editing state.protected void
Used to refresh the entry fields when the browser closes.protected void
Refreshes the GUI including locale-dependent resource strings.protected void
refreshGUI
(boolean andRebuild) void
protected void
removeNode
(LibraryTreeNode node) Removes a given tree node.protected void
revert()
Discards collection edits and reverts to the previous state.protected String
save()
Saves the current resource.protected boolean
saveChanges
(String name) Gives the user an opportunity to save changes.protected void
scrollToPath
(TreePath path, boolean andSelect) protected void
Called whenever a resource changes due to a user edit.protected void
setEditing
(boolean edit) Sets the editing state.protected void
setFontLevel
(int level) Sets the font level.void
setRootResource
(LibraryResource resource, String path, boolean editable, boolean pathIsXML) Sets the root resource or collection displayed in the tree.protected void
Sets the selected node.protected void
setSelectionPath
(List<String> treePath) Sets the selection path.protected static void
showHTMLDocument
(LibraryTreePanel.HTMLPane htmlPane, URL url, String htmlStr) protected void
showHTMLPane
(LibraryTreeNode node) Displays the HTMLPane for a given tree node.protected void
showInfo
(LibraryTreeNode node, String why) 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, 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, 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, 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, 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:
false
if 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()
-