/**
   * Paints the word-wrapped text.
   *
   * @param g The graphics context in which to paint.
   * @param a The shape (usually a rectangle) in which to paint.
   */
  public void paint(Graphics g, Shape a) {

    Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
    tabBase = alloc.x;

    Graphics2D g2d = (Graphics2D) g;
    host = (RSyntaxTextArea) getContainer();
    int ascent = host.getMaxAscent();
    int fontHeight = host.getLineHeight();
    FoldManager fm = host.getFoldManager();
    TokenPainter painter = host.getTokenPainter();
    Element root = getElement();

    // Whether token styles should always be painted, even in selections
    int selStart = host.getSelectionStart();
    int selEnd = host.getSelectionEnd();
    boolean useSelectedTextColor = host.getUseSelectedTextColor();

    int n = getViewCount(); // Number of lines.
    int x = alloc.x + getLeftInset();
    tempRect.y = alloc.y + getTopInset();
    Rectangle clip = g.getClipBounds();
    for (int i = 0; i < n; i++) {

      tempRect.x = x + getOffset(X_AXIS, i);
      // tempRect.y = y + getOffset(Y_AXIS, i);
      tempRect.width = getSpan(X_AXIS, i);
      tempRect.height = getSpan(Y_AXIS, i);
      // System.err.println("For line " + i + ": tempRect==" + tempRect);

      if (tempRect.intersects(clip)) {
        Element lineElement = root.getElement(i);
        int startOffset = lineElement.getStartOffset();
        int endOffset = lineElement.getEndOffset() - 1; // Why always "-1"?
        View view = getView(i);
        if (!useSelectedTextColor
            || selStart == selEnd
            || (startOffset >= selEnd || endOffset < selStart)) {
          drawView(painter, g2d, alloc, view, fontHeight, tempRect.y + ascent);
        } else {
          // System.out.println("Drawing line with selection: " + i);
          drawViewWithSelection(
              painter, g2d, alloc, view, fontHeight, tempRect.y + ascent, selStart, selEnd);
        }
      }

      tempRect.y += tempRect.height;

      Fold possibleFold = fm.getFoldForLine(i);
      if (possibleFold != null && possibleFold.isCollapsed()) {
        i += possibleFold.getCollapsedLineCount();
        // Visible indicator of collapsed lines
        Color c = RSyntaxUtilities.getFoldedLineBottomColor(host);
        if (c != null) {
          g.setColor(c);
          g.drawLine(x, tempRect.y - 1, alloc.width, tempRect.y - 1);
        }
      }
    }
  }
Example #2
0
  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);
      }
    }
  }
Example #3
0
  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);
    }
  }
  @Override
  protected void paintContentBorderTopEdge(
      Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
    if (tabPane.getTabCount() < 1) return;

    g.setColor(shadow);
    g.drawLine(x, y, x + w - 2, y);
  }
Example #5
0
  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);
    }
  }
 @Override
 protected void paintTabBackground(
     Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
   g = g.create();
   try {
     internalPaintTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
   } finally {
     g.dispose();
   }
 }
Example #7
0
 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);
 }
  @Override
  protected void paintContentBorderBottomEdge(
      Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
    if (tabPane.getTabCount() < 1) return;

    g.setColor(shadow);
    g.drawLine(x + 1, y + h - 3, x + w - 2, y + h - 3);
    g.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
    g.setColor(shadow.brighter());
    g.drawLine(x + 2, y + h - 1, x + w - 1, y + h - 1);
  }
    public void paint(Graphics g) {
      g.setColor(getBackground());
      g.fillRect(0, 0, getWidth(), getHeight());

      for (int i = 0; i < numImages; i++) {
        if (x[i] > 3 * i) {
          nudge(i);
          squish(g, icon[i], xh[i], yh[i], scale[i]);
        } else {
          x[i] += .05;
          y[i] += .05;
        }
      }
    }
Example #10
0
  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.getSelectionEnd();

    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.getSelectionEndLine();
      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;
        x2 = textArea._offsetToX(line, selectionEnd - lineStart);
      } else {
        x1 = 0;
        x2 = getWidth();
      }

      // "inlined" min/max()
      gfx.fillRect(x1 > x2 ? x2 : x1, y, x1 > x2 ? (x1 - x2) : (x2 - x1), height);
    }
  }
