@Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { synchronized (this.docLock) { super.insertString(offs, str, a); this.color(offs, str.length()); this.documentReader.update(offs, str.length()); } }
DefaultStyledDocument document = new DefaultStyledDocument(); JTextPane textpane = new JTextPane(document); StyleContext context = new StyleContext(); // build a style Style style = context.addStyle("test", null); // set some style properties StyleConstants.setForeground(style, Color.BLUE); // add some data to the document document.insertString(0, "", style);
protected void superInsertString(int offs, String str, AttributeSet a) throws BadLocationException { super.insertString(offs, str, a); }
@Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { str = str.replaceAll("\t", " "); super.insertString(offs, str, a); } }
@Override public void insertString(final int offset, final String str, final AttributeSet attr) throws BadLocationException { super.insertString(offset, str, attr); processChangedLines(offset, str.length()); }
@Override public void actionPerformed( final ActionEvent event ) { try { final int caret = getInsertCaret(); _piperDocument .insertString( caret, "\n// Add a Package that contains Pipe Bits or Piper files\npackage ", null ); } catch ( BadLocationException blE ) { LOGGER.error( blE.getMessage() ); } _runButton.setEnabled( false ); } }
@Override public void actionPerformed( final ActionEvent event ) { try { final int caret = getInsertCaret(); _piperDocument.insertString( caret, "\n// Load a Piper file containing a partial Pipeline\nload ", null ); } catch ( BadLocationException blE ) { LOGGER.error( blE.getMessage() ); } _runButton.setEnabled( false ); } }
@Override public void insertString(final int offset, final String string, final AttributeSet attributes) throws BadLocationException { int length = getLength(); if (string == null) { return; } if (length + string.length() > maxLength) { Toolkit.getDefaultToolkit().beep(); return; } super.insertString(offset, string, attributes); } }
@Override public void actionPerformed( final ActionEvent event ) { try { // TODO - hook "set" to the parameter selected in the parameter table. Can use Value from table. // Would require tracking. Or maybe a constant parse and track of variables set when the formatting is done. // Then the "add" button would need to be enabled accordingly ... // and the parameter table could display the mapped value. final int caret = getInsertCaret(); _piperDocument.insertString( caret, "\n// Set a global value\nset ", null ); } catch ( BadLocationException blE ) { LOGGER.error( blE.getMessage() ); } _runButton.setEnabled( false ); } }
DefaultStyledDocument doc = new DefaultStyledDocument(); StyleContext sc = new StyleContext(); Style style = sc.addStyle("strikethru", null); StyleConstants.setStrikeThrough (style,true); doc.insertString (0, "Hello ", null); doc.insertString (6, "strike through ", style); JTextPane pane = new JTextPane(doc);
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { synchronized (docLock) { super.insertString(offs, str, a); color(offs, str.length()); documentReader.update(offs, str.length()); } }
private void setParseText(String text) { try { // Add the text to the document expressionTextDoc.remove(0, expressionTextPane.getText().length()); expressionTextDoc.insertString(0, text, null); } catch (BadLocationException e) { e.printStackTrace(); throw new RuntimeException(e); } }
public void run() { try { doc.insertString(index, text, style); index = index + text.length(); invalidate(); repaint(); } catch (BadLocationException e) { e.printStackTrace(); } } });
private void addCom(String text){ AttributeSet attribute = attributes.get("0"); try{ int len = doc.getLength(); doc.insertString(len, text, attribute); }catch (BadLocationException e){ e.printStackTrace(); } chat.setCaretPosition(chat.getDocument().getLength()); }
private void createNewPiper() { final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern( "MMMM dd, yyyy" ); final LocalDate date = LocalDate.now(); final String text = "// *** Piper File ***\n" + "// Created by " + System.getProperty( "user.name" ) + "\n" + "// on " + date.format( dateFormatter ) + "\n\n"; try { _piperDocument.remove( 0, _piperDocument.getLength() ); _piperDocument.insertString( 0, text, null ); _textPane.setCaretPosition( _piperDocument.getLength() ); } catch ( BadLocationException blE ) { LOGGER.warn( blE.getMessage() ); } _runButton.setEnabled( false ); }
@Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { setOldState(); final String origin = getText(0, getLength()); final int index = StringUtils.getLen(origin, str, maxNumberOfCharacters); if (index > 0) { super.insertString(offs, str.substring(0, index), a); } }
public void run() { Style style = document.getStyle(styleName); try { document.insertString( document.getEndPosition().getOffset() - 1, message, style); } catch (BadLocationException exc) { exc.printStackTrace(); } } });
public void uncolorize() { try { String text = getText(0, getLength()); super.remove(0, getLength()); super.insertString(0, text, null); } catch (BadLocationException ex) {} }
DefaultStyledDocument document = new DefaultStyledDocument(); JTextPane textpane = new JTextPane(document); StyleContext context = new StyleContext(); // build a style Style style = context.addStyle("test", null); // set some style color StyleConstants.setForeground(style, Color.RED); // add some data to the document document.insertString(0, "", style); OR JTextPane pane = new JTextPane(); SimpleAttributeSet set = new SimpleAttributeSet(); StyleConstants.setForeground(set, Color.red); Document doc = pane.getStyledDocument(); doc.insertString(doc.getLength(), "Kleine ", set);
private void updatePatterns() { final String text = loggerConfigTextPane.getText(); final List<LogPattern> resultList = getLogPatterns(text); try { styledDocument.remove(0, styledDocument.getLength()); for (LogPattern result : resultList) { resultTextPane.insertIcon(result.isValid() ? Icons.STATUS_OK : Icons.STATUS_ERROR); styledDocument.insertString(styledDocument.getLength(), " " + result.getPattern() + "\n", defaultStyle); } } catch (BadLocationException ignore) { } if (resultList.isEmpty()) { resultTextPane.setText("No logger patterns detected in project opened in IDE."); } }