Java Code Examples for javax.swing.text.AbstractDocument

The following examples show how to use javax.swing.text.AbstractDocument. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: PacketProxy   Source File: WrapEditorKit.java    License: Apache License 2.0 6 votes vote down vote up
public View create(Element elem) {
	String kind = elem.getName();
	if (kind != null) {
		if (kind.equals(AbstractDocument.ContentElementName)) {
			return new WrapLabelView(elem);
		} else if (kind.equals(AbstractDocument.ParagraphElementName)) {
			return new CustomParagraphView(elem);
		} else if (kind.equals(AbstractDocument.SectionElementName)) {
			return new BoxView(elem, View.Y_AXIS);
		} else if (kind.equals(StyleConstants.ComponentElementName)) {
			return new ComponentView(elem);
		} else if (kind.equals(StyleConstants.IconElementName)) {
			return new IconView(elem);
		}
	}
	return new LabelView(elem);
}
 
Example 2
Source Project: stendhal   Source File: KTextEdit.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public View create(Element elem) {
	String kind = elem.getName();
	if (kind != null) {
		if (kind.equals(AbstractDocument.ContentElementName)) {
			return new WrapLabelView(elem);
		} else if (kind.equals(AbstractDocument.ParagraphElementName)) {
			return new ParagraphView(elem);
		} else if (kind.equals(AbstractDocument.SectionElementName)) {
			return new BoxView(elem, View.Y_AXIS);
		} else if (kind.equals(StyleConstants.ComponentElementName)) {
			return new ComponentView(elem);
		} else if (kind.equals(StyleConstants.IconElementName)) {
			return new IconView(elem);
		}
	}

	// default to text display
	return new LabelView(elem);
}
 
Example 3
Source Project: Explvs-AIO   Source File: DoubleField.java    License: MIT License 6 votes vote down vote up
public DoubleField() {
    ((AbstractDocument) getDocument()).setDocumentFilter(new DoubleDocumentFilter());

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });
}
 
Example 4
Source Project: Explvs-AIO   Source File: IntegerField.java    License: MIT License 6 votes vote down vote up
public IntegerField() {
    ((AbstractDocument) getDocument()).setDocumentFilter(new IntegerDocumentFilter());

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });
}
 
Example 5
Source Project: netbeans   Source File: HighlightingTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check highlight ranges.
 *
 * @param content Javadoc
 * @param offsetRanges start and end offset ranges
 */
private void checkHighlights(String content, int[] offsetRanges) {
    Document document = createDocument(content);
    ((AbstractDocument) document).readLock();
    try {
        Highlighting highlighting = new Highlighting(document);
        HighlightsSequence hs = highlighting.getHighlights(0, document.getLength());
        assertEquals(0, offsetRanges.length % 2);
        assertTrue(hs.moveNext());
        for (int i = 0; i < offsetRanges.length; i += 2) {
            assertEquals(offsetRanges[i], hs.getStartOffset());
            assertEquals(offsetRanges[i + 1], hs.getEndOffset());
            if (!hs.moveNext()) {
                assertEquals(offsetRanges.length, i + 2);
                break;
            }
        }
    } finally {
        ((AbstractDocument) document).readUnlock();
    }
}
 
Example 6
Source Project: netbeans   Source File: TokenSequenceTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testSubSequenceInUnfinishedTH() throws Exception {
    Document doc = new ModificationTextDocument();
    //             012345678
    String text = "ab cd efg";
    doc.insertString(0, text, null);
    
    doc.putProperty(Language.class,TestTokenId.language());
    TokenHierarchy<?> hi = TokenHierarchy.get(doc);

    ((AbstractDocument)doc).readLock();
    try {
        TokenSequence<?> ts = hi.tokenSequence();
        assertTrue(ts.moveNext());

        ts = ts.subSequence(2, 6);
        assertTrue(ts.moveNext());
        LexerTestUtilities.assertTokenEquals(ts,TestTokenId.WHITESPACE, " ", 2);
        assertTrue(ts.moveNext());
        LexerTestUtilities.assertTokenEquals(ts,TestTokenId.IDENTIFIER, "cd", 3);
        assertTrue(ts.moveNext());
        LexerTestUtilities.assertTokenEquals(ts,TestTokenId.WHITESPACE, " ", 5);
        assertFalse(ts.moveNext());
    } finally {
        ((AbstractDocument)doc).readUnlock();
    }
}
 
