コード例 #1
0
ファイル: Outline.java プロジェクト: ShifuCifuentes/ridixcr
  /**
   * Called to recursively paint the check box for the specified item.
   *
   * @param item row number
   * @param g graphics object to paint.
   * @param bookmark to check selected value.
   * @return the next row number to paint.
   */
  public int paintCheckbox(final int item, final Graphics g, final Bookmark bookmark) {
    int nextItem = item + 1;

    if (bookmark != null) {
      final Rectangle checkboxBounds =
          getCheckboxBounds(item, bookmark, getDepthMap().get(bookmark));
      final int yCheckboxMidPoint = checkboxBounds.y + (checkboxBounds.height / 2);
      final int xCheckboxMidPoint = checkboxBounds.x + (checkboxBounds.width / 2);
      final Enumeration e = bookmark.elements();

      if (e.hasMoreElements()) {
        // clear any lines crossing through the checkbox.
        g.clearRect(
            checkboxBounds.x, checkboxBounds.y, checkboxBounds.width, checkboxBounds.height);

        // draw box around checkbox
        g.drawRect(checkboxBounds.x, checkboxBounds.y, checkboxBounds.width, checkboxBounds.height);

        // draw dash inside checkbox
        g.drawLine(
            checkboxBounds.x + 2,
            yCheckboxMidPoint,
            (checkboxBounds.x + checkboxBounds.width) - 2,
            yCheckboxMidPoint);

        boolean drawPlus = true;

        do {
          final Bookmark child = (Bookmark) e.nextElement();
          final Bookmark next = getBookmark(nextItem);

          if (child != next) {
            break;
          }

          drawPlus = false;
          nextItem = paintCheckbox(nextItem, g, child);
        } while (e.hasMoreElements());

        if (drawPlus) {
          g.drawLine(
              xCheckboxMidPoint,
              checkboxBounds.y + 2,
              xCheckboxMidPoint,
              (checkboxBounds.y + checkboxBounds.height) - 2);
        }
      }
    }

    return nextItem;
  }
コード例 #2
0
ファイル: Outline.java プロジェクト: ShifuCifuentes/ridixcr
  /**
   * Called to recursively paint text and lines for the specified item.
   *
   * @param item row number
   * @param g graphics object to paint.
   * @param bookmark to check selected value.
   * @return the next row number to paint.
   */
  public int paintItem(final int item, final Graphics g, final Bookmark bookmark) {
    int nextItem = item + 1;

    if (bookmark != null) {
      final Rectangle textBounds = getTextBounds(item, bookmark, getDepthMap().get(bookmark));
      final int yTextMidPoint = textBounds.y + (textBounds.height / 2);
      final Enumeration e = bookmark.elements();

      final String displayName = bookmark.getDisplayName();

      if (displayName != null) {
        g.drawString(displayName, textBounds.x, textBounds.y + textBounds.height);
      }

      if (e.hasMoreElements()) {
        // draw line from checkbox to text
        g.drawLine(textBounds.x - getFontWidth(), yTextMidPoint, textBounds.x - 2, yTextMidPoint);

        final int xLineToChildren = textBounds.x - (getFontWidth() / 2);
        int southLine = yTextMidPoint;

        do {
          final Bookmark child = (Bookmark) e.nextElement();
          final Bookmark next = getBookmark(nextItem);

          if (child != next) {
            break;
          }

          southLine = (((2 * nextItem) + 1) * getFontHeight()) / 2;
          g.drawLine(xLineToChildren, southLine, textBounds.x - 2, southLine);
          nextItem = paintItem(nextItem, g, child);
        } while (e.hasMoreElements());

        if (southLine > yTextMidPoint) {
          g.drawLine(xLineToChildren, yTextMidPoint, xLineToChildren, southLine);
        }
      } else if (displayName != null) {
        g.drawLine(textBounds.x - getFontWidth(), yTextMidPoint, textBounds.x - 2, yTextMidPoint);
      }
    }

    return nextItem;
  }