| 1 | |
package net.miginfocom.swing; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
import net.miginfocom.layout.*; |
| 37 | |
|
| 38 | |
import javax.swing.*; |
| 39 | |
import javax.swing.Timer; |
| 40 | |
import java.awt.*; |
| 41 | |
import java.awt.event.ActionEvent; |
| 42 | |
import java.awt.event.ActionListener; |
| 43 | |
import java.io.*; |
| 44 | |
import java.util.*; |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public final class MigLayout implements LayoutManager2, Externalizable |
| 51 | |
{ |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
private final Map<Component, Object> scrConstrMap = new IdentityHashMap<Component, Object>(8); |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
private Object layoutConstraints = "", colConstraints = "", rowConstraints = ""; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
private transient ContainerWrapper cacheParentW = null; |
| 65 | |
|
| 66 | |
private transient final Map<ComponentWrapper, CC> ccMap = new HashMap<ComponentWrapper, CC>(8); |
| 67 | |
private transient javax.swing.Timer debugTimer = null; |
| 68 | |
|
| 69 | |
private transient LC lc = null; |
| 70 | |
private transient AC colSpecs = null, rowSpecs = null; |
| 71 | |
private transient Grid grid = null; |
| 72 | |
private transient int lastModCount = PlatformDefaults.getModCount(); |
| 73 | |
private transient int lastHash = -1; |
| 74 | |
private transient Dimension lastInvalidSize = null; |
| 75 | |
private transient boolean lastWasInvalid = false; |
| 76 | |
private transient Dimension lastParentSize = null; |
| 77 | |
|
| 78 | |
private transient ArrayList<LayoutCallback> callbackList = null; |
| 79 | |
|
| 80 | |
private transient boolean dirty = true; |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
public MigLayout() |
| 85 | |
{ |
| 86 | |
this("", "", ""); |
| 87 | |
} |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
public MigLayout(String layoutConstraints) |
| 93 | |
{ |
| 94 | |
this(layoutConstraints, "", ""); |
| 95 | |
} |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
public MigLayout(String layoutConstraints, String colConstraints) |
| 102 | |
{ |
| 103 | |
this(layoutConstraints, colConstraints, ""); |
| 104 | |
} |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
public MigLayout(String layoutConstraints, String colConstraints, String rowConstraints) |
| 112 | |
{ |
| 113 | |
setLayoutConstraints(layoutConstraints); |
| 114 | |
setColumnConstraints(colConstraints); |
| 115 | |
setRowConstraints(rowConstraints); |
| 116 | |
} |
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
public MigLayout(LC layoutConstraints) |
| 122 | |
{ |
| 123 | |
this(layoutConstraints, null, null); |
| 124 | |
} |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
public MigLayout(LC layoutConstraints, AC colConstraints) |
| 131 | |
{ |
| 132 | |
this(layoutConstraints, colConstraints, null); |
| 133 | |
} |
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
public MigLayout(LC layoutConstraints, AC colConstraints, AC rowConstraints) |
| 141 | |
{ |
| 142 | |
setLayoutConstraints(layoutConstraints); |
| 143 | |
setColumnConstraints(colConstraints); |
| 144 | |
setRowConstraints(rowConstraints); |
| 145 | |
} |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
public Object getLayoutConstraints() |
| 153 | |
{ |
| 154 | |
return layoutConstraints; |
| 155 | |
} |
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
public void setLayoutConstraints(Object constr) |
| 164 | |
{ |
| 165 | |
if (constr == null || constr instanceof String) { |
| 166 | |
constr = ConstraintParser.prepare((String) constr); |
| 167 | |
lc = ConstraintParser.parseLayoutConstraint((String) constr); |
| 168 | |
} else if (constr instanceof LC) { |
| 169 | |
lc = (LC) constr; |
| 170 | |
} else { |
| 171 | |
throw new IllegalArgumentException("Illegal constraint type: " + constr.getClass().toString()); |
| 172 | |
} |
| 173 | |
layoutConstraints = constr; |
| 174 | |
dirty = true; |
| 175 | |
} |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
public Object getColumnConstraints() |
| 182 | |
{ |
| 183 | |
return colConstraints; |
| 184 | |
} |
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
public void setColumnConstraints(Object constr) |
| 193 | |
{ |
| 194 | |
if (constr == null || constr instanceof String) { |
| 195 | |
constr = ConstraintParser.prepare((String) constr); |
| 196 | |
colSpecs = ConstraintParser.parseColumnConstraints((String) constr); |
| 197 | |
} else if (constr instanceof AC) { |
| 198 | |
colSpecs = (AC) constr; |
| 199 | |
} else { |
| 200 | |
throw new IllegalArgumentException("Illegal constraint type: " + constr.getClass().toString()); |
| 201 | |
} |
| 202 | |
colConstraints = constr; |
| 203 | |
dirty = true; |
| 204 | |
} |
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
public Object getRowConstraints() |
| 213 | |
{ |
| 214 | |
return rowConstraints; |
| 215 | |
} |
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
public void setRowConstraints(Object constr) |
| 224 | |
{ |
| 225 | |
if (constr == null || constr instanceof String) { |
| 226 | |
constr = ConstraintParser.prepare((String) constr); |
| 227 | |
rowSpecs = ConstraintParser.parseRowConstraints((String) constr); |
| 228 | |
} else if (constr instanceof AC) { |
| 229 | |
rowSpecs = (AC) constr; |
| 230 | |
} else { |
| 231 | |
throw new IllegalArgumentException("Illegal constraint type: " + constr.getClass().toString()); |
| 232 | |
} |
| 233 | |
rowConstraints = constr; |
| 234 | |
dirty = true; |
| 235 | |
} |
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
public Map<Component, Object> getConstraintMap() |
| 241 | |
{ |
| 242 | |
return new IdentityHashMap<Component, Object>(scrConstrMap); |
| 243 | |
} |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
public void setConstraintMap(Map<Component, Object> map) |
| 249 | |
{ |
| 250 | |
scrConstrMap.clear(); |
| 251 | |
ccMap.clear(); |
| 252 | |
for (Map.Entry<Component, Object> e : map.entrySet()) |
| 253 | |
setComponentConstraintsImpl(e.getKey(), e.getValue(), true); |
| 254 | |
} |
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
public Object getComponentConstraints(Component comp) |
| 266 | |
{ |
| 267 | |
synchronized(comp.getParent().getTreeLock()) { |
| 268 | |
return scrConstrMap.get(comp); |
| 269 | |
} |
| 270 | |
} |
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
public void setComponentConstraints(Component comp, Object constr) |
| 281 | |
{ |
| 282 | |
setComponentConstraintsImpl(comp, constr, false); |
| 283 | |
} |
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
private void setComponentConstraintsImpl(Component comp, Object constr, boolean noCheck) |
| 295 | |
{ |
| 296 | |
Container parent = comp.getParent(); |
| 297 | |
synchronized(parent != null ? parent.getTreeLock() : new Object()) { |
| 298 | |
if (noCheck == false && scrConstrMap.containsKey(comp) == false) |
| 299 | |
throw new IllegalArgumentException("Component must already be added to parent!"); |
| 300 | |
|
| 301 | |
ComponentWrapper cw = new SwingComponentWrapper(comp); |
| 302 | |
|
| 303 | |
if (constr == null || constr instanceof String) { |
| 304 | |
String cStr = ConstraintParser.prepare((String) constr); |
| 305 | |
|
| 306 | |
scrConstrMap.put(comp, constr); |
| 307 | |
ccMap.put(cw, ConstraintParser.parseComponentConstraint(cStr)); |
| 308 | |
|
| 309 | |
} else if (constr instanceof CC) { |
| 310 | |
|
| 311 | |
scrConstrMap.put(comp, constr); |
| 312 | |
ccMap.put(cw, (CC) constr); |
| 313 | |
|
| 314 | |
} else { |
| 315 | |
throw new IllegalArgumentException("Constraint must be String or ComponentConstraint: " + constr.getClass().toString()); |
| 316 | |
} |
| 317 | |
|
| 318 | |
dirty = true; |
| 319 | |
} |
| 320 | |
} |
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
public boolean isManagingComponent(Component c) |
| 327 | |
{ |
| 328 | |
return scrConstrMap.containsKey(c); |
| 329 | |
} |
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
public void addLayoutCallback(LayoutCallback callback) |
| 335 | |
{ |
| 336 | |
if (callback == null) |
| 337 | |
throw new NullPointerException(); |
| 338 | |
|
| 339 | |
if (callbackList == null) |
| 340 | |
callbackList = new ArrayList<LayoutCallback>(1); |
| 341 | |
|
| 342 | |
callbackList.add(callback); |
| 343 | |
} |
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
public void removeLayoutCallback(LayoutCallback callback) |
| 349 | |
{ |
| 350 | |
if (callbackList != null) |
| 351 | |
callbackList.remove(callback); |
| 352 | |
} |
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
private void setDebug(final ComponentWrapper parentW, boolean b) |
| 366 | |
{ |
| 367 | |
if (b && (debugTimer == null || debugTimer.getDelay() != getDebugMillis())) { |
| 368 | |
if (debugTimer != null) |
| 369 | |
debugTimer.stop(); |
| 370 | |
|
| 371 | |
ContainerWrapper pCW = parentW.getParent(); |
| 372 | |
final Component parent = pCW != null ? (Component) pCW.getComponent() : null; |
| 373 | |
|
| 374 | |
debugTimer = new Timer(getDebugMillis(), new MyDebugRepaintListener()); |
| 375 | |
|
| 376 | |
if (parent != null) { |
| 377 | |
SwingUtilities.invokeLater(new Runnable() { |
| 378 | |
public void run() { |
| 379 | |
Container p = parent.getParent(); |
| 380 | |
if (p != null) { |
| 381 | |
if (p instanceof JComponent) { |
| 382 | |
((JComponent) p).revalidate(); |
| 383 | |
} else { |
| 384 | |
parent.invalidate(); |
| 385 | |
p.validate(); |
| 386 | |
} |
| 387 | |
} |
| 388 | |
} |
| 389 | |
}); |
| 390 | |
} |
| 391 | |
|
| 392 | |
debugTimer.setInitialDelay(100); |
| 393 | |
debugTimer.start(); |
| 394 | |
|
| 395 | |
} else if (!b && debugTimer != null) { |
| 396 | |
debugTimer.stop(); |
| 397 | |
debugTimer = null; |
| 398 | |
} |
| 399 | |
} |
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
|
| 404 | |
private boolean getDebug() |
| 405 | |
{ |
| 406 | |
return debugTimer != null; |
| 407 | |
} |
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
|
| 412 | |
private int getDebugMillis() |
| 413 | |
{ |
| 414 | |
int globalDebugMillis = LayoutUtil.getGlobalDebugMillis(); |
| 415 | |
return globalDebugMillis > 0 ? globalDebugMillis : lc.getDebugMillis(); |
| 416 | |
} |
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
private void checkCache(Container parent) |
| 422 | |
{ |
| 423 | |
if (parent == null) |
| 424 | |
return; |
| 425 | |
|
| 426 | |
if (dirty) |
| 427 | |
grid = null; |
| 428 | |
|
| 429 | |
|
| 430 | |
int mc = PlatformDefaults.getModCount(); |
| 431 | |
if (lastModCount != mc) { |
| 432 | |
grid = null; |
| 433 | |
lastModCount = mc; |
| 434 | |
} |
| 435 | |
|
| 436 | |
if (parent.isValid() == false) { |
| 437 | |
if (lastWasInvalid == false) { |
| 438 | |
lastWasInvalid = true; |
| 439 | |
|
| 440 | |
int hash = 0; |
| 441 | |
boolean resetLastInvalidOnParent = false; |
| 442 | |
for (ComponentWrapper wrapper : ccMap.keySet()) { |
| 443 | |
Object component = wrapper.getComponent(); |
| 444 | |
if (component instanceof JTextArea || component instanceof JEditorPane) |
| 445 | |
resetLastInvalidOnParent = true; |
| 446 | |
hash ^= wrapper.getLayoutHashCode(); |
| 447 | |
hash += 285134905; |
| 448 | |
} |
| 449 | |
if (resetLastInvalidOnParent) |
| 450 | |
resetLastInvalidOnParent(parent); |
| 451 | |
|
| 452 | |
if (hash != lastHash) { |
| 453 | |
grid = null; |
| 454 | |
lastHash = hash; |
| 455 | |
} |
| 456 | |
|
| 457 | |
Dimension ps = parent.getSize(); |
| 458 | |
if (lastInvalidSize == null || !lastInvalidSize.equals(ps)) { |
| 459 | |
if (grid != null) |
| 460 | |
grid.invalidateContainerSize(); |
| 461 | |
lastInvalidSize = ps; |
| 462 | |
} |
| 463 | |
} |
| 464 | |
} else { |
| 465 | |
lastWasInvalid = false; |
| 466 | |
} |
| 467 | |
|
| 468 | |
ContainerWrapper par = checkParent(parent); |
| 469 | |
|
| 470 | |
setDebug(par, getDebugMillis() > 0); |
| 471 | |
|
| 472 | |
if (grid == null) |
| 473 | |
grid = new Grid(par, lc, rowSpecs, colSpecs, ccMap, callbackList); |
| 474 | |
|
| 475 | |
dirty = false; |
| 476 | |
} |
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
private void resetLastInvalidOnParent(Container parent) |
| 482 | |
{ |
| 483 | |
while (parent != null) { |
| 484 | |
LayoutManager layoutManager = parent.getLayout(); |
| 485 | |
if (layoutManager instanceof MigLayout) { |
| 486 | |
((MigLayout) layoutManager).lastWasInvalid = false; |
| 487 | |
} |
| 488 | |
parent = parent.getParent(); |
| 489 | |
} |
| 490 | |
} |
| 491 | |
|
| 492 | |
private ContainerWrapper checkParent(Container parent) |
| 493 | |
{ |
| 494 | |
if (parent == null) |
| 495 | |
return null; |
| 496 | |
|
| 497 | |
if (cacheParentW == null || cacheParentW.getComponent() != parent) |
| 498 | |
cacheParentW = new SwingContainerWrapper(parent); |
| 499 | |
|
| 500 | |
return cacheParentW; |
| 501 | |
} |
| 502 | |
|
| 503 | |
private long lastSize = 0; |
| 504 | |
|
| 505 | |
public void layoutContainer(final Container parent) |
| 506 | |
{ |
| 507 | |
synchronized(parent.getTreeLock()) { |
| 508 | |
checkCache(parent); |
| 509 | |
|
| 510 | |
Insets i = parent.getInsets(); |
| 511 | |
int[] b = new int[] { |
| 512 | |
i.left, |
| 513 | |
i.top, |
| 514 | |
parent.getWidth() - i.left - i.right, |
| 515 | |
parent.getHeight() - i.top - i.bottom |
| 516 | |
}; |
| 517 | |
|
| 518 | |
if (grid.layout(b, lc.getAlignX(), lc.getAlignY(), getDebug(), true)) { |
| 519 | |
grid = null; |
| 520 | |
checkCache(parent); |
| 521 | |
grid.layout(b, lc.getAlignX(), lc.getAlignY(), getDebug(), false); |
| 522 | |
} |
| 523 | |
|
| 524 | |
long newSize = grid.getHeight()[1] + (((long) grid.getWidth()[1]) << 32); |
| 525 | |
if (lastSize != newSize) { |
| 526 | |
lastSize = newSize; |
| 527 | |
final ContainerWrapper containerWrapper = checkParent(parent); |
| 528 | |
Window win = ((Window) SwingUtilities.getAncestorOfClass(Window.class, (Component)containerWrapper.getComponent())); |
| 529 | |
if (win != null) { |
| 530 | |
if (win.isVisible()) { |
| 531 | |
SwingUtilities.invokeLater(new Runnable() { |
| 532 | |
public void run() { |
| 533 | |
adjustWindowSize(containerWrapper); |
| 534 | |
} |
| 535 | |
}); |
| 536 | |
} else { |
| 537 | |
adjustWindowSize(containerWrapper); |
| 538 | |
} |
| 539 | |
} |
| 540 | |
} |
| 541 | |
lastInvalidSize = null; |
| 542 | |
} |
| 543 | |
} |
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | |
|
| 548 | |
private void adjustWindowSize(ContainerWrapper parent) |
| 549 | |
{ |
| 550 | |
BoundSize wBounds = lc.getPackWidth(); |
| 551 | |
BoundSize hBounds = lc.getPackHeight(); |
| 552 | |
|
| 553 | |
if (wBounds == null && hBounds == null) |
| 554 | |
return; |
| 555 | |
|
| 556 | |
Window win = ((Window) SwingUtilities.getAncestorOfClass(Window.class, (Component) parent.getComponent())); |
| 557 | |
if (win == null) |
| 558 | |
return; |
| 559 | |
|
| 560 | |
Dimension prefSize = win.getPreferredSize(); |
| 561 | |
int targW = constrain(checkParent(win), win.getWidth(), prefSize.width, wBounds); |
| 562 | |
int targH = constrain(checkParent(win), win.getHeight(), prefSize.height, hBounds); |
| 563 | |
|
| 564 | |
int x = Math.round(win.getX() - ((targW - win.getWidth()) * (1 - lc.getPackWidthAlign()))); |
| 565 | |
int y = Math.round(win.getY() - ((targH - win.getHeight()) * (1 - lc.getPackHeightAlign()))); |
| 566 | |
|
| 567 | |
win.setBounds(x, y, targW, targH); |
| 568 | |
} |
| 569 | |
|
| 570 | |
private int constrain(ContainerWrapper parent, int winSize, int prefSize, BoundSize constrain) |
| 571 | |
{ |
| 572 | |
if (constrain == null) |
| 573 | |
return winSize; |
| 574 | |
|
| 575 | |
int retSize = winSize; |
| 576 | |
UnitValue wUV = constrain.getPreferred(); |
| 577 | |
if (wUV != null) |
| 578 | |
retSize = wUV.getPixels(prefSize, parent, parent); |
| 579 | |
|
| 580 | |
retSize = constrain.constrain(retSize, prefSize, parent); |
| 581 | |
|
| 582 | |
return constrain.getGapPush() ? Math.max(winSize, retSize) : retSize; |
| 583 | |
} |
| 584 | |
|
| 585 | |
public Dimension minimumLayoutSize(Container parent) |
| 586 | |
{ |
| 587 | |
synchronized(parent.getTreeLock()) { |
| 588 | |
return getSizeImpl(parent, LayoutUtil.MIN); |
| 589 | |
} |
| 590 | |
} |
| 591 | |
|
| 592 | |
public Dimension preferredLayoutSize(Container parent) |
| 593 | |
{ |
| 594 | |
synchronized(parent.getTreeLock()) { |
| 595 | |
if (lastParentSize == null || !parent.getSize().equals(lastParentSize)) { |
| 596 | |
for (ComponentWrapper wrapper : ccMap.keySet()) { |
| 597 | |
Component c = (Component) wrapper.getComponent(); |
| 598 | |
if (c instanceof JTextArea || c instanceof JEditorPane || (c instanceof JComponent && Boolean.TRUE.equals(((JComponent)c).getClientProperty("migLayout.dynamicAspectRatio")))) { |
| 599 | |
layoutContainer(parent); |
| 600 | |
break; |
| 601 | |
} |
| 602 | |
} |
| 603 | |
} |
| 604 | |
|
| 605 | |
lastParentSize = parent.getSize(); |
| 606 | |
return getSizeImpl(parent, LayoutUtil.PREF); |
| 607 | |
} |
| 608 | |
} |
| 609 | |
|
| 610 | |
public Dimension maximumLayoutSize(Container parent) |
| 611 | |
{ |
| 612 | |
return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); |
| 613 | |
} |
| 614 | |
|
| 615 | |
|
| 616 | |
private Dimension getSizeImpl(Container parent, int sizeType) |
| 617 | |
{ |
| 618 | |
checkCache(parent); |
| 619 | |
|
| 620 | |
Insets i = parent.getInsets(); |
| 621 | |
|
| 622 | |
int w = LayoutUtil.getSizeSafe(grid != null ? grid.getWidth() : null, sizeType) + i.left + i.right; |
| 623 | |
int h = LayoutUtil.getSizeSafe(grid != null ? grid.getHeight() : null, sizeType) + i.top + i.bottom; |
| 624 | |
|
| 625 | |
return new Dimension(w, h); |
| 626 | |
} |
| 627 | |
|
| 628 | |
public float getLayoutAlignmentX(Container parent) |
| 629 | |
{ |
| 630 | |
return lc != null && lc.getAlignX() != null ? lc.getAlignX().getPixels(1, checkParent(parent), null) : 0; |
| 631 | |
} |
| 632 | |
|
| 633 | |
public float getLayoutAlignmentY(Container parent) |
| 634 | |
{ |
| 635 | |
return lc != null && lc.getAlignY() != null ? lc.getAlignY().getPixels(1, checkParent(parent), null) : 0; |
| 636 | |
} |
| 637 | |
|
| 638 | |
public void addLayoutComponent(String s, Component comp) |
| 639 | |
{ |
| 640 | |
addLayoutComponent(comp, s); |
| 641 | |
} |
| 642 | |
|
| 643 | |
public void addLayoutComponent(Component comp, Object constraints) |
| 644 | |
{ |
| 645 | |
synchronized(comp.getParent().getTreeLock()) { |
| 646 | |
setComponentConstraintsImpl(comp, constraints, true); |
| 647 | |
} |
| 648 | |
} |
| 649 | |
|
| 650 | |
public void removeLayoutComponent(Component comp) |
| 651 | |
{ |
| 652 | |
synchronized(comp.getParent().getTreeLock()) { |
| 653 | |
scrConstrMap.remove(comp); |
| 654 | |
ccMap.remove(new SwingComponentWrapper(comp)); |
| 655 | |
} |
| 656 | |
} |
| 657 | |
|
| 658 | |
public void invalidateLayout(Container target) |
| 659 | |
{ |
| 660 | |
|
| 661 | |
dirty = true; |
| 662 | |
|
| 663 | |
|
| 664 | |
} |
| 665 | |
|
| 666 | |
|
| 667 | |
|
| 668 | |
|
| 669 | |
|
| 670 | |
private Object readResolve() throws ObjectStreamException |
| 671 | |
{ |
| 672 | |
return LayoutUtil.getSerializedObject(this); |
| 673 | |
} |
| 674 | |
|
| 675 | |
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException |
| 676 | |
{ |
| 677 | |
LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in)); |
| 678 | |
} |
| 679 | |
|
| 680 | |
public void writeExternal(ObjectOutput out) throws IOException |
| 681 | |
{ |
| 682 | |
if (getClass() == MigLayout.class) |
| 683 | |
LayoutUtil.writeAsXML(out, this); |
| 684 | |
} |
| 685 | |
|
| 686 | |
private class MyDebugRepaintListener implements ActionListener |
| 687 | |
{ |
| 688 | |
public void actionPerformed(ActionEvent e) |
| 689 | |
{ |
| 690 | |
if (grid != null) { |
| 691 | |
Component comp = (Component) grid.getContainer().getComponent(); |
| 692 | |
if (comp.isShowing()) { |
| 693 | |
grid.paintDebug(); |
| 694 | |
return; |
| 695 | |
} |
| 696 | |
} |
| 697 | |
debugTimer.stop(); |
| 698 | |
debugTimer = null; |
| 699 | |
} |
| 700 | |
} |
| 701 | |
} |