List of usage examples for javax.swing.text StyledDocument getText
public String getText(int offset, int length) throws BadLocationException;
From source file:org.debux.webmotion.netbeans.Utils.java
public static int getRowFirstNonWhite(StyledDocument doc, int offset) throws BadLocationException { Element lineElement = doc.getParagraphElement(offset); int start = lineElement.getStartOffset(); while (start + 1 < lineElement.getEndOffset()) { try {/*from www. ja v a 2 s. co m*/ char charAt = doc.getText(start, 1).charAt(0); if (charAt != ' ') { break; } } catch (BadLocationException ex) { throw (BadLocationException) new BadLocationException( "calling getText(" + start + ", " + (start + 1) + ") on doc of length: " + doc.getLength(), start).initCause(ex); } start++; } return start; }
From source file:pl.otros.logview.gui.actions.search.SearchAction.java
private void scrollToSearchResult(ArrayList<String> toHighlight, JTextPane textPane) { if (toHighlight.size() == 0) { return;/*from ww w. jav a2s . co m*/ } try { StyledDocument logDetailsDocument = textPane.getStyledDocument(); String text = logDetailsDocument.getText(0, logDetailsDocument.getLength()); String string = toHighlight.get(0); textPane.setCaretPosition(Math.max(text.indexOf(string), 0)); } catch (BadLocationException e) { e.printStackTrace(); } }
From source file:pl.otros.logview.gui.message.update.MessageUpdateUtils.java
public static void highlightSearchResult(OtrosJTextWithRulerScrollPane<JTextPane> otrosJTextWithRulerScrollPane, PluginableElementsContainer<MessageColorizer> colorizersContainer) { MessageUpdateUtils messageUpdateUtils = new MessageUpdateUtils(); StyledDocument styledDocument = otrosJTextWithRulerScrollPane.getjTextComponent().getStyledDocument(); String text;//from ww w.j av a2 s . co m try { text = styledDocument.getText(0, styledDocument.getLength()); } catch (BadLocationException e) { LOGGER.log(Level.SEVERE, "Cant get document text for log details view: ", e); return; } MessageColorizer messageColorizer = colorizersContainer.getElement(SearchResultColorizer.class.getName()); List<MessageFragmentStyle> messageFragmentStyles = new ArrayList<MessageFragmentStyle>(); if (messageColorizer != null) { messageFragmentStyles .addAll(messageUpdateUtils.colorizeMessageWithTimeLimit(text, 0, messageColorizer, 10)); } markSearchResult(messageFragmentStyles, otrosJTextWithRulerScrollPane); }