/** Get the word around the given position . * @param c component to work with * @param offset position in document - usually the caret.getDot() * @return the word. */ public static String getWord(JTextComponent c, int offset) throws BadLocationException { int[] blk = getIdentifierBlock(c, offset); Document doc = c.getDocument(); return (blk != null) ? doc.getText(blk[0], blk[1] - blk[0]) : null; }
/** * Get the identifier around the given position or null if there's no * identifier * * @see getIdentifierBlock() */ public static String getIdentifier(BaseDocument doc, int offset) throws BadLocationException { int[] blk = getIdentifierBlock(doc, offset); return (blk != null) ? doc.getText(blk[0], blk[1] - blk[0]) : null; }
/** Get the identifier around the given position or null if there's no identifier * @see getIdentifierBlock() */ public static String getIdentifier(BaseDocument doc, int offset) throws BadLocationException { int[] blk = getIdentifierBlock(doc, offset); return (blk != null) ? doc.getText(blk[0], blk[1] - blk[0]) : null; }
private static int[] getIdentifierAndMethodBlock(BaseDocument doc, int offset) throws BadLocationException { int[] idBlk = Utilities.getIdentifierBlock(doc, offset); if (idBlk != null) { int[] funBlk = getFunctionBlock(doc, idBlk); if (funBlk != null) { return new int[] { idBlk[0], idBlk[1], funBlk[1] }; } } return idBlk; }
private static int[] getIdentifierAndInstantiationBlock(BaseDocument doc, int offset) throws BadLocationException { int[] idBlk = Utilities.getIdentifierBlock(doc, offset); if (idBlk != null) { int[] instBlk = getInstantiationBlock(doc, idBlk); if (instBlk != null) { return new int[] { idBlk[0], idBlk[1], instBlk[1] }; } } return idBlk; }
public int[] getFunctionBlock(int offset) throws BadLocationException { return getFunctionBlock(Utilities.getIdentifierBlock(getDocument(), offset)); }
public int[] getFunctionBlock(int offset) throws BadLocationException { return getFunctionBlock(Utilities.getIdentifierBlock(getDocument(), offset)); }
public JavaFastImport(JTextComponent target) { this.target = target; try{ block = Utilities.getIdentifierBlock (target, target.getCaret().getDot()); javax.swing.text.Document doc = target.getDocument(); exp = (block != null) ? doc.getText(block[0], block[1] - block[0]) : null; }catch(BadLocationException ble){ ble.printStackTrace(); } importType = getPackageImportSetting(); // Bugfix for #26966 if (exp != null) { // Eliminating extra spaces String untrimmedExp = exp; exp = exp.trim(); // Recalculating block beginning and ending int nLeadingSpaces = untrimmedExp.indexOf(exp); int nTrailingSpaces = untrimmedExp.length() - exp.length() - nLeadingSpaces; block[0] += nLeadingSpaces; block[1] -= nTrailingSpaces; } }
/** Get the selection if there's any or get the identifier around * the position if there's no selection. * @param c component to work with * @param offset position in document - usually the caret.getDot() * @return the block (starting and ending position) enclosing the identifier * or null if no identifier was found */ public static int[] getSelectionOrIdentifierBlock(JTextComponent c, int offset) throws BadLocationException { Document doc = c.getDocument(); Caret caret = c.getCaret(); int[] ret; if (caret.isSelectionVisible()) { ret = new int[] { c.getSelectionStart(), c.getSelectionEnd() }; } else if (doc instanceof BaseDocument){ ret = getIdentifierBlock((BaseDocument)doc, caret.getDot()); } else { ret = getIdentifierBlock(c, offset); } return ret; }
try { int[] block = org.netbeans.editor.Utilities.getIdentifierBlock(doc, dotPos);
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { if (!target.isEditable() || !target.isEnabled()) { target.getToolkit().beep(); return; } try { Caret caret = target.getCaret(); BaseDocument doc = (BaseDocument)target.getDocument(); int[] idBlk = Utilities.getIdentifierBlock(doc, caret.getDot()); if (idBlk != null) { Utilities.changeCase(doc, idBlk[0], 1, Utilities.CASE_SWITCH); } } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
private synchronized boolean instantSubstitutionImpl(int caretPos){ if (getLastResult() == null) return false; JTextComponent comp = extEditorUI.getComponent(); try{ if (comp != null) { int[] block = Utilities.getIdentifierBlock(comp,caretPos); if (block == null || block[1] == caretPos) return getLastResult().substituteText(0, false); } }catch(BadLocationException ble){ } return false; }
try { int[] block = org.netbeans.editor.Utilities.getIdentifierBlock(doc, dotPos);
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { if (!target.isEditable() || !target.isEnabled()) { target.getToolkit().beep(); return; } try { Caret caret = target.getCaret(); BaseDocument doc = (BaseDocument) target.getDocument(); int[] idBlk = Utilities.getIdentifierBlock(doc, caret.getDot()); if (idBlk != null) { Utilities.changeCase(doc, idBlk[0], 1, Utilities.CASE_SWITCH); } } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
/** * Get the selection if there's any or get the identifier around the * position if there's no selection. * * @param c * component to work with * @param offset * position in document - usually the caret.getDot() * @return the block (starting and ending position) enclosing the identifier * or null if no identifier was found */ public static int[] getSelectionOrIdentifierBlock(JTextComponent c, int offset) throws BadLocationException { BaseDocument doc = (BaseDocument) c.getDocument(); Caret caret = c.getCaret(); int[] ret; if (caret.isSelectionVisible()) { ret = new int[] { c.getSelectionStart(), c.getSelectionEnd() }; } else { ret = getIdentifierBlock(doc, caret.getDot()); } return ret; }
public boolean gotoDeclaration(JTextComponent target) { try { Caret caret = target.getCaret(); int dotPos = caret.getDot(); BaseDocument doc = (BaseDocument) target.getDocument(); int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos); ExtSyntaxSupport extSup = (ExtSyntaxSupport) doc.getSyntaxSupport(); if (idBlk != null) { int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]); if (decPos >= 0) { caret.setDot(decPos); return true; } } } catch (BadLocationException e) { } return false; }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { Caret caret = target.getCaret(); try { if (caret.isSelectionVisible()) { caret.setSelectionVisible(false); // unselect if // anything selected } else { // selection not visible int block[] = Utilities.getIdentifierBlock((BaseDocument) target.getDocument(), caret.getDot()); if (block != null) { caret.setDot(block[0]); caret.moveDot(block[1]); } } } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { Caret caret = target.getCaret(); try { if (caret.isSelectionVisible()) { caret.setSelectionVisible(false); // unselect if anything selected } else { // selection not visible int block[] = Utilities.getIdentifierBlock((BaseDocument)target.getDocument(), caret.getDot()); if (block != null) { caret.setDot(block[0]); caret.moveDot(block[1]); } } } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
public boolean gotoDeclaration(JTextComponent target) { try { Caret caret = target.getCaret(); int dotPos = caret.getDot(); BaseDocument doc = (BaseDocument)target.getDocument(); int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos); ExtSyntaxSupport extSup = (ExtSyntaxSupport)doc.getSyntaxSupport(); if (idBlk != null) { int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]); if (decPos >= 0) { caret.setDot(decPos); return true; } } } catch (BadLocationException e) { } return false; }
org.netbeans.editor.Utilities.getIdentifierBlock((BaseDocument)doc, offset);