KickJava   Java API By Example, From Geeks To Geeks.

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


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/NullLayoutManager.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 that doesn't move things around.
34  * Attempts to set the bounds of components to accomodate them
35  * but doesn't move them.
36  */

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

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

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

66     public Dimension preferredLayoutSize (Container target)
67     {
68         int count;
69         Container parent;
70         Component component;
71         Point point;
72         Dimension dimension;
73         Insets insets;
74         Dimension ret;
75         
76         synchronized (target.getTreeLock ())
77         {
78             count = target.getComponentCount ();
79             if (0 == count)
80             {
81                 // be the same size unless we have a parent
82
ret = target.getSize ();
83                 parent = target.getParent ();
84                 if (null != parent)
85                 {
86                     insets = parent.getInsets ();
87                     ret = parent.getSize ();
88                     ret.setSize (
89                         ret.width - insets.left - insets.right,
90                         ret.height - insets.top - insets.bottom);
91                 }
92             }
93             else
94             {
95                 ret = new Dimension (0, 0);
96                 for (int i = 0 ; i < count ; i++)
97                 {
98                     component = target.getComponent (i);
99                     if (component.isVisible ())
100                     {
101                         point = component.getLocation ();
102                         dimension = component.getPreferredSize();
103                         ret.width = Math.max (ret.width, point.x + dimension.width);
104                         ret.height = Math.max (ret.height, point.y + dimension.height);
105                     }
106                 }
107                 insets = target.getInsets ();
108                 ret.width += insets.left + insets.right;
109                 ret.height += insets.top + insets.bottom;
110             }
111         }
112
113         return (ret);
114     }
115   
116     /**
117      * Returns the maximum size of this component.
118      * @param target The component to be laid out.
119      * @see java.awt.Component#getMinimumSize
120      * @see java.awt.Component#getPreferredSize
121      * @see java.awt.LayoutManager
122      */

123     public Dimension maximumLayoutSize (Container target)
124     {
125         return (preferredLayoutSize (target));
126     }
127   
128     //
129
// LayoutManager Interface
130
//
131

132     /**
133      * Adds the specified component with the specified name to
134      * the layout.
135      * @param name the component name
136      * @param comp the component to be added
137      */

138     public void addLayoutComponent (String JavaDoc name, Component comp)
139     {
140     }
141   
142     /**
143      * Removes the specified component from the layout.
144      * @param comp the component ot be removed
145      */

146     public void removeLayoutComponent (Component comp)
147     {
148     }
149   
150     /**
151      * Lays out the container.
152      * @param target The container which needs to be laid out.
153      */

154     public void layoutContainer (Container target)
155     {
156         int count;
157         Component component;
158         Dimension dimension;
159         
160         synchronized (target.getTreeLock ())
161         {
162             count = target.getComponentCount ();
163             for (int i = 0 ; i < count ; i++)
164             {
165                 component = target.getComponent (i);
166                 if (component.isVisible ())
167                 {
168                     dimension = component.getPreferredSize();
169                     component.setSize (dimension.width, dimension.height);
170                 }
171             }
172         }
173     }
174   
175     //
176
// LayoutManager2 Interface
177
//
178

179     /**
180      * Adds the specified component to the layout, using the specified
181      * constraint object.
182      * @param comp the component to be added
183      * @param constraints where/how the component is added to the layout.
184      */

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

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

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

220     public void invalidateLayout (Container target)
221     {
222     }
223 }
224
Popular Tags