1 | /*
|
---|
2 | * Sun Public License Notice
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the Sun Public License
|
---|
5 | * Version 1.0 (the "License"). You may not use this file except in
|
---|
6 | * compliance with the License. A copy of the License is available at
|
---|
7 | * http://www.sun.com/
|
---|
8 | *
|
---|
9 | * The Original Code is NetBeans. The Initial Developer of the Original
|
---|
10 | * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
|
---|
11 | * Microsystems, Inc. All Rights Reserved.
|
---|
12 | */
|
---|
13 |
|
---|
14 | //package org.netbeans.lib.awtextra;
|
---|
15 | package org.greenstone3.ms;
|
---|
16 |
|
---|
17 | import java.awt.*;
|
---|
18 |
|
---|
19 | /** AbsoluteLayout is a LayoutManager that works as a replacement for "null" layout to
|
---|
20 | * allow placement of components in absolute positions.
|
---|
21 | *
|
---|
22 | * @see AbsoluteConstraints
|
---|
23 | * @version 1.01, Aug 19, 1998
|
---|
24 | */
|
---|
25 | public class AbsoluteLayout implements LayoutManager2, java.io.Serializable {
|
---|
26 | /** generated Serialized Version UID */
|
---|
27 | static final long serialVersionUID = -1919857869177070440L;
|
---|
28 |
|
---|
29 | /** Adds the specified component with the specified name to
|
---|
30 | * the layout.
|
---|
31 | * @param name the component name
|
---|
32 | * @param comp the component to be added
|
---|
33 | */
|
---|
34 | public void addLayoutComponent(String name, Component comp) {
|
---|
35 | throw new IllegalArgumentException();
|
---|
36 | }
|
---|
37 |
|
---|
38 | /** Removes the specified component from the layout.
|
---|
39 | * @param comp the component to be removed
|
---|
40 | */
|
---|
41 | public void removeLayoutComponent(Component comp) {
|
---|
42 | constraints.remove(comp);
|
---|
43 | }
|
---|
44 |
|
---|
45 | /** Calculates the preferred dimension for the specified
|
---|
46 | * panel given the components in the specified parent container.
|
---|
47 | * @param parent the component to be laid out
|
---|
48 | *
|
---|
49 | * @see #minimumLayoutSize
|
---|
50 | */
|
---|
51 | public Dimension preferredLayoutSize(Container parent) {
|
---|
52 | int maxWidth = 0;
|
---|
53 | int maxHeight = 0;
|
---|
54 | for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) {
|
---|
55 | Component comp = (Component) e.nextElement();
|
---|
56 | AbsoluteConstraints ac = (AbsoluteConstraints) constraints.get(comp);
|
---|
57 | Dimension size = comp.getPreferredSize();
|
---|
58 |
|
---|
59 | int width = ac.getWidth();
|
---|
60 | if (width == -1) width = size.width;
|
---|
61 | int height = ac.getHeight();
|
---|
62 | if (height == -1) height = size.height;
|
---|
63 |
|
---|
64 | if (ac.x + width > maxWidth)
|
---|
65 | maxWidth = ac.x + width;
|
---|
66 | if (ac.y + height > maxHeight)
|
---|
67 | maxHeight = ac.y + height;
|
---|
68 | }
|
---|
69 | return new Dimension(maxWidth, maxHeight);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /** Calculates the minimum dimension for the specified
|
---|
73 | * panel given the components in the specified parent container.
|
---|
74 | * @param parent the component to be laid out
|
---|
75 | * @see #preferredLayoutSize
|
---|
76 | */
|
---|
77 | public Dimension minimumLayoutSize(Container parent) {
|
---|
78 | int maxWidth = 0;
|
---|
79 | int maxHeight = 0;
|
---|
80 | for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) {
|
---|
81 | Component comp = (Component) e.nextElement();
|
---|
82 | AbsoluteConstraints ac = (AbsoluteConstraints) constraints.get(comp);
|
---|
83 |
|
---|
84 | Dimension size = comp.getMinimumSize();
|
---|
85 |
|
---|
86 | int width = ac.getWidth();
|
---|
87 | if (width == -1) width = size.width;
|
---|
88 | int height = ac.getHeight();
|
---|
89 | if (height == -1) height = size.height;
|
---|
90 |
|
---|
91 | if (ac.x + width > maxWidth)
|
---|
92 | maxWidth = ac.x + width;
|
---|
93 | if (ac.y + height > maxHeight)
|
---|
94 | maxHeight = ac.y + height;
|
---|
95 | }
|
---|
96 | return new Dimension(maxWidth, maxHeight);
|
---|
97 | }
|
---|
98 |
|
---|
99 | /** Lays out the container in the specified panel.
|
---|
100 | * @param parent the component which needs to be laid out
|
---|
101 | */
|
---|
102 | public void layoutContainer(Container parent) {
|
---|
103 | for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) {
|
---|
104 | Component comp = (Component) e.nextElement();
|
---|
105 | AbsoluteConstraints ac = (AbsoluteConstraints) constraints.get(comp);
|
---|
106 | Dimension size = comp.getPreferredSize();
|
---|
107 | int width = ac.getWidth();
|
---|
108 | if (width == -1) width = size.width;
|
---|
109 | int height = ac.getHeight();
|
---|
110 | if (height == -1) height = size.height;
|
---|
111 |
|
---|
112 | comp.setBounds(ac.x, ac.y, width, height);
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | /** Adds the specified component to the layout, using the specified
|
---|
117 | * constraint object.
|
---|
118 | * @param comp the component to be added
|
---|
119 | * @param constr where/how the component is added to the layout.
|
---|
120 | */
|
---|
121 | public void addLayoutComponent(Component comp, Object constr) {
|
---|
122 | if (!(constr instanceof AbsoluteConstraints))
|
---|
123 | throw new IllegalArgumentException();
|
---|
124 | constraints.put(comp, constr);
|
---|
125 | }
|
---|
126 |
|
---|
127 | /** Returns the maximum size of this component.
|
---|
128 | * @see java.awt.Component#getMinimumSize()
|
---|
129 | * @see java.awt.Component#getPreferredSize()
|
---|
130 | * @see LayoutManager
|
---|
131 | */
|
---|
132 | public Dimension maximumLayoutSize(Container target) {
|
---|
133 | return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
---|
134 | }
|
---|
135 |
|
---|
136 | /** Returns the alignment along the x axis. This specifies how
|
---|
137 | * the component would like to be aligned relative to other
|
---|
138 | * components. The value should be a number between 0 and 1
|
---|
139 | * where 0 represents alignment along the origin, 1 is aligned
|
---|
140 | * the furthest away from the origin, 0.5 is centered, etc.
|
---|
141 | */
|
---|
142 | public float getLayoutAlignmentX(Container target) {
|
---|
143 | return 0;
|
---|
144 | }
|
---|
145 |
|
---|
146 | /** Returns the alignment along the y axis. This specifies how
|
---|
147 | * the component would like to be aligned relative to other
|
---|
148 | * components. The value should be a number between 0 and 1
|
---|
149 | * where 0 represents alignment along the origin, 1 is aligned
|
---|
150 | * the furthest away from the origin, 0.5 is centered, etc.
|
---|
151 | */
|
---|
152 | public float getLayoutAlignmentY(Container target) {
|
---|
153 | return 0;
|
---|
154 | }
|
---|
155 |
|
---|
156 | /** Invalidates the layout, indicating that if the layout manager
|
---|
157 | * has cached information it should be discarded.
|
---|
158 | */
|
---|
159 | public void invalidateLayout(Container target) {
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 | /** A mapping <Component, AbsoluteConstraints> */
|
---|
164 | protected java.util.Hashtable constraints = new java.util.Hashtable();
|
---|
165 | }
|
---|
166 |
|
---|