javax.swing.text.Utilities.getRowEnd()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(71)

本文整理了Java中javax.swing.text.Utilities.getRowEnd()方法的一些代码示例,展示了Utilities.getRowEnd()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utilities.getRowEnd()方法的具体详情如下:
包路径:javax.swing.text.Utilities
类名称:Utilities
方法名:getRowEnd

Utilities.getRowEnd介绍

暂无

代码示例

代码示例来源:origin: skylot/jadx

g.drawString(lineNumber, x, y);
  rowStartOffset = Utilities.getRowEnd(codeArea, rowStartOffset) + 1;
} catch (Exception e) {
  if (LOG.isDebugEnabled()) {

代码示例来源:origin: groovy/groovy-core

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", "");
        TextEditor.this.replaceSelection(text);
        TextEditor.this.select(start, start + text.length());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: SonarSource/sonarqube

rowStartOffset = Utilities.getRowEnd(component, rowStartOffset) + 1;
} catch (Exception e) {
 break;

代码示例来源:origin: groovy/groovy-core

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);
        TextEditor.this.replaceSelection(toReplace);
        TextEditor.this.select(start, start + toReplace.length());
      } else {
        int pos = TextEditor.this.getCaretPosition();
        doc.insertString(pos, text, null);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: apache/pdfbox

private String getRowText(int offset)
  {
    try
    {
      int rowStart = Utilities.getRowStart(textComponent, offset);
      int rowEnd = Utilities.getRowEnd(textComponent, offset);
      return textComponent.getDocument().getText(rowStart, rowEnd - rowStart + 1);
    }
    catch (BadLocationException e)
    {
      e.printStackTrace();
    }
    return null;
  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

/** Get the end position of the row right before the new-line character.
* @param c text component to operate on
* @param offset position in document where to start searching
* @param relLine shift offset forward/back by some amount of lines
* @return position of the end of the row or -1 for invalid position
*/
public static int getRowEnd(JTextComponent c, int offset)
throws BadLocationException {
  return javax.swing.text.Utilities.getRowEnd(c, offset);
  //return getRowEnd((BaseDocument)c.getDocument(), offset);
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
  int offs = textArea.getCaretPosition();
  int endOffs = 0;
  try {
    if (textArea.getLineWrap()) {
      // Must check per character, since one logical line may be
      // many physical lines.
      // FIXME:  Replace Utilities call with custom version to
      // cut down on all of the modelToViews, as each call causes
      // a getTokenList => expensive!
      endOffs = Utilities.getRowEnd(textArea, offs);
    }
    else {
      Element root = textArea.getDocument().getDefaultRootElement();
      int line = root.getElementIndex(offs);
      endOffs = root.getElement(line).getEndOffset() - 1;
    }
    if (select) {
      textArea.moveCaretPosition(endOffs);
    }
    else {
      textArea.setCaretPosition(endOffs);
    }
  } catch (Exception ex) {
    UIManager.getLookAndFeel().provideErrorFeedback(textArea);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-editor-fold-nbui

private boolean dotInFoldArea(JTextComponent target, Fold fold, int dot) throws BadLocationException{
  int foldStart = fold.getStartOffset();
  int foldEnd = fold.getEndOffset();
  int foldRowStart = javax.swing.text.Utilities.getRowStart(target, foldStart);
  int foldRowEnd = javax.swing.text.Utilities.getRowEnd(target, foldEnd);
  if (foldRowStart > dot || foldRowEnd < dot) return false; // it's not fold encapsulating dot
  return true;
  }

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

private boolean dotInFoldArea(JTextComponent target, Fold fold, int dot) throws BadLocationException{
  int foldStart = fold.getStartOffset();
  int foldEnd = fold.getEndOffset();
  int foldRowStart = javax.swing.text.Utilities.getRowStart(target, foldStart);
  int foldRowEnd = javax.swing.text.Utilities.getRowEnd(target, foldEnd);
  if (foldRowStart > dot || foldRowEnd < dot) return false; // it's not fold encapsulating dot
  return true;
  }

代码示例来源:origin: wildfly/wildfly-core

@Override
public void mouseClicked(MouseEvent me) {
  if (me.getClickCount() < 2) return;
  int pos = output.viewToModel(me.getPoint());
  try {
    int rowStart = Utilities.getRowStart(output, pos);
    int rowEnd = Utilities.getRowEnd(output, pos);
    String line = output.getDocument().getText(rowStart, rowEnd - rowStart);
    if (opListener.getCmdHistory().contains(line)) {
      output.select(rowStart, rowEnd);
      cliGuiCtx.getCommandLine().getCmdText().setText(line);
      systemClipboard.setContents(new StringSelection(line), this);
    }
  } catch (BadLocationException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: org.wildfly.core/wildfly-cli

@Override
public void mouseClicked(MouseEvent me) {
  if (me.getClickCount() < 2) return;
  int pos = output.viewToModel(me.getPoint());
  try {
    int rowStart = Utilities.getRowStart(output, pos);
    int rowEnd = Utilities.getRowEnd(output, pos);
    String line = output.getDocument().getText(rowStart, rowEnd - rowStart);
    if (opListener.getCmdHistory().contains(line)) {
      output.select(rowStart, rowEnd);
      cliGuiCtx.getCommandLine().getCmdText().setText(line);
      systemClipboard.setContents(new StringSelection(line), this);
    }
  } catch (BadLocationException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: org.nuiton.thirdparty/rsyntaxtextarea

public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
  try {
    int offs = textArea.getCaretPosition();
    // FIXME:  Replace Utilities call with custom version to
    // cut down on all of the modelToViews, as each call causes
    // a getTokenList => expensive!
    int endOffs = Utilities.getRowEnd(textArea, offs);
    if (select) {
      textArea.moveCaretPosition(endOffs);
    }
    else {
      textArea.setCaretPosition(endOffs);
    }
  } catch (Exception ex) {
    UIManager.getLookAndFeel().provideErrorFeedback(textArea);
  }
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-editor

public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
  try {
    int offs = textArea.getCaretPosition();
      // FIXME:  Replace Utilities call with custom version to
      // cut down on all of the modelToViews, as each call causes
      // a getTokenList => expensive!
    int endOffs = Utilities.getRowEnd(textArea, offs);
    if (select) {
      textArea.moveCaretPosition(endOffs);
    }
    else {
      textArea.setCaretPosition(endOffs);
    }
  } catch (Exception ex) {
    UIManager.getLookAndFeel().provideErrorFeedback(textArea);
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy-console

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", "");
        TextEditor.this.replaceSelection(text);
        TextEditor.this.select(start, start + text.length());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

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", "");
        TextEditor.this.replaceSelection(text);
        TextEditor.this.select(start, start + text.length());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

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);
        TextEditor.this.replaceSelection(toReplace);
        TextEditor.this.select(start, start + toReplace.length());
      } else {
        int pos = TextEditor.this.getCaretPosition();
        doc.insertString(pos, text, null);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: protegeproject/protege

private static int getStyleEnd(JTextPane text, int pos, Style style)
    throws BadLocationException {
  StyledDocument doc = text.getStyledDocument();
  int maxPos = doc.getLength();
  String styleName = style.getName();
  for (;;) {
    pos = Utilities.getRowEnd(text, pos);
    if (pos == maxPos) {
      return pos;
    }
    Element element = doc.getCharacterElement(pos + 1);
    AttributeSet addtributes = element.getAttributes();
    if (!styleName.equals(
        addtributes.getAttribute(StyleConstants.NameAttribute))) {
      return pos;
    }
    // else
    pos++;
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy-console

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);
        TextEditor.this.replaceSelection(toReplace);
        TextEditor.this.select(start, start + toReplace.length());
      } else {
        int pos = TextEditor.this.getCaretPosition();
        doc.insertString(pos, text, null);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-editor-fold-nbui

@Override
  public void run() {
    FoldHierarchy hierarchy = FoldHierarchy.get(target);
    int dot = target.getCaret().getDot();
    hierarchy.lock();
    try {
      try {
        int rowStart = javax.swing.text.Utilities.getRowStart(target, dot);
        int rowEnd = javax.swing.text.Utilities.getRowEnd(target, dot);
        Fold fold = getLineFold(hierarchy, dot, rowStart, rowEnd);
        if (fold != null) {
          hierarchy.expand(fold);
        }
      } catch (BadLocationException ble) {
        Exceptions.printStackTrace(ble);
      }
    } finally {
      hierarchy.unlock();
    }
  }
});

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

public void actionPerformed(ActionEvent evt, JTextComponent target) {
    FoldHierarchy hierarchy = FoldHierarchy.get(target);
    int dot = target.getCaret().getDot();
    hierarchy.lock();
    try{
      try{
        int rowStart = javax.swing.text.Utilities.getRowStart(target, dot);
        int rowEnd = javax.swing.text.Utilities.getRowEnd(target, dot);
        Fold fold = getLineFold(hierarchy, dot, rowStart, rowEnd);
        if (fold!=null){
          hierarchy.expand(fold);
        }
      }catch(BadLocationException ble){
        ble.printStackTrace();
      }
    }finally {
      hierarchy.unlock();
    }
  }
}

相关文章