KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > parserapplications > filterbuilder > layouts > VerticalLayoutManager


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2005 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/layouts/VerticalLayoutManager.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2005/02/13 20:43:13 $
10
// $Revision: 1.1 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.parserapplications.filterbuilder.layouts;
28
29 import java.awt.*;
30 import java.io.*;
31
32 /**
33  * A layout manager like a vertical FlowLayout.
34  * Stacks components vertically like GridLayout(0,1) but doesn't
35  * resize each component equally. More like a vertical FlowLayout
36  * but doesn't snake columns or align things.
37  */

38 public class VerticalLayoutManager
39     implements
40         LayoutManager2,
41         Serializable
42 {
43     /**
44      * Constructs a VerticalLayoutManager object.
45      */

46     public VerticalLayoutManager ()
47     {
48     }
49   
50     /**
51      * Calculates the minimum size dimensions for the specified
52      * panel given the components in the specified parent container.
53      * @param target The component to be laid out.
54      * @see #preferredLayoutSize
55      */

56     public Dimension minimumLayoutSize (Container target)
57     {
58         return (preferredLayoutSize (target));
59     }
60   
61     /**
62      * Calculates the preferred size dimensions for the specified
63      * panel given the components in the specified parent container.
64      * @param target The component to be laid out.
65      * @see #minimumLayoutSize
66      */

67     public Dimension preferredLayoutSize (Container target)
68     {
69         int count;
70         Component component;
71         Dimension dimension;
72         Insets insets;
73         Dimension ret;
74         
75         synchronized (target.getTreeLock ())
76         {
77             // get the the total height and maximum width component
78
ret = new Dimension (0, 0);
79             count = target.getComponentCount ();
80             for (int i = 0 ; i < count ; i++)
81             {
82                 component = target.getComponent (i);
83                 if (component.isVisible ())
84                 {
85                     dimension = component.getPreferredSize ();
86                     ret.width = Math.max (ret.width, dimension.width);
87                     ret.height += dimension.height;
88                 }
89             }
90             insets = target.getInsets ();
91             ret.width += insets.left + insets.right;
92             ret.height += insets.top + insets.bottom;
93         }
94
95         return (ret);
96     }
97   
98     /**
99      * Returns the maximum size of this component.
100      * @param target The component to be laid out.
101      * @see java.awt.Component#getMinimumSize
102      * @see java.awt.Component#getPreferredSize
103      * @see java.awt.LayoutManager
104      */

105     public Dimension maximumLayoutSize (Container target)
106     {
107         return (preferredLayoutSize (target));
108     }
109   
110     //
111
// LayoutManager Interface
112
//
113

114     /**
115      * Adds the specified component with the specified name to
116      * the layout.
117      * @param name the component name
118      * @param comp the component to be added
119      */

120     public void addLayoutComponent (String JavaDoc name, Component comp)
121     {
122     }
123   
124     /**
125      * Removes the specified component from the layout.
126      * @param comp the component ot be removed
127      */

128     public void removeLayoutComponent (Component comp)
129     {
130     }
131   
132     /**
133      * Lays out the container.
134      * @param target The container which needs to be laid out.
135      */

136     public void layoutContainer (Container target)
137     {
138         Insets insets;
139         int x;
140         int y;
141         int count;
142         int width;
143         Component component;
144         Dimension dimension;
145         
146         synchronized (target.getTreeLock ())
147         {
148             insets = target.getInsets ();
149             x = insets.left;
150             y = insets.top;
151             count = target.getComponentCount ();
152             width = 0;
153             for (int i = 0 ; i < count ; i++)
154             {
155                 component = target.getComponent (i);
156                 if (component.isVisible ())
157                 {
158                     dimension = component.getPreferredSize ();
159                     width = Math.max (width, dimension.width);
160                     component.setSize (dimension.width, dimension.height);
161                     component.setLocation (x, y);
162                     y += dimension.height;
163                 }
164             }
165             // now set them all to the same width
166
for (int i = 0 ; i < count ; i++)
167             {
168                 component = target.getComponent (i);
169                 if (component.isVisible ())
170                 {
171                     dimension = component.getSize ();
172                     dimension.width = width;
173                     component.setSize (dimension.width, dimension.height);
174                 }
175             }
176         }
177     }
178   
179     //
180
// LayoutManager2 Interface
181
//
182

183     /**
184      * Adds the specified component to the layout, using the specified
185      * constraint object.
186      * @param comp the component to be added
187      * @param constraints where/how the component is added to the layout.
188      */

189     public void addLayoutComponent (Component comp, Object JavaDoc constraints)
190     {
191     }
192   
193     /**
194      * Returns the alignment along the x axis. This specifies how
195      * the component would like to be aligned relative to other
196      * components. The value should be a number between 0 and 1
197      * where 0 represents alignment along the origin, 1 is aligned
198      * the furthest away from the origin, 0.5 is centered, etc.
199      * @param target The target container.
200      */

201     public float getLayoutAlignmentX (Container target)
202     {
203         return (0.0f);
204     }
205   
206     /**
207      * Returns the alignment along the y axis. This specifies how
208      * the component would like to be aligned relative to other
209      * components. The value should be a number between 0 and 1
210      * where 0 represents alignment along the origin, 1 is aligned
211      * the furthest away from the origin, 0.5 is centered, etc.
212      * @param target The target container.
213      */

214     public float getLayoutAlignmentY (Container target)
215     {
216         return (0.0f);
217     }
218   
219     /**
220      * Invalidates the layout, indicating that if the layout manager
221      * has cached information it should be discarded.
222      * @param target The target container.
223      */

224     public void invalidateLayout (Container target)
225     {
226     }
227 }
228
Popular Tags