org.opensourcephysics.tools
Class LibraryBrowser

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.LibraryBrowser
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class LibraryBrowser
extends javax.swing.JPanel

A GUI for browsing OSP digital library collections.

Author:
Douglas Brown
See Also:
Serialized Form

Nested Class Summary
 
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.JMenuItem aboutItem
           
protected static javax.swing.border.Border buttonBorder
           
protected static java.lang.String collectionFileName
           
protected  javax.swing.JMenu collectionsMenu
           
protected  javax.swing.Action commandAction
           
protected  javax.swing.JButton commandButton
           
protected  javax.swing.JTextField commandField
           
protected  javax.swing.JLabel commandLabel
           
protected  javax.swing.JMenuItem deleteItem
           
protected  javax.swing.JButton editButton
           
protected  javax.swing.JMenuItem exitItem
           
protected  boolean exitOnClose
           
protected  javax.swing.JMenuItem exportItem
           
protected static javax.swing.JDialog externalDialog
           
protected  javax.swing.JMenu fileMenu
           
protected static javax.swing.JFrame frame
           
protected static java.lang.String helpBase
           
protected  TextFrame helpFrame
           
protected  javax.swing.JMenuItem helpItem
           
protected  javax.swing.JMenu helpMenu
           
protected static java.lang.String helpName
           
protected  javax.swing.JTextPane htmlAboutPane
           
protected static java.lang.String htmlAboutPath
           
protected  javax.swing.JScrollPane htmlScroller
           
protected  boolean keyPressed
           
protected  Library library
           
protected static java.lang.String libraryFileName
           
protected  javax.swing.JMenuItem libraryManagerItem
           
protected  java.lang.String libraryPath
           
protected  java.awt.event.ActionListener loadCollectionAction
           
protected  javax.swing.JMenuItem logItem
           
protected static javax.swing.JMenuBar menubar
           
protected  javax.swing.JMenuItem newItem
           
protected  javax.swing.JMenuItem openItem
           
protected  javax.swing.JMenuItem saveAsItem
           
protected  javax.swing.JMenuItem saveItem
           
protected  javax.swing.JTabbedPane tabbedPane
           
protected  boolean textChanged
           
protected  javax.swing.JToolBar toolbar
           
protected  java.beans.PropertyChangeListener treePanelListener
           
protected static boolean webConnected
           
 
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
 
Method Summary
 void addComPADRECollection(java.lang.String path)
          Adds a ComPADRE collection with a specified path.
 void addOSPLibrary(java.lang.String path)
          Adds an OSP-sponsored library with a specified path.
protected  int addTab(java.lang.String path, boolean addToMyLibrary)
          Adds a tab displaying collection with a given path.
protected  void addToCollections(java.lang.String path)
          Adds a collection to this browser's library after prompting the user to assign it a name.
protected  void createGUI()
          Creates the visible components of this panel.
protected  LibraryTreePanel createLibraryTreePanel()
          Creates a new empty LibraryTreePanel.
protected  void createNewCollection()
          Creates a new empty LibraryCollection file.
 boolean exit()
          Exits this browser.
protected  void export(Library library)
          Exports a library by saving a clone of this browser's library after the user is prompted to give the clone a descriptive name.
static LibraryBrowser getBrowser()
          Gets the shared singleton browser.
static LibraryBrowser getBrowser(javax.swing.JDialog dialog)
          Gets the shared singleton browser in a JDialog or, if none, in a shared JFrame.
protected  java.lang.String getSavePath()
          Returns a path to which a collection or library file can be saved.
protected  LibraryTreePanel getSelectedTreePanel()
          Gets the selected LibraryTreePanel, if any.
protected  int getTabIndexFromPath(java.lang.String path)
          Gets the index of the tab associated with a given path.
protected  java.lang.String getTabTitle(int index)
          Gets the title of the tab at a given index.
protected  java.lang.String getTabTitle(java.lang.String path)
          Gets the title of the tab associated with a given path.
 java.lang.String getTitle()
           
protected  LibraryTreePanel getTreePanel(int index)
          Gets the LibraryTreePanel at a specified tab index.
protected  java.lang.String getUniqueName(java.lang.String proposed, java.lang.String nameToIgnore)
          Returns a name that is not a duplicate of an existing name.
 void importLibrary(java.lang.String path)
          Imports a library with a specified path.
