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

Quick Search    Search Deep

Source code: com/voytechs/html/component/Container.java


1   /*
2    * File: Container.java
3    * Auth: Mark Bednarczyk
4    * Date: DATE
5    *   Id: $Id: Container.java,v 1.1.1.1 2002/01/23 23:52:47 voytechs Exp $
6    ********************************************
7    * $Log: Container.java,v $
8    * Revision 1.1.1.1  2002/01/23 23:52:47  voytechs
9    * Initial public release, BETA 1.0 - voytechs
10   *
11   */
12  package com.voytechs.html.component;
13  
14  import com.voytechs.html.io.HtmlWriter;
15  import com.voytechs.html.event.EventException;
16  import com.voytechs.html.event.HtmlDispatcher;
17  import com.voytechs.html.util.LogFacility;
18  
19  import java.lang.*;
20  import java.util.*;
21  import java.io.IOException;
22  
23  /**
24   * A generic container object is a component that can
25   * contain other components. 
26   * <BR>
27   * Components added to a container are tracked in a list. The order of the list
28   * will define the components' front-to-back stacking order within the 
29   * container. If no index is specified when adding a component to a container,
30   * it will be added to the end of the list (and hence to the bottom of the 
31   * stacking order).
32   */
33  public class Container 
34    extends SimpleComponent {
35  
36    /* Internal attributes */
37  
38    private ComponentVector children = null;
39  
40    public Container() {
41      super();
42  
43      children = new ComponentVector(this);
44    }
45  
46    /**
47     * Function that initializes the object relationships. Late bindings, 
48     * adding delayed listeners, etc. Called after the full component tree 
49     * is built.
50     */
51    protected void init(Frame root, HtmlDispatcher dispatcher) 
52        throws com.voytechs.html.event.EventException {
53  
54      super.init(root, dispatcher);
55  
56      children.init(root, dispatcher);
57    }
58  
59    /**
60     * Add a child component to the list of children to manage.
61     * Components are displayed in the order they were added.
62     */
63    protected void addChild(Component child) throws EventException {
64      LogFacility.log.println(this + "::Container::addChild() - adding a child=" +
65                              child);
66                              
67      children.addElement(child);
68  
69      child.setParent(this);
70  
71      if(areFlagsSet(Component.COMPONENT_FLAG_INIT))
72        child.init(getRootFrame(), getRootFrame().getDispatcher());
73    }
74  
75    /**
76     * Removes a previously added Component from the tree.
77     */
78    public void removeElement(Component child)
79        throws EventException {
80    
81      if(children.removeElement(child) == false)
82        throw new EventException(this + "Container::removeElement() - trying to remove an unexistent element: " + child);
83  
84      if(child.areFlagsSet(Component.COMPONENT_FLAG_DISPATCHABLE)) {
85        DispatchableComponent dc = (DispatchableComponent)child;
86        getRootFrame().getDispatcher().removeSource(dc.getElementType(), dc.getElementId());
87      }
88    }
89  
90    /**
91     * Calls the paint method for all is children components.
92     * @param htmlOut HtmlWriter where output should be sent to.
93     * @exception Any stream output errors.
94     */
95    protected void paint(HtmlWriter htmlOut) throws IOException {
96      if(show() == false)
97        return;
98  
99      process();
100 
101     paintChildren(htmlOut);
102   }
103 
104   /**
105    * A method that allows a subclass to override and do special processing.
106    * Does nothing by default;
107    */
108   protected void process() {
109     LogFacility.log.println(this + "::Container::process()");
110   }
111 
112   /**
113    * Calls the paint method for all its children conponents.
114    * @param htmlOut HtmlWriter where output should be sent to.
115    * @exception Any stream output errors.
116    */
117   protected void paintChildren(HtmlWriter htmlOut) throws IOException {
118     
119     children.paintElements(htmlOut);
120   }
121 
122   /**
123    * A debuging function to print out the component tree.
124    */
125   public String toStringTree(String prefix) {
126     String s = "";
127 
128     s += super.toStringTree(prefix);
129 
130     s += children.toStringTree(prefix + Component.toStringPrefixCap());
131 
132     return(s);
133   }
134 
135   /**
136    * Test function for Container
137    * @param args command line arguments
138    */
139   public static void main(String [] args) {
140   }
141 
142 } /* END OF: Container */