57 |
protected GridBagLayoutInfo layoutInfo; |
protected GridBagLayoutInfo layoutInfo; |
58 |
protected GridBagConstraints defaultConstraints = new GridBagConstraints(); |
protected GridBagConstraints defaultConstraints = new GridBagConstraints(); |
59 |
|
|
60 |
public double[] columnWeights; |
public double[] colWeights; |
61 |
public int[] columnWidths; |
public int[] colWidths; |
62 |
public double[] rowWeights; |
public double[] rowWeights; |
63 |
public int[] rowHeights; |
public int[] rowHeights; |
64 |
|
|
67 |
// Do nothing here. |
// Do nothing here. |
68 |
} |
} |
69 |
|
|
70 |
|
/** |
71 |
|
* Helper method to calc the sum of all elements in an int array. |
72 |
|
*/ |
73 |
|
private int sumIntArray (int[] array) |
74 |
|
{ |
75 |
|
int result = 0; |
76 |
|
|
77 |
|
for (int i = 0; i < array.length; i++) |
78 |
|
result += array [i]; |
79 |
|
|
80 |
|
return result; |
81 |
|
} |
82 |
|
|
83 |
|
/** |
84 |
|
* Helper method to calc the sum of all elements in an double array. |
85 |
|
*/ |
86 |
|
private double sumDoubleArray (double[] array) |
87 |
|
{ |
88 |
|
double result = 0; |
89 |
|
|
90 |
|
for (int i = 0; i < array.length; i++) |
91 |
|
result += array [i]; |
92 |
|
|
93 |
|
return result; |
94 |
|
} |
95 |
|
|
96 |
public void addLayoutComponent (String name, Component component) |
public void addLayoutComponent (String name, Component component) |
97 |
{ |
{ |
98 |
// do nothing here. |
// do nothing here. |
99 |
} |
} |
100 |
|
|
101 |
|
public void removeLayoutComponent (Component component) |
102 |
|
{ |
103 |
|
// do nothing here |
104 |
|
} |
105 |
|
|
106 |
public void addLayoutComponent (Component component, Object constraints) |
public void addLayoutComponent (Component component, Object constraints) |
107 |
{ |
{ |
108 |
if (!(constraints instanceof GridBagConstraints)) |
if (!(constraints instanceof GridBagConstraints)) |
111 |
setConstraints (component, (GridBagConstraints) constraints); |
setConstraints (component, (GridBagConstraints) constraints); |
112 |
} |
} |
113 |
|
|
|
public void removeLayoutComponent (Component component) |
|
|
{ |
|
|
// do nothing here |
|
|
} |
|
|
|
|
114 |
public Dimension preferredLayoutSize (Container parent) |
public Dimension preferredLayoutSize (Container parent) |
115 |
{ |
{ |
116 |
if (parent == null) |
if (parent == null) |
154 |
this.layoutInfo = null; |
this.layoutInfo = null; |
155 |
} |
} |
156 |
|
|
|
/** |
|
|
* @since 1.4 |
|
|
*/ |
|
|
protected void adjustForGravity (GridBagConstraints gbc, Rectangle rect) |
|
|
{ |
|
|
throw new Error ("Not implemented"); |
|
|
} |
|
|
|
|
|
protected void AdjustForGravity (GridBagConstraints gbc, Rectangle rect) |
|
|
{ |
|
|
adjustForGravity (gbc, rect); |
|
|
} |
|
|
|
|
|
/** |
|
|
* @since 1.4 |
|
|
*/ |
|
|
protected void arrangeGrid (Container parent) |
|
|
{ |
|
|
throw new Error ("Not implemented"); |
|
|
} |
|
|
|
|
|
protected void ArrangeGrid (Container parent) |
|
|
{ |
|
|
arrangeGrid (parent); |
|
|
} |
|
|
|
|
157 |
public void setConstraints (Component component, |
public void setConstraints (Component component, |
158 |
GridBagConstraints constraints) |
GridBagConstraints constraints) |
159 |
{ |
{ |
256 |
} |
} |
257 |
|
|
258 |
/** |
/** |
259 |
* @since 1.4 |
* Obsolete. |
260 |
*/ |
*/ |
261 |
protected GridBagLayoutInfo getLayoutInfo (Container parent, int sizeflag) |
protected void AdjustForGravity (GridBagConstraints gbc, Rectangle rect) |
262 |
{ |
{ |
263 |
if (sizeflag != MINSIZE && sizeflag != PREFERREDSIZE) |
adjustForGravity (gbc, rect); |
264 |
throw new IllegalArgumentException(); |
} |
265 |
|
|
266 |
throw new Error ("Not implemented"); |
/** |
267 |
|
* Obsolete. |
268 |
|
*/ |
269 |
|
protected void ArrangeGrid (Container parent) |
270 |
|
{ |
271 |
|
arrangeGrid (parent); |
272 |
} |
} |
273 |
|
|
274 |
|
/** |
275 |
|
* Obsolete. |
276 |
|
*/ |
277 |
protected GridBagLayoutInfo GetLayoutInfo (Container parent, int sizeflag) |
protected GridBagLayoutInfo GetLayoutInfo (Container parent, int sizeflag) |
278 |
{ |
{ |
279 |
return getLayoutInfo (parent, sizeflag); |
return getLayoutInfo (parent, sizeflag); |
280 |
} |
} |
281 |
|
|
282 |
/** |
/** |
283 |
|
* Obsolete. |
284 |
|
*/ |
285 |
|
protected Dimension GetMinSize (Container parent, GridBagLayoutInfo info) |
286 |
|
{ |
287 |
|
return getMinSize (parent, info); |
288 |
|
} |
289 |
|
|
290 |
|
/** |
291 |
* @since 1.4 |
* @since 1.4 |
292 |
*/ |
*/ |
293 |
protected Dimension getMinSize (Container parent, GridBagLayoutInfo info) |
protected Dimension getMinSize (Container parent, GridBagLayoutInfo info) |
295 |
if (parent == null || info == null) |
if (parent == null || info == null) |
296 |
return new Dimension (0, 0); |
return new Dimension (0, 0); |
297 |
|
|
298 |
int width = 0; |
Insets insets = parent.getInsets(); |
299 |
int height = 0; |
int width = sumIntArray (info.colWidths) + insets.left + insets.right; |
300 |
|
int height = sumIntArray (info.rowHeights) + insets.top + insets.bottom; |
301 |
|
return new Dimension (width, height); |
302 |
|
} |
303 |
|
|
304 |
|
private void calcCellSizes (int[] sizes, double[] weights) |
305 |
|
{ |
306 |
|
int diff = sumIntArray (sizes); |
307 |
|
|
308 |
|
if (diff == 0) |
309 |
|
return; |
310 |
|
|
311 |
|
double weight = sumDoubleArray (weights); |
312 |
|
|
313 |
for (int i = 0; i < info.cols; i++) |
for (int i = 0; i < sizes.length; i++) |
314 |
width += info.colWidths [i]; |
{ |
315 |
|
sizes [i] += (int) (((double) diff) * weights [i] / weight ); |
316 |
|
|
317 |
|
if (sizes [i] < 0) |
318 |
|
sizes [i] = 0; |
319 |
|
} |
320 |
|
} |
321 |
|
|
322 |
for (int i = 0; i < info.rows; i++) |
private void dumpLayoutInfo (GridBagLayoutInfo info) |
323 |
height += info.rowHeights [i]; |
{ |
324 |
|
System.out.println ("GridBagLayoutInfo:"); |
325 |
|
System.out.println ("cols: " + info.cols + ", rows: " + info.rows); |
326 |
|
System.out.println ("colWiths: " + info.colWidths); |
327 |
|
System.out.println ("rowHeights: " + info.rowHeights); |
328 |
|
System.out.println ("colWeights: " + info.colWeights); |
329 |
|
System.out.println ("rowWeights: " + info.rowWeights); |
330 |
|
} |
331 |
|
|
332 |
|
/** |
333 |
|
* @since 1.4 |
334 |
|
*/ |
335 |
|
protected void arrangeGrid (Container parent) |
336 |
|
{ |
337 |
Insets insets = parent.getInsets(); |
Insets insets = parent.getInsets(); |
338 |
width += insets.left + insets.right; |
Component[] components = parent.getComponents(); |
|
height += insets.top + insets.bottom; |
|
339 |
|
|
340 |
return new Dimension (width, height); |
if (components.length == 0 |
341 |
|
&& (colWidths == null || colWidths.length == 0) |
342 |
|
&& (rowHeights == null || rowHeights.length == 0)) |
343 |
|
return; |
344 |
|
|
345 |
|
GridBagLayoutInfo info = getLayoutInfo (parent, PREFERREDSIZE); |
346 |
|
if (info.cols == 0 && info.rows == 0) |
347 |
|
return; |
348 |
|
layoutInfo = info; |
349 |
|
|
350 |
|
// DEBUG |
351 |
|
dumpLayoutInfo (layoutInfo); |
352 |
|
|
353 |
|
calcCellSizes (layoutInfo.colWidths, layoutInfo.colWeights); |
354 |
|
calcCellSizes (layoutInfo.rowHeights, layoutInfo.rowWeights); |
355 |
|
|
356 |
|
// DEBUG |
357 |
|
dumpLayoutInfo (layoutInfo); |
358 |
|
|
359 |
|
throw new Error ("Not implemented"); |
360 |
} |
} |
361 |
|
|
362 |
protected Dimension GetMinSize (Container parent, GridBagLayoutInfo info) |
/** |
363 |
|
* @since 1.4 |
364 |
|
*/ |
365 |
|
protected GridBagLayoutInfo getLayoutInfo (Container parent, int sizeflag) |
366 |
{ |
{ |
367 |
return getMinSize (parent, info); |
if (sizeflag != MINSIZE && sizeflag != PREFERREDSIZE) |
368 |
|
throw new IllegalArgumentException(); |
369 |
|
|
370 |
|
GridBagLayoutInfo info = new GridBagLayoutInfo (MAXGRIDSIZE, MAXGRIDSIZE); |
371 |
|
Dimension dimension = sizeflag == MINSIZE ? parent.getMinimumSize() |
372 |
|
: parent.getPreferredSize(); |
373 |
|
|
374 |
|
// FIXME |
375 |
|
|
376 |
|
return info; |
377 |
|
} |
378 |
|
|
379 |
|
/** |
380 |
|
* @since 1.4 |
381 |
|
*/ |
382 |
|
protected void adjustForGravity (GridBagConstraints gbc, Rectangle rect) |
383 |
|
{ |
384 |
|
// FIXME |
385 |
|
throw new Error ("Not implemented"); |
386 |
} |
} |
387 |
} |
} |