Example 7
Source Project: netbeans   Source File: JoinSectionsPositioningTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testShortDoc() throws Exception {
    //             000000000011111111112222222222
    //             012345678901234567890123456789
    String text = "a<b>c";
    ModificationTextDocument doc = new ModificationTextDocument();
    doc.insertString(0, text, null);
    doc.putProperty(Language.class, TestJoinTopTokenId.language());
    TokenHierarchy<?> hi = TokenHierarchy.get(doc);
    ((AbstractDocument)doc).readLock();
    try {
        TokenSequence<?> ts = hi.tokenSequence();
        assertTrue(ts.moveNext());
        ts.embedded(); // Creates JTL
    } finally {
        ((AbstractDocument)doc).readUnlock();
    }
}
 
Example 8
Source Project: PolyGlot   Source File: GlyphVectorEditorKit.java    License: MIT License 6 votes vote down vote up
public View create(Element elem) {
    String kind = elem.getName();
    if (kind != null) {
        if (kind.equals(AbstractDocument.ContentElementName)) {
            return new PainterLabelView(elem);
        }
        else if (kind.equals(AbstractDocument.ParagraphElementName)) {
            return new ParagraphView(elem);
        }
        else if (kind.equals(AbstractDocument.SectionElementName)) {
            return new BoxView(elem, View.Y_AXIS);
        }
        else if (kind.equals(StyleConstants.ComponentElementName)) {
            return new ComponentView(elem);
        }
        else if (kind.equals(StyleConstants.IconElementName)) {
            return new IconView(elem);
        }
    }

    // default to text display
    return new LabelView(elem);
}
 
Example 9
Source Project: netbeans   Source File: XMLSyntaxSupport.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get token at given offet or previous one if at token boundary.
 * It does not lock the document. Returns {@code null} for invalid offsets.
 * 
 * @param offset valid position in document
 * @return Token instance
 */
public Token<XMLTokenId> getNextToken( int offset) throws BadLocationException {
    if (offset == 0) {
        offset = 1;
    }
    if (offset < 0) throw new BadLocationException("Offset " +
            offset + " cannot be less than 0.", offset);  //NOI18N
    ((AbstractDocument)document).readLock();
    try {
        TokenSequence ts = getSequence();
        synchronized (ts) {
            return getToken(ts, offset, true, null);
        }
    } finally {
        ((AbstractDocument)document).readUnlock();
    }
}
 
Example 10
Source Project: netbeans   Source File: NbGenerateCodeAction.java    License: Apache License 2.0 6 votes vote down vote up
private static MimePath getFullMimePath(Document document, int offset) {
    String langPath = null;

    if (document instanceof AbstractDocument) {
        AbstractDocument adoc = (AbstractDocument)document;
        adoc.readLock();
        try {
            List<TokenSequence<?>> list = TokenHierarchy.get(document).embeddedTokenSequences(offset, true);
            if (list.size() > 1) {
                langPath = list.get(list.size() - 1).languagePath().mimePath();
            }
        } finally {
            adoc.readUnlock();
        }
    }

    if (langPath == null) {
        langPath = NbEditorUtilities.getMimeType(document);
    }

    if (langPath != null) {
        return MimePath.parse(langPath);
    } else {
        return null;
    }
}
 
Example 11
Source Project: netbeans   Source File: LanguageManagerTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testKnownMimeType() {
    PlainDocument doc = new PlainDocument();
    doc.putProperty("mimeType", MIME_TYPE_KNOWN);
    
    TokenHierarchy th = TokenHierarchy.get(doc);
    ((AbstractDocument)doc).readLock();
    try {
        Language lang = th.tokenSequence().language();
        assertNotNull("There should be language for " + MIME_TYPE_KNOWN, lang);

        assertNotNull("Invalid mime type", lang.mimeType());
        assertEquals("Wrong language's mime type", MIME_TYPE_KNOWN, lang.mimeType());
    } finally {
        ((AbstractDocument)doc).readUnlock();
    }
}
 
