protected void paintCaret(Graphics gfx, int line, int y) {
    // System.out.println("painting caret " + line + " " + y);
    if (textArea.isCaretVisible()) {
      // System.out.println("caret is visible");
      int offset = textArea.getCaretPosition() - textArea.getLineStartOffset(line);
      int caretX = textArea._offsetToX(line, offset);
      int caretWidth = ((blockCaret || textArea.isOverwriteEnabled()) ? fm.charWidth('w') : 1);
      y += fm.getLeading() + fm.getMaxDescent();
      int height = fm.getHeight();

      // System.out.println("caretX, width = " + caretX + " " + caretWidth);

      gfx.setColor(caretColor);

      if (textArea.isOverwriteEnabled()) {
        gfx.fillRect(caretX, y + height - 1, caretWidth, 1);

      } else {
        // some machines don't like the drawRect for the single
        // pixel caret.. this caused a lot of hell because on that
        // minority of machines, the caret wouldn't show up past
        // the first column. the fix is to use drawLine() in
        // those cases, as a workaround.
        if (caretWidth == 1) {
          gfx.drawLine(caretX, y, caretX, y + height - 1);
        } else {
          gfx.drawRect(caretX, y, caretWidth - 1, height - 1);
        }
        // gfx.drawRect(caretX, y, caretWidth, height - 1);
      }
    }
  }
  protected void paintSyntaxLine(
      Graphics gfx,
      TokenMarker tokenMarker,
      int line,
      Font defaultFont,
      Color defaultColor,
      int x,
      int y) {
    textArea.getLineText(currentLineIndex, currentLine);
    currentLineTokens = tokenMarker.markTokens(currentLine, currentLineIndex);

    paintHighlight(gfx, line, y);

    gfx.setFont(defaultFont);
    gfx.setColor(defaultColor);
    y += fm.getHeight();
    x = SyntaxUtilities.paintSyntaxLine(currentLine, currentLineTokens, styles, this, gfx, x, y);
    /*
     * Draw characters via input method.
     */
    if (compositionTextPainter != null && compositionTextPainter.hasComposedTextLayout()) {
      compositionTextPainter.draw(gfx, lineHighlightColor);
    }
    if (eolMarkers) {
      gfx.setColor(eolMarkerColor);
      gfx.drawString(".", x, y);
    }
  }
  protected void paintLineHighlight(Graphics gfx, int line, int y) {
    int height = fm.getHeight();
    y += fm.getLeading() + fm.getMaxDescent();

    int selectionStart = textArea.getSelectionStart();
    int selectionEnd = textArea.getSelectionStop();

    if (selectionStart == selectionEnd) {
      if (lineHighlight) {
        gfx.setColor(lineHighlightColor);
        gfx.fillRect(0, y, getWidth(), height);
      }
    } else {
      gfx.setColor(selectionColor);

      int selectionStartLine = textArea.getSelectionStartLine();
      int selectionEndLine = textArea.getSelectionStopLine();
      int lineStart = textArea.getLineStartOffset(line);

      int x1, x2;
      if (textArea.isSelectionRectangular()) {
        int lineLen = textArea.getLineLength(line);
        x1 =
            textArea._offsetToX(
                line,
                Math.min(
                    lineLen, selectionStart - textArea.getLineStartOffset(selectionStartLine)));
        x2 =
            textArea._offsetToX(
                line,
                Math.min(lineLen, selectionEnd - textArea.getLineStartOffset(selectionEndLine)));
        if (x1 == x2) x2++;
      } else if (selectionStartLine == selectionEndLine) {
        x1 = textArea._offsetToX(line, selectionStart - lineStart);
        x2 = textArea._offsetToX(line, selectionEnd - lineStart);
      } else if (line == selectionStartLine) {
        x1 = textArea._offsetToX(line, selectionStart - lineStart);
        x2 = getWidth();
      } else if (line == selectionEndLine) {
        // x1 = 0;
        // hack from stendahl to avoid doing weird side selection thing
        x1 = textArea._offsetToX(line, 0);
        // attempt at getting the gutter too, but doesn't seem to work
        // x1 = textArea._offsetToX(line, -textArea.getHorizontalOffset());
        x2 = textArea._offsetToX(line, selectionEnd - lineStart);
      } else {
        // x1 = 0;
        // hack from stendahl to avoid doing weird side selection thing
        x1 = textArea._offsetToX(line, 0);
        // attempt at getting the gutter too, but doesn't seem to work
        // x1 = textArea._offsetToX(line, -textArea.getHorizontalOffset());
        x2 = getWidth();
      }

      // "inlined" min/max()
      gfx.fillRect(x1 > x2 ? x2 : x1, y, x1 > x2 ? (x1 - x2) : (x2 - x1), height);
    }
  }
 /* (non-Javadoc)
  * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
  */
 public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
   int ret = PAGE_EXISTS;
   String line = null;
   try {
     if (fph.knownPage(page)) {
       in.seek(fph.getFileOffset(page));
       line = in.readLine();
     } else {
       long offset = in.getFilePointer();
       line = in.readLine();
       if (line == null) {
         ret = NO_SUCH_PAGE;
       } else {
         fph.createPage(page);
         fph.setFileOffset(page, offset);
       }
     }
     if (ret == PAGE_EXISTS) {
       // Seite ausgeben, Grafikkontext vorbereiten
       Graphics2D g2 = (Graphics2D) g;
       g2.scale(1.0 / RESMUL, 1.0 / RESMUL);
       int ypos = (int) pf.getImageableY() * RESMUL;
       int xpos = ((int) pf.getImageableX() + 2) * RESMUL;
       int yd = 12 * RESMUL;
       int ymax = ypos + (int) pf.getImageableHeight() * RESMUL - yd;
       // Seitentitel ausgeben
       ypos += yd;
       g2.setColor(Color.black);
       g2.setFont(new Font("Monospaced", Font.BOLD, 10 * RESMUL));
       g.drawString(fbname + " Seite " + (page + 1), xpos, ypos);
       g.drawLine(
           xpos,
           ypos + 6 * RESMUL,
           xpos + (int) pf.getImageableWidth() * RESMUL,
           ypos + 6 * RESMUL);
       ypos += 2 * yd;
       // Zeilen ausgeben
       g2.setColor(new Color(0, 0, 127));
       g2.setFont(new Font("Monospaced", Font.PLAIN, 10 * RESMUL));
       while (line != null) {
         g.drawString(line, xpos, ypos);
         ypos += yd;
         if (ypos >= ymax) {
           break;
         }
         line = in.readLine();
       }
     }
   } catch (IOException e) {
     throw new PrinterException(e.toString());
   }
   return ret;
 }
 protected void paintBracketHighlight(Graphics gfx, int line, int y) {
   int position = textArea.getBracketPosition();
   if (position == -1) {
     return;
   }
   y += fm.getLeading() + fm.getMaxDescent();
   int x = textArea._offsetToX(line, position);
   gfx.setColor(bracketHighlightColor);
   // Hack!!! Since there is no fast way to get the character
   // from the bracket matching routine, we use ( since all
   // brackets probably have the same width anyway
   gfx.drawRect(x, y, fm.charWidth('(') - 1, fm.getHeight() - 1);
 }
