List of usage examples for javax.swing.text Utilities getRowStart
@SuppressWarnings("deprecation") public static final int getRowStart(JTextComponent c, int offs) throws BadLocationException
From source file:Main.java
public static int getColumn(int pos, JTextComponent editor) { try {/*from ww w.j a va 2s . c o m*/ return pos - Utilities.getRowStart(editor, pos) + 1; } catch (BadLocationException e) { e.printStackTrace(); } return -1; }
From source file:Main.java
public static int getRow(int pos, JTextComponent editor) throws BadLocationException { int rn = (pos == 0) ? 1 : 0; int offs = pos; while (offs > 0) { offs = Utilities.getRowStart(editor, offs) - 1; rn++;/* w w w . jav a 2s. com*/ } return rn; }
From source file:Main.java
public static int getColumn(JTextComponent editor, int pos) { try {/*from ww w.j av a 2 s .c o m*/ return pos - Utilities.getRowStart(editor, pos) + 1; } catch (BadLocationException e) { e.printStackTrace(); } return -1; }
From source file:Main.java
public static int getRow(JTextComponent editor, int pos) { int rn = (pos == 0) ? 1 : 0; try {/* w ww . jav a 2s.c o m*/ int offs = pos; while (offs > 0) { offs = Utilities.getRowStart(editor, offs) - 1; rn++; } } catch (BadLocationException e) { e.printStackTrace(); } return rn; }
From source file:Main.java
/** * Method getCaretCol.//from w w w. j a v a2 s . c o m * * @param idx * @param comp * @return int * @throws Exception */ public static int getCaretCol(int idx, JTextComponent comp) throws BadLocationException { return Math.abs(Utilities.getRowStart(comp, idx) - idx); }
From source file:Main.java
private void initComponents() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane textPane = new JTextPane(); ((AbstractDocument) textPane.getDocument()).addDocumentListener(new DocumentListener() { @Override//w w w . jav a2 s . co m public void insertUpdate(final DocumentEvent de) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { StyledDocument doc = (StyledDocument) de.getDocument(); int start = Utilities.getRowStart(textPane, Math.max(0, de.getOffset() - 1)); int end = Utilities.getWordStart(textPane, de.getOffset() + de.getLength()); String text = doc.getText(start, end - start); for (String emoticon : imageTokens) { int i = text.indexOf(emoticon); while (i >= 0) { final SimpleAttributeSet attrs = new SimpleAttributeSet( doc.getCharacterElement(start + i).getAttributes()); if (StyleConstants.getIcon(attrs) == null) { switch (emoticon) { case imageToken: StyleConstants.setIcon(attrs, anImage); break; } doc.remove(start + i, emoticon.length()); doc.insertString(start + i, emoticon, attrs); } i = text.indexOf(emoticon, i + emoticon.length()); } } } catch (BadLocationException ex) { ex.printStackTrace(); } } }); } @Override public void removeUpdate(DocumentEvent e) { } @Override public void changedUpdate(DocumentEvent e) { } }); JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(300, 300)); frame.add(scrollPane); frame.pack(); frame.setVisible(true); }
From source file:com.igormaznitsa.sciareto.ui.editors.mmeditors.NoteEditor.java
private static int getRow(final int pos, final JTextComponent editor) { int rn = (pos == 0) ? 1 : 0; try {// w w w.jav a2s . co m int offs = pos; while (offs > 0) { offs = Utilities.getRowStart(editor, offs) - 1; rn++; } } catch (BadLocationException e) { LOGGER.error("Bad location", e); } return rn; }
From source file:com.igormaznitsa.sciareto.ui.editors.mmeditors.NoteEditor.java
private static int getColumn(final int pos, final JTextComponent editor) { try {//from w w w. java 2s . co m return pos - Utilities.getRowStart(editor, pos) + 1; } catch (BadLocationException e) { LOGGER.error("Bad location", e); } return -1; }