protected  boolean isDuplicateName(java.lang.String name, java.lang.String nameToIgnore)
          Determines if a name duplicates an existing name.
static boolean isWebConnected()
          Returns true if connected to the web.
protected  void loadCollection(java.lang.String path)
          Loads the collection with a given path.
protected  LibraryCollection loadXML(java.lang.String path)
          Loads the collection with a given path.
static void main(java.lang.String[] args)
          Entry point when run as an independent application.
protected  void open()
          Opens a collection file using a file chooser.
 void rebuildCollectionsMenu()
          Rebuilds the collection menu.
protected  void refreshGUI()
          Refreshes the GUI, including locale-dependent resources strings.
protected  void refreshTabTitle(java.lang.String path, LibraryCollection collection)
          Refreshes the title of a tab based on the properties of a LibraryCollection and the path associated with that collection.
protected  void save()
          Saves the selected LibraryTreePanel collection.
protected  void saveAs()
          Saves the current collection as a new file.
 void setTitle(java.lang.String title)
           
 void setVisible(boolean vis)
           
protected  void showAboutDialog()
          Shows the about dialog.
protected  void showHelp()
          Shows the help frame and displays a help HTML page.
 
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, 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

buttonBorder

protected static javax.swing.border.Border buttonBorder

libraryFileName

protected static java.lang.String libraryFileName

collectionFileName

protected static java.lang.String collectionFileName

helpName

protected static java.lang.String helpName

helpBase

protected static java.lang.String helpBase

htmlAboutPath

protected static java.lang.String htmlAboutPath

webConnected

protected static boolean webConnected

frame

protected static javax.swing.JFrame frame

externalDialog

protected static javax.swing.JDialog externalDialog

menubar

protected static javax.swing.JMenuBar menubar

library

protected Library library

libraryPath

protected java.lang.String libraryPath

toolbar

protected javax.swing.JToolBar toolbar

commandAction

protected javax.swing.Action commandAction

commandLabel

protected javax.swing.JLabel commandLabel

commandField

protected javax.swing.JTextField commandField

fileMenu

protected javax.swing.JMenu fileMenu

collectionsMenu

protected javax.swing.JMenu collectionsMenu

helpMenu

protected javax.swing.JMenu helpMenu

newItem

protected javax.swing.JMenuItem newItem

openItem

protected javax.swing.JMenuItem openItem

saveItem

protected javax.swing.JMenuItem saveItem

saveAsItem

protected javax.swing.JMenuItem saveAsItem

exportItem

protected javax.swing.JMenuItem exportItem

exitItem

protected javax.swing.JMenuItem exitItem

deleteItem

protected javax.swing.JMenuItem deleteItem

libraryManagerItem

protected javax.swing.JMenuItem libraryManagerItem

aboutItem

protected javax.swing.JMenuItem aboutItem

logItem

protected javax.swing.JMenuItem logItem

helpItem

protected javax.swing.JMenuItem helpItem

commandButton

protected javax.swing.JButton commandButton

editButton

protected javax.swing.JButton editButton

loadCollectionAction

protected java.awt.event.ActionListener loadCollectionAction

exitOnClose

protected boolean exitOnClose

tabbedPane

protected javax.swing.JTabbedPane tabbedPane

htmlScroller

protected javax.swing.JScrollPane htmlScroller

treePanelListener

protected java.beans.PropertyChangeListener treePanelListener

keyPressed

protected boolean keyPressed

textChanged

protected boolean textChanged

helpFrame

protected TextFrame helpFrame

htmlAboutPane

protected javax.swing.JTextPane htmlAboutPane
Method Detail

getBrowser

public static LibraryBrowser getBrowser()
Gets the shared singleton browser.

Returns:
the shared LibraryBrowser

getBrowser

public static LibraryBrowser getBrowser(javax.swing.JDialog dialog)
Gets the shared singleton browser in a JDialog or, if none, in a shared JFrame.

Parameters:
dialog - a JDialog (if null, browser is returned in a JFrame)
Returns:
the shared LibraryBrowser

isWebConnected

public static boolean isWebConnected()
Returns true if connected to the web.

Returns:
true if web connected

importLibrary

public void importLibrary(java.lang.String path)
Imports a library with a specified path.

