40 |
import java.io.Serializable; |
import java.io.Serializable; |
41 |
|
|
42 |
/** |
/** |
43 |
* SizeRequirements |
* This class calculates information about the size and position requirements |
44 |
* @author Andrew Selkirk |
* of components. |
45 |
* @version 1.0 |
* |
46 |
|
* Two types of layout are supported: |
47 |
|
* <ul> |
48 |
|
* <li>Tiled: the components are placed at position top-left or bottom-right |
49 |
|
* position within their allocated space</li> |
50 |
|
* <li>Aligned: the components are placed aligned in their allocated space |
51 |
|
* according to their alignment value</li> |
52 |
|
* </ul> |
53 |
|
* |
54 |
|
* @author Andrew Selkirk |
55 |
|
* @author Roman Kennke (roman@kennke.org) |
56 |
*/ |
*/ |
57 |
public class SizeRequirements implements Serializable |
public class SizeRequirements implements Serializable |
58 |
{ |
{ |
59 |
|
/** |
60 |
|
* The serialVersionUID. |
61 |
|
*/ |
62 |
private static final long serialVersionUID = 9217749429906736553L; |
private static final long serialVersionUID = 9217749429906736553L; |
63 |
|
|
64 |
/** |
/** |
65 |
* minimum |
* The minimum reasonable width or height of a component. |
66 |
*/ |
*/ |
67 |
public int minimum; |
public int minimum; |
68 |
|
|
69 |
/** |
/** |
70 |
* preferred |
* The preferred width or height of a component. |
71 |
*/ |
*/ |
72 |
public int preferred; |
public int preferred; |
73 |
|
|
74 |
/** |
/** |
75 |
* maximum |
* The maximum reasonable width or height of a component. |
76 |
*/ |
*/ |
77 |
public int maximum; |
public int maximum; |
78 |
|
|
79 |
/** |
/** |
80 |
* alignment |
* The horizontal or vertical alignment of a component. |
81 |
*/ |
*/ |
82 |
public float alignment; |
public float alignment; |
83 |
|
|
84 |
/** |
/** |
85 |
* Constructor SizeRequirements |
* Creates a SizeRequirements object with minimum, preferred and |
86 |
|
* maximum size set to zero, and an alignment value of 0.5. |
87 |
*/ |
*/ |
88 |
public SizeRequirements() |
public SizeRequirements() |
89 |
{ |
{ |
90 |
// TODO |
// TODO |
91 |
} // SizeRequirements() |
} |
92 |
|
|
93 |
/** |
/** |
94 |
* Constructor SizeRequirements |
* Creates a SizeRequirements object with the specified minimum, |
95 |
* @param min TODO |
* preferred, maximum and alignment values. |
96 |
* @param pref TODO |
* |
97 |
* @param max TODO |
* @param min the minimum reasonable size of the component |
98 |
* @param align TODO |
* @param pref the preferred size of the component |
99 |
|
* @param max the maximum size of the component |
100 |
|
* @param align the alignment of the component |
101 |
*/ |
*/ |
102 |
public SizeRequirements(int min, int pref, int max, float align) |
public SizeRequirements(int min, int pref, int max, float align) |
103 |
{ |
{ |
105 |
} |
} |
106 |
|
|
107 |
/** |
/** |
108 |
* toString |
* Returns a String representation of this SizeRequirements object, |
109 |
* @returns String |
* containing information about the minimum, preferred, maximum and |
110 |
|
* alignment value. |
111 |
|
* |
112 |
|
* @return a String representation of this SizeRequirements object |
113 |
*/ |
*/ |
114 |
public String toString() |
public String toString() |
115 |
{ |
{ |
117 |
} |
} |
118 |
|
|
119 |
/** |
/** |
120 |
* getTiledSizeRequirements |
* Calculates how much space is nessecary to place a set of components |
121 |
* @param children TODO |
* end-to-end. The size requirements of the components is specified |
122 |
* @returns SizeRequirements |
* in <code>children</code>. |
123 |
|
* |
124 |
|
* @param children the SizeRequirements of each of the components |
125 |
|
* |
126 |
|
* @return the SizeRequirements that describe how much space is needed |
127 |
|
* to place the components end-to-end |
128 |
*/ |
*/ |
129 |
public static SizeRequirements |
public static SizeRequirements |
130 |
getTiledSizeRequirements(SizeRequirements[] children) |
getTiledSizeRequirements(SizeRequirements[] children) |
133 |
} |
} |
134 |
|
|
135 |
/** |
/** |
136 |
* getAlignedSizeRequirements |
* Calculates how much space is nessecary to place a set of components |
137 |
* @param children TODO |
* aligned according to their alignment value. |
138 |
* @returns SizeRequirements |
* The size requirements of the components is specified in |
139 |
|
* <code>children</code>. |
140 |
|
* |
141 |
|
* @param children the SizeRequirements of each of the components |
142 |
|
* |
143 |
|
* @return the SizeRequirements that describe how much space is needed |
144 |
|
* to place the components aligned |
145 |
*/ |
*/ |
146 |
public static SizeRequirements |
public static SizeRequirements |
147 |
getAlignedSizeRequirements(SizeRequirements[] children) |
getAlignedSizeRequirements(SizeRequirements[] children) |
150 |
} |
} |
151 |
|
|
152 |
/** |
/** |
153 |
* calculateTiledPositions |
* Calculate the offsets and spans of the components, when they should |
154 |
* @param allocated TODO |
* be placed end-to-end. |
155 |
* @param total TODO |
* |
156 |
* @param children TODO |
* You must specify the amount of allocated space in |
157 |
* @param offset TODO |
* <code>allocated</code>, the total size requirements of the set of |
158 |
* @param spans TODO |
* components in <code>total</code> (this can be calculated using |
159 |
|
* {@link #getTiledSizeRequirements} and the size requirements of the |
160 |
|
* components in <code>children</code>. |
161 |
|
* |
162 |
|
* The calculated offset and span values for each component are then |
163 |
|
* stored in the arrays <code>offsets</code> and <code>spans</code>. |
164 |
|
* |
165 |
|
* @param allocated the amount of allocated space |
166 |
|
* @param total the total size requirements of the components |
167 |
|
* @param children the size requirement of each component |
168 |
|
* @param offsets will hold the offset values for each component |
169 |
|
* @param spans will hold the span values for each component |
170 |
*/ |
*/ |
171 |
public static void calculateTiledPositions(int allocated, |
public static void calculateTiledPositions(int allocated, |
172 |
SizeRequirements total, |
SizeRequirements total, |
177 |
} |
} |
178 |
|
|
179 |
/** |
/** |
180 |
* calculateAlignedPositions |
* Calculate the offsets and spans of the components, when they should |
181 |
* @param allocated TODO |
* be placed end-to-end. |
182 |
* @param total TODO |
* |
183 |
* @param children TODO |
* You must specify the amount of allocated space in |
184 |
* @param offset TODO |
* <code>allocated</code>, the total size requirements of the set of |
185 |
* @param spans TODO |
* components in <code>total</code> (this can be calculated using |
186 |
|
* {@link #getTiledSizeRequirements} and the size requirements of the |
187 |
|
* components in <code>children</code>. |
188 |
|
* |
189 |
|
* The calculated offset and span values for each component are then |
190 |
|
* stored in the arrays <code>offsets</code> and <code>spans</code>. |
191 |
|
* |
192 |
|
* @param allocated the amount of allocated space |
193 |
|
* @param total the total size requirements of the components |
194 |
|
* @param children the size requirement of each component |
195 |
|
* @param offsets will hold the offset values for each component |
196 |
|
* @param spans will hold the span values for each component |
197 |
*/ |
*/ |
198 |
public static void calculateAlignedPositions(int allocated, |
public static void calculateAlignedPositions(int allocated, |
199 |
SizeRequirements total, |
SizeRequirements total, |
204 |
} |
} |
205 |
|
|
206 |
/** |
/** |
207 |
* adjustSizes |
* Returns an array of new preferred sizes for the children based on |
208 |
* @param delta TODO |
* <code>delta</code>. <code>delta</code> specifies a change in the |
209 |
* @param children TODO |
* allocated space. The sizes of the children will be shortened or |
210 |
* @returns int[] |
* lengthened to accomodate the new allocation. |
211 |
|
* |
212 |
|
* @param delta the change of the size of the total allocation for |
213 |
|
* the components |
214 |
|
* @param children the size requirements of each component |
215 |
|
* |
216 |
|
* @return the new preferred sizes for each component |
217 |
*/ |
*/ |
218 |
public static int[] adjustSizes(int delta, SizeRequirements[] children) |
public static int[] adjustSizes(int delta, SizeRequirements[] children) |
219 |
{ |
{ |