protected void paintHighlight(Graphics gfx, int line, int y) { if (line >= textArea.getSelectionStartLine() && line <= textArea.getSelectionEndLine()) paintLineHighlight(gfx, line, y); if (highlights != null) highlights.paintHighlight(gfx, line, y); if (bracketHighlight && line == textArea.getBracketLine()) paintBracketHighlight(gfx, line, y); if (line == textArea.getCaretLine()) paintCaret(gfx, line, y); }
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); }
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 (tokenMarker == null) { paintPlainLine(gfx, line, defaultFont, defaultColor, x, y); } else if (line >= 0 && line < textArea.getLineCount()) { paintSyntaxLine(gfx, tokenMarker, line, defaultFont, defaultColor, x, y); } }
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 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 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 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); } }
public EditorLineStatus(JEditTextArea textarea) { this.textarea = textarea; textarea.editorLineStatus = this; background = Theme.getColor("linestatus.bgcolor"); font = Theme.getFont("linestatus.font"); foreground = Theme.getColor("linestatus.color"); high = Theme.getInteger("linestatus.height"); if (Base.isMacOS()) { resize = Base.getThemeImage("resize.gif", this); } // linestatus.bgcolor = #000000 // linestatus.font = SansSerif,plain,10 // linestatus.color = #FFFFFF }
/** * Finds the next instance of the search string in the specified buffer. * * @param view The view * @param buffer The buffer * @param start Location where to start the search * @param firstTime See {@link * SearchMatcher#nextMatch(CharSequence,boolean,boolean,boolean,boolean)}. * @since jEdit 4.1pre7 */ public static boolean find( View view, Buffer buffer, int start, boolean firstTime, boolean reverse) throws Exception { EditBus.send(new PositionChanging(view.getEditPane())); SearchMatcher matcher = getSearchMatcher(); if (matcher == null) { view.getToolkit().beep(); return false; } CharSequence text; boolean startOfLine; boolean endOfLine; if (reverse) { text = new ReverseCharSequence(buffer.getSegment(0, start)); startOfLine = true; endOfLine = (buffer.getLineEndOffset(buffer.getLineOfOffset(start)) - 1 == start); } else { text = buffer.getSegment(start, buffer.getLength() - start); startOfLine = (buffer.getLineStartOffset(buffer.getLineOfOffset(start)) == start); endOfLine = true; } String noWordSep = buffer.getStringProperty("noWordSep"); matcher.setNoWordSep(noWordSep); SearchMatcher.Match match = matcher.nextMatch(text, startOfLine, endOfLine, firstTime, reverse); if (match != null) { jEdit.commitTemporary(buffer); view.setBuffer(buffer, true); JEditTextArea textArea = view.getTextArea(); if (reverse) { textArea.setSelection(new Selection.Range(start - match.end, start - match.start)); // make sure end of match is visible textArea.scrollTo(start - match.start, false); textArea.moveCaretPosition(start - match.end); } else { textArea.setSelection(new Selection.Range(start + match.start, start + match.end)); textArea.moveCaretPosition(start + match.end); // make sure start of match is visible textArea.scrollTo(start + match.start, false); } return true; } else return false; } // }}}
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); } }
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); } } }
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); } }
/** * Finds the next occurrence of the search string. * * @param view The view * @return True if the operation was successful, false otherwise */ public static boolean find(View view) { // component that will parent any dialog boxes Component comp = SearchDialog.getSearchDialog(view); if (comp == null || !comp.isShowing()) comp = view; String path = fileset.getNextFile(view, null); if (path == null) { GUIUtilities.error(comp, "empty-fileset", null); return false; } try { view.showWaitCursor(); SearchMatcher matcher = getSearchMatcher(); if (matcher == null) { view.getToolkit().beep(); return false; } record(view, "find(view)", false, true); boolean repeat = false; loop: for (; ; ) { while (path != null) { Buffer buffer = jEdit.openTemporary(view, null, path, false); /* this is stupid and misleading. * but 'path' is not used anywhere except * the above line, and if this is done * after the 'continue', then we will * either hang, or be forced to duplicate * it inside the buffer == null, or add * a 'finally' clause. you decide which one's * worse. */ if (reverse) { path = fileset.getPrevFile(view, path); } else { path = fileset.getNextFile(view, path); } if (buffer == null) continue loop; // Wait for the buffer to load if (!buffer.isLoaded()) VFSManager.waitForRequests(); int start; if (view.getBuffer() == buffer && !repeat) { JEditTextArea textArea = view.getTextArea(); Selection s = textArea.getSelectionAtOffset(textArea.getCaretPosition()); if (s == null) start = textArea.getCaretPosition(); else if (reverse) start = s.getStart(); else start = s.getEnd(); } else if (reverse) start = buffer.getLength(); else start = 0; if (find(view, buffer, start, repeat, reverse)) return true; } if (repeat) { if (!BeanShell.isScriptRunning()) { view.getStatus().setMessageAndClear(jEdit.getProperty("view.status.search-not-found")); view.getToolkit().beep(); } return false; } boolean restart; // if auto wrap is on, always restart search. // if auto wrap is off, and we're called from // a macro, stop search. If we're called // interactively, ask the user what to do. if (wrap) { if (!BeanShell.isScriptRunning()) { view.getStatus().setMessageAndClear(jEdit.getProperty("view.status.auto-wrap")); // beep if beep property set if (jEdit.getBooleanProperty("search.beepOnSearchAutoWrap")) { view.getToolkit().beep(); } } restart = true; } else if (BeanShell.isScriptRunning()) { restart = false; } else { Integer[] args = {Integer.valueOf(reverse ? 1 : 0)}; int result = GUIUtilities.confirm( comp, "keepsearching", args, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); restart = (result == JOptionPane.YES_OPTION); } if (restart) { // start search from beginning path = fileset.getFirstFile(view); repeat = true; } else break loop; } } catch (Exception e) { handleError(comp, e); } finally { view.hideWaitCursor(); } return false; } // }}}
/** * Replaces the current selection with the replacement string. * * @param view The view * @return True if the operation was successful, false otherwise */ public static boolean replace(View view) { // component that will parent any dialog boxes Component comp = SearchDialog.getSearchDialog(view); if (comp == null) comp = view; JEditTextArea textArea = view.getTextArea(); Buffer buffer = view.getBuffer(); if (!buffer.isEditable()) return false; boolean smartCaseReplace = getSmartCaseReplace(); Selection[] selection = textArea.getSelection(); if (selection.length == 0) { view.getToolkit().beep(); return false; } record(view, "replace(view)", true, false); // a little hack for reverse replace and find int caret = textArea.getCaretPosition(); Selection s = textArea.getSelectionAtOffset(caret); if (s != null) caret = s.getStart(); try { buffer.beginCompoundEdit(); SearchMatcher matcher = getSearchMatcher(); if (matcher == null) return false; initReplace(); int retVal = 0; for (int i = 0; i < selection.length; i++) { s = selection[i]; retVal += replaceInSelection(view, textArea, buffer, matcher, smartCaseReplace, s); } if (reverse) { // so that Replace and Find continues from // the right location textArea.moveCaretPosition(caret); } else { s = textArea.getSelectionAtOffset(textArea.getCaretPosition()); if (s != null) textArea.moveCaretPosition(s.getEnd()); } if (!BeanShell.isScriptRunning()) { Object[] args = {Integer.valueOf(retVal), Integer.valueOf(1)}; view.getStatus().setMessageAndClear(jEdit.getProperty("view.status.replace-all", args)); } if (retVal == 0) { view.getToolkit().beep(); return false; } return true; } catch (Exception e) { handleError(comp, e); } finally { buffer.endCompoundEdit(); } return false; } // }}}
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); } }
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); } }
public void actionPerformed(ActionEvent evt) { if (focusedComponent != null && focusedComponent.hasFocus()) focusedComponent.blinkCaret(); }