for (int line = 0; line < textArea.getLineCount(); line++) { int start = textArea.getLineStartOffset(line); int end = textArea.getLineEndOffset(line);
ta.setCaretPosition(ta.getLineStartOffset(ta.getLineCount() - 1)); } catch (BadLocationException e) {
void read(Reader reader) throws IOException { // Feed the file's contents to text area textArea.read(reader, null); // If there are more than one lines, there is a line separator lineSeparatorExists = textArea.getLineCount() > 1; // Move cursor to the top textArea.setCaretPosition(0); }
public void addDebug(String message) { //System.out.println ("Free memory : " + Runtime.getRuntime().freeMemory() ); if (this.txtDebug.getLineCount() > 500) { //this.txtDebug.setText("Info: Trunc...\n"); } this.txtDebug.append("Debug: " + message + "\n"); this.txtDebug.setCaretPosition(this.txtDebug.getDocument().getLength() - 1); }
public int getLineNumber() { return sparqlQueryEditor.getTextAreaLines().getLineCount(); }
public int getLineNumber() { return sparqlQueryEditor.getTextAreaLines().getLineCount(); }
/** * Appends the given text to that displayed. No additional newlines * are added after the text. * * @param text the text to append * @param indent indent width as number of spaces */ private void append(final String text, final int indent) { int startLine = textArea.getLineCount(); String appendText; if (indent > 0) { char[] c = new char[indent]; Arrays.fill(c, ' '); String pad = String.valueOf(c); appendText = pad + text.replaceAll("\\n", "\n" + pad); } else { appendText = text; } textArea.append(appendText); textArea.setCaretPosition(textArea.getDocument().getLength()); }
public void run() { Document doc = textArea.getDocument(); if (textArea.getLineCount() >= MAX_LINES) { String backupString = ""; try { backupString = textArea.getText( Math.max(textArea.getDocument().getLength() - BACKUP_SIZE, 0), Math.min(textArea.getDocument().getLength(), BACKUP_SIZE)); } catch (BadLocationException ignored) { } textArea.setText(backupString + "\n...too many output\n"); } textArea.append(msg); textArea.setCaretPosition(textArea.getDocument().getLength()); } });
public String[] getTextLines() { int numLines = mTextArea.getLineCount(); String[] lines = new String[numLines]; for(int i = 0; i < numLines; i++) { try { int start = mTextArea.getLineStartOffset(i); int end = mTextArea.getLineEndOffset(i); // treats last line specially if (i == numLines-1) { // Last line end++; // Allow for missing terminator } lines[i]=mTextArea.getText(start, end-start-1); } catch (BadLocationException e) { // should not happen throw new IllegalStateException("Could not read line "+i,e); } } return lines; } }
public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { if (address.getLineCount() < 5 || !string.contains("\n")) super.insertString(fb, offset, string, attr); public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { if (address.getLineCount() < 5 || !text.contains("\n")) super.replace(fb, offset, length, text, attrs);
@Override public void write(int b) throws IOException { console.append(String.valueOf((char)b)); if(shouldLimitLines.isSelected() && console.getLineCount() > 100) { try { console.replaceRange("", 0, console.getLineEndOffset(0)); }catch(Exception e) { } } } }
private void updateCaretStatus() { JTextArea currentArea = getCurrentArea(); if ( currentArea == null ) return; try { int offset = currentArea.getCaretPosition(); int line = currentArea.getLineOfOffset( offset ); int lineStart = currentArea.getLineStartOffset( line ); int col = offset - lineStart; int lineCount = currentArea.getLineCount(); statusLbl.setText( String.format( "Line: %4d/%4d Col: %3d", line+1, lineCount, col+1 ) ); } catch ( BadLocationException e ) { statusLbl.setText( String.format( "Line: ???/ ??? Col: ???" ) ); } }
/** * <p>Write output to the console of the Graphing Panel.</p> * * @param input */ public void toConsole(final String input) { // Use a FILO for the output to the console, never exceeding 500 lines if (console.getLineCount() > 500) { try { console.select(console.getLineStartOffset(0), console .getLineEndOffset(console.getLineCount() - 500)); console.replaceSelection("...\n"); } catch (final BadLocationException e) { Logger.log("Could not clear the console", 3); } } console.append("> " + input + "\n"); console.setCaretPosition(console.getText().length()); } }
private void setParameter(ParameterObj obj){ int position = desArea.getCaretPosition(); System.out.println(desArea.getLineCount()); System.out.println(desArea.getCaretPosition()); String str = " <parameter name=\"" + obj.getName() + "\" locked=\"false\">" + obj.getValue() + "</parameter>\n"; desArea.insert(str, position + 1); } private void setModule(String module){
public void trunkTextArea(JTextArea txtWin){ int numLinesToTrunk = txtWin.getLineCount() - SCROLL_BUFFER_SIZE; if(numLinesToTrunk > 0) { try { int posOfLastLineToTrunk = txtWin.getLineEndOffset(numLinesToTrunk - 1); txtWin.replaceRange("",0,posOfLastLineToTrunk); } catch (BadLocationException ex) { ex.printStackTrace(); } } }
private void selectCurrentLine(int x, int y) { // This is just temporary placeholder code int ln = ta.getLineCount(); if (ln > 0) { try { selected_area_start = ta.getLineStartOffset(ln); selected_area_end = ta.getLineEndOffset(ln); ta.select(selected_area_start, selected_area_end); } catch (javax.swing.text.BadLocationException e) { //selected_area_start = 0; //selected_area_end = 0; } } }
final int SCROLL_BUFFER_SIZE = 100; public void trunkTextArea(JTextArea txtWin) { int numLinesToTrunk = txtWin.getLineCount() - SCROLL_BUFFER_SIZE; if(numLinesToTrunk > 0) { try { int posOfLastLineToTrunk = txtWin.getLineEndOffset(numLinesToTrunk - 1); txtWin.replaceRange("",0,posOfLastLineToTrunk); } catch (BadLocationException ex) { ex.printStackTrace(); } } }
if (inputTextArea.getLineOfOffset(inputTextArea.getCaretPosition())==inputTextArea.getLineCount())
String text, AttributeSet attrs) throws BadLocationException { if(area.getLineCount()<=lineCount && area.getLineOfOffset(area.getCaretPosition())<lineCount) if(text.contains("\n") && area.getLineCount()<lineCount) super.replace(fb, offset, length, text, attrs); else if(!text.contains("\n"))
public void run () { if (ui.isDestroyed ()) { logger.removeListener (this); text.setText (""); return; } int lc = text.getLineCount (); if (lc > maxLines) { try { int startOffset = text.getLineStartOffset (maxLines); int endOffset = text.getLineEndOffset(lc-1); text.getDocument ().remove (startOffset, endOffset-startOffset); } catch (BadLocationException ex) { text.setText (ex.toString()); } } } public LogEvent log (LogEvent evt) {