View Javadoc

1   /*
2   Copyright (C) 2000 - 2007 Grid Systems, S.A.
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License, version 2, as
6   published by the Free Software Foundation.
7   
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17  
18  /*
19   * Project: KernelConfigurator
20   * Created on 24-feb-2004
21   *
22   * Copyright (c)2003 Grid Systems
23   */
24  package com.gridsystems.config.app;
25  
26  import javax.swing.event.TreeModelListener;
27  import javax.swing.tree.TreeModel;
28  import javax.swing.tree.TreePath;
29  
30  /**
31   * A tree model that uses ConfigNodes as its backend data structure.
32   * <p>
33   * This version uses "immutable" trees, so it does not implements the model listener
34   * and path change related methods.
35   *
36   * @author <a href="mailto:rruiz@gridsystems.com">Rodrigo Ruiz Aguayo</a>
37   * @version 1.0
38   */
39  public class ConfigNodeModel implements TreeModel {
40    /**
41     * The tree root.
42     */
43    private ConfigNode root;
44  
45    /**
46     * Creates a model with the specified node as the tree root.
47     *
48     * @param root The root node
49     */
50    public ConfigNodeModel(ConfigNode root) {
51      this.root = root;
52    }
53  
54    /**
55     * {@inheritDoc}
56     */
57    public Object getRoot() {
58      return root;
59    }
60  
61    /**
62     * {@inheritDoc}
63     */
64    public int getChildCount(Object parent) {
65      ConfigNode node = (ConfigNode)parent;
66      return node.getChildCount();
67    }
68  
69    /**
70     * {@inheritDoc}
71     */
72    public boolean isLeaf(Object node) {
73      return getChildCount(node) == 0;
74    }
75  
76    /**
77     * {@inheritDoc}
78     */
79    public void addTreeModelListener(TreeModelListener l) {
80      // unimplemented
81    }
82  
83    /**
84     * {@inheritDoc}
85     */
86    public void removeTreeModelListener(TreeModelListener l) {
87      // unimplemented
88    }
89  
90    /**
91     * {@inheritDoc}
92     */
93    public Object getChild(Object parent, int index) {
94      ConfigNode node = (ConfigNode)parent;
95      return node.getChild(index);
96    }
97  
98    /**
99     * {@inheritDoc}
100    */
101   public int getIndexOfChild(Object parent, Object child) {
102     ConfigNode node = (ConfigNode)parent;
103     return node.indexOf((ConfigNode)child);
104   }
105 
106   /**
107    * {@inheritDoc}
108    */
109   public void valueForPathChanged(TreePath path, Object newValue) {
110     // unimplemented
111   }
112 }