Example #11
0
    /** @{inheritDoc} */
    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);

      g = g.create();

      try {
        AntialiasingManager.activateAntialiasing(g);

        g.setColor(Color.DARK_GRAY);
        g.fillRoundRect(0, 0, this.getWidth(), this.getHeight(), 10, 10);
      } finally {
        g.dispose();
      }
    }
  protected void paintBackgroundSafely(final Graphics g) {
    final JTextComponent c = getComponent();
    final int width = c.getWidth();
    final int height = c.getHeight();

    // a delegate takes precedence
    if (delegate != null) {
      delegate.paint(c, g, 0, 0, width, height);
      return;
    }

    final boolean isOpaque = c.isOpaque();
    if (!(c.getBorder() instanceof AquaTextFieldBorder)) {
      // developer must have set a custom border
      if (!isOpaque && AquaUtils.hasOpaqueBeenExplicitlySet(c)) return;

      // must fill whole region with background color if opaque
      g.setColor(c.getBackground());
      g.fillRect(0, 0, width, height);
      return;
    }

    // using our own border
    g.setColor(c.getBackground());
    if (isOpaque) {
      g.fillRect(0, 0, width, height);
      return;
    }

    final Insets margin = c.getMargin();
    Insets insets = c.getInsets();

    if (insets == null) insets = new Insets(0, 0, 0, 0);
    if (margin != null) {
      insets.top -= margin.top;
      insets.left -= margin.left;
      insets.bottom -= margin.bottom;
      insets.right -= margin.right;
    }

    // the common case
    final int shrinkage = AquaTextFieldBorder.getShrinkageFor(c, height);
    g.fillRect(
        insets.left - 2,
        insets.top - shrinkage - 1,
        width - insets.right - insets.left + 4,
        height - insets.bottom - insets.top + shrinkage * 2 + 2);
  }
Example #13
0
 /**
  * Renders using the given rendering surface and area on that surface.
  *
  * @param g the rendering surface to use
  * @param allocation the allocated region to render into
  * @see View#paint
  */
 public void paint(Graphics g, Shape allocation) {
   super.paint(g, allocation);
   Rectangle alloc = allocation.getBounds();
   Rectangle clip = g.getClipBounds();
   // Since listPainter paints in the insets we have to check for the
   // case where the child is not painted because the paint region is
   // to the left of the child. This assumes the ListPainter paints in
   // the left margin.
   if ((clip.x + clip.width) < (alloc.x + getLeftInset())) {
     Rectangle childRect = alloc;
     alloc = getInsideAllocation(allocation);
     int n = getViewCount();
     int endY = clip.y + clip.height;
     for (int i = 0; i < n; i++) {
       childRect.setBounds(alloc);
       childAllocation(i, childRect);
       if (childRect.y < endY) {
         if ((childRect.y + childRect.height) >= clip.y) {
           listPainter.paint(
               g, childRect.x, childRect.y, childRect.width, childRect.height, this, i);
         }
       } else {
         break;
       }
     }
   }
 }
Example #14
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();
  }
Example #15
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);

    if (eolMarkers) {
      gfx.setColor(eolMarkerColor);
      gfx.drawString(".", x, y);
    }
  }
Example #16
0
  /**
   * 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();
    }
  }
Example #17
0
  protected void paintCaret(Graphics gfx, int line, int y) {
    if (textArea.isCaretVisible()) {
      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();

      gfx.setColor(caretColor);

      if (textArea.isOverwriteEnabled()) {
        gfx.fillRect(caretX, y + height - 1, caretWidth, 1);
      } else {
        gfx.drawRect(caretX, y, caretWidth - 1, height - 1);
      }
    }
  }
 public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(Color.white);
   g.fillRect(0, 0, c.getWidth(), c.getHeight());
   if (getImageObserver() == null) {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         c);
   } else {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         getImageObserver());
   }
 }
Example #19
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);
    }
  }
 public void squish(Graphics g, ImageIcon icon, int x, int y, double scale) {
   if (isVisible()) {
     g.drawImage(
         icon.getImage(),
         x,
         y,
         (int) (icon.getIconWidth() * scale),
         (int) (icon.getIconHeight() * scale),
         this);
   }
 }
Example #21
0
  /**
   * Draw the line numbers
   *
   * @param g
   */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    //	Determine the width of the space available to draw the line number

    FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
    Insets insets = getInsets();
    int availableWidth = getSize().width - insets.left - insets.right;

    //  Determine the rows to draw within the clipped bounds.

    Rectangle clip = g.getClipBounds();
    int rowStartOffset = component.viewToModel(new Point(0, clip.y));
    int endOffset = component.viewToModel(new Point(0, clip.y + clip.height));

    while (rowStartOffset <= endOffset) {
      try {
        if (isCurrentLine(rowStartOffset)) g.setColor(getCurrentLineForeground());
        else g.setColor(getForeground());

        //  Get the line number as a string and then determine the
        //  "X" and "Y" offsets for drawing the string.

        String lineNumber = getTextLineNumber(rowStartOffset);
        int stringWidth = fontMetrics.stringWidth(lineNumber);
        int x = getOffsetX(availableWidth, stringWidth) + insets.left;
        int y = getOffsetY(rowStartOffset, fontMetrics);
        g.drawString(lineNumber, x, y);

        //  Move to the next row

        rowStartOffset = Utilities.getRowEnd(component, rowStartOffset) + 1;
      } catch (Exception e) {
        break;
      }
    }
  }
