示例#1
0
文件: TextArea.java 项目: kewgen/awt
  public void drawItem(Graphics graphics, int itemIndex, int position) {
    graphics.setColor(color);
    String string = (String) strings.elementAt(itemIndex);

    com.geargames.common.Render render = Render.getInstance();
    if (font == null) {
      byte old = render.getFont();
      render.setFont(customFontId);
      render.drawString(
          graphics,
          string,
          indexes[itemIndex * 2 + 1],
          position + fontMetric.getAscent(graphics),
          0,
          com.geargames.common.Render.FONT_SMALL);
      render.setFont(old);
    } else {
      render.drawString(
          graphics,
          string,
          indexes[itemIndex * 2 + 1],
          position + fontMetric.getAscent(graphics),
          0,
          com.geargames.common.Render.FONT_SYSTEM);
    }
  }
示例#2
0
文件: TextArea.java 项目: kewgen/awt
  public void initiate(Graphics graphics) {
    if (data == null || graphics == null) {
      throw new IllegalArgumentException();
    }
    getRegion().setMinX(getX());
    getRegion().setMinY(getY());
    getRegion().setWidth(getWidth());
    getRegion().setHeight(getHeight());
    com.geargames.common.Render render = Render.getInstance();
    byte oldFontId = 0;
    if (font == null) {
      fontMetric = CustomFontMetric.getInstance();
      oldFontId = render.getFont();
      render.setFont(customFontId);
    } else {
      fontMetric = AwtFontMetric.getInstance();
    }
    indexes = TextHelper.indexData(data, getRegion(), graphics, fontMetric, format);
    strings = new Vector(indexes.length / 2 + 1);
    if (!isEllipsis()) {
      motionListener =
          ScrollHelper.createVerticalMotionListener(
              vericalMotionListener,
              stubMotionListener,
              getRegion(),
              indexes.length / 2,
              rawHeight,
              format);
    } else {
      motionListener =
          ScrollHelper.createStubMotionListener(
              stubMotionListener, getRegion(), indexes.length / 2, rawHeight, format);
    }
    setStrictlyClipped(isEllipsis());
    if (font == null) {
      render.setFont(oldFontId);
    } else graphics.setFont(font, false);
    String string;
    for (int i = 0; i < getItemsAmount(); i++) {
      if (!isEllipsis() || i + 1 != getRegion().getHeight() / getRawHeight()) {
        if (i != getItemsAmount() - 1) {
          string = data.substring(indexes[i * 2], indexes[(i + 1) * 2]).concat(NEW_STRING);
        } else {
          string = data.substring(indexes[i * 2], indexes[(i + 1) * 2]);
        }
      } else {
        if (i != getItemsAmount() - 1) {
          string = data.substring(indexes[i * 2], indexes[(i + 1) * 2] - 3).concat("...");
        } else {
          string = data.substring(indexes[i * 2], indexes[(i + 1) * 2]).concat(NEW_STRING);
        }
      }
      strings.addElement(string);
    }

    setInitiated(true);
  }