String text = null; try { text = doc.getText(0, doc.getLength()); } catch (Exception e) { throw new RuntimeException(e);
String text = null; try { text = doc.getText(0, doc.getLength()); } catch (Exception e) { log.err(e);
styledDocument.getText(0, styledDocument.getLength(), segment);
DefaultStyledDocument document = (DefaultStyledDocument) jTextPane1.getDocument(); try { contText = document.getText(0, document.getLength()); } catch (BadLocationException ex) { Logger.getLogger(JTextPaneTest.class.getName()).log(Level.SEVERE, null, ex); }
@Override public void actionPerformed( final ActionEvent event ) { if ( _piperDocument.getLength() == 0 ) { return; } final int option = _chooser.showSaveDialog( null ); if ( option != JFileChooser.APPROVE_OPTION ) { return; } final File file = _chooser.getSelectedFile(); try { String path = file.getPath(); if ( !path.endsWith( ".piper" ) ) { path += ".piper"; } final String text = _piperDocument.getText( 0, _piperDocument.getLength() ); Files.write( Paths.get( path ), text.getBytes() ); } catch ( BadLocationException | IOException multE ) { LOGGER.warn( multE.getMessage() ); } } }
private int getInsertCaret() throws BadLocationException { int caret = _textPane.getCaretPosition(); if ( caret > 1 && _piperDocument.getText( caret - 1, 1 ).charAt( 0 ) == '\n' ) { return caret; } final int length = _piperDocument.getLength() - caret; final String docText = _piperDocument.getText( caret, length ); boolean careted = false; for ( int i = 0; i < length - 1; i++ ) { if ( docText.charAt( i ) == '\n' ) { caret += i + 1; careted = true; break; } } if ( !careted ) { caret = _piperDocument.getLength(); } return caret; }
private String getElementText(Element element) { try { return doc.getText(element.getStartOffset(), element.getEndOffset() - element.getStartOffset()); } catch (BadLocationException ex) { LOGGER.warning("Bad location"); } return ""; }
/** * {@inheritDoc} */ public Reader extractText(InputStream stream, String type, String encoding) throws IOException { try { RTFEditorKit rek = new RTFEditorKit(); DefaultStyledDocument doc = new DefaultStyledDocument(); rek.read(stream, doc, 0); String text = doc.getText(0, doc.getLength()); return new StringReader(text); } catch (Throwable t) { logger.warn("Failed to extract RTF text content", t); return new StringReader(""); } finally { stream.close(); } } }
/** * {@inheritDoc} */ public Reader extractText(InputStream stream, String type, String encoding) throws IOException { try { RTFEditorKit rek = new RTFEditorKit(); DefaultStyledDocument doc = new DefaultStyledDocument(); rek.read(stream, doc, 0); String text = doc.getText(0, doc.getLength()); return new StringReader(text); } catch (BadLocationException e) { logger.warn("Failed to extract RTF text content", e); return new StringReader(""); } finally { stream.close(); } } }
jTextPane1.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent evt) { if(evt.getDot() == evt.getMark())return; JTextPane txtPane = (JTextPane) evt.getSource(); DefaultHighlighter highlighter = (DefaultHighlighter) txtPane.getHighlighter(); highlighter.removeAllHighlights(); DefaultHighlightPainter hPainter = new DefaultHighlightPainter(new Color(0xFFAA00)); String selText = txtPane.getSelectedText(); String contText = "";// = jTextPane1.getText(); DefaultStyledDocument document = (DefaultStyledDocument) txtPane.getDocument(); try { contText = document.getText(0, document.getLength()); } catch (BadLocationException ex) { Logger.getLogger(JTextPaneTest.class.getName()).log(Level.SEVERE, null, ex); } int index = 0; while((index = contText.indexOf(selText, index)) > -1){ try { highlighter.addHighlight(index, selText.length()+index, hPainter); index = index + selText.length(); } catch (BadLocationException ex) { Logger.getLogger(JTextPaneTest.class.getName()).log(Level.SEVERE, null, ex); //System.out.println(index); } } } });
public void setDocument(DefaultStyledDocument doc) { try { // System.out.println(this.getClass().getName() + " - setDocument(" + doc + ")"); m_document.removeDocumentListener(this); m_document = doc; m_tune = m_parser.parse(doc.getText(0, doc.getLength())); m_document.addDocumentListener(this); } catch (Exception e) { e.printStackTrace(); } }
protected void initializeReader() throws IOException { InputStream in; try { in = blob.getStream(); } catch (RepositoryException e) { throw new IOException(e.getMessage()); } try { doc.remove(0, doc.getLength()); rek.read(in, doc, 0); String text = doc.getText(0, doc.getLength()); delegate = new StringReader(text); } catch (BadLocationException e) { throw new IOException(e.getMessage()); } finally { in.close(); } } };
styledDocument.getText(0, styledDocument.getLength(), segment);
styledDocument.getText(0, styledDocument.getLength(), segment);
styledDocument.getText(0, styledDocument.getLength(), segment);
styledDocument.getText(0, styledDocument.getLength(), segment);
@Override public void run() { final JFrame frame = (JFrame)SwingUtilities.getRoot( MainPanel2.this ); frame.setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) ); DisablerPane.getInstance().setVisible( true ); try { final PiperFileReader reader = new PiperFileReader(); final String text = _piperDocument.getText( 0, _piperDocument.getLength() ); final String[] lines = text.split( "\\n" ); for ( String line : lines ) { reader.parsePipelineLine( line ); } reader.getBuilder().run(); } catch ( Throwable t ) { LOGGER.error( "Pipeline Run caused Exception:", t ); } DisablerPane.getInstance().setVisible( false ); frame.setCursor( Cursor.getDefaultCursor() ); } }
styledDocument.getText(0, styledDocument.getLength(), segment);
/** * Determine how many lines have been changed, then apply highlighting to each * line. * * @param offset the offset of the changed lines * @param length the length of the change * @throws BadLocationException if offset is invalid */ public void processChangedLines(int offset, int length) throws BadLocationException { String content = m_Self.getText(0, m_Self.getLength()); // The lines affected by the latest document update int startLine = m_RootElement.getElementIndex(offset); int endLine = m_RootElement.getElementIndex(offset + length); // Make sure all comment lines prior to the start line are commented // and determine if the start line is still in a multi line comment if (getMultiLineComment()) { setInsideMultiLineComment(commentLinesBefore(content, startLine)); } // Do the actual highlighting for (int i = startLine; i <= endLine; i++) { applyHighlighting(content, i); } // Resolve highlighting to the next end multi line delimiter if (isMultiLineComment()) { commentLinesAfter(content, endLine); } else { highlightLinesAfter(content, endLine); } }
/** * Determine how many lines have been changed, then apply highlighting to each * line. * * @param offset the offset of the changed lines * @param length the length of the change * @throws BadLocationException if offset is invalid */ public void processChangedLines(int offset, int length) throws BadLocationException { String content = m_Self.getText(0, m_Self.getLength()); // The lines affected by the latest document update int startLine = m_RootElement.getElementIndex(offset); int endLine = m_RootElement.getElementIndex(offset + length); // Make sure all comment lines prior to the start line are commented // and determine if the start line is still in a multi line comment if (getMultiLineComment()) { setInsideMultiLineComment(commentLinesBefore(content, startLine)); } // Do the actual highlighting for (int i = startLine; i <= endLine; i++) { applyHighlighting(content, i); } // Resolve highlighting to the next end multi line delimiter if (isMultiLineComment()) { commentLinesAfter(content, endLine); } else { highlightLinesAfter(content, endLine); } }