View Javadoc

    1   /*
    2    * Created on Jun 20, 2004
    3    */
    4   package baseCode.gui;
    5
    6   import java.awt.Dimension;
    7
    8   import javax.swing.JPanel;
    9   import javax.swing.JScrollPane;
    10  import javax.swing.JSplitPane;
    11  import javax.swing.JTextArea;
    12  import javax.swing.JTree;
    13  import javax.swing.event.TreeSelectionEvent;
    14  import javax.swing.event.TreeSelectionListener;
    15  import javax.swing.tree.DefaultMutableTreeNode;
    16  import javax.swing.tree.TreeSelectionModel;
    17
    18  import baseCode.dataStructure.graph.DirectedGraphNode;
    19
    20  /***
    21   * <p>
    22   * Copyright (c) Columbia University
    23   *
    24   * @author Paul Pavlidis
    25   * @version $Id: TreePanel.java,v 1.5 2004/07/27 03:18:58 pavlidis Exp $
    26   * @todo - this really doesn't do much.
    27   */
    28  public class TreePanel extends JPanel implements TreeSelectionListener {
    29
    30     private JTree tree;
    31     private JTextArea detailPane;
    32
    33     public TreePanel( JTree t ) {
    34        this.tree = t;
    35        tree.getSelectionModel().setSelectionMode(
    36              TreeSelectionModel.SINGLE_TREE_SELECTION );
    37
    38        tree.addTreeSelectionListener( this );
    39
    40        JScrollPane treeView = new JScrollPane( tree );
    41        // Create the viewing pane that shows the contents of the node.
    42        detailPane = new JTextArea();
    43        detailPane.setEditable( false );
    44        detailPane.setLineWrap( true );
    45        detailPane.setWrapStyleWord( true );
    46
    47        JScrollPane detailView = new JScrollPane( detailPane );
    48
    49        //Add the scroll panes to a split pane.
    50        JSplitPane splitPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT );
    51        splitPane.setTopComponent( treeView );
    52        splitPane.setBottomComponent( detailPane );
    53        Dimension minimumSize = new Dimension( 200, 250 );
    54        detailView.setMinimumSize( minimumSize );
    55        treeView.setMinimumSize( minimumSize );
    56        splitPane.setDividerLocation( 100 );
    57        treeView.setPreferredSize( new Dimension( 500, 200 ) );
    58
    59        splitPane.setPreferredSize( new Dimension( 500, 500 ) );
    60        add( splitPane );
    61     }
    62
    63     public void valueChanged( TreeSelectionEvent e ) {
    64        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) tree
    65              .getLastSelectedPathComponent();
    66
    67        if ( node == null ) return;
    68
    69        DirectedGraphNode nodeInfo = ( DirectedGraphNode ) node.getUserObject();
    70        //    if (node.isLeaf()) {
    71        //    System.out.println(nodeInfo); // debugging
    72
    73        detailPane.setText( nodeInfo.toString() );
    74
    75        //     }
    76
    77        //   System.out.println(nodeInfo); // debugging
    78
    79     }
    80
    81  }