Beispiel #6
0
  public void paint(Graphics g) {
    gRef = (Graphics2D) g;

    // change size of font
    gRef.setFont(gRef.getFont().deriveFont(9.0f));

    fmRef = g.getFontMetrics();

    // Clear background

    if (Preferences.monochrome) {
      gRef.setColor(Preferences.whiteColor);
    } else {
      gRef.setColor(Preferences.backgroundColor);
    }
    gRef.fillRect(0, 0, getWidth(), getHeight());

    // set colour to correct drawing colour
    if (Preferences.monochrome) {
      gRef.setColor(Preferences.blackColor);
    } else {
      gRef.setColor(Preferences.penColor);
    }

    gRef.translate(0, margin);

    // Call c code to draw tree
    gRef.scale(scale, scale);
    nativeDrawTree();
  }
  /**
   * Repaints the text.
   *
   * @param gfx The graphics context
   */
  public void paint(Graphics gfx) {
    Graphics2D g2 = (Graphics2D) gfx;
    g2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING,
        antialias
            ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON
            : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

    tabSize =
        fm.charWidth(' ')
            * ((Integer) textArea.getDocument().getProperty(PlainDocument.tabSizeAttribute))
                .intValue();

    Rectangle clipRect = gfx.getClipBounds();

    gfx.setColor(getBackground());
    gfx.fillRect(clipRect.x, clipRect.y, clipRect.width, clipRect.height);

    // We don't use yToLine() here because that method doesn't
    // return lines past the end of the document
    int height = fm.getHeight();
    int firstLine = textArea.getFirstLine();
    int firstInvalid = firstLine + clipRect.y / height;
    // Because the clipRect's height is usually an even multiple
    // of the font height, we subtract 1 from it, otherwise one
    // too many lines will always be painted.
    int lastInvalid = firstLine + (clipRect.y + clipRect.height - 1) / height;

    try {
      TokenMarker tokenMarker = textArea.getDocument().getTokenMarker();
      int x = textArea.getHorizontalOffset();

      for (int line = firstInvalid; line <= lastInvalid; line++) {
        paintLine(gfx, tokenMarker, line, x);
      }

      if (tokenMarker != null && tokenMarker.isNextLineRequested()) {
        int h = clipRect.y + clipRect.height;
        repaint(0, h, getWidth(), getHeight() - h);
      }
    } catch (Exception e) {
      System.err.println(
          "Error repainting line" + " range {" + firstInvalid + "," + lastInvalid + "}:");
      e.printStackTrace();
    }
  }
