/** Mark part of a document as guarded (immutable to the user). * @param doc styled document * @param offset offset to start at * @param len length of text to mark as guarded * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void markGuarded (StyledDocument doc, int offset, int len) { checkDocParameter(doc); doc.setCharacterAttributes (offset, len, ATTR_ADD, false); }
/** Inserts a text into given offset and marks it guarded. * @param doc document to insert to * @param offset offset of insertion * @param txt string text to insert * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void insertGuarded (StyledDocument doc, int offset, String txt) throws BadLocationException { checkDocParameter(doc); doc.insertString (offset, txt, ATTR_ADD); }
/** Mark part of a document as guarded (immutable to the user). * @param doc styled document * @param offset offset to start at * @param len length of text to mark as guarded * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void markGuarded(StyledDocument doc, int offset, int len) { checkDocParameter(doc); doc.setCharacterAttributes(offset, len, ATTR_ADD, false); }
/** Inserts a text into given offset and marks it guarded. * @param doc document to insert to * @param offset offset of insertion * @param txt string text to insert * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void insertGuarded(StyledDocument doc, int offset, String txt) throws BadLocationException { checkDocParameter(doc); doc.insertString(offset, txt, ATTR_ADD); }
/** Remove guarded mark on a block of a document. * @param doc styled document * @param offset offset to start at * @param len length of text to mark as unguarded * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void unmarkGuarded (StyledDocument doc, int offset, int len) { checkDocParameter(doc); doc.setCharacterAttributes (offset, len, ATTR_REMOVE, false); }
/** Remove guarded mark on a block of a document. * @param doc styled document * @param offset offset to start at * @param len length of text to mark as unguarded * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void unmarkGuarded (StyledDocument doc, int offset, int len) { checkDocParameter(doc); doc.setCharacterAttributes (offset, len, ATTR_REMOVE, false); }
/** Mark part of a document as guarded (immutable to the user). * @param doc styled document * @param offset offset to start at * @param len length of text to mark as guarded * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void markGuarded (StyledDocument doc, int offset, int len) { checkDocParameter(doc); doc.setCharacterAttributes (offset, len, ATTR_ADD, false); }
/** Inserts a text into given offset and marks it guarded. * @param doc document to insert to * @param offset offset of insertion * @param txt string text to insert * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void insertGuarded (StyledDocument doc, int offset, String txt) throws BadLocationException { checkDocParameter(doc); doc.insertString (offset, txt, ATTR_ADD); }
/** Remove guarded mark on a block of a document. * @param doc styled document * @param offset offset to start at * @param len length of text to mark as unguarded * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void unmarkGuarded(StyledDocument doc, int offset, int len) { checkDocParameter(doc); doc.setCharacterAttributes(offset, len, ATTR_REMOVE, false); }
/** Locks the document to have exclusive access to it. * Documents implementing {@link Lockable} can specify exactly how to do this. * * @param doc document to lock * @param run the action to run * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void runAtomic(StyledDocument doc, Runnable run) { checkDocParameter(doc); if (doc instanceof WriteLockable) { // use the method ((WriteLockable) doc).runAtomic(run); } else { // transfer the runnable to event dispatch thread synchronized (doc) { run.run(); } } }
/** Locks the document to have exclusive access to it. * Documents implementing {@link Lockable} can specify exactly how to do this. * * @param doc document to lock * @param run the action to run * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void runAtomic (StyledDocument doc, Runnable run) { checkDocParameter(doc); if (doc instanceof WriteLockable) { // use the method ((WriteLockable)doc).runAtomic (run); } else { // transfer the runnable to event dispatch thread synchronized (doc) { run.run (); } } }
/** Executes given runnable in "user mode" does not allowing any modifications * to parts of text marked as guarded. The actions should be run as "atomic" so * either happen all at once or none at all (if a guarded block should be modified). * * @param doc document to modify * @param run runnable to run in user mode that will have exclusive access to modify the document * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. * @exception BadLocationException if a modification of guarded text occured * and that is why no changes to the document has been done. */ public static void runAtomicAsUser (StyledDocument doc, Runnable run) throws BadLocationException { checkDocParameter(doc); if (doc instanceof WriteLockable) { // use the method ((WriteLockable)doc).runAtomicAsUser (run); } else { // transfer the runnable to event dispatch thread synchronized (doc) { run.run (); } } }
/** Locks the document to have exclusive access to it. * Documents implementing {@link Lockable} can specify exactly how to do this. * * @param doc document to lock * @param run the action to run * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static void runAtomic (StyledDocument doc, Runnable run) { checkDocParameter(doc); if (doc instanceof WriteLockable) { // use the method ((WriteLockable)doc).runAtomic (run); } else { // transfer the runnable to event dispatch thread synchronized (doc) { run.run (); } } }
/** * Mark a line as normal (no special attributes). * This uses the dummy style named {@link #NORMAL_STYLE_NAME}. * This method should be used to undo the effect of {@link #markBreakpoint}, {@link #markError} and {@link #markCurrent}. * @param doc the document * @param offset identified the line to unmark * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. * * @deprecated since 1.20. Use addAnnotation() instead */ @Deprecated public static void markNormal(StyledDocument doc, int offset) { checkDocParameter(doc); Style st = doc.getStyle(NORMAL_STYLE_NAME); if (st == null) { st = doc.addStyle(NORMAL_STYLE_NAME, null); } if (st != null) { doc.setLogicalStyle(offset, st); } }
/** Find the root element of all lines. * All conforming NetBeans documents * should return a valid element. * * @param doc styled document (expecting NetBeans document) * @return the root element * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static Element findLineRootElement(StyledDocument doc) { checkDocParameter(doc); Element e = doc.getParagraphElement(0).getParentElement(); if (e == null) { // try default root (should work for text/plain) e = doc.getDefaultRootElement(); } return e; }
/** Find the root element of all lines. * All conforming NetBeans documents * should return a valid element. * * @param doc styled document (expecting NetBeans document) * @return the root element * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static Element findLineRootElement (StyledDocument doc) { checkDocParameter(doc); Element e = doc.getParagraphElement (0).getParentElement (); if (e == null) { // try default root (should work for text/plain) e = doc.getDefaultRootElement (); } return e; }
/** Find the root element of all lines. * All conforming NetBeans documents * should return a valid element. * * @param doc styled document (expecting NetBeans document) * @return the root element * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static Element findLineRootElement (StyledDocument doc) { checkDocParameter(doc); Element e = doc.getParagraphElement (0).getParentElement (); if (e == null) { // try default root (should work for text/plain) e = doc.getDefaultRootElement (); } return e; }
/** * Mark a line as normal (no special attributes). * This uses the dummy style named {@link #NORMAL_STYLE_NAME}. * This method should be used to undo the effect of {@link #markBreakpoint}, {@link #markError} and {@link #markCurrent}. * @param doc the document * @param offset identified the line to unmark * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. * * @deprecated since 1.20. Use addAnnotation() instead */ public static void markNormal (StyledDocument doc, int offset) { checkDocParameter(doc); Style st = doc.getStyle (NORMAL_STYLE_NAME); if (st == null) st = doc.addStyle (NORMAL_STYLE_NAME, null); if (st != null) { doc.setLogicalStyle (offset, st); } }
/** * Mark a line as normal (no special attributes). * This uses the dummy style named {@link #NORMAL_STYLE_NAME}. * This method should be used to undo the effect of {@link #markBreakpoint}, {@link #markError} and {@link #markCurrent}. * @param doc the document * @param offset identified the line to unmark * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. * * @deprecated since 1.20. Use addAnnotation() instead */ public static void markNormal (StyledDocument doc, int offset) { checkDocParameter(doc); Style st = doc.getStyle (NORMAL_STYLE_NAME); if (st == null) st = doc.addStyle (NORMAL_STYLE_NAME, null); if (st != null) { doc.setLogicalStyle (offset, st); } }
/** Marks a line as current (e.g. for the debugger). * If the document has a defined style named {@link #CURRENT_STYLE_NAME}, it is used. * Otherwise, a new style is defined. * * @param doc the document * @param offset identifies the line to mark * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. * * @deprecated since 1.20. Use addAnnotation() instead */ public static void markCurrent (StyledDocument doc, int offset) { checkDocParameter(doc); Style bp = doc.getStyle (CURRENT_STYLE_NAME); if (bp == null) { // create the style bp = doc.addStyle (CURRENT_STYLE_NAME, null); if (bp == null) return; bp.addAttribute ( StyleConstants.ColorConstants.Background, Color.blue ); bp.addAttribute ( StyleConstants.ColorConstants.Foreground, Color.white ); } doc.setLogicalStyle (offset, bp); }