Example #22
0
 public void actionPerformed(ActionEvent e) {
   PrintJob pjob = getToolkit().getPrintJob(textViewerFrame, "Printing Nslm", null);
   if (pjob != null) {
     Graphics pg = pjob.getGraphics();
     if (pg != null) {
       // todo: this should print from
       // the file not from the screen.
       // if (editor1!=null) {
       //    editor1.print(pg); //print crashes, must use printAll
       // }
       // if (scroller1!=null) {
       //    scroller1.printAll(pg); //is clipping on left
       // }
       if (scroller1 != null) {
         JViewport jvp = scroller1.getViewport();
         jvp.printAll(pg);
       }
       pg.dispose();
     }
     pjob.end();
   }
 }
  /**
   * Paints the word-wrapped text.
   *
   * @param g The graphics context in which to paint.
   * @param a The shape (usually a rectangle) in which to paint.
   */
  public void paint(Graphics g, Shape a) {

    Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
    tabBase = alloc.x;

    Graphics2D g2d = (Graphics2D) g;
    host = (RSyntaxTextArea) getContainer();
    int ascent = host.getMaxAscent();
    int fontHeight = host.getLineHeight();
    FoldManager fm = host.getFoldManager();

    int n = getViewCount(); // Number of lines.
    int x = alloc.x + getLeftInset();
    tempRect.y = alloc.y + getTopInset();
    Rectangle clip = g.getClipBounds();
    for (int i = 0; i < n; i++) {
      tempRect.x = x + getOffset(X_AXIS, i);
      // tempRect.y = y + getOffset(Y_AXIS, i);
      tempRect.width = getSpan(X_AXIS, i);
      tempRect.height = getSpan(Y_AXIS, i);
      // System.err.println("For line " + i + ": tempRect==" + tempRect);
      if (tempRect.intersects(clip)) {
        View view = getView(i);
        drawView(g2d, alloc, view, fontHeight, tempRect.y + ascent);
      }
      tempRect.y += tempRect.height;
      Fold possibleFold = fm.getFoldForLine(i);
      if (possibleFold != null && possibleFold.isCollapsed()) {
        i += possibleFold.getCollapsedLineCount();
        // Visible indicator of collapsed lines
        Color c = RSyntaxUtilities.getFoldedLineBottomColor(host);
        if (c != null) {
          g.setColor(c);
          g.drawLine(x, tempRect.y - 1, alloc.width, tempRect.y - 1);
        }
      }
    }
  }
Example #24
0
  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);

    if (eolMarkers) {
      gfx.setColor(eolMarkerColor);
      gfx.drawString(".", x, y);
    }
  }
Example #25
0
 public void paint(Graphics g) {
   super.paint(g);
   if (!isEditing) return;
   Dimension psize = getPreferredSize();
   if (isFocused) g.setColor(Color.yellow);
   else g.setColor(Color.green);
   g.drawLine(0, 0, psize.width, 0);
   g.drawLine(0, 0, 0, psize.height);
   g.drawLine(0, psize.height - 1, psize.width - 1, psize.height - 1);
   g.drawLine(psize.width - 1, 0, psize.width - 1, psize.height - 1);
 }
