Java Code Examples for javax.swing.text.Utilities#getParagraphElement()
The following examples show how to use
javax.swing.text.Utilities#getParagraphElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextEditor.java From groovy with Apache License 2.0 | 6 votes |
public void actionPerformed(ActionEvent ae) { try { if (multiLineTab && TextEditor.this.getSelectedText() != null) { int end = Utilities.getRowEnd(TextEditor.this, getSelectionEnd()); TextEditor.this.setSelectionEnd(end); Element el = Utilities.getParagraphElement(TextEditor.this, getSelectionStart()); int start = el.getStartOffset(); TextEditor.this.setSelectionStart(start); // remove text and reselect the text String text = tabsAsSpaces ? TAB_BACK_PATTERN.matcher(getSelectedText()).replaceAll("") : getSelectedText().replaceAll("^\t", ""); int stop = start + text.length(); setRenderRange(start, stop); TextEditor.this.replaceSelection(text); TextEditor.this.select(start, stop); } } catch (Exception e) { e.printStackTrace(); } }
Example 2
Source File: TextEditor.java From groovy with Apache License 2.0 | 5 votes |
public void actionPerformed(ActionEvent ae) { try { Document doc = TextEditor.this.getDocument(); String text = tabsAsSpaces ? TABBED_SPACES : "\t"; if (multiLineTab && getSelectedText() != null) { int end = Utilities.getRowEnd(TextEditor.this, getSelectionEnd()); TextEditor.this.setSelectionEnd(end); Element el = Utilities.getParagraphElement(TextEditor.this, getSelectionStart()); int start = el.getStartOffset(); TextEditor.this.setSelectionStart(start); String toReplace = TextEditor.this.getSelectedText(); toReplace = LINE_START.matcher(toReplace).replaceAll(text); int stop = start + toReplace.length(); setRenderRange(start, stop); TextEditor.this.replaceSelection(toReplace); TextEditor.this.select(start, stop); } else { int pos = TextEditor.this.getCaretPosition(); doc.insertString(pos, text, null); } } catch (Exception e) { e.printStackTrace(); } }