1 11 package org.eclipse.swt.layout; 12 13 import org.eclipse.swt.*; 14 import org.eclipse.swt.graphics.*; 15 import org.eclipse.swt.widgets.*; 16 17 47 public final class GridData { 48 61 public int verticalAlignment = CENTER; 62 63 76 public int horizontalAlignment = BEGINNING; 77 78 87 public int widthHint = SWT.DEFAULT; 88 89 98 public int heightHint = SWT.DEFAULT; 99 100 106 public int horizontalIndent = 0; 107 108 116 public int verticalIndent = 0; 117 118 124 public int horizontalSpan = 1; 125 126 132 public int verticalSpan = 1; 133 134 163 public boolean grabExcessHorizontalSpace = false; 164 165 194 public boolean grabExcessVerticalSpace = false; 195 196 209 public int minimumWidth = 0; 210 211 224 public int minimumHeight = 0; 225 226 237 public boolean exclude = false; 238 239 244 public static final int BEGINNING = SWT.BEGINNING; 245 246 251 public static final int CENTER = 2; 252 253 258 public static final int END = 3; 259 260 265 public static final int FILL = SWT.FILL; 266 267 274 public static final int VERTICAL_ALIGN_BEGINNING = 1 << 1; 275 276 283 public static final int VERTICAL_ALIGN_CENTER = 1 << 2; 284 285 292 public static final int VERTICAL_ALIGN_END = 1 << 3; 293 294 301 public static final int VERTICAL_ALIGN_FILL = 1 << 4; 302 303 310 public static final int HORIZONTAL_ALIGN_BEGINNING = 1 << 5; 311 312 319 public static final int HORIZONTAL_ALIGN_CENTER = 1 << 6; 320 321 328 public static final int HORIZONTAL_ALIGN_END = 1 << 7; 329 330 337 public static final int HORIZONTAL_ALIGN_FILL = 1 << 8; 338 339 346 public static final int GRAB_HORIZONTAL = 1 << 9; 347 348 355 public static final int GRAB_VERTICAL = 1 << 10; 356 357 366 public static final int FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL; 367 368 377 public static final int FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL; 378 379 388 public static final int FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL; 389 390 int cacheWidth = -1, cacheHeight = -1; 391 int defaultWhint, defaultHhint, defaultWidth = -1, defaultHeight = -1; 392 int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1; 393 394 398 public GridData () { 399 super (); 400 } 401 402 408 public GridData (int style) { 409 super (); 410 if ((style & VERTICAL_ALIGN_BEGINNING) != 0) verticalAlignment = BEGINNING; 411 if ((style & VERTICAL_ALIGN_CENTER) != 0) verticalAlignment = CENTER; 412 if ((style & VERTICAL_ALIGN_FILL) != 0) verticalAlignment = FILL; 413 if ((style & VERTICAL_ALIGN_END) != 0) verticalAlignment = END; 414 if ((style & HORIZONTAL_ALIGN_BEGINNING) != 0) horizontalAlignment = BEGINNING; 415 if ((style & HORIZONTAL_ALIGN_CENTER) != 0) horizontalAlignment = CENTER; 416 if ((style & HORIZONTAL_ALIGN_FILL) != 0) horizontalAlignment = FILL; 417 if ((style & HORIZONTAL_ALIGN_END) != 0) horizontalAlignment = END; 418 grabExcessHorizontalSpace = (style & GRAB_HORIZONTAL) != 0; 419 grabExcessVerticalSpace = (style & GRAB_VERTICAL) != 0; 420 } 421 422 432 public GridData (int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace) { 433 this (horizontalAlignment, verticalAlignment, grabExcessHorizontalSpace, grabExcessVerticalSpace, 1, 1); 434 } 435 436 448 public GridData (int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace, int horizontalSpan, int verticalSpan) { 449 super (); 450 this.horizontalAlignment = horizontalAlignment; 451 this.verticalAlignment = verticalAlignment; 452 this.grabExcessHorizontalSpace = grabExcessHorizontalSpace; 453 this.grabExcessVerticalSpace = grabExcessVerticalSpace; 454 this.horizontalSpan = horizontalSpan; 455 this.verticalSpan = verticalSpan; 456 } 457 458 468 public GridData (int width, int height) { 469 super (); 470 this.widthHint = width; 471 this.heightHint = height; 472 } 473 474 void computeSize (Control control, int wHint, int hHint, boolean flushCache) { 475 if (cacheWidth != -1 && cacheHeight != -1) return; 476 if (wHint == this.widthHint && hHint == this.heightHint) { 477 if (defaultWidth == -1 || defaultHeight == -1 || wHint != defaultWhint || hHint != defaultHhint) { 478 Point size = control.computeSize (wHint, hHint, flushCache); 479 defaultWhint = wHint; 480 defaultHhint = hHint; 481 defaultWidth = size.x; 482 defaultHeight = size.y; 483 } 484 cacheWidth = defaultWidth; 485 cacheHeight = defaultHeight; 486 return; 487 } 488 if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) { 489 Point size = control.computeSize (wHint, hHint, flushCache); 490 currentWhint = wHint; 491 currentHhint = hHint; 492 currentWidth = size.x; 493 currentHeight = size.y; 494 } 495 cacheWidth = currentWidth; 496 cacheHeight = currentHeight; 497 } 498 499 void flushCache () { 500 cacheWidth = cacheHeight = -1; 501 defaultWidth = defaultHeight = -1; 502 currentWidth = currentHeight = -1; 503 } 504 505 String getName () { 506 String string = getClass ().getName (); 507 int index = string.lastIndexOf ('.'); 508 if (index == -1) return string; 509 return string.substring (index + 1, string.length ()); 510 } 511 512 518 public String toString () { 519 String hAlign = ""; 520 switch (horizontalAlignment) { 521 case SWT.FILL: hAlign = "SWT.FILL"; break; 522 case SWT.BEGINNING: hAlign = "SWT.BEGINNING"; break; 523 case SWT.LEFT: hAlign = "SWT.LEFT"; break; 524 case SWT.END: hAlign = "SWT.END"; break; 525 case END: hAlign = "GridData.END"; break; 526 case SWT.RIGHT: hAlign = "SWT.RIGHT"; break; 527 case SWT.CENTER: hAlign = "SWT.CENTER"; break; 528 case CENTER: hAlign = "GridData.CENTER"; break; 529 default: hAlign = "Undefined "+horizontalAlignment; break; 530 } 531 String vAlign = ""; 532 switch (verticalAlignment) { 533 case SWT.FILL: vAlign = "SWT.FILL"; break; 534 case SWT.BEGINNING: vAlign = "SWT.BEGINNING"; break; 535 case SWT.TOP: vAlign = "SWT.TOP"; break; 536 case SWT.END: vAlign = "SWT.END"; break; 537 case END: vAlign = "GridData.END"; break; 538 case SWT.BOTTOM: vAlign = "SWT.BOTTOM"; break; 539 case SWT.CENTER: vAlign = "SWT.CENTER"; break; 540 case CENTER: vAlign = "GridData.CENTER"; break; 541 default: vAlign = "Undefined "+verticalAlignment; break; 542 } 543 String string = getName()+" {"; 544 string += "horizontalAlignment="+hAlign+" "; 545 if (horizontalIndent != 0) string += "horizontalIndent="+horizontalIndent+" "; 546 if (horizontalSpan != 1) string += "horizontalSpan="+horizontalSpan+" "; 547 if (grabExcessHorizontalSpace) string += "grabExcessHorizontalSpace="+grabExcessHorizontalSpace+" "; 548 if (widthHint != SWT.DEFAULT) string += "widthHint="+widthHint+" "; 549 if (minimumWidth != 0) string += "minimumWidth="+minimumWidth+" "; 550 string += "verticalAlignment="+vAlign+" "; 551 if (verticalIndent != 0) string += "verticalIndent="+verticalIndent+" "; 552 if (verticalSpan != 1) string += "verticalSpan="+verticalSpan+" "; 553 if (grabExcessVerticalSpace) string += "grabExcessVerticalSpace="+grabExcessVerticalSpace+" "; 554 if (heightHint != SWT.DEFAULT) string += "heightHint="+heightHint+" "; 555 if (minimumHeight != 0) string += "minimumHeight="+minimumHeight+" "; 556 if (exclude) string += "exclude="+exclude+" "; 557 string = string.trim(); 558 string += "}"; 559 return string; 560 } 561 } 562 | Popular Tags |