예제 #1
0
  private int calcMaxSegment() {
    String text = label.getText();
    char[] chars = text.toCharArray();
    int position = 0;
    int maxWidth = 0;

    for (int i = 0; i < chars.length; i++) {
      if (canBreakAfter(chars[i])) {
        int tempMaxWidth;
        String st = text.substring(position, i + 1);
        tempMaxWidth = FigureUtilities.getStringExtents(st, getFont()).width;

        if (tempMaxWidth > maxWidth) {
          maxWidth = tempMaxWidth;
        }
        position = i;
      }
    }
    String st = text.substring(position, chars.length);
    int tempMaxWidth = FigureUtilities.getStringExtents(st, getFont()).width;

    if (tempMaxWidth > maxWidth) {
      maxWidth = tempMaxWidth;
    }
    return maxWidth + getInsets().getWidth();
  }
예제 #2
0
 private static int getFontAverageCharWidth(Font f) {
   StringBuffer buf = new StringBuffer(""); // $NON-NLS-1$
   for (int i = 'A'; i <= 'Z'; i++) {
     buf.append((char) i);
   }
   for (int i = 'a'; i <= 'z'; i++) {
     buf.append((char) i);
   }
   Dimension dim = FigureUtilities.getStringExtents(buf.toString(), f);
   return (int) div(dim.width, 52);
 }