20 package net.sf.gridarta.gui.utils;
22 import java.awt.Component;
23 import java.awt.Container;
24 import java.awt.Dimension;
25 import java.awt.Insets;
26 import java.awt.LayoutManager2;
27 import java.io.Serializable;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
76 private static final Dimension
EMPTY =
new Dimension(0, 0);
110 private Component
cN;
124 private Component
cE;
138 private Component
cS;
152 private Component
cW;
159 private Component
cC;
166 private Component
cU;
173 private Component
cD;
192 @SuppressWarnings(
"ChainOfInstanceofChecks")
195 if (constraints ==
null) {
200 if (constraints instanceof Integer) {
202 }
else if (!(constraints instanceof
Direction)) {
203 throw new IllegalArgumentException(
"DirectionLayout does not support " + constraints.getClass().getName() +
" constraints.");
207 synchronized (comp.getTreeLock()) {
248 throw new IllegalArgumentException(
"DirectionLayout does not support String constraints.");
252 @SuppressWarnings(
"ObjectEquality")
254 synchronized (comp.getTreeLock()) {
257 }
else if (
cN == comp) {
259 }
else if (
cE == comp) {
261 }
else if (
cS == comp) {
263 }
else if (
cW == comp) {
265 }
else if (
cNE == comp) {
267 }
else if (
cSE == comp) {
269 }
else if (
cSW == comp) {
271 }
else if (
cNW == comp) {
273 }
else if (
cU == comp) {
275 }
else if (
cD == comp) {
284 synchronized (parent.getTreeLock()) {
285 final Dimension dim =
new Dimension(0, 0);
297 dim.height =
vGap * 4 + dNW.height +
max(dW.height, dN.height) +
max(dSW.height, dC.height, dNE.height) +
max(dS.height, dE.height) + dSE.height +
max(dU.height, dD.height);
298 dim.width =
max(
hGap * 2 + dSW.width +
max(dNW.width, dC.width, dSE.width) + dNE.width,
hGap +
max(dW.width, dS.width) +
max(dN.width, dE.width),
max(dNW.width, dSE.width));
299 final Insets insets = parent.getInsets();
300 dim.width += insets.left + insets.right;
301 dim.height += insets.top + insets.bottom;
314 return component ==
null ?
EMPTY : component.getMinimumSize();
320 synchronized (parent.getTreeLock()) {
321 final Dimension dim =
new Dimension(0, 0);
333 dim.height =
vGap * 4 + dNW.height +
max(dW.height, dN.height) +
max(dSW.height, dC.height, dNE.height) +
max(dS.height, dE.height) + dSE.height +
max(dU.height, dD.height);
334 dim.width =
hGap * 2 + dSW.width +
max(dNW.width, dC.width, dSE.width) + dNE.width;
335 final Insets insets = parent.getInsets();
336 dim.width += insets.left + insets.right;
337 dim.height += insets.top + insets.bottom;
350 return component ==
null ?
EMPTY : component.getMinimumSize();
356 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
376 synchronized (parent.getTreeLock()) {
377 final Dimension size = parent.getSize();
378 final Insets padding = parent.getInsets();
379 final int innerWidth = size.width - padding.left - padding.right;
380 final int innerHeight = size.height - padding.top - padding.bottom;
386 if (
cW !=
null ||
cN !=
null) {
389 if (
cSW !=
null ||
cC !=
null ||
cNE !=
null) {
392 if (
cS !=
null ||
cE !=
null) {
399 if (
cU !=
null ||
cD !=
null) {
405 final int colWidth = (innerWidth -
hGap * 2) / 3;
406 final int rowHeight = (innerHeight -
vGap * (rows - 1)) / rows;
407 int top = padding.top;
408 final int left = padding.left;
410 cNW.setBounds(left + colWidth +
hGap, top, colWidth, rowHeight);
411 top += rowHeight +
vGap;
413 if (
cW !=
null ||
cN !=
null) {
415 cW.setBounds(left + ((colWidth +
hGap) / 2), top, colWidth, rowHeight);
418 cN.setBounds(left + ((colWidth +
hGap) * 3 / 2), top, colWidth, rowHeight);
420 top += rowHeight +
vGap;
422 if (
cSW !=
null ||
cC !=
null ||
cNE !=
null) {
424 cSW.setBounds(left, top, colWidth, rowHeight);
427 cC.setBounds(left + colWidth +
hGap, top, colWidth, rowHeight);
430 cNE.setBounds(left + ((colWidth +
hGap) * 2), top, colWidth, rowHeight);
432 top += rowHeight +
vGap;
434 if (
cS !=
null ||
cE !=
null) {
436 cS.setBounds(left + ((colWidth +
hGap) / 2), top, colWidth, rowHeight);
439 cE.setBounds(left + ((colWidth +
hGap) * 3 / 2), top, colWidth, rowHeight);
441 top += rowHeight +
vGap;
444 cSE.setBounds(left + colWidth +
hGap, top, colWidth, rowHeight);
445 top += rowHeight +
vGap;
447 if (
cU !=
null ||
cD !=
null) {
449 cU.setBounds(left + ((colWidth +
hGap) / 2), top, colWidth, rowHeight);
452 cD.setBounds(left + ((colWidth +
hGap) * 3 / 2), top, colWidth, rowHeight);
454 top += rowHeight +
vGap;
462 return getClass().getName() +
"[hGap=" +
hGap +
",vGap=" +
vGap +
']';
473 private static int max(@NotNull
final int... numbers) {
474 int ret = Integer.MIN_VALUE;
475 for (
final int number : numbers) {