示例#1
0
  @Override
  public Point computeSizeHint() {
    updateInput();
    final Point sizeConstraints = getSizeConstraints();
    final Rectangle trim = computeTrim();

    //		int charWidth= 20;
    //		if (fInput.detailInfo != null) {
    //			final int count= Math.min(6, fInfoText.getLineCount());
    //			for (int i= 0; i < count; i++) {
    //				charWidth= Math.max(charWidth, fInfoText.getLine(i).length());
    //			}
    //		}
    int widthHint =
        this.infoText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x + LayoutUtil.defaultHSpacing();
    final int widthMax2 = LayoutUtil.hintWidth(this.infoText, PREF_DETAIL_PANE_FONT, 80);
    final int widthMax =
        ((sizeConstraints != null && sizeConstraints.x != SWT.DEFAULT)
                ? sizeConstraints.x
                : widthMax2)
            - trim.width;
    this.layoutHint = true;
    final int titleHint =
        LayoutUtil.defaultHMargin()
            + this.titleImage.getSize().x
            + LayoutUtil.defaultHSpacing()
            + this.titleText.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
    this.layoutHint = false;
    if (titleHint > widthHint && widthMax2 > widthHint) {
      widthHint = Math.min(widthMax2, titleHint);
    }
    if (widthMax < widthHint) {
      widthHint = widthMax;
    }
    // avoid change of wrapping caused by scrollbar
    if (widthHint < titleHint
        && widthHint + this.infoText.computeTrim(0, 0, 0, 0).width >= titleHint) {
      widthHint = titleHint;
    }

    final int heightMax =
        ((sizeConstraints != null && sizeConstraints.y != SWT.DEFAULT)
                ? sizeConstraints.y
                : this.infoText.getLineHeight() * 12)
            - trim.height;

    final Point size = this.contentComposite.computeSize(widthHint, SWT.DEFAULT, true);
    size.y += LayoutUtil.defaultVSpacing();
    size.x = Math.max(Math.min(size.x, widthMax), 200) + trim.width;
    size.y = Math.max(Math.min(size.y, heightMax), 100) + trim.height;
    return size;
  }
  @Override
  protected void createContent(final Composite parent) {
    fContentComposite =
        new Composite(parent, SWT.NONE) {
          @Override
          public Point computeSize(final int width, final int height, final boolean changed) {
            return super.computeSize(width, height, changed || width != getSize().x);
          }
        };
    fContentComposite.setBackgroundMode(SWT.INHERIT_FORCE);

    final GridLayout gridLayout = LayoutUtil.applyCompositeDefaults(new GridLayout(), 2);
    gridLayout.horizontalSpacing = (int) ((gridLayout.horizontalSpacing) / 1.5);
    fContentComposite.setLayout(gridLayout);

    final int vIndent = Math.max(1, LayoutUtil.defaultVSpacing() / 4);
    final int hIndent = Math.max(2, LayoutUtil.defaultHSpacing() / 3);

    { // Title image
      fTitleImage = new Label(fContentComposite, SWT.NULL);
      final Image image = SharedUIResources.getImages().get(SharedUIResources.PLACEHOLDER_IMAGE_ID);
      fTitleImage.setImage(image);

      final GridData textGd = new GridData(SWT.FILL, SWT.TOP, false, false);
      fTitleText =
          new StyledText(fContentComposite, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP) {
            @Override
            public Point computeSize(int width, final int height, final boolean changed) {
              if (!fLayoutHint && width <= 0 && fContentComposite.getSize().x > 0) {
                width =
                    fContentComposite.getSize().x
                        - LayoutUtil.defaultHMargin()
                        - fTitleImage.getSize().x
                        - LayoutUtil.defaultHSpacing()
                        - 10;
              }

              final Point size = super.computeSize(width, -1, true);
              //					if (width >= 0) {
              //						size.x = Math.min(size.x, width);
              //					}
              return size;
            }
          };

      fTitleText.setFont(JFaceResources.getDialogFont());
      final GC gc = new GC(fTitleText);
      final FontMetrics fontMetrics = gc.getFontMetrics();
      final GridData imageGd = new GridData(SWT.FILL, SWT.TOP, false, false);
      imageGd.horizontalIndent = hIndent;
      final int textHeight = fontMetrics.getAscent() + fontMetrics.getLeading();
      final int imageHeight = image.getBounds().height;
      final int shift = Math.max(3, (int) ((fontMetrics.getDescent()) / 1.5));
      if (textHeight + shift < imageHeight) {
        imageGd.verticalIndent = vIndent + shift;
        textGd.verticalIndent = vIndent + (imageHeight - textHeight);
      } else {
        imageGd.verticalIndent = vIndent + (textHeight - imageHeight) + shift;
        textGd.verticalIndent = vIndent;
      }
      fTitleImage.setLayoutData(imageGd);
      fTitleText.setLayoutData(textGd);
      fLayoutWorkaround = true;

      gc.dispose();
    }

    fInfoText =
        new StyledText(
            fContentComposite,
            fMode == MODE_FOCUS
                ? (SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL)
                : (SWT.MULTI | SWT.READ_ONLY));
    fInfoText.setIndent(hIndent);
    fInfoText.setFont(JFaceResources.getFont(PREF_DETAIL_PANE_FONT));

    final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    //		gd.widthHint = LayoutUtil.hintWidth(fInfoText, INFO_FONT, 50);
    fInfoText.setLayoutData(gd);

    setBackgroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    setForegroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));

    updateInput();
  }