1 11 package org.eclipse.ui.forms.widgets; 12 13 import org.eclipse.jface.action.IMenuManager; 14 import org.eclipse.jface.action.IToolBarManager; 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.dnd.DragSourceListener; 17 import org.eclipse.swt.dnd.DropTargetListener; 18 import org.eclipse.swt.dnd.Transfer; 19 import org.eclipse.swt.graphics.Color; 20 import org.eclipse.swt.graphics.Font; 21 import org.eclipse.swt.graphics.Image; 22 import org.eclipse.swt.graphics.Point; 23 import org.eclipse.swt.graphics.Rectangle; 24 import org.eclipse.swt.widgets.Composite; 25 import org.eclipse.swt.widgets.Control; 26 import org.eclipse.swt.widgets.Layout; 27 import org.eclipse.swt.widgets.Menu; 28 import org.eclipse.ui.forms.IFormColors; 29 import org.eclipse.ui.forms.IMessage; 30 import org.eclipse.ui.forms.events.IHyperlinkListener; 31 import org.eclipse.ui.internal.forms.widgets.FormHeading; 32 import org.eclipse.ui.internal.forms.widgets.FormUtil; 33 34 92 public class Form extends Composite { 93 private FormHeading head; 94 95 private Composite body; 96 97 private SizeCache bodyCache = new SizeCache(); 98 99 private SizeCache headCache = new SizeCache(); 100 101 private FormText selectionText; 102 103 private class FormLayout extends Layout implements ILayoutExtension { 104 public int computeMinimumWidth(Composite composite, boolean flushCache) { 105 return computeSize(composite, 5, SWT.DEFAULT, flushCache).x; 106 } 107 108 public int computeMaximumWidth(Composite composite, boolean flushCache) { 109 return computeSize(composite, SWT.DEFAULT, SWT.DEFAULT, flushCache).x; 110 } 111 112 public Point computeSize(Composite composite, int wHint, int hHint, 113 boolean flushCache) { 114 if (flushCache) { 115 bodyCache.flush(); 116 headCache.flush(); 117 } 118 bodyCache.setControl(body); 119 headCache.setControl(head); 120 121 int width = 0; 122 int height = 0; 123 124 Point hsize = headCache.computeSize(FormUtil.getWidthHint(wHint, 125 head), SWT.DEFAULT); 126 width = Math.max(hsize.x, width); 127 height = hsize.y; 128 129 boolean ignoreBody=getData(FormUtil.IGNORE_BODY)!=null; 130 131 Point bsize; 132 if (ignoreBody) 133 bsize = new Point(0,0); 134 else 135 bsize = bodyCache.computeSize(FormUtil.getWidthHint(wHint, 136 body), SWT.DEFAULT); 137 width = Math.max(bsize.x, width); 138 height += bsize.y; 139 return new Point(width, height); 140 } 141 142 protected void layout(Composite composite, boolean flushCache) { 143 if (flushCache) { 144 bodyCache.flush(); 145 headCache.flush(); 146 } 147 bodyCache.setControl(body); 148 headCache.setControl(head); 149 Rectangle carea = composite.getClientArea(); 150 151 Point hsize = headCache.computeSize(carea.width, SWT.DEFAULT); 152 headCache.setBounds(0, 0, carea.width, hsize.y); 153 bodyCache 154 .setBounds(0, hsize.y, carea.width, carea.height - hsize.y); 155 } 156 } 157 158 164 public Form(Composite parent, int style) { 165 super(parent, SWT.NO_BACKGROUND | style); 166 super.setLayout(new FormLayout()); 167 head = new FormHeading(this, SWT.NULL); 168 head.setMenu(parent.getMenu()); 169 body = new LayoutComposite(this, SWT.NULL); 170 body.setMenu(parent.getMenu()); 171 } 172 173 179 public void setMenu(Menu menu) { 180 super.setMenu(menu); 181 head.setMenu(menu); 182 body.setMenu(menu); 183 } 184 185 188 public final Point computeSize(int wHint, int hHint, boolean changed) { 189 return ((FormLayout) getLayout()).computeSize(this, wHint, hHint, 190 changed); 191 } 192 193 196 public final void setLayout(Layout layout) { 197 } 198 199 204 public String getText() { 205 return head.getText(); 206 } 207 208 214 public Image getImage() { 215 return head.getImage(); 216 } 217 218 225 public void setForeground(Color fg) { 226 super.setForeground(fg); 227 head.setForeground(fg); 228 body.setForeground(fg); 229 } 230 231 238 public void setBackground(Color bg) { 239 super.setBackground(bg); 240 head.setBackground(bg); 241 body.setBackground(bg); 242 } 243 244 250 public void setFont(Font font) { 251 super.setFont(font); 252 head.setFont(font); 253 } 254 255 270 public void setText(String text) { 271 head.setText(text); 272 layout(); 273 redraw(); 274 } 275 276 290 public void setImage(Image image) { 291 head.setImage(image); 292 layout(); 293 redraw(); 294 } 295 296 311 312 public void setTextBackground(Color[] gradientColors, int[] percents, 313 boolean vertical) { 314 head.setTextBackground(gradientColors, percents, vertical); 315 } 316 317 322 public Image getBackgroundImage() { 323 return head.getHeadingBackgroundImage(); 324 } 325 326 337 public void setBackgroundImage(Image backgroundImage) { 338 head.setHeadingBackgroundImage(backgroundImage); 339 } 340 341 347 public IToolBarManager getToolBarManager() { 348 return head.getToolBarManager(); 349 } 350 351 360 361 public void setToolBarVerticalAlignment(int alignment) { 362 head.setToolBarAlignment(alignment); 363 } 364 365 371 372 public int getToolBarVerticalAlignment() { 373 return head.getToolBarAlignment(); 374 } 375 376 383 public IMenuManager getMenuManager() { 384 return head.getMenuManager(); 385 } 386 387 391 public void updateToolBar() { 392 head.updateToolBar(); 393 } 394 395 402 public Composite getHead() { 403 return head; 404 } 405 406 413 public Control getHeadClient() { 414 return head.getHeadClient(); 415 } 416 417 429 public void setHeadClient(Control headClient) { 430 head.setHeadClient(headClient); 431 layout(); 432 } 433 434 441 public Composite getBody() { 442 return body; 443 } 444 445 452 public boolean isBackgroundImageTiled() { 453 return head.isBackgroundImageTiled(); 454 } 455 456 465 public void setBackgroundImageTiled(boolean backgroundImageTiled) { 466 head.setBackgroundImageTiled(backgroundImageTiled); 467 } 468 469 476 public int getBackgroundImageAlignment() { 477 return SWT.LEFT; 478 } 479 480 489 public void setBackgroundImageAlignment(int backgroundImageAlignment) { 490 } 491 492 500 public boolean isBackgroundImageClipped() { 501 return true; 502 } 503 504 513 public void setBackgroundImageClipped(boolean backgroundImageClipped) { 514 } 515 516 523 public boolean isSeparatorVisible() { 524 return head.isSeparatorVisible(); 525 } 526 527 537 public void setSeparatorVisible(boolean addSeparator) { 538 head.setSeparatorVisible(addSeparator); 539 } 540 541 550 551 public Color getSeparatorColor() { 552 return head.getColor(IFormColors.H_BOTTOM_KEYLINE2); 553 } 554 555 565 public void setSeparatorColor(Color separatorColor) { 566 head.putColor(IFormColors.H_BOTTOM_KEYLINE2, separatorColor); 567 } 568 569 580 581 public void setHeadColor(String key, Color color) { 582 head.putColor(key, color); 583 } 584 585 594 595 public Color getHeadColor(String key) { 596 return head.getColor(key); 597 } 598 599 608 public void setMessage(String message) { 609 this.setMessage(message, 0, null); 610 } 611 612 628 629 public void setMessage(String newMessage, int newType) { 630 this.setMessage(newMessage, newType, null); 631 } 632 633 656 657 public void setMessage(String newMessage, int newType, IMessage[] children) { 658 head.showMessage(newMessage, newType, children); 659 layout(); 660 } 661 662 670 public void addMessageHyperlinkListener(IHyperlinkListener listener) { 671 head.addMessageHyperlinkListener(listener); 672 } 673 674 681 public void removeMessageHyperlinkListener(IHyperlinkListener listener) { 682 head.removeMessageHyperlinkListener(listener); 683 } 684 685 692 693 public boolean isBusy() { 694 return head.isBusy(); 695 } 696 697 705 706 public void setBusy(boolean busy) { 707 head.setBusy(busy); 708 } 709 710 726 public void addTitleDragSupport(int operations, Transfer[] transferTypes, 727 DragSourceListener listener) { 728 head.addDragSupport(operations, transferTypes, listener); 729 } 730 731 747 public void addTitleDropSupport(int operations, Transfer[] transferTypes, 748 DropTargetListener listener) { 749 head.addDropSupport(operations, transferTypes, listener); 750 } 751 752 757 public String getMessage() { 758 return head.getMessage(); 759 } 760 761 766 public int getMessageType() { 767 return head.getMessageType(); 768 } 769 770 778 public IMessage[] getChildrenMessages() { 779 return head.getChildrenMessages(); 780 } 781 782 void setSelectionText(FormText text) { 783 if (selectionText != null && selectionText != text) { 784 selectionText.clearSelection(); 785 } 786 this.selectionText = text; 787 } 788 } | Popular Tags |