Beispiel #8
0
  @Override
  public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
    Graphics2D g2;

    if (pageIndex > 0) return Printable.NO_SUCH_PAGE;

    g2 = (Graphics2D) g;

    g2.translate(pf.getImageableX(), pf.getImageableY());

    Dimension imageSize = calcDimension(image, pf.getImageableWidth(), pf.getImageableHeight());

    g2.drawImage(
        image,
        (int) (pf.getImageableWidth() / 2 - imageSize.width / 2),
        (int) (pf.getImageableHeight() / 2 - imageSize.height / 2),
        imageSize.width,
        imageSize.height,
        this);

    g.setXORMode(Color.white);

    Font font = g2.getFont().deriveFont(6);
    g2.setFont(font);
    int fileNameWidth = g2.getFontMetrics(font).stringWidth(fileName);

    if (fileNameWidth > imageSize.width) {
      pathStrings = fileName.split("\\\\");
      result = pathStrings[0] + "\\...\\" + pathStrings[pathStrings.length - 1];
      resultWidth = g.getFontMetrics(font).stringWidth(result);

      // TODO:
      // Add another if for truncating to just a few letters if needed.
    } else {
      result = fileName;
      resultWidth = g.getFontMetrics(font).stringWidth(result);
    }

    g.drawString(
        result,
        (int) (pf.getImageableWidth() / 2 + imageSize.width / 2 - resultWidth - 5),
        (int) (pf.getImageableHeight() / 2 + imageSize.height / 2 - 5));
    return Printable.PAGE_EXISTS;
  }
Beispiel #9
0
  public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {

    if (pi >= 5) {
      return NO_SUCH_PAGE;
    }

    g.drawString("Page : " + (pi + 1), 200, 200);

    return PAGE_EXISTS;
  }
Beispiel #10
0
  protected void paintPlainLine(
      Graphics gfx, int line, Font defaultFont, Color defaultColor, int x, int y) {
    paintHighlight(gfx, line, y);
    textArea.getLineText(line, currentLine);

    gfx.setFont(defaultFont);
    gfx.setColor(defaultColor);

    y += fm.getHeight();
    x = Utilities.drawTabbedText(currentLine, x, y, gfx, this, 0);
    // Draw characters via input method.
    if (compositionTextPainter != null && compositionTextPainter.hasComposedTextLayout()) {
      compositionTextPainter.draw(gfx, lineHighlightColor);
    }
    if (eolMarkers) {
      gfx.setColor(eolMarkerColor);
      gfx.drawString(".", x, y);
    }
  }
Beispiel #11
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (image != null) {
      Dimension imageSize = calcDimension(image);
      System.out.println(imageSize + " or " + imageSize.getWidth());
      g.drawImage(
          image,
          getWidth() / 2 - imageSize.width / 2,
          getHeight() / 2 - imageSize.height / 2,
          imageSize.width,
          imageSize.height,
          this);

      g.setXORMode(Color.white);

      Font font = g.getFont().deriveFont(8);
      g.setFont(font);
      int fileNameWidth = g.getFontMetrics(font).stringWidth(fileName);

      if (fileNameWidth > imageSize.width) {
        pathStrings = fileName.split("\\\\");
        result = pathStrings[0] + "\\...\\" + pathStrings[pathStrings.length - 1];
        resultWidth = g.getFontMetrics(font).stringWidth(result);

        // TODO:
        // Add another if for truncating to just a few letters if needed.
      } else {
        result = fileName;
        resultWidth = g.getFontMetrics(font).stringWidth(result);
      }

      g.drawString(
          result,
          getWidth() / 2 + imageSize.width / 2 - resultWidth - 5,
          getHeight() / 2 + imageSize.height / 2 - 5);
    } else g.drawImage(image, 0, 0, this);
  }
