001: package com.calipso.reportgenerator.common;
002:
003: /*
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License
007: * Version 1.0 (the "License"). You may not use this file except in
008: * compliance with the License. A copy of the License is available at
009: * http://www.sun.com/
010: *
011: * The Original Code is NetBeans. The Initial Developer of the Original
012: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
013: * Microsystems, Inc. All Rights Reserved.
014: */
015:
016: //package org.netbeans.lib.awtextra;
017: import com.calipso.reportgenerator.common.AbsoluteConstraints;
018:
019: import java.awt.*;
020:
021: /** AbsoluteLayout is a LayoutManager that works as a replacement for "null" layout to
022: * allow placement of components in absolute positions.
023: *
024: //* @see AbsoluteConstraints
025: * @version 1.01, Aug 19, 1998
026: */
027: public class AbsoluteLayout implements LayoutManager2,
028: java.io.Serializable {
029: /** generated Serialized Version UID */
030: static final long serialVersionUID = -1919857869177070440L;
031:
032: /** Adds the specified component with the specified name to
033: * the layout.
034: * @param name the component name
035: * @param comp the component to be added
036: */
037: public void addLayoutComponent(String name, Component comp) {
038: throw new IllegalArgumentException();
039: }
040:
041: /** Removes the specified component from the layout.
042: * @param comp the component to be removed
043: */
044: public void removeLayoutComponent(Component comp) {
045: constraints.remove(comp);
046: }
047:
048: /** Calculates the preferred dimension for the specified
049: * panel given the components in the specified parent container.
050: * @param parent the component to be laid out
051: *
052: * @see #minimumLayoutSize
053: */
054: public Dimension preferredLayoutSize(Container parent) {
055: int maxWidth = 0;
056: int maxHeight = 0;
057: for (java.util.Enumeration e = constraints.keys(); e
058: .hasMoreElements();) {
059: Component comp = (Component) e.nextElement();
060: AbsoluteConstraints ac = (AbsoluteConstraints) constraints
061: .get(comp);
062: Dimension size = comp.getPreferredSize();
063:
064: int width = ac.getWidth();
065: if (width == -1)
066: width = size.width;
067: int height = ac.getHeight();
068: if (height == -1)
069: height = size.height;
070:
071: if (ac.x + width > maxWidth)
072: maxWidth = ac.x + width;
073: if (ac.y + height > maxHeight)
074: maxHeight = ac.y + height;
075: }
076: return new Dimension(maxWidth, maxHeight);
077: }
078:
079: /** Calculates the minimum dimension for the specified
080: * panel given the components in the specified parent container.
081: * @param parent the component to be laid out
082: * @see #preferredLayoutSize
083: */
084: public Dimension minimumLayoutSize(Container parent) {
085: int maxWidth = 0;
086: int maxHeight = 0;
087: for (java.util.Enumeration e = constraints.keys(); e
088: .hasMoreElements();) {
089: Component comp = (Component) e.nextElement();
090: com.calipso.reportgenerator.common.AbsoluteConstraints ac = (AbsoluteConstraints) constraints
091: .get(comp);
092:
093: Dimension size = comp.getMinimumSize();
094:
095: int width = ac.getWidth();
096: if (width == -1)
097: width = size.width;
098: int height = ac.getHeight();
099: if (height == -1)
100: height = size.height;
101:
102: if (ac.x + width > maxWidth)
103: maxWidth = ac.x + width;
104: if (ac.y + height > maxHeight)
105: maxHeight = ac.y + height;
106: }
107: return new Dimension(maxWidth, maxHeight);
108: }
109:
110: /** Lays out the container in the specified panel.
111: * @param parent the component which needs to be laid out
112: */
113: public void layoutContainer(Container parent) {
114: for (java.util.Enumeration e = constraints.keys(); e
115: .hasMoreElements();) {
116: Component comp = (Component) e.nextElement();
117: AbsoluteConstraints ac = (AbsoluteConstraints) constraints
118: .get(comp);
119: Dimension size = comp.getPreferredSize();
120: int width = ac.getWidth();
121: if (width == -1)
122: width = size.width;
123: int height = ac.getHeight();
124: if (height == -1)
125: height = size.height;
126:
127: comp.setBounds(ac.x, ac.y, width, height);
128: }
129: }
130:
131: /** Adds the specified component to the layout, using the specified
132: * constraint object.
133: * @param comp the component to be added
134: * @param constr where/how the component is added to the layout.
135: */
136: public void addLayoutComponent(Component comp, Object constr) {
137: if (!(constr instanceof AbsoluteConstraints))
138: throw new IllegalArgumentException();
139: constraints.put(comp, constr);
140: }
141:
142: /** Returns the maximum size of this component.
143: * @see java.awt.Component#getMinimumSize()
144: * @see java.awt.Component#getPreferredSize()
145: * @see LayoutManager
146: */
147: public Dimension maximumLayoutSize(Container target) {
148: return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
149: }
150:
151: /** Returns the alignment along the x axis. This specifies how
152: * the component would like to be aligned relative to other
153: * components. The value should be a number between 0 and 1
154: * where 0 represents alignment along the origin, 1 is aligned
155: * the furthest away from the origin, 0.5 is centered, etc.
156: */
157: public float getLayoutAlignmentX(Container target) {
158: return 0;
159: }
160:
161: /** Returns the alignment along the y axis. This specifies how
162: * the component would like to be aligned relative to other
163: * components. The value should be a number between 0 and 1
164: * where 0 represents alignment along the origin, 1 is aligned
165: * the furthest away from the origin, 0.5 is centered, etc.
166: */
167: public float getLayoutAlignmentY(Container target) {
168: return 0;
169: }
170:
171: /** Invalidates the layout, indicating that if the layout manager
172: * has cached information it should be discarded.
173: */
174: public void invalidateLayout(Container target) {
175: }
176:
177: /** A mapping <Component, AbsoluteConstraints> */
178: protected java.util.Hashtable constraints = new java.util.Hashtable();
179: }
|