Java Code Examples for javax.swing.text.Utilities#getRowStart()

The following examples show how to use javax.swing.text.Utilities#getRowStart() . 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: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
@Override public void mousePressed(MouseEvent e) {
  super.mousePressed(e);
  int clickCount = e.getClickCount();
  if (SwingUtilities.isLeftMouseButton(e) && !e.isConsumed()) {
    if (clickCount == 2) {
      selectingMode = SelectingMode.WORD;
      p0 = Math.min(getDot(), getMark());
      p1 = Math.max(getDot(), getMark());
    } else if (clickCount >= 3) {
      selectingMode = SelectingMode.ROW;
      JTextComponent target = getComponent();
      int offs = target.getCaretPosition();
      try {
        p0 = Utilities.getRowStart(target, offs);
        p1 = Utilities.getRowEnd(target, offs);
        setDot(p0);
        moveDot(p1);
      } catch (BadLocationException ex) {
        UIManager.getLookAndFeel().provideErrorFeedback(target);
      }
    }
  } else {
    selectingMode = SelectingMode.CHAR;
  }
}
 
Example 2
Source File: SelectPreviousOpMouseAdapter.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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();
    }

}
 
Example 3
Source File: NoteEditor.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
private static int getRow(final int pos, final JTextComponent editor) {
  int rn = (pos == 0) ? 1 : 0;
  try {
    int offs = pos;
    while (offs > 0) {
      offs = Utilities.getRowStart(editor, offs) - 1;
      rn++;
    }
  } catch (BadLocationException e) {
    LOGGER.error("Bad location", e); //NOI18N
  }
  return rn;
}
 
Example 4
Source File: NoteEditor.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
private static int getColumn(final int pos, final JTextComponent editor) {
  try {
    return pos - Utilities.getRowStart(editor, pos) + 1;
  } catch (BadLocationException e) {
    LOGGER.error("Bad location", e); //NOI18N
  }
  return -1;
}