Beispiel #12
0
    public void doPaint(Graphics g) {
      Graphics2D g2 = (Graphics2D) g;

      g2.setColor(Color.black);

      BufferedImage bimg = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);
      Graphics ig = bimg.getGraphics();
      Color alphared = new Color(255, 0, 0, 128);
      Color alphagreen = new Color(0, 255, 0, 128);
      Color alphablue = new Color(0, 0, 255, 128);
      ig.setColor(alphared);
      ig.fillRect(0, 0, 200, 200);
      ig.setColor(alphagreen);
      ig.fillRect(25, 25, 150, 150);
      ig.setColor(alphablue);
      ig.fillRect(75, 75, 125, 125);
      g.drawImage(bimg, 10, 25, this);

      GradientPaint gp = new GradientPaint(10.0f, 10.0f, alphablue, 210.0f, 210.0f, alphared, true);
      g2.setPaint(gp);
      g2.fillRect(10, 240, 200, 200);
    }
  public int print(Graphics g, PageFormat pf, int pageIndex) {
    Font f1 = new Font("SERIF", Font.PLAIN, 8);
    FontMetrics metric = g.getFontMetrics(f1);
    int lineHeight = metric.getHeight();

    if (pageBreak == null) {
      initLines();
      int s = (numLines % 3);
      if (s > 0) numLines = numLines + (3 - s);
      numLines /= 3;

      int linesPerPage = (int) (pf.getImageableHeight() / lineHeight);
      int numBreaks = (numLines / linesPerPage);
      pageBreak = new int[numBreaks];
      for (int b = 0; b < numBreaks; b++) {
        pageBreak[b] = (b + 1) * linesPerPage;
      }
    }

    if (pageIndex > pageBreak.length) {
      return NO_SUCH_PAGE;
    }

    Graphics2D g2d = (Graphics2D) g;
    g2d.translate(pf.getImageableX(), pf.getImageableY());

    int y = 0;

    g.setFont(new Font("SERIF", Font.PLAIN, 9));

    int start = 0;
    if (pageIndex == 0) start = 0;
    else start = pageBreak[pageIndex - 1];

    int end = 0;

    if (pageIndex == pageBreak.length) end = numLines;
    else end = pageBreak[pageIndex];

    if (chk % 2 == 1 && (end - start) != lineHeight) {

      for (int line = start; line < end && i < x; line += 9) {
        y += (2 * lineHeight);
        g.drawString("" + textLines[i][0], 30, y);
        g.drawString(textLines[i][1], 30, y + lineHeight);
        g.drawString(textLines[i][2], 30, y + 2 * lineHeight);
        g.drawString(textLines[i][3], 30, y + 3 * lineHeight);
        g.drawString(textLines[i][4], 30, y + 4 * lineHeight);
        g.drawString(textLines[i][5], 30, y + 5 * lineHeight);
        g.drawString(textLines[i][6], 30, y + 6 * lineHeight);

        if ((i + 1) < x) {
          g.drawString(textLines[i + 1][0], 225, y);
          g.drawString(textLines[i + 1][1], 225, y + lineHeight);
          g.drawString(textLines[i + 1][2], 225, y + 2 * lineHeight);
          g.drawString(textLines[i + 1][3], 225, y + 3 * lineHeight);
          g.drawString(textLines[i + 1][4], 225, y + 4 * lineHeight);
          g.drawString(textLines[i + 1][5], 225, y + 5 * lineHeight);
          g.drawString(textLines[i + 1][6], 225, y + 6 * lineHeight);
        }
        if ((i + 2) < x) {
          g.drawString(textLines[i + 2][0], 415, y);
          g.drawString(textLines[i + 2][1], 415, y + lineHeight);
          g.drawString(textLines[i + 2][2], 415, y + 2 * lineHeight);
          g.drawString(textLines[i + 2][3], 415, y + 3 * lineHeight);
          g.drawString(textLines[i + 2][4], 415, y + 4 * lineHeight);
          g.drawString(textLines[i + 2][5], 415, y + 5 * lineHeight);
          g.drawString(textLines[i + 2][6], 415, y + 6 * lineHeight);
        }
        y += 7 * lineHeight;
        i += 3;
      }

    } else {

      for (int line = start; line < end && i < x; line += 8) {}
    }
    chk++;

    return PAGE_EXISTS;
  }