bodhidharma
Class TaxonomyPanel

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 bodhidharma.TaxonomyPanel
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class TaxonomyPanel
extends javax.swing.JPanel
implements java.awt.event.ActionListener

Part of the Bodhidharma automatic music classification project. This is the panel of the GUI that allows users to see, edit, load and save taxonomies that will be used for classification.

The currently loaded taxonomy can be seen in one of two views. The first, called the Hierarchical View, allows users to see a hierarchal tree reflecting the relationships of broad categories going down to narrower categories. The names of these categories may be edited by clicking on them (the return button must be pressed to register changes) or by using the buttons described below.

The second view, called the Ancestry View, allows users to see the taxonomy in the form of a list of leaf categories. Children of leaf categories represent a list of all ancestors of the given category. Leaf categories that appear more than once in the taxonomy field are combined into one under this view (the taxonomy field itself is not changed) so that all of the combined ancestors are listed together. The taxonomy is not editable in this view.

Both of the trees in the above two views are sorted alphebetically. The Display Hierarchy and Display Ancestry buttons allow users to switch between the two views respectively.

The New Taxonomy button deletes the current taxonomy and creates a new empty taxonomy.

The Load Taxonomy button loads a taxonomy_file XML file into memorey and displays it.

Note that it is also possible to load tab delimited text files in the MIREX 2005 format that hold taxonomies an alternative to the XML files. This functionality is intended primarily for use with the command line use of Bodhidharma.

The Save Taxonomy button saves the current contents of the taxonomy field into the path referred to in the ConfigureFileLocationsJFrame dialog box. The Save As button allows the user to choose the path to which the file is to be saved and updates the path in the ConfigureFileLocationsJFrame dialog box.

The Add New Sibling Category and the Add New Child buttons add a new sibling or a new child category to the taxonomy respectively, with a location based on the node that is currently selected. The Delete Branch button removes the selected category and its decendants.

The taxonomy field can be accessed by other objects in order to gain access to the taxonomy.

The getLeafsAndTheirParents method can also be used by other objects to obtain the information of the Ancestry View in the form of a 2-D array of strings. Similarly, the getLeafLabels/code>, getParentLabels and getMiddleLabels methods can be called to get arrays holding the labels of all leaf categories in the taxonomy field, the labels of all parent categories (i.e. categories at the highest level of the taxonomy) in the taxonomy field and the labels in the taxonomy field that are neither leaves nor parent categories resepectively.

The getAllParentsAndTheirDirectChildren method can be called to obtain the direct descendants of each parent node (whether it be at the root or intermediate).

The saveTaxonomyFile method can be called by other objects in order to save the contents of the taxonomy field.

The isTreeEmpty method can be called by other objects in order to check if thetaxonomy field is empty.

See Also:
ConfigureFileLocationsJFrame, MainJFrame, XMLDocumentParser, ParseTaxonomyFileHandler, JTree, DefaultTreeModel, DefaultMutableTreeNode, Serialized Form
Author:
Cory McKay

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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 javax.swing.tree.DefaultTreeModel taxonomy
          The tree holding the taxonomy
 
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
TaxonomyPanel(MainJFrame parent)
          Basic constructor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          Calls the appropriate methods when the buttons are pressed.
