List of usage examples for javax.swing.text StyledDocument getLength
public int getLength();
From source file:ome.formats.importer.gui.GuiCommonElements.java
/** * A version of addTextPane that lets you add a style and context * /* w ww .j ava 2 s . c o m*/ * @param container - parent container * @param text - text for new Text Pane * @param placement - TableLayout placement within the parent container * @param context - context for new text pane * @param style - style to apply to new text pane * @param debug - turn on/off red debug borders * @return new JTextPane */ public static synchronized JTextPane addTextPane(Container container, String text, String placement, StyleContext context, Style style, boolean debug) { StyledDocument document = new DefaultStyledDocument(context); try { document.insertString(document.getLength(), text, style); } catch (BadLocationException e) { log.error("BadLocationException inserting text to document."); } JTextPane textPane = new JTextPane(document); textPane.setOpaque(false); textPane.setEditable(false); textPane.setFocusable(false); container.add(textPane, placement); if (debug == true) textPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), textPane.getBorder())); return textPane; }
From source file:ome.formats.importer.gui.GuiImporter.java
/** * This method appends data to the output window * //from www .j a va 2s . c o m * @param s - text to append */ public void appendToOutput(String s) { try { StyledDocument doc = (StyledDocument) outputTextPane.getDocument(); Style style = doc.addStyle("StyleName", null); StyleConstants.setForeground(style, Color.black); StyleConstants.setFontFamily(style, "SansSerif"); StyleConstants.setFontSize(style, 12); StyleConstants.setBold(style, false); doc.insertString(doc.getLength(), s, style); //trim the document size so it doesn't grow to big int maxChars = 200000; if (doc.getLength() > maxChars) doc.remove(0, doc.getLength() - maxChars); //outputTextPane.setDocument(doc); } catch (BadLocationException e) { } }
From source file:ome.formats.importer.gui.GuiImporter.java
/** * This method appends data to the output window. * //from ww w . jav a 2 s . com * @param s - string to append */ public void appendToDebug(String s) { log.debug(s); try { StyledDocument doc = (StyledDocument) debugTextPane.getDocument(); Style style = doc.addStyle("StyleName", null); StyleConstants.setForeground(style, Color.black); StyleConstants.setFontFamily(style, "SansSerif"); StyleConstants.setFontSize(style, 12); StyleConstants.setBold(style, false); doc.insertString(doc.getLength(), s, style); //trim the document size so it doesn't grow to big int maxChars = 200000; if (doc.getLength() > maxChars) doc.remove(0, doc.getLength() - maxChars); //debugTextPane.setDocument(doc); } catch (BadLocationException e) { } }
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 {// w w w . j ava 2 s . c o 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:org.dodjsoft.tail.TailFilePanel.java
@Override public void handle(final String string) { SwingUtilities.invokeLater(new Runnable() { @Override//from w w w .ja va 2 s.c o m public void run() { StyledDocument document = (StyledDocument) tailTextPanel.getDocument(); try { document.insertString(document.getLength(), string + "\n", null); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } tailTextPanel.setCaretPosition(document.getLength()); } }); }
From source file:org.drugis.addis.gui.wizard.AddStudyWizard.java
private static JComponent buildTip(String tip) { JTextPane area = new JTextPane(); StyledDocument doc = area.getStyledDocument(); addStylesToDoc(doc);/*from ww w.java 2 s .c o m*/ area.setBackground(new Color(255, 180, 180)); try { doc.insertString(0, "x", doc.getStyle("tip")); doc.insertString(doc.getLength(), " Tip: \n", doc.getStyle("bold")); doc.insertString(doc.getLength(), tip, doc.getStyle("regular")); } catch (BadLocationException e) { e.printStackTrace(); } area.setEditable(false); JScrollPane pane = new JScrollPane(area); pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); pane.setPreferredSize(TextComponentFactory.textPaneDimension(area, 270, 70)); pane.setWheelScrollingEnabled(true); pane.getVerticalScrollBar().setValue(0); return pane; }
From source file:org.fit.cssbox.scriptbox.demo.tester.ConsoleInjector.java
private static void clearStyledDocumentImpl(final StyledDocument doc) { try {//from ww w. j a v a 2 s . c o m doc.remove(0, doc.getLength()); } catch (BadLocationException e) { e.printStackTrace(); } }
From source file:org.netbeans.jcode.core.util.JavaSourceHelper.java
public static void reformat(DataObject dob) { try {/*from w w w .j a va 2s. c om*/ EditorCookie ec = dob.getLookup().lookup(EditorCookie.class); if (ec == null) { return; } final StyledDocument doc = ec.openDocument(); final Reformat reformat = Reformat.get(doc); reformat.lock(); try { NbDocument.runAtomicAsUser(doc, new Runnable() { @Override public void run() { try { reformat.reformat(0, doc.getLength()); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } }); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } finally { reformat.unlock(); ec.saveDocument(); } } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
From source file:org.openmicroscopy.shoola.agents.fsimporter.view.ImporterUI.java
/** * Adds the text to the debug pane.// w w w. j a v a 2 s . c o m * * @param text The text to display. */ void appendDebugText(String text) { if (debugTextPane == null) return; StyledDocument doc = (StyledDocument) debugTextPane.getDocument(); try { doc.insertString(doc.getLength(), text, doc.getStyle(STYLE)); if (doc.getLength() > MAX_CHAR) doc.remove(0, doc.getLength() - MAX_CHAR); } catch (Exception e) { //ignore } }
From source file:org.openmicroscopy.shoola.util.ui.MessengerDialog.java
/** * Builds the UI component displaying the exception. * //from w w w. j a v a 2 s . c om * @return See above. */ private JTextPane buildExceptionArea() { JTextPane pane = UIUtilities.buildExceptionArea(); StyledDocument document = pane.getStyledDocument(); Style style = pane.getLogicalStyle(); //Get the full debug text StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); exception.printStackTrace(pw); try { document.insertString(document.getLength(), sw.toString(), style); } catch (BadLocationException e) { } return pane; }