[6152] | 1 | /* |
---|
| 2 | Copyright 2006 by Sean Luke |
---|
| 3 | Licensed under the Academic Free License version 3.0 |
---|
| 4 | See the file "LICENSE" for more information |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | /* |
---|
| 9 | * Created on Apr 6, 2005 7:12:32 PM |
---|
| 10 | * |
---|
| 11 | * By: spaus |
---|
| 12 | */ |
---|
| 13 | package ec.util; |
---|
| 14 | |
---|
| 15 | import java.util.Comparator; |
---|
| 16 | |
---|
| 17 | import javax.swing.tree.DefaultTreeModel; |
---|
| 18 | import javax.swing.tree.TreeNode; |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * @author spaus |
---|
| 22 | */ |
---|
| 23 | public class ParameterDatabaseTreeModel |
---|
| 24 | extends DefaultTreeModel { |
---|
| 25 | |
---|
| 26 | private boolean visibleLeaves; |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * @param root |
---|
| 30 | */ |
---|
| 31 | public ParameterDatabaseTreeModel(TreeNode root) { |
---|
| 32 | super(root); |
---|
| 33 | visibleLeaves = true; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | * @param root |
---|
| 38 | * @param asksAllowsChildren |
---|
| 39 | */ |
---|
| 40 | public ParameterDatabaseTreeModel(TreeNode root, boolean asksAllowsChildren) { |
---|
| 41 | super(root, asksAllowsChildren); |
---|
| 42 | visibleLeaves = true; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * @param visibleLeaves |
---|
| 47 | */ |
---|
| 48 | public void setVisibleLeaves(boolean visibleLeaves) { |
---|
| 49 | this.visibleLeaves = visibleLeaves; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * @return |
---|
| 54 | */ |
---|
| 55 | public boolean getVisibleLeaves() { |
---|
| 56 | return visibleLeaves; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | /* (non-Javadoc) |
---|
| 60 | * @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int) |
---|
| 61 | */ |
---|
| 62 | public Object getChild(Object parent, int index) { |
---|
| 63 | if (!visibleLeaves) { |
---|
| 64 | if (parent instanceof ParameterDatabaseTreeNode) { |
---|
| 65 | return ((ParameterDatabaseTreeNode)parent).getChildAt(index,visibleLeaves); |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | return ((TreeNode)parent).getChildAt(index); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | /* (non-Javadoc) |
---|
| 73 | * @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object) |
---|
| 74 | */ |
---|
| 75 | public int getChildCount(Object parent) { |
---|
| 76 | if (!visibleLeaves) { |
---|
| 77 | if (parent instanceof ParameterDatabaseTreeNode) { |
---|
| 78 | return ((ParameterDatabaseTreeNode)parent).getChildCount(visibleLeaves); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | return ((TreeNode)parent).getChildCount(); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * @param parent |
---|
| 87 | * @param comp |
---|
| 88 | */ |
---|
| 89 | public void sort(Object parent, Comparator comp) { |
---|
| 90 | ((ParameterDatabaseTreeNode)parent).sort(comp); |
---|
| 91 | } |
---|
| 92 | } |
---|