KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > common > AbsoluteLayout


1 package com.calipso.reportgenerator.common;
2
3 /*
4  * Sun Public License Notice
5  *
6  * The contents of this file are subject to the Sun Public License
7  * Version 1.0 (the "License"). You may not use this file except in
8  * compliance with the License. A copy of the License is available at
9  * http://www.sun.com/
10  *
11  * The Original Code is NetBeans. The Initial Developer of the Original
12  * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
13  * Microsystems, Inc. All Rights Reserved.
14  */

15
16 //package org.netbeans.lib.awtextra;
17

18 import com.calipso.reportgenerator.common.AbsoluteConstraints;
19
20 import java.awt.*;
21
22 /** AbsoluteLayout is a LayoutManager that works as a replacement for "null" layout to
23 * allow placement of components in absolute positions.
24 *
25 //* @see AbsoluteConstraints
26 * @version 1.01, Aug 19, 1998
27 */

28 public class AbsoluteLayout implements LayoutManager2, java.io.Serializable JavaDoc {
29     /** generated Serialized Version UID */
30     static final long serialVersionUID = -1919857869177070440L;
31
32     /** Adds the specified component with the specified name to
33     * the layout.
34     * @param name the component name
35     * @param comp the component to be added
36     */

37     public void addLayoutComponent(String JavaDoc name, Component comp) {
38         throw new IllegalArgumentException JavaDoc();
39     }
40
41     /** Removes the specified component from the layout.
42     * @param comp the component to be removed
43     */

44     public void removeLayoutComponent(Component comp) {
45         constraints.remove(comp);
46     }
47
48     /** Calculates the preferred dimension for the specified
49     * panel given the components in the specified parent container.
50     * @param parent the component to be laid out
51     *
52     * @see #minimumLayoutSize
53     */

54     public Dimension preferredLayoutSize(Container parent) {
55         int maxWidth = 0;
56         int maxHeight = 0;
57         for (java.util.Enumeration JavaDoc e = constraints.keys(); e.hasMoreElements();) {
58             Component comp = (Component)e.nextElement();
59             AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp);
60             Dimension size = comp.getPreferredSize();
61
62             int width = ac.getWidth ();
63             if (width == -1) width = size.width;
64             int height = ac.getHeight ();
65             if (height == -1) height = size.height;
66
67             if (ac.x + width > maxWidth)
68                 maxWidth = ac.x + width;
69             if (ac.y + height > maxHeight)
70                 maxHeight = ac.y + height;
71         }
72         return new Dimension (maxWidth, maxHeight);
73     }
74
75     /** Calculates the minimum dimension for the specified
76     * panel given the components in the specified parent container.
77     * @param parent the component to be laid out
78     * @see #preferredLayoutSize
79     */

80     public Dimension minimumLayoutSize(Container parent) {
81         int maxWidth = 0;
82         int maxHeight = 0;
83         for (java.util.Enumeration JavaDoc e = constraints.keys(); e.hasMoreElements();) {
84             Component comp = (Component)e.nextElement();
85             com.calipso.reportgenerator.common.AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp);
86
87             Dimension size = comp.getMinimumSize();
88
89             int width = ac.getWidth ();
90             if (width == -1) width = size.width;
91             int height = ac.getHeight ();
92             if (height == -1) height = size.height;
93
94             if (ac.x + width > maxWidth)
95                 maxWidth = ac.x + width;
96             if (ac.y + height > maxHeight)
97                 maxHeight = ac.y + height;
98         }
99         return new Dimension (maxWidth, maxHeight);
100     }
101
102     /** Lays out the container in the specified panel.
103     * @param parent the component which needs to be laid out
104     */

105     public void layoutContainer(Container parent) {
106         for (java.util.Enumeration JavaDoc e = constraints.keys(); e.hasMoreElements();) {
107             Component comp = (Component)e.nextElement();
108             AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp);
109             Dimension size = comp.getPreferredSize();
110             int width = ac.getWidth ();
111             if (width == -1) width = size.width;
112             int height = ac.getHeight ();
113             if (height == -1) height = size.height;
114
115             comp.setBounds(ac.x, ac.y, width, height);
116         }
117     }
118
119     /** Adds the specified component to the layout, using the specified
120     * constraint object.
121     * @param comp the component to be added
122     * @param constr where/how the component is added to the layout.
123     */

124     public void addLayoutComponent(Component comp, Object JavaDoc constr) {
125         if (!(constr instanceof AbsoluteConstraints))
126             throw new IllegalArgumentException JavaDoc();
127         constraints.put(comp, constr);
128     }
129
130     /** Returns the maximum size of this component.
131     * @see java.awt.Component#getMinimumSize()
132     * @see java.awt.Component#getPreferredSize()
133     * @see LayoutManager
134     */

135     public Dimension maximumLayoutSize(Container target) {
136         return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
137     }
138
139     /** Returns the alignment along the x axis. This specifies how
140     * the component would like to be aligned relative to other
141     * components. The value should be a number between 0 and 1
142     * where 0 represents alignment along the origin, 1 is aligned
143     * the furthest away from the origin, 0.5 is centered, etc.
144     */

145     public float getLayoutAlignmentX(Container target) {
146         return 0;
147     }
148
149     /** Returns the alignment along the y axis. This specifies how
150     * the component would like to be aligned relative to other
151     * components. The value should be a number between 0 and 1
152     * where 0 represents alignment along the origin, 1 is aligned
153     * the furthest away from the origin, 0.5 is centered, etc.
154     */

155     public float getLayoutAlignmentY(Container target) {
156         return 0;
157     }
158
159     /** Invalidates the layout, indicating that if the layout manager
160     * has cached information it should be discarded.
161     */

162     public void invalidateLayout(Container target) {
163     }
164
165
166     /** A mapping <Component, AbsoluteConstraints> */
167     protected java.util.Hashtable JavaDoc constraints = new java.util.Hashtable JavaDoc();
168 }
169
170
Popular Tags