Example #26
0
  protected void paintLine(Graphics gfx, TokenMarker tokenMarker, int line, int x) {
    Font defaultFont = getFont();
    Color defaultColor = getForeground();

    currentLineIndex = line;
    int y = textArea.lineToY(line);

    if (line < 0 || line >= textArea.getLineCount()) {
      if (paintInvalid) {
        paintHighlight(gfx, line, y);
        styles[Token.INVALID].setGraphicsFlags(gfx, defaultFont);
        gfx.drawString("~", 0, y + fm.getHeight());
      }
    } else if (tokenMarker == null) {
      paintPlainLine(gfx, line, defaultFont, defaultColor, x, y);
    } else {
      paintSyntaxLine(gfx, tokenMarker, line, defaultFont, defaultColor, x, y);
    }
  }
 protected void paintRoundedBottomTabBorder(
     int tabIndex, Graphics g, int x1, int y1, int x2, int y2, boolean isSelected) {
   Graphics2D g2D = (Graphics2D) g;
   Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
   g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   int d = 2 * GAP;
   if (isSelected) {
     g.setColor(AbstractLookAndFeel.getTheme().getFrameColor());
   } else {
     g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getTheme().getFrameColor(), 40));
   }
   g.drawLine(x1 + GAP, y2, x2 - GAP, y2);
   g.drawArc(x1, y2 - d, d, d, 180, 90);
   g.drawArc(x2 - d, y2 - d, d, d, -90, 90);
   g.drawLine(x1, y1, x1, y2 - GAP - 1);
   g.drawLine(x2, y1, x2, y2 - GAP - 1);
   g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint);
 }
    @Override
    public void paint(Graphics g) {
      Color origColor;
      boolean isPressed, isRollOver, isEnabled;
      int w, h, size;

      w = getWidth();
      h = getHeight();
      origColor = g.getColor();
      isPressed = getModel().isPressed();
      isRollOver = getModel().isRollover();
      isEnabled = isEnabled();

      g.setColor(getBackground());
      g.fillRect(0, 0, w, h);

      g.setColor(shadow);
      // Using the background color set above
      if (direction == WEST) {
        g.drawLine(0, 0, 0, h - 1); // left
        g.drawLine(w - 1, 0, w - 1, 0); // right
      } else g.drawLine(w - 2, h - 1, w - 2, 0); // right

      g.drawLine(0, 0, w - 2, 0); // top

      if (isRollOver) {
        // do highlights or shadows
        Color color1;
        Color color2;

        if (isPressed) {
          color2 = Color.WHITE;
          color1 = shadow;
        } else {
          color1 = Color.WHITE;
          color2 = shadow;
        }

        g.setColor(color1);

        if (direction == WEST) {
          g.drawLine(1, 1, 1, h - 1); // left
          g.drawLine(1, 1, w - 2, 1); // top
          g.setColor(color2);
          g.drawLine(w - 1, h - 1, w - 1, 1); // right
        } else {
          g.drawLine(0, 1, 0, h - 1);
          g.drawLine(0, 1, w - 3, 1); // top
          g.setColor(color2);
          g.drawLine(w - 3, h - 1, w - 3, 1); // right
        }
      }

      // g.drawLine(0, h - 1, w - 1, h - 1); //bottom

      // If there's no room to draw arrow, bail
      if (h < 5 || w < 5) {
        g.setColor(origColor);
        return;
      }

      if (isPressed) {
        g.translate(1, 1);
      }

      // Draw the arrow
      size = Math.min((h - 4) / 3, (w - 4) / 3);
      size = Math.max(size, 2);

      boolean highlight = false;

      if (!highlightedTabs.isEmpty()
          && ((direction == WEST && tabScroller.scrollBackwardButton.isEnabled())
              || (direction == EAST && tabScroller.scrollForwardButton.isEnabled()))) {
        Rectangle viewRect = tabScroller.viewport.getViewRect();

        if (direction == WEST) {
          int leadingTabIndex = getClosestTab(viewRect.x, viewRect.y);

          for (int i = 0; i < leadingTabIndex; i++) {
            if (highlightedTabs.contains(i) && !isScrollTabVisible(i)) {
              highlight = true;
              break;
            }
          }
        } else {
          int leadingTabIndex = getClosestTab(viewRect.x + viewRect.y, viewRect.y);

          for (int i = leadingTabIndex; i < tabPane.getTabCount(); i++) {
            if (highlightedTabs.contains(i) && !isScrollTabVisible(i)) {
              highlight = true;
              break;
            }
          }
        }

        if (highlight) {
          Image img =
              DesktopUtilActivator.getImage(
                  direction == WEST
                      ? "service.gui.icons.TAB_UNREAD_BACKWARD_ICON"
                      : "service.gui.icons.TAB_UNREAD_FORWARD_ICON");

          int wi = img.getWidth(null);

          g.drawImage(img, (w - wi) / 2, (h - size) / 2 - 2 /* 2 borders 1px width*/, null);
        }
      }

      if (!highlight) paintTriangle(g, (w - size) / 2, (h - size) / 2, size, direction, isEnabled);

      // Reset the Graphics back to it's original settings
      if (isPressed) {
        g.translate(-1, -1);
      }
      g.setColor(origColor);
    }
  /**
   * Actually paints the text area. Only lines that have been damaged are repainted.
   *
   * @param g The graphics context with which to paint.
   * @param a The allocated region in which to render.
   */
  @Override
  public void paint(Graphics g, Shape a) {

    RSyntaxDocument document = (RSyntaxDocument) getDocument();

    Rectangle alloc = a.getBounds();

    tabBase = alloc.x;
    host = (RSyntaxTextArea) getContainer();

    Rectangle clip = g.getClipBounds();
    // An attempt to speed things up for files with long lines.  Note that
    // this will actually slow things down a bit for the common case of
    // regular-length lines, but it doesn't make a perceivable difference.
    clipStart = clip.x;
    clipEnd = clipStart + clip.width;

    lineHeight = host.getLineHeight();
    ascent = host.getMaxAscent(); // metrics.getAscent();
    int heightAbove = clip.y - alloc.y;
    int linesAbove = Math.max(0, heightAbove / lineHeight);

    FoldManager fm = host.getFoldManager();
    linesAbove += fm.getHiddenLineCountAbove(linesAbove, true);
    Rectangle lineArea = lineToRect(a, linesAbove);
    int y = lineArea.y + ascent;
    int x = lineArea.x;
    Element map = getElement();
    int lineCount = map.getElementCount();

    // Whether token styles should always be painted, even in selections
    int selStart = host.getSelectionStart();
    int selEnd = host.getSelectionEnd();

    RSyntaxTextAreaHighlighter h = (RSyntaxTextAreaHighlighter) host.getHighlighter();

    Graphics2D g2d = (Graphics2D) g;
    Token token;
    // System.err.println("Painting lines: " + linesAbove + " to " + (endLine-1));

    TokenPainter painter = host.getTokenPainter();
    int line = linesAbove;
    // int count = 0;
    while (y < clip.y + clip.height + ascent && line < lineCount) {

      Fold fold = fm.getFoldForLine(line);
      Element lineElement = map.getElement(line);
      int startOffset = lineElement.getStartOffset();
      // int endOffset = (line==lineCount ? lineElement.getEndOffset()-1 :
      //							lineElement.getEndOffset()-1);
      int endOffset = lineElement.getEndOffset() - 1; // Why always "-1"?
      h.paintLayeredHighlights(g2d, startOffset, endOffset, a, host, this);

      // Paint a line of text.
      token = document.getTokenListForLine(line);
      if (selStart == selEnd || startOffset >= selEnd || endOffset < selStart) {
        drawLine(painter, token, g2d, x, y, line);
      } else {
        // System.out.println("Drawing line with selection: " + line);
        drawLineWithSelection(painter, token, g2d, x, y, selStart, selEnd);
      }

      if (fold != null && fold.isCollapsed()) {

        // Visible indicator of collapsed lines
        Color c = RSyntaxUtilities.getFoldedLineBottomColor(host);
        if (c != null) {
          g.setColor(c);
          g.drawLine(x, y + lineHeight - ascent - 1, host.getWidth(), y + lineHeight - ascent - 1);
        }

        // Skip to next line to paint, taking extra care for lines with
        // block ends and begins together, e.g. "} else {"
        do {
          int hiddenLineCount = fold.getLineCount();
          if (hiddenLineCount == 0) {
            // Fold parser identified a zero-line fold region.
            // This is really a bug, but we'll be graceful here
            // and avoid an infinite loop.
            break;
          }
          line += hiddenLineCount;
          fold = fm.getFoldForLine(line);
        } while (fold != null && fold.isCollapsed());
      }

      y += lineHeight;
      line++;
      // count++;

    }

    // System.out.println("SyntaxView: lines painted=" + count);

  }
Example #30
0
 public void paint(Graphics g) {
   g.drawImage(logo, 0, 0, this);
 }