Esempio n. 1
0
 /**
  * Initializes the renderer.
  *
  * @param g graphics reference
  * @param pos current text position
  */
 private void init(final Graphics g, final int pos) {
   font = dfont;
   color = Color.black;
   syntax.init();
   text.init();
   x = off;
   y = off + fontH - pos - 2;
   if (g != null) g.setFont(font);
 }
Esempio n. 2
0
  /**
   * Writes the current string to the graphics reference.
   *
   * @param g graphics reference
   */
  private void write(final Graphics g) {
    if (high) {
      high = false;
    } else {
      color = isEnabled() ? syntax.getColor(text) : Color.gray;
    }

    final int ch = text.curr();
    if (y > 0 && y < h) {
      if (ch == TokenBuilder.MARK) {
        color = GUIConstants.GREEN;
        high = true;
      }

      // mark error
      if (text.erroneous()) {
        g.setColor(GUIConstants.LRED);
        g.fillRect(x, y - fontH + 4, wordW, fontH);
      }

      // mark text
      int xx = x;
      if (text.markStart()) {
        final int p = text.pos();
        while (text.more()) {
          final int cw = charW(g, text.curr());
          if (text.inMark()) {
            g.setColor(GUIConstants.color(3));
            g.fillRect(xx, y - fontH + 4, cw, fontH);
          }
          xx += cw;
          text.next();
        }
        text.pos(p);
      }
      if (found()) {
        int cw = 0;
        for (int c = 0; c < keyword.length(); ++c) {
          cw += charW(g, keyword.charAt(c));
        }
        g.setColor(GUIConstants.color(text.cursor() == text.pos() ? 5 : 2));
        g.fillRect(x, y - fontH + 4, cw, fontH);
      }

      // don't write whitespaces
      if (ch > ' ') {
        g.setColor(color);
        String n = text.nextWord();
        int ww = w - x;
        if (x + wordW > ww) {
          // shorten string if it cannot be completely shown (saves memory)
          int c = 0;
          for (final int nl = n.length(); c < nl && ww > 0; c++) {
            ww -= charW(g, n.charAt(c));
          }
          n = n.substring(0, c);
        }
        g.drawString(n, x, y);
      } else if (ch <= TokenBuilder.MARK) {
        g.setFont(font);
      }

      // show cursor
      if (cursor && text.edited()) {
        xx = x;
        final int p = text.pos();
        while (text.more()) {
          if (text.cursor() == text.pos()) {
            cursor(g, xx);
            break;
          }
          xx += charW(g, text.next());
        }
        text.pos(p);
      }
    }
    next();
  }
Esempio n. 3
0
  /**
   * Writes the current string to the graphics reference.
   *
   * @param g graphics reference
   */
  private void write(final Graphics g) {
    if (high) {
      high = false;
    } else {
      color = isEnabled() ? syntax.getColor(text) : Color.gray;
    }

    final int ch = text.curr();
    if (y > 0 && y < h) {
      if (ch == TokenBuilder.MARK) {
        color = GUIConstants.GREEN;
        high = true;
      }

      // mark selected text
      final int cp = text.pos();
      if (text.selectStart()) {
        int xx = x, cw = 0;
        while (!text.inSelect() && text.more()) xx += charW(g, text.next());
        while (text.inSelect() && text.more()) cw += charW(g, text.next());
        g.setColor(GUIConstants.color(3));
        g.fillRect(xx, y - fontH * 4 / 5, cw, fontH);
        text.pos(cp);
      }

      // mark found text
      int xx = x;
      while (text.more() && text.searchStart()) {
        int cw = 0;
        while (!text.inSearch() && text.more()) xx += charW(g, text.next());
        while (text.inSearch() && text.more()) cw += charW(g, text.next());
        g.setColor(GUIConstants.color2A);
        g.fillRect(xx, y - fontH * 4 / 5, cw, fontH);
        xx += cw;
      }
      text.pos(cp);

      if (text.erroneous()) drawError(g);

      // don't write whitespaces
      if (ch > ' ') {
        g.setColor(color);
        String n = text.nextString();
        int ww = w - x;
        if (x + wordW > ww) {
          // shorten string if it cannot be completely shown (saves memory)
          int c = 0;
          for (final int nl = n.length(); c < nl && ww > 0; c++) {
            ww -= charW(g, n.charAt(c));
          }
          n = n.substring(0, c);
        }
        g.drawString(n, x, y);
      } else if (ch <= TokenBuilder.MARK) {
        g.setFont(font);
      }

      // show cursor
      if (cursor && text.edited()) {
        xx = x;
        while (text.more()) {
          if (text.cursor() == text.pos()) {
            drawCursor(g, xx);
            break;
          }
          xx += charW(g, text.next());
        }
        text.pos(cp);
      }
    }
    next();
  }