source: other-projects/trunk/greenstone3-extension/mat/src/org/greenstone/gsdl3_extension/mat/AbsoluteLayout.java@ 18093

Last change on this file since 18093 was 18093, checked in by cc108, 15 years ago

new Mat source code

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