static java.lang.String assembleTreeXMLElements(javax.swing.tree.DefaultMutableTreeNode node, int depth)
          Recursively assembles the XML code to represent the contents of the given tree structure.
 java.lang.String[][] getAllParentsAndTheirDirectChildren()
          Returns the name of each parent category (root or intermediate) and their direct descendants.
 java.lang.String[] getLeafLabels()
          Returns an array holding the labels of all leaf categories in the taxonomy field.
 java.lang.String[][] getLeafsAndTheirParents()
          Returns each leaf category in the taxonomy field and its ancestry.
 java.lang.String[] getMiddleLabels()
          Returns an array holding the labels in the taxonomy field that are neither leaves nor parent categories (i.e.
 java.lang.String[] getParentLabels()
          Returns an array holding the labels of all parent categories (i.e.
 boolean isTreeEmpty()
          Returns true if the taxonomy field is empty and false if it is not.
 void saveTaxonomyFile(java.lang.String comments, boolean is_basic_save)
          Saves a taxonomy_file XML file with the contents specified in the taxonomy field and the comments specified in the comments parameter.
 
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, 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, 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

taxonomy

public javax.swing.tree.DefaultTreeModel taxonomy
The tree holding the taxonomy

Constructor Detail

TaxonomyPanel

public TaxonomyPanel(MainJFrame parent)
Basic constructor. Configures the panel and loads the taxonomy specified in the taxonomy_file XML file specified in the ConfigureFileLocationsJFrame object. Creates a new empty taxonomy if a valid taxonomy file is not specified there.

Parameters:
parent - Name of the MainJFrame window that holds this panel.
See Also:
ConfigureFileLocationsJFrame, MainJFrame
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Calls the appropriate methods when the buttons are pressed.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
event - The event that is to be reacted to.

getLeafsAndTheirParents

public java.lang.String[][] getLeafsAndTheirParents()
Returns each leaf category in the taxonomy field and its ancestry. Duplicates are removed (i.e. if the same leaf category appears more than once in taxonomy then the duplicate is removed and the ancestors are combined).

This information is returned in the form of a 2-D array of Strings. The first indice specifies a particular leaf category and its ancestors. The second indice specifies the particular ancestor of a given leaf category or the leaf category itself. Indice 0 always corresponds to the name of the leaf category itself, but the order of the ancestors is not necessarily meaningful.

Returns:
The leaf categories and their ancestors.
See Also:
DefaultMutableTreeNode

getLeafLabels

public java.lang.String[] getLeafLabels()
Returns an array holding the labels of all leaf categories in the taxonomy field. No duplicates are present.

Returns:
The labels of all leaf categories in the taxonomy field.

getParentLabels

public java.lang.String[] getParentLabels()
Returns an array holding the labels of all parent categories (i.e. categories at the highest level of the taxonomy) in the taxonomy field. No duplicates are present.

Returns:
The labels of all parent categories in the taxonomy field.

getMiddleLabels

public java.lang.String[] getMiddleLabels()
Returns an array holding the labels in the taxonomy field that are neither leaves nor parent categories (i.e. categories at the highest level of the taxonomy). No duplicates are present.

Returns:
The labels of all mid-level categories in the taxonomy field.

getAllParentsAndTheirDirectChildren

public java.lang.String[][] getAllParentsAndTheirDirectChildren()
Returns the name of each parent category (root or intermediate) and their direct descendants. The first indice corresponds to the different parents. The second indice goes through the children. The first entry of each row is the name of the parent.


saveTaxonomyFile

public void saveTaxonomyFile(java.lang.String comments,
                             boolean is_basic_save)
Saves a taxonomy_file XML file with the contents specified in the taxonomy field and the comments specified in the comments parameter.

If the is_basic_save parameter is true, then the file is saved at the path specified in the ConfigureFileLocationsJFrame object's taxonomy_path field (automatically overwriting any existing files with the same path). If the is_basic_save parameter is false, then the file is saved at a location chosen by the user with a JFileChooser dialog box.

Parameters:
comments - Any comments to be saved inside the comments element of the XML file.
is_basic_save - Whether this is a save (true) or save as (false) operation.
See Also:
ConfigureFileLocationsJFrame, DefaultMutableTreeNode

isTreeEmpty

public boolean isTreeEmpty()
Returns true if the taxonomy field is empty and false if it is not.

Returns:
Whether or not the taxonomy field is empty.

assembleTreeXMLElements

public static java.lang.String assembleTreeXMLElements(javax.swing.tree.DefaultMutableTreeNode node,
                                                       int depth)
Recursively assembles the XML code to represent the contents of the given tree structure.

Parameters:
node - The root node of the tree.
depth - The depth of the tree.