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.event.TreeExpansionEvent;
025 import javax.swing.event.TreeExpansionListener;
026 import javax.swing.tree.TreeNode;
027 import javax.swing.tree.TreePath;
028
029 /**
030 * A tree expansion listener that asks the node being expanded to
031 * to add child nodes for all its references.
032 * @author Einar Pehrson
033 */
034 public class ExpansionPopulator implements TreeExpansionListener {
035
036 /**
037 * Creates a new expansion populator.
038 */
039 public ExpansionPopulator() {}
040
041 /**
042 * Populates the node that was expanded.
043 * @param event the event that was fired
044 */
045 public void treeExpanded(TreeExpansionEvent event) {
046 TreePath path = event.getPath();
047 TreeNode lastNode = (TreeNode)path.getLastPathComponent();
048 if (lastNode instanceof CellNode) {
049 // Populates the cell node
050 CellNode node = (CellNode)lastNode;
051 node.populate();
052 }
053 }
054
055 /**
056 * Does nothing.
057 * @param event the event that was fired
058 */
059 public void treeCollapsed(TreeExpansionEvent event) {}
060 }