public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { if (!target.isEditable() || !target.isEnabled()) { target.getToolkit().beep(); return; } Caret caret = target.getCaret(); try { BaseDocument doc = (BaseDocument) target.getDocument(); int dotPos = caret.getDot(); int bolPos = Utilities.getRowStart(target, dotPos); int eolPos = Utilities.getRowEnd(target, dotPos); eolPos = Math.min(eolPos + 1, doc.getLength()); // include // '\n' doc.remove(bolPos, eolPos - bolPos); } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
public JMenuItem getPopupMenuItem(JTextComponent target) { EditorUI ui = Utilities.getEditorUI(target); try { return ui.getDocument().getAnnotations().createMenu(Utilities.getKit(target), Utilities.getLineOffset(ui.getDocument(),target.getCaret().getDot())); } catch (BadLocationException ex) { return null; } }
protected boolean hasTextBefore(JTextComponent target, String typedText) { BaseDocument doc = Utilities.getDocument(target); int dotPos = target.getCaret().getDot(); try { int fnw = Utilities.getRowFirstNonWhite(doc, dotPos); return dotPos != fnw+typedText.length(); } catch (BadLocationException e) { return false; } }
public static int getFirstNonWhiteRow(BaseDocument doc, int offset, boolean downDir) throws BadLocationException { if (isRowWhite(doc, offset)) { if (downDir) { // search down for non-white line offset = getFirstNonWhiteFwd(doc, offset); } else { // search up for non-white line offset = getFirstNonWhiteBwd(doc, offset); } } return offset; }
/** Reformat the line around the given position. */ public static void reformatLine(BaseDocument doc, int pos) throws BadLocationException { int lineStart = getRowStart(doc, pos); int lineEnd = getRowEnd(doc, pos); reformat(doc, lineStart, lineEnd); }
public static String getLine(final JTextComponent component, final int offset) { final BaseDocument workingDocument = org.netbeans.editor.Utilities.getDocument(component); try { final int lineStartOffset = org.netbeans.editor.Utilities.getRowStart(workingDocument, offset); final int lineEndOffset = org.netbeans.editor.Utilities.getRowEnd(workingDocument, offset); return String.valueOf(workingDocument.getChars(lineStartOffset, lineEndOffset - lineStartOffset)); } catch (BadLocationException ble) { return ""; } }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { if (!target.isEditable() || !target.isEnabled()) { target.getToolkit().beep(); return; } Caret caret = target.getCaret(); try { BaseDocument doc = (BaseDocument) target.getDocument(); int dotPos = caret.getDot(); int bolPos = Utilities.getRowStart(doc, dotPos); int wsPos = Utilities.getPreviousWord(target, dotPos); wsPos = (dotPos == bolPos) ? wsPos : Math.max(bolPos, wsPos); doc.remove(wsPos, dotPos - wsPos); } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { Caret caret = target.getCaret(); try { int pos = Utilities.getRowFirstNonWhite((BaseDocument) target.getDocument(), caret.getDot()); if (pos >= 0) { if (select) { caret.moveDot(pos); } else { caret.setDot(pos); } } } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { Caret caret = target.getCaret(); try { int pos = Utilities.getRowLastNonWhite((BaseDocument) target.getDocument(), caret.getDot()); if (pos >= 0) { if (select) { caret.moveDot(pos); } else { caret.setDot(pos); } } } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { if (!target.isEditable() || !target.isEnabled()) { target.getToolkit().beep(); return; EditorUI editorUI = Utilities.getEditorUI(target); Caret caret = target.getCaret(); final BaseDocument doc = Utilities.getDocument(target); if (caret.isSelectionVisible()) { target.replaceSelection(null); int dotPos = caret.getDot(); String s = editorUI.getWordMatch().getMatchWord(dotPos, direction); String prevWord = editorUI.getWordMatch().getPreviousWord(); if (s != null) { doc.atomicLock(); try { int pos = dotPos; if (prevWord != null && prevWord.length() > 0) { pos -= prevWord.length(); doc.remove(pos, prevWord.length()); doc.insertString(pos, s, null); } catch (BadLocationException e) { target.getToolkit().beep(); } finally { doc.atomicUnlock();
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { try { Caret caret = target.getCaret(); BaseDocument doc = Utilities.getDocument(target); int dotPos = caret.getDot(); ExtSyntaxSupport sup = (ExtSyntaxSupport) doc.getSyntaxSupport(); if (dotPos > 0) { int[] matchBlk = sup.findMatchingBlock(dotPos - 1, false); if (matchBlk != null) { if (select) { caret.moveDot(matchBlk[1]); } else { caret.setDot(matchBlk[1]); } } } } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
@SuppressWarnings("unchecked") private PPBlockInfo getBlock(final JTextComponent component) { try { final BaseDocument doc = (BaseDocument) component.getDocument(); final int lineNumber = Utilities.getLineOffset(doc, component.getCaret().getDot()); final ArrayList<PPLine> lineList = (ArrayList) doc.getProperty(DocumentPreprocessor.PREPROCESSOR_LINE_LIST); if (lineList != null) { PPLine myPpLine = null; if (lineNumber >= 0 && lineNumber < lineList.size()) { myPpLine = lineList.get(lineNumber); if (myPpLine != null) return myPpLine.getBlock(); } } } catch (BadLocationException ble) { } return null; }
public void run() { try { final BaseDocument doc = (BaseDocument)txt.getDocument(); final int s = Utilities.getRowStartFromLineOffset(doc, getSelectionStartLine(txt) - 1); final int e = Utilities.getRowEnd(txt, Utilities.getRowStartFromLineOffset(doc, getSelectionEndLine(txt) - 1)); doc.insertString(e, "\n//#enddebug", null); //NOI18N doc.insertString(s, "//#mdebug\n", null); //NOI18N txt.setSelectionEnd(txt.getSelectionStart()); } catch (BadLocationException ble) { ErrorManager.getDefault().notify(ble); } RecommentAction.actionPerformed(txt); } });
public void run() { try { final BaseDocument doc = (BaseDocument)txt.getDocument(); final int s = Utilities.getRowStartFromLineOffset(doc, getSelectionStartLine(txt) - 1); final int e = Utilities.getRowEnd(txt, Utilities.getRowStartFromLineOffset(doc, getSelectionEndLine(txt) - 1)); final String text = doc.getText(s, e-s); doc.insertString(e, "\n//#else\n" + text + "\n//#endif", null); //NOI18N doc.insertString(s, "//#if \n", null); //NOI18N txt.setSelectionStart(s + 6); txt.setSelectionEnd(s + 6); } catch (BadLocationException ble) { ErrorManager.getDefault().notify(ble); } RecommentAction.actionPerformed(txt); } });
if (getActiveParameterIndex() == -1) { // not showing active parm try { int fnwpos = Utilities.getFirstNonWhiteFwd(doc, offset + len); if (fnwpos > -1 && doc.getChars(fnwpos, 1)[0] == ')') { // NOI18N text = doc.getText(offset + len, fnwpos + 1 - offset - len); len = fnwpos + 1 - offset; try { doc.insertString(c.getCaretPosition(), paramName, null); substed = true; } catch (BadLocationException e) { boolean addSpace = CodeStyle.getDefault(doc).spaceAfterComma(); try { if (addSpace && (ind == 0 || (offset > 0 && Character.isWhitespace(DocumentUtilities.getText(doc, offset - 1, 1).charAt(0))))) { addSpace = false; String paramsText = null; try { int fnwpos = Utilities.getFirstNonWhiteFwd(doc, offset + len); if (fnwpos > -1 && fnwpos <= Utilities.getRowEnd(doc, offset + len) && doc.getChars(fnwpos, 1)[0] == '(') { // NOI18N int fnwpos = Utilities.getFirstNonWhiteFwd(doc, offset + len); c.setCaretPosition(insertOffset + insertText.length());
/** * Get the starting position of the row. * * @param c * text component to operate on * @param offset * position in document where to start searching * @return position of the start of the row or -1 for invalid position */ public static int getRowStart(JTextComponent c, int offset) throws BadLocationException { return getRowStart((BaseDocument) c.getDocument(), offset, 0); }
private boolean handleInsertion(BaseDocument doc, Caret caret, char c) { int dotPos = caret.getDot(); String s = doc.getText(dotPos-2, 2); if ("%=".equals(s) && dotPos >= 3) { // NOI18N s = doc.getText(dotPos-3, 3); doc.insertString(dotPos, " ", null); caret.setDot(dotPos+1); return true; if (token.id() == RhtmlTokenId.HTML && doc.getText(dotPos-1, 1).charAt(0) == '<') { int first = Utilities.getFirstNonWhiteFwd(doc, dotPos, Utilities.getRowEnd(doc, dotPos)); if (first == -1) { doc.insertString(dotPos, "%%>", null); // NOI18N caret.setDot(dotPos+1); return true; CharSequence suffix = DocumentUtilities.getText(doc, tokenPos, 2); if (CharSequenceUtilities.textEquals(suffix, "%>")) { // NOI18N caret.setDot(dotPos+1); int first = Utilities.getFirstNonWhiteFwd(doc, dotPos, Utilities.getRowEnd(doc, dotPos)); if (first == -1) { doc.insertString(dotPos, "%%>", null); // NOI18N
JTextComponent target = Utilities.getFocusedComponent(); if (target == null || target.getDocument() != bdoc) return null; ExtSyntaxSupport sup = (ExtSyntaxSupport)bdoc.getSyntaxSupport(); TokenItem token = sup.getTokenChain(offset, offset+1); if (token == null || token.getTokenID().getNumericID() != JSFEditorUtilities.XML_TEXT)
@Override public void performClickAction(Document originalDoc, final int offset, final HyperlinkType type) { if (originalDoc == null) { return; } final Document doc = originalDoc; final JTextComponent target = Utilities.getFocusedComponent(); if (target == null || target.getDocument() != doc) { return; } Runnable run = new Runnable() { @Override public void run() { int[] span = CsmMacroExpansion.getMacroExpansionSpan(doc, offset, false); if (type == HyperlinkType.ALT_HYPERLINK && (span != null && span[0] != span[1])) { // in this mode we open MacroView CsmMacroExpansion.showMacroExpansionView(doc, offset); } else { performAction(doc, target, offset, type); } } }; if (hyperLinkTask != null) { hyperLinkTask.cancel(); } hyperLinkTask = CsmModelAccessor.getModel().enqueue(run, "Following hyperlink");// NOI18N }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { try { Caret caret = target.getCaret(); BaseDocument doc = Utilities.getDocument(target); int caretLine = Utilities.getLineOffset(doc, caret.getDot()); AnnotationDesc aDesc = doc.getAnnotations().activateNextAnnotation(caretLine); } catch (BadLocationException e) { e.printStackTrace(); } } } }