Parameters:
path - the path to the Library xml file

addOSPLibrary

public void addOSPLibrary(java.lang.String path)
Adds an OSP-sponsored library with a specified path.

Parameters:
path - the path to the Library xml file

addComPADRECollection

public void addComPADRECollection(java.lang.String path)
Adds a ComPADRE collection with a specified path.

Parameters:
path - the ComPADRE query

rebuildCollectionsMenu

public void rebuildCollectionsMenu()
Rebuilds the collection menu.


getSelectedTreePanel

protected LibraryTreePanel getSelectedTreePanel()
Gets the selected LibraryTreePanel, if any.

Returns:
the selected treePanel, or null if none

getTreePanel

protected LibraryTreePanel getTreePanel(int index)
Gets the LibraryTreePanel at a specified tab index.

Parameters:
index - the tab index
Returns:
the treePanel

getTabTitle

protected java.lang.String getTabTitle(java.lang.String path)
Gets the title of the tab associated with a given path.

Parameters:
path - the collection path
Returns:
the tab title

getTabTitle

protected java.lang.String getTabTitle(int index)
Gets the title of the tab at a given index.

Parameters:
index - the tab index
Returns:
the tab title

getTabIndexFromPath

protected int getTabIndexFromPath(java.lang.String path)
Gets the index of the tab associated with a given path.

Parameters:
path - the collection path
Returns:
the tab index

loadCollection

protected void loadCollection(java.lang.String path)
Loads the collection with a given path.

Parameters:
path - the collection path

loadXML

protected LibraryCollection loadXML(java.lang.String path)
Loads the collection with a given path.

Parameters:
path - the collection path

addTab

protected int addTab(java.lang.String path,
                     boolean addToMyLibrary)
Adds a tab displaying collection with a given path.

Parameters:
path - the collection path
Returns:
the tab index added

refreshTabTitle

protected void refreshTabTitle(java.lang.String path,
                               LibraryCollection collection)
Refreshes the title of a tab based on the properties of a LibraryCollection and the path associated with that collection.

Parameters:
path - the collection path
collection - the LibraryCollection itself

createGUI

protected void createGUI()
Creates the visible components of this panel.


refreshGUI

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


getTitle

public java.lang.String getTitle()

setTitle

public void setTitle(java.lang.String title)

open

protected void open()
Opens a collection file using a file chooser.


save

protected void save()
Saves the selected LibraryTreePanel collection.


export

protected void export(Library library)
Exports a library by saving a clone of this browser's library after the user is prompted to give the clone a descriptive name.

Parameters:
library - the library to export

setVisible

public void setVisible(boolean vis)
Overrides:
setVisible in class javax.swing.JComponent

exit

public boolean exit()
Exits this browser.


saveAs

protected void saveAs()
Saves the current collection as a new file.


getSavePath

protected java.lang.String getSavePath()
Returns a path to which a collection or library file can be saved. This adds the extension ".xml", if none, and checks for duplicates.

Returns:
the save path

addToCollections

protected void addToCollections(java.lang.String path)
Adds a collection to this browser's library after prompting the user to assign it a name.

Parameters:
path - the path to the collection

createNewCollection

protected void createNewCollection()
Creates a new empty LibraryCollection file.


getUniqueName

protected java.lang.String getUniqueName(java.lang.String proposed,
                                         java.lang.String nameToIgnore)
Returns a name that is not a duplicate of an existing name.

Parameters:
proposed - a proposed name
nameToIgnore - a name that is ignored when comparing
Returns:
a unique name that is the proposed name plus a possible suffix

isDuplicateName

protected boolean isDuplicateName(java.lang.String name,
                                  java.lang.String nameToIgnore)
Determines if a name duplicates an existing name.

Parameters:
name - the proposed name
nameToIgnore - a name that is ignored when comparing
Returns:
true if name is a duplicate

createLibraryTreePanel

protected LibraryTreePanel createLibraryTreePanel()
Creates a new empty LibraryTreePanel.


showAboutDialog

protected void showAboutDialog()
Shows the about dialog.


showHelp

protected void showHelp()
Shows the help frame and displays a help HTML page.


main

public static void main(java.lang.String[] args)
Entry point when run as an independent application.

Parameters:
args - String[] ignored