Example 12
Source Project: netbeans   Source File: XMLSyntaxSupport.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Executes user code on token sequence from the document.
 * Read-locks the document, obtains {@link TokenSequence} from the Lexer and executes {@code userCode} 
 * passing the initialized sequence. The sequence is moved to the desired offset and the token that contains
 * or starts at that position. The client can move the sequence elsewhere.
 * <p/>
 * If the {@code userCode} calls this {@code SyntaxSupport} methods like {@link #getNextToken(int)}, they will use
 * the <b>same TokenSequence</b> as passed to {@code userCode}. This allows to combine navigation calls from {@link XMLSyntaxSupport}
 * with client's own sequence movements. The TokenSequence instance passed to {@code userCode} can be queried for
 * current token offset after navigation.
 * 
 * @param <T>
 * @param offset offset to position the sequence at
 * @param userCode code to execute
 * @return user-defined value
 * @throws BadLocationException if the user code throws BadLocationException
 * @throws IllegalStateException if the user code throws a checked exception
 */
@NullUnknown
public <T> T runWithSequence(int offset, SequenceCallable<T> userCode) throws BadLocationException {
    T result;
    TokenSequence old = null;
    try {
        ((AbstractDocument)document).readLock();
        old = cachedSequence.get();
        cachedSequence.remove();
        TokenSequence ts = getSequence();
        if (ts == null) {
            throw new BadLocationException("No sequence for position", offset); // NOI18N
        }
        cachedSequence.set(ts);
        synchronized (ts) {
            ts.move(offset);
            ts.moveNext();
            result = userCode.call(ts);
        }
    } finally {
        cachedSequence.set(old);
        ((AbstractDocument)document).readUnlock();
    }
    return result;
}
 
Example 13
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
@Override public View create(Element elem) {
  switch (elem.getName()) {
    // case AbstractDocument.ContentElementName:
    //   return new WhitespaceLabelView(elem);
    case AbstractDocument.ParagraphElementName:
      return new ParagraphWithEopmView(elem);
    case AbstractDocument.SectionElementName:
      return new BoxView(elem, View.Y_AXIS);
    case StyleConstants.ComponentElementName:
      return new ComponentView(elem);
    case StyleConstants.IconElementName:
      return new IconView(elem);
    default:
      return new WhitespaceLabelView(elem);
  }
}
 
Example 14
Source Project: netbeans   Source File: CompletionUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks to see if this document declares any DOCTYPE or not?
 * If exists, it must appear before the first xml tag.
 * @return true if found, else false.
 */
public static boolean isDTDBasedDocument(Document document) {
    ((AbstractDocument)document).readLock();
    try {
        TokenHierarchy th = TokenHierarchy.get(document);
        TokenSequence ts = th.tokenSequence();
        while(ts.moveNext()) {
            Token token = ts.token();
            //if an xml tag is found, we have come too far.
            if(token.id() == XMLTokenId.TAG)
                return false;
            if(token.id() == XMLTokenId.DECLARATION)
                return true;
        }
    } finally {
        ((AbstractDocument)document).readUnlock();
    }
    return false;
}
 
Example 15
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
private MainPanel() {
  super(new GridLayout(2, 1));
  JTextField field = new JTextField(12);

  ((AbstractDocument) field.getDocument()).setDocumentFilter(new SizeFilter());
  // ((AbstractDocument) field.getDocument()).setDocumentFilter(new DocumentSizeFilter(5));

  ActionMap am = field.getActionMap();

  String key = DefaultEditorKit.deletePrevCharAction; // "delete-previous";
  am.put(key, new SilentDeleteTextAction(key, am.get(key)));

  key = DefaultEditorKit.deleteNextCharAction; // "delete-next";
  am.put(key, new SilentDeleteTextAction(key, am.get(key)));

  add(makeTitledPanel("Default", new JTextField()));
  add(makeTitledPanel("Override delete-previous, delete-next beep", field));
  setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
  setPreferredSize(new Dimension(320, 240));
}
 
Example 16
Source Project: netbeans   Source File: CodeTemplateManagerOperation.java    License: Apache License 2.0 6 votes vote down vote up
private static MimePath getFullMimePath(Document document, int offset) {
    String langPath = null;

    if (document instanceof AbstractDocument) {
        AbstractDocument adoc = (AbstractDocument)document;
        adoc.readLock();
        try {
            List<TokenSequence<?>> list = TokenHierarchy.get(document).embeddedTokenSequences(offset, true);
            if (list.size() > 1) {
                langPath = list.get(list.size() - 1).languagePath().mimePath();
            }
        } finally {
            adoc.readUnlock();
        }
    }

    if (langPath == null) {
        langPath = NbEditorUtilities.getMimeType(document);
    }

    if (langPath != null) {
        return MimePath.parse(langPath);
    } else {
        return null;
    }
}
 
Example 17
Source Project: netbeans   Source File: ViewFactoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
public View create(Element elem) {
    String kind = elem.getName();
    if (kind != null) {
        if (kind.equals(AbstractDocument.ContentElementName)) {
            return new LabelView(elem);
        } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
            return null;
        } else if (kind.equals(AbstractDocument.SectionElementName)) {
            return new DocumentView(elem);
        } else if (kind.equals(StyleConstants.ComponentElementName)) {
            return new ComponentView(elem);
        } else if (kind.equals(StyleConstants.IconElementName)) {
            return new IconView(elem);
        }
    }
    return null;
}
 
