Java Code Examples for javax.swing.JTextPane#moveCaretPosition()
The following examples show how to use
javax.swing.JTextPane#moveCaretPosition() .
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: AddTextAction.java From wpcleaner with Apache License 2.0 | 6 votes |
/** * Replace text. * * @param localNewText New text. * @param localElement Element. * @param localTextPane Text Pane. */ private void replace( String localNewText, Element localElement, JTextPane localTextPane) { if ((localElement == null) || (localTextPane == null) || (localNewText == null)) { return; } // Initialize int startOffset = MWPaneFormatter.getUUIDStartOffset(localTextPane, localElement); int endOffset = MWPaneFormatter.getUUIDEndOffet(localTextPane, localElement); // Replace try { localTextPane.getDocument().remove(startOffset, endOffset - startOffset); localTextPane.getDocument().insertString(startOffset, localNewText, localElement.getAttributes()); localTextPane.setCaretPosition(startOffset); localTextPane.moveCaretPosition(startOffset + localNewText.length()); } catch (BadLocationException e1) { // Nothing to be done } }
Example 2
Source File: AddInternalLinkAction.java From wpcleaner with Apache License 2.0 | 6 votes |
/** * Replace text. * * @param localNewText New text. * @param localElement Element. * @param localTextPane Text pane. */ private void replace( String localNewText, Element localElement, JTextPane localTextPane) { if ((localElement == null) || (localTextPane == null) || (localNewText == null)) { return; } // Initialize int startOffset = MWPaneFormatter.getUUIDStartOffset(localTextPane, localElement); int endOffset = MWPaneFormatter.getUUIDEndOffet(localTextPane, localElement); // Replace try { localTextPane.getDocument().remove(startOffset, endOffset - startOffset); localTextPane.getDocument().insertString(startOffset, localNewText, localElement.getAttributes()); localTextPane.setCaretPosition(startOffset); localTextPane.moveCaretPosition(startOffset + localNewText.length()); } catch (BadLocationException e1) { // Nothing to be done } }
Example 3
Source File: ReplaceLinkAction.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Replace link and displayed text. */ private void fullyReplace( String localOldTitle, String localNewTitle, String localText, Element localElement, JTextPane localTextPane) { if ((localElement != null) && (localTextPane != null) && (localNewTitle != null) && (localNewTitle.length() > 0)) { localTextPane.setCaretPosition(MWPaneFormatter.getUUIDStartOffset(localTextPane, localElement)); localTextPane.moveCaretPosition(MWPaneFormatter.getUUIDEndOffet(localTextPane, localElement)); String newText = null; if ((localText != null) && (localText.length() > 0) && (localNewTitle.length() > 0) && (localText.charAt(0) != localNewTitle.charAt(0)) && (Character.toUpperCase(localText.charAt(0)) == Character.toUpperCase(localNewTitle.charAt(0)))) { newText = "[[" + localText.charAt(0) + localNewTitle.substring(1) + "]]"; } else { newText = "[[" + localNewTitle + "]]"; } localTextPane.replaceSelection(newText); LinkReplacement.addLastReplacement(localOldTitle, localNewTitle); } }
Example 4
Source File: ReplaceTextAction.java From wpcleaner with Apache License 2.0 | 4 votes |
/** * Replace text. * * @param localNewText New text. * @param localElement Element. * @param localTextPane Text pane. */ private void replace( String localNewText, Element localElement, JTextPane localTextPane) { if ((localElement == null) || (localTextPane == null) || (localNewText == null)) { return; } // Text finalization if (page != null) { try { PageAnalysis analysis = page.getAnalysis(localNewText, false); List<PageElementFunction> functions = analysis.getFunctions(); boolean parseNeeded = false; if (functions != null) { for (PageElementFunction function : functions) { if (function.getMagicWord() == null) { parseNeeded = true; } else if (!function.getMagicWord().isFunctionNotPSTMagicWord()) { parseNeeded = true; } } } if (parseNeeded) { API api = APIFactory.getAPI(); localNewText = api.parseText(page.getWikipedia(), page.getTitle(), localNewText, false); } } catch (APIException e) { // Nothing to do } } // Initialize int startOffset = MWPaneFormatter.getUUIDStartOffset(localTextPane, localElement); int endOffset = MWPaneFormatter.getUUIDEndOffet(localTextPane, localElement); // Replace try { localTextPane.getDocument().remove(startOffset, endOffset - startOffset); localTextPane.getDocument().insertString(startOffset, localNewText, localElement.getAttributes()); localTextPane.setCaretPosition(startOffset); localTextPane.moveCaretPosition(startOffset + localNewText.length()); } catch (BadLocationException e1) { // Nothing to be done } }