001 /*
002 * Copyright (c) 2005 Einar Pehrson, Malin Johansson and Sofia Nilsson
003 *
004 * This file is part of
005 * CleanSheets Extension for Dependency Trees
006 *
007 * CleanSheets Extension for Dependency Trees is free software; you can
008 * redistribute it and/or modify it under the terms of the GNU General Public
009 * License as published by the Free Software Foundation; either version 2 of
010 * the License, or (at your option) any later version.
011 *
012 * CleanSheets Extension for Dependency Trees is distributed in the hope that
013 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
014 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
015 * See the GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with CleanSheets Extension for Dependency Trees; if not, write to the
019 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020 * Boston, MA 02111-1307 USA
021 */
022 package csheets.ext.deptree;
023
024 import javax.swing.JTree;
025 import javax.swing.ToolTipManager;
026 import javax.swing.tree.DefaultTreeModel;
027 import javax.swing.tree.TreeSelectionModel;
028
029 import csheets.ui.ctrl.SelectionEvent;
030 import csheets.ui.ctrl.SelectionListener;
031 import csheets.ui.ctrl.UIController;
032
033 /**
034 * An abstract base-class for trees displaying cell dependencies.
035 * @author Einar Pehrson
036 */
037 public abstract class DependencyTree extends JTree implements SelectionListener {
038
039 /** The user interface controller */
040 protected UIController uiController;
041
042 /** The data model that defines the tree */
043 protected DefaultTreeModel treeModel;
044
045 /**
046 * Creates a mew dependency tree.
047 * @param uiController the user interface controller
048 */
049 public DependencyTree(UIController uiController) {
050 super(new DefaultTreeModel(null));
051
052 // Stores members
053 this.treeModel = (DefaultTreeModel)super.treeModel;
054 this.uiController = uiController;
055 uiController.addSelectionListener(this);
056
057 // Creates and configures tree
058 getSelectionModel().setSelectionMode(
059 TreeSelectionModel.SINGLE_TREE_SELECTION);
060 setToggleClickCount(Integer.MAX_VALUE);
061 addTreeExpansionListener(new ExpansionPopulator());
062 addMouseListener(new DoubleClickNavigator(this, uiController));
063 setCellRenderer(new DependencyTreeCellRenderer());
064 ToolTipManager.sharedInstance().registerComponent(this);
065 }
066
067 /**
068 * Rebuilds the tree by updating its root node when the active cell is changed.
069 * @param event the selection event that was fired
070 */
071 public abstract void selectionChanged(SelectionEvent event);
072 }