Example #1
0
  /**
   * Allows reuse of the multi-line text element for computing bounds of changed font/text content
   *
   * @param fd
   */
  public final void reuse(Label la, double forceWrappingSize) {

    final Font f = (Font) xs.createFont(la.getCaption().getFont());
    fm = g2d.getFontMetrics(f);
    final FontRenderContext frc = g2d.getFontRenderContext();

    cachedwidth = Double.NaN;

    String s = la.getCaption().getValue();
    if (s == null) {
      s = IConstants.NULL_STRING;
    } else {
      // trim leading and trailing spaces.
      s = s.trim();
    }

    if (s.length() == 0) // TextLayout DOESN'T LIKE EMPTY STRINGS
    {
      s = IConstants.ONE_SPACE;
    }
    String[] sa = splitOnBreaks(s, forceWrappingSize, f);
    if (sa == null) {
      iLineCount = 1;
      oText = s;
      tla = new TextLayout[1];
      fsa = new String[1];
      tla[0] = new TextLayout(s, f.getAttributes(), frc);
      fsa[0] = s;
    } else {
      iLineCount = sa.length;
      oText = sa;
      tla = new TextLayout[iLineCount];
      fsa = new String[iLineCount];
      for (int i = 0; i < iLineCount; i++) {
        tla[i] = new TextLayout(sa[i], f.getAttributes(), frc);
        fsa[i] = sa[i];
      }
    }
    ins = la.getInsets().scaledInstance(pointsToPixels());

    if (forceWrappingSize > 0) {
      // update label with new broken content.
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < fsa.length; i++) {
        sb.append(fsa[i]).append("\n"); // $NON-NLS-1$
      }

      if (sb.length() > 0) {
        sb.deleteCharAt(sb.length() - 1);
      }

      la.getCaption().setValue(sb.toString());
    }
  }
Example #2
0
 public IText getCaption() {
   Text caption = label.getCaption();
   if (caption == null) {
     caption = ChartComponentUtil.createEMFText();
     label.setCaption(caption);
   }
   return ChartComponentUtil.convertText(caption);
 }
Example #3
0
  /** Only anti-alias rotated, bold text, and font size > 13 */
  private void computeTextAntialiasing() {
    FontDefinition font = la.getCaption().getFont();

    if (font.isBold() || (font.getRotation() % 90 != 0) || font.getSize() > 13) {
      g2d.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    } else {
      g2d.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    }
  }