Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/gui/imprt/ImportTreeNode.java


1   /*
2    * ImportTreeNode.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:30 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.gui.imprt;
12  
13  import java.util.ArrayList;
14  
15  import com.flexstor.common.awt.tree.FlexTreeNode;
16  
17  /**
18   * Class represents Import Tree Node.
19   * @author Praveen Jani
20   * @see com.flexstor.common.awt.tree.FlexTreeNode
21   */
22  public class ImportTreeNode extends FlexTreeNode
23     implements Cloneable
24  {
25  
26    /**
27     * Exact file\dir structure represented by this node.
28     */
29    protected StringBuffer structure             = null;
30  
31  
32    /**
33     * Constructor.
34     */
35  
36    public ImportTreeNode()
37    {
38      super();
39    }
40  
41    /**
42     * Constructor that takes the label of the node. This is usually the name
43     * of the file\dir.
44     */
45  
46    public ImportTreeNode( String label )
47    {
48      super ( label );
49    }
50  
51    /**
52     * Constructor that takes the label of the node. This is usually the name
53     * of the file\dir. It also takes the expanded and collapsed images as parameters.
54     */
55  
56    public ImportTreeNode( String label,
57                             java.awt.Image image1,
58                             java.awt.Image image2 )
59  
60    {
61      super ( label, image1, image2 );
62    }
63  
64    /**
65     * Constructor that takes the label of the node. This is usually the name
66     * of the file\dir. It also takes A flag 'bExpanded' which determines whether
67     * the node to be expanded or not. The other flag 'bRecurExpanded' indicates whether
68     * it is expanded recursively or not, if to be expanded (bExpanded to should be true).
69     */
70  
71    public ImportTreeNode( String label,
72                             boolean bExpanded,
73                             boolean bRecurExpanded  )
74    {
75      super ( label );
76      setExpanded ( bExpanded, bRecurExpanded );
77    }
78  
79    /**
80     * Constructor.
81     *
82     * @param label          : Label of the the node
83     * @param image1         : expanded image
84     * @param image2         : collapsed image
85     * @param bExpanded      : if node to be expanded upto first level
86     * @param bRecurExpanded : if node to be expanded upto the leaves recursively
87     *
88     */
89  
90    public ImportTreeNode( String label,
91                             java.awt.Image image1,
92                             java.awt.Image image2,
93                             boolean bExpanded,
94                             boolean bRecurExpanded  )
95  
96    {
97      super ( label, image1, image2 );
98      setExpanded ( bExpanded, bRecurExpanded );
99    }
100   /**
101    * Returns the dir structure of the file\dir.
102    */
103   public String getStructure() // hierarchical strcture in the tree
104   {
105      if ( structure != null )
106        return structure.toString();
107 
108      return null;
109   }
110   /**
111    * Sets the dir structure of the file\dir.
112    */
113   public void setStructure( String stru )
114   {
115      if ( stru == null )
116      {
117        structure = null;
118        return;
119      }
120 
121      structure = new StringBuffer ( stru );
122   }
123   /**
124    * Adds a dir\file branch to the dir structure of the file\dir.
125    */
126   public void addBranch( String branch )
127   {
128     if ( structure == null )
129        structure = new StringBuffer();
130 
131     structure.append ( branch + ImportTree.SEPARATOR );
132   }
133 
134   /**
135    * Finds a node provided a label.
136    */
137   public ImportTreeNode findNode ( String label )
138   {
139     if ( label == null )
140       return null;
141 
142     ArrayList childs = getChildren();
143 
144     if ( childs == null )
145      return null;
146 
147     ImportTreeNode node = null;
148     for ( int i=0; i<childs.size(); i++ )
149     {
150        node = ( ImportTreeNode ) childs.get ( i );
151        if ( node.getLabel().equals( label ) )
152          return node;
153     }
154     return null;
155   }
156 
157   /**
158    * Though not legal yet, but clones the object.
159    * NOTE that this cloning is on 'Need to clone' basis.
160    * Add properties as you might need them.
161    */
162 
163   public Object clone ()
164   {
165     ImportTreeNode treeNode = new ImportTreeNode ( getLabel(),
166                                                        getExpandedImage(),
167                                                        getCollapsedImage() );
168     treeNode.setStructure ( getStructure() );
169     treeNode.setAlwaysShowPlusMinus ( getAlwaysShowPlusMinus () );
170     return treeNode;
171   }
172 
173 }
174