Example 18
Source Project: jeveassets   Source File: TextManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void installTextComponent(final JTextComponent component) {
	//Make sure this component does not already have a UndoManager
	Document document = component.getDocument();
	boolean found = false;
	if (document instanceof AbstractDocument) {
		AbstractDocument abstractDocument = (AbstractDocument) document;
		for (UndoableEditListener editListener : abstractDocument.getUndoableEditListeners()) {
			if (editListener.getClass().equals(CompoundUndoManager.class)) {
				CompoundUndoManager undoManager = (CompoundUndoManager) editListener;
				undoManager.reset();
				return;
			}
		}
	}
	if (!found) {
		new TextManager(component);
	}
}
 
Example 19
Source Project: libreveris   Source File: LogPane.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create the log pane, with a standard mailbox.
 */
public LogPane ()
{
    // Build the scroll pane
    component = new JScrollPane();
    component.setBorder(null);

    // log/status area
    logArea = new JTextPane();
    logArea.setEditable(false);
    logArea.setMargin(new Insets(5, 5, 5, 5));
    document = (AbstractDocument) logArea.getStyledDocument();

    // Let the scroll pane display the log area
    component.setViewportView(logArea);
}
 
Example 20
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
@Override public ViewFactory getViewFactory() {
  return new HTMLEditorKit.HTMLFactory() {
    @Override public View create(Element elem) {
      View view = super.create(elem);
      if (view instanceof LabelView) {
        System.out.println("debug: " + view.getAlignment(View.Y_AXIS));
      }
      AttributeSet attrs = elem.getAttributes();
      Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
      Object o = Objects.nonNull(elementName) ? null : attrs.getAttribute(StyleConstants.NameAttribute);
      if (o instanceof HTML.Tag) {
        HTML.Tag kind = (HTML.Tag) o;
        if (kind == HTML.Tag.IMG) {
          return new ImageView(elem) {
            @Override public float getAlignment(int axis) {
              // .8125f magic number...
              return axis == View.Y_AXIS ? .8125f : super.getAlignment(axis);
            }
          };
        }
      }
      return view;
    }
  };
}
 
Example 21
Source Project: Bytecoder   Source File: ImageView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Invokes <code>preferenceChanged</code> on the event displatching
 * thread.
 */
private void safePreferenceChanged() {
    if (SwingUtilities.isEventDispatchThread()) {
        Document doc = getDocument();
        if (doc instanceof AbstractDocument) {
            ((AbstractDocument)doc).readLock();
        }
        preferenceChanged(null, true, true);
        if (doc instanceof AbstractDocument) {
            ((AbstractDocument)doc).readUnlock();
        }
    }
    else {
        SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    safePreferenceChanged();
                }
            });
    }
}
 
