@Override protected void init() { super.init(); // Initialize currentLine; otherwise, the current line won't start // off as highlighted. currentLine = 0; setLineNumberingStartIndex(1); visibleRect = new Rectangle(); // Must be initialized addMouseListener(this); addMouseMotionListener(this); aaHints = RSyntaxUtilities.getDesktopAntiAliasHints(); }
/** * Creates a line number list to use in the gutter for a text area. * * @param textArea The text area. * @return The line number list. */ public LineNumberList createLineNumberList(RTextArea textArea) { return new LineNumberList(textArea); }
visibleRect = getVisibleRect(); Color bg = getBackground(); if (getGutter()!=null) { // Should always be true bg = getGutter().getBackground(); g.setFont(getFont()); if (aaHints!=null) { ((Graphics2D)g).addRenderingHints(aaHints); paintWrappedLineNumbers(g, visibleRect); return; final int rhsBorderWidth = getRhsBorderWidth(); g.setColor(getForeground()); boolean ltr = getComponentOrientation().isLeftToRight(); if (ltr) { FontMetrics metrics = g.getFontMetrics(); int rhs = getWidth() - rhsBorderWidth; int line = topLine + 1; while (y<visibleRect.y+visibleRect.height+ascent && line<=textArea.getLineCount()) { String number = Integer.toString(line + getLineNumberingStartIndex() - 1); int width = metrics.stringWidth(number); g.drawString(number, rhs-width,y); int line = topLine + 1; while (y<visibleRect.y+visibleRect.height && line<textArea.getLineCount()) { String number = Integer.toString(line + getLineNumberingStartIndex() - 1);
/** * Changes the width of the cells in the JList so you can see every digit * of each. */ void updateCellWidths() { int oldCellWidth = cellWidth; cellWidth = getRhsBorderWidth(); // Adjust the amount of space the line numbers take up, if necessary. if (textArea!=null) { Font font = getFont(); if (font!=null) { FontMetrics fontMetrics = getFontMetrics(font); int count = 0; int lineCount = textArea.getLineCount() + getLineNumberingStartIndex() - 1; do { lineCount = lineCount/10; count++; } while (lineCount >= 10); cellWidth += fontMetrics.charWidth('9')*(count+1) + 3; } } if (cellWidth!=oldCellWidth) { // Always true revalidate(); } }
int width = getWidth(); Rectangle r = LineNumberList.getChildViewBounds(v, topLine, visibleEditorRect); int y = r.y; final int rhsBorderWidth = getRhsBorderWidth(); int rhs; boolean ltr = getComponentOrientation().isLeftToRight(); if (ltr) { rhs = width - rhsBorderWidth; g.setColor(getForeground()); r = LineNumberList.getChildViewBounds(v, topLine, visibleEditorRect); int index = (topLine+1) + getLineNumberingStartIndex() - 1; String number = Integer.toString(index); if (ltr) {
/** * Constructs a new <code>LineNumberList</code>. * * @param textArea The text component for which line numbers will be * displayed. * @param numberColor The color to use for the line numbers. */ public LineNumberList(RTextArea textArea, Color numberColor) { super(textArea); if (numberColor!=null) { setForeground(numberColor); } else { setForeground(Color.GRAY); } // Initialize currentLine; otherwise, the current line won't start // off as highlighted. currentLine = 0; setLineNumberingStartIndex(1); visibleRect = new Rectangle(); // Must be initialized addMouseListener(this); addMouseMotionListener(this); }
/** * Changes the width of the cells in the JList so you can see every digit * of each. */ private void updateCellWidths() { int oldCellWidth = cellWidth; cellWidth = RHS_BORDER_WIDTH; // Adjust the amount of space the line numbers take up, if necessary. if (textArea!=null) { Font font = getFont(); if (font!=null) { FontMetrics fontMetrics = getFontMetrics(font); int count = 0; int lineCount = textArea.getLineCount(); while (lineCount >= 10) { lineCount = lineCount/10; count++; } cellWidth += fontMetrics.charWidth('9')*(count+1) + 5; } } if (cellWidth!=oldCellWidth) { // Always true revalidate(); } }
/** * Sets the text area being displayed. This will clear any tracking * icons currently displayed. * * @param textArea The text area. */ void setTextArea(RTextArea textArea) { if (this.textArea!=null) { listener.uninstall(); } if (lineNumberList==null) { lineNumberList = new LineNumberList(textArea); } else { lineNumberList.setTextArea(textArea); } if (iconArea==null) { iconArea = new IconRowHeader(textArea); } else { iconArea.setTextArea(textArea); } if (textArea!=null) { listener.install(textArea); } this.textArea = textArea; }
/** * Calculates the last line number index painted in this component. * * @return The last line number index painted in this component. */ private int calculateLastVisibleLineNumber() { int lastLine = 0; if (textArea!=null) { lastLine = textArea.getLineCount()+getLineNumberingStartIndex()-1; } return lastLine; }
Rectangle r = LineNumberList.getChildViewBounds(v, topLine, visibleEditorRect); int y = r.y; int curLineH = LineNumberList.getChildViewBounds(v, line, visibleEditorRect).height; y += LineNumberList.getChildViewBounds(v, line, visibleEditorRect).height; line += fold.getLineCount() + 1;
@Override public LineNumberList createLineNumberList(RTextArea textArea) { this.textArea = (PSTextArea) textArea; numberList = super.createLineNumberList(textArea); //numberList.setBorder(BorderFactory.createLineBorder(Color.RED)); numberList.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { PSTextAreaEditorKit.this.textArea.trataCliqueNoNumeroDaLinha(me.getPoint()); } }); return numberList; }
/** * Returns the font used for line numbers. * * @return The font used for line numbers. * @see #setLineNumberFont(Font) */ public Font getLineNumberFont() { return lineNumberList.getFont(); }
/** * Returns the color to use to paint line numbers. * * @return The color used when painting line numbers. * @see #setLineNumberColor(Color) */ public Color getLineNumberColor() { return lineNumberList.getForeground(); }
int width = getWidth(); Rectangle r = LineNumberList.getChildViewBounds(v, topLine, visibleEditorRect); int y = r.y; boolean ltr = getComponentOrientation().isLeftToRight(); if (ltr) { rhs = width - RHS_BORDER_WIDTH; g.setColor(getForeground()); r = LineNumberList.getChildViewBounds(v, topLine, visibleEditorRect); g.setColor(textArea.getCurrentLineHighlightColor()); g.fillRect(0,y, width,(r.y+r.height)-y); g.setColor(getForeground()); int index = (topLine+1) + getLineNumberingStartIndex() - 1; String number = Integer.toString(index); if (ltr) {
/** * Changes the width of the cells in the JList so you can see every digit * of each. */ void updateCellWidths() { int oldCellWidth = cellWidth; cellWidth = getRhsBorderWidth(); // Adjust the amount of space the line numbers take up, if necessary. if (textArea!=null) { Font font = getFont(); if (font!=null) { FontMetrics fontMetrics = getFontMetrics(font); int count = 0; int lineCount = textArea.getLineCount() + getLineNumberingStartIndex() - 1; do { lineCount = lineCount/10; count++; } while (lineCount >= 10); cellWidth += fontMetrics.charWidth('9')*(count+1) + 3; } } if (cellWidth!=oldCellWidth) { // Always true revalidate(); } }
/** * Constructs a new <code>LineNumberList</code>. * * @param textArea The text component for which line numbers will be * displayed. * @param numberColor The color to use for the line numbers. */ public LineNumberList(RTextArea textArea, Color numberColor) { super(textArea); if (numberColor!=null) { setForeground(numberColor); } else { setForeground(Color.GRAY); } // Initialize currentLine; otherwise, the current line won't start // off as highlighted. currentLine = 0; setLineNumberingStartIndex(1); visibleRect = new Rectangle(); // Must be initialized addMouseListener(this); addMouseMotionListener(this); }
/** * Changes the width of the cells in the JList so you can see every digit * of each. */ private void updateCellWidths() { int oldCellWidth = cellWidth; cellWidth = RHS_BORDER_WIDTH; // Adjust the amount of space the line numbers take up, if necessary. if (textArea!=null) { Font font = getFont(); if (font!=null) { FontMetrics fontMetrics = getFontMetrics(font); int count = 0; int lineCount = textArea.getLineCount(); while (lineCount >= 10) { lineCount = lineCount/10; count++; } cellWidth += fontMetrics.charWidth('9')*(count+1) + 5; } } if (cellWidth!=oldCellWidth) { // Always true revalidate(); } }
/** * Sets the text area being displayed. This will clear any tracking * icons currently displayed. * * @param textArea The text area. */ void setTextArea(RTextArea textArea) { if (this.textArea!=null) { listener.uninstall(); } if (lineNumberList==null) { lineNumberList = new LineNumberList(textArea); } else { lineNumberList.setTextArea(textArea); } if (iconArea==null) { iconArea = new IconRowHeader(textArea); } else { iconArea.setTextArea(textArea); } if (textArea!=null) { listener.install(textArea); } this.textArea = textArea; }
/** * Returns the starting line's line number. The default value is * <code>1</code>. * * @return The index * @see #setLineNumberingStartIndex(int) */ public int getLineNumberingStartIndex() { return lineNumberList.getLineNumberingStartIndex(); }
Rectangle r = LineNumberList.getChildViewBounds(v, topLine, visibleEditorRect); int y = r.y; int curLineH = LineNumberList.getChildViewBounds(v, line, visibleEditorRect).height; y += LineNumberList.getChildViewBounds(v, line, visibleEditorRect).height; line += fold.getLineCount() + 1;