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

Quick Search    Search Deep

Source code: com/virtuosotechnologies/lib/basiccommand/builder/AbstractGroupBuilderNode.java


1   /*
2   ================================================================================
3   
4     FILE:  AbstractGroupBuilderNode.java
5     
6     PROJECT:
7     
8       Virtuoso Utilities
9     
10    CONTENTS:
11    
12      A builder that creates a group of related elements
13    
14    PROGRAMMERS:
15    
16      Daniel Azuma (DA)  <dazuma@kagi.com>
17    
18    COPYRIGHT:
19    
20      Copyright (C) 2003  Daniel Azuma  (dazuma@kagi.com)
21      
22      This program is free software; you can redistribute it and/or
23      modify it under the terms of the GNU General Public License as
24      published by the Free Software Foundation; either version 2
25      of the License, or (at your option) any later version.
26      
27      This program is distributed in the hope that it will be useful,
28      but WITHOUT ANY WARRANTY; without even the implied warranty of
29      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30      GNU General Public License for more details.
31      
32      You should have received a copy of the GNU General Public
33      License along with this program; if not, write to
34        Free Software Foundation, Inc.
35        59 Temple Place, Suite 330
36        Boston, MA 02111-1307 USA
37  
38  ================================================================================
39  */
40  
41  
42  package com.virtuosotechnologies.lib.basiccommand.builder;
43  
44  import com.virtuosotechnologies.lib.command.CommandNode;
45  
46  
47  /**
48   * A builder that creates a group of related elements based on its
49   * children, but creates no element of its own. Subclass this
50   * class and override createChildNode to create the proper types of
51   * children.
52   */
53  public abstract class AbstractGroupBuilderNode
54  extends AbstractBranchBuilderNode
55  {
56    /**
57     * Constructor
58     */
59    protected AbstractGroupBuilderNode(
60      CommandNode commandNode,
61      AbstractBranchBuilderNode parent,
62      int index)
63    {
64      super(commandNode, parent, index);
65      buildChildren();
66      if (isHidden())
67      {
68        for (int i=getNumChildren()-1; i>=0; --i)
69        {
70          AbstractBuilderNode child = getChild(i);
71          child.incMaskLevel();
72        }
73      }
74      if (isDisabled())
75      {
76        for (int i=getNumChildren()-1; i>=0; --i)
77        {
78          AbstractBuilderNode child = getChild(i);
79          child.incGrayLevel();
80        }
81      }
82    }
83    
84    
85    /**
86     * Get the cardinality (number of swing objects this node represents).
87     * Most things have a cardinality of 1. Groups have variable cardinality.
88     */
89    protected int getCardinality()
90    {
91      return getPosition(getNumChildren());
92    }
93    
94    
95    /**
96     * Add indexed element
97     */
98    protected void addElementAt(
99      int pos,
100     Object element)
101   {
102     AbstractBranchBuilderNode parent = getParent();
103     if (pos == END_POSITION)
104     {
105       pos = getCardinality();
106     }
107     parent.addElementAt(pos+parent.getPosition(this), element);
108   }
109   
110   
111   /**
112    * Set indexed element
113    */
114   protected void setElementAt(
115     int pos,
116     Object element)
117   {
118     AbstractBranchBuilderNode parent = getParent();
119     parent.setElementAt(pos+parent.getPosition(this), element);
120   }
121   
122   
123   /**
124    * Remove indexed element
125    */
126   protected void removeElementAt(
127     int pos)
128   {
129     AbstractBranchBuilderNode parent = getParent();
130     parent.removeElementAt(pos+parent.getPosition(this));
131   }
132   
133   
134   /**
135    * Remove all elements
136    */
137   protected void removeAllElements()
138   {
139     getParent().removeChildElements(this);
140   }
141   
142   
143   /**
144    * The hidden state has changed.
145    */
146   protected void hiddenStateChanged(
147     boolean nowHidden)
148   {
149     AbstractBranchBuilderNode parent = getParent();
150     if (parent != null)
151     {
152       if (nowHidden)
153       {
154         for (int i=getNumChildren()-1; i>=0; --i)
155         {
156           AbstractBuilderNode child = getChild(i);
157           child.incMaskLevel();
158         }
159       }
160       else
161       {
162         for (int i=getNumChildren()-1; i>=0; --i)
163         {
164           AbstractBuilderNode child = getChild(i);
165           child.decMaskLevel();
166         }
167       }
168     }
169   }
170   
171   
172   /**
173    * The disabled state has changed.
174    */
175   protected void disabledStateChanged(
176     boolean nowDisabled)
177   {
178     AbstractBranchBuilderNode parent = getParent();
179     if (parent != null)
180     {
181       if (nowDisabled)
182       {
183         for (int i=getNumChildren()-1; i>=0; --i)
184         {
185           AbstractBuilderNode child = getChild(i);
186           child.incGrayLevel();
187         }
188       }
189       else
190       {
191         for (int i=getNumChildren()-1; i>=0; --i)
192         {
193           AbstractBuilderNode child = getChild(i);
194           child.decGrayLevel();
195         }
196       }
197     }
198   }
199 }