Example 22
Source Project: netbeans   Source File: LegacyEssMatcher.java    License: Apache License 2.0 6 votes vote down vote up
public int[] findOrigin() throws BadLocationException {
    ((AbstractDocument) context.getDocument()).readLock();
    try {
        int offset;

        if (context.isSearchingBackward()) {
            offset = context.getSearchOffset() - 1;
        } else {
            offset = context.getSearchOffset();
        }

        block = ess.findMatchingBlock(offset, false);
        if (block == null) {
            return null;
        } else if (block.length == 0) {
            return block;
        } else {
            return new int [] { offset, offset };
        }
    } finally {
        ((AbstractDocument) context.getDocument()).readUnlock();
    }
}
 
Example 23
Source Project: netbeans   Source File: CharacterMatcher.java    License: Apache License 2.0 6 votes vote down vote up
public int [] findOrigin() throws BadLocationException {
    ((AbstractDocument) context.getDocument()).readLock();
    try {
        int result [] = BracesMatcherSupport.findChar(
            context.getDocument(),
            context.getSearchOffset(),
            context.isSearchingBackward() ?
                Math.max(context.getLimitOffset(), lowerBound) :
                Math.min(context.getLimitOffset(), upperBound),
            matchingPairs
        );

        if (result != null) {
            originOffset = result[0];
            originalChar = matchingPairs[result[1]];
            matchingChar = matchingPairs[result[1] + result[2]];
            backward = result[2] < 0;
            return new int [] { originOffset, originOffset + 1 };
        } else {
            return null;
        }
    } finally {
        ((AbstractDocument) context.getDocument()).readUnlock();
    }
}
 
Example 24
Source Project: netbeans   Source File: CharacterMatcher.java    License: Apache License 2.0 6 votes vote down vote up
public int [] findMatches() throws BadLocationException {
    ((AbstractDocument) context.getDocument()).readLock();
    try {
        int offset = BracesMatcherSupport.matchChar(
            context.getDocument(),
            backward ? originOffset : originOffset + 1,
            backward ?
                Math.max(0, lowerBound) :
                Math.min(context.getDocument().getLength(), upperBound),
            originalChar,
            matchingChar
        );

        return offset != -1 ? new int [] { offset, offset + 1 } : null;
    } finally {
        ((AbstractDocument) context.getDocument()).readUnlock();
    }
}
 
Example 25
Source Project: jdk8u-dev-jdk   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void checkStructureEquivalence(AbstractDocument.AbstractElement elem) {
    String name = elem.getName();
    if (!goldenName.equals(name)) {
        throw new RuntimeException("Bad structure: expected element name is '" + goldenName + "' but the actual name was '" + name + "'.");
    }
    int goldenChildCount = goldenChildren.size();
    int childCount = elem.getChildCount();
    if (childCount != goldenChildCount) {
        System.out.print("D: children: ");
        for (int i = 0; i < childCount; i++) {
            System.out.print(" " + elem.getElement(i).getName());
        }
        System.out.println("");
        System.out.print("D: goldenChildren: ");
        for (GoldenElement ge : goldenChildren) {
            System.out.print(" " + ge.goldenName);
        }
        System.out.println("");

        throw new RuntimeException("Bad structure: expected child count of element '" + goldenName + "' is '" + goldenChildCount + "' but the actual count was '" + childCount + "'.");
    }
    for (int i = 0; i < childCount; i++) {
        AbstractDocument.AbstractElement nextElem = (AbstractDocument.AbstractElement) elem.getElement(i);
        GoldenElement goldenElement = goldenChildren.get(i);
        goldenElement.checkStructureEquivalence(nextElem);
    }
}
 
Example 26
Source Project: netbeans   Source File: EmbeddingUpdateTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testEmbeddingActivityChange() throws Exception {
    ModificationTextDocument doc = new ModificationTextDocument();
    // Assign a language to the document
    doc.putProperty(Language.class,TestTokenId.language());
    doc.insertString(0, "a/*abc def*/", null);
    LexerTestUtilities.initLastTokenHierarchyEventListening(doc);
    TokenHierarchy<?> hi = TokenHierarchy.get(doc);
    ((AbstractDocument)doc).readLock();
    try {
        TokenSequence<?> ts = hi.tokenSequence();
        assertTrue(ts.moveNext());
        LexerTestUtilities.assertTokenEquals(ts,TestTokenId.IDENTIFIER, "a", 0);
        assertTrue(ts.moveNext());
        LexerTestUtilities.assertTokenEquals(ts,TestTokenId.BLOCK_COMMENT, "/*abc def*/", 1);
        TokenSequence<?> ets = ts.embedded();
        assertNotNull(ets);
        assertTrue(ts.moveNext());
        assertTrue(ets.moveNext());
        LexerTestUtilities.assertTokenEquals(ets,TestPlainTokenId.WORD, "abc", 3);
        assertTrue(ets.moveNext());
        LexerTestUtilities.assertTokenEquals(ets,TestPlainTokenId.WHITESPACE, " ", 6);
        assertTrue(ets.moveNext());
        LexerTestUtilities.assertTokenEquals(ets,TestPlainTokenId.WORD, "def", 7);
        assertFalse(ets.moveNext());
    } finally {
        ((AbstractDocument)doc).readUnlock();
    }

    MutableTextInput input = (MutableTextInput) doc.getProperty(MutableTextInput.class);
    final TokenHierarchyControl control = input.tokenHierarchyControl();
    doc.runAtomic(new Runnable() {
        @Override
        public void run() {
            control.setActive(false);
            control.setActive(true);
        }
    });

}
 
Example 27
Source Project: littleluck   Source File: HTMLPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View create(Element element) {
    AttributeSet attrs = element.getAttributes();
    Object elementName =
            attrs.getAttribute(AbstractDocument.ElementNameAttribute);
    Object o = (elementName != null) ?
            null : attrs.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {
        if (o == HTML.Tag.OBJECT) {
            return new ComponentView(element);
        }
    }
    return super.create(element);
}
 
Example 28
Source Project: TencentKona-8   Source File: bug7165725.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void checkStructureEquivalence(AbstractDocument.AbstractElement elem) {
    String name = elem.getName();
    if (!goldenName.equals(name)) {
        throw new RuntimeException("Bad structure: expected element name is '" + goldenName + "' but the actual name was '" + name + "'.");
    }
    int goldenChildCount = goldenChildren.size();
    int childCount = elem.getChildCount();
    if (childCount != goldenChildCount) {
        System.out.print("D: children: ");
        for (int i = 0; i < childCount; i++) {
            System.out.print(" " + elem.getElement(i).getName());
        }
        System.out.println("");
        System.out.print("D: goldenChildren: ");
        for (GoldenElement ge : goldenChildren) {
            System.out.print(" " + ge.goldenName);
        }
        System.out.println("");

        throw new RuntimeException("Bad structure: expected child count of element '" + goldenName + "' is '" + goldenChildCount + "' but the actual count was '" + childCount + "'.");
    }
    for (int i = 0; i < childCount; i++) {
        AbstractDocument.AbstractElement nextElem = (AbstractDocument.AbstractElement) elem.getElement(i);
        GoldenElement goldenElement = goldenChildren.get(i);
        goldenElement.checkStructureEquivalence(nextElem);
    }
}
 
Example 29
Source Project: netbeans   Source File: FoldUtilitiesImpl.java    License: Apache License 2.0 5 votes vote down vote up
public static void collapseOrExpand(FoldHierarchy hierarchy, Collection foldTypes,
boolean collapse) {

    Document d = hierarchy.getComponent().getDocument();
    if (!(d instanceof AbstractDocument)) {
        // no op, the folding hierarchy does not work for != AbstractDocument
        return;
    }
    AbstractDocument adoc = (AbstractDocument)d;
    adoc.readLock();
    try {
        hierarchy.lock();
        try {
            List foldList = findRecursive(null,
                hierarchy.getRootFold(), foldTypes);
            if (collapse) {
                hierarchy.collapse(foldList);
            } else {
                hierarchy.expand(foldList);
            }
        } finally {
            hierarchy.unlock();
        }
    } finally {
        adoc.readUnlock();
    }
}
 
Example 30
Source Project: netbeans   Source File: AbbrevDetection.java    License: Apache License 2.0 5 votes vote down vote up
private static void sendUndoableEdit(Document d, UndoableEdit ue) {
    if(d instanceof AbstractDocument) {
        UndoableEditListener[] uels = ((AbstractDocument)d).getUndoableEditListeners();
        UndoableEditEvent ev = new UndoableEditEvent(d, ue);
        for(UndoableEditListener uel : uels) {
            uel.undoableEditHappened(ev);
        }
    }
}