Package javax.swing.text

Examples of javax.swing.text.AbstractDocument


                    final String sender = getOwnIdentitiesComboBox().getEditor().getItem().toString();
                    updateHeaderArea(sender);
                }
            });

            final AbstractDocument doc = (AbstractDocument) editor.getDocument();
            doc.setDocumentFilter(new DocumentFilter() {
                @Override
                public void insertString(final DocumentFilter.FilterBypass fb, final int offset, String string,
                        final AttributeSet attr) throws BadLocationException
                {
                    if (((TextComboBoxEditor)getOwnIdentitiesComboBox().getEditor()).isSigned() == false ) {
View Full Code Here


        eventCounter = null;
    }

    public void guiTestConstructors() {
        JTextField textComponent = new JTextField();
        AbstractDocument document = (AbstractDocument) textComponent.getDocument();
        int initialDocumentListenerCount = document.getDocumentListeners().length;
        TextFilterator<String> textFilterator = GlazedLists.toStringTextFilterator();
        TextComponentMatcherEditor<String> tcme;

        tcme = new TextComponentMatcherEditor<String>(textComponent, textFilterator);
        assertEquals(0, textComponent.getActionListeners().length);
        assertEquals(initialDocumentListenerCount+1, document.getDocumentListeners().length);
        assertSame(textFilterator, tcme.getFilterator());
        assertTrue(tcme.isLive());

        tcme.dispose();
        tcme = new TextComponentMatcherEditor<String>(textComponent, textFilterator, true);
        assertEquals(0, textComponent.getActionListeners().length);
        assertEquals(initialDocumentListenerCount+1, document.getDocumentListeners().length);
        assertSame(textFilterator, tcme.getFilterator());
        assertTrue(tcme.isLive());

        tcme.dispose();
        tcme = new TextComponentMatcherEditor<String>(textComponent, textFilterator, false);
        assertEquals(1, textComponent.getActionListeners().length);
        assertEquals(initialDocumentListenerCount, document.getDocumentListeners().length);
        assertSame(textFilterator, tcme.getFilterator());
        assertFalse(tcme.isLive());

        tcme.dispose();
        tcme = new TextComponentMatcherEditor<String>(document, textFilterator);
        assertEquals(0, textComponent.getActionListeners().length);
        assertEquals(initialDocumentListenerCount+1, document.getDocumentListeners().length);
        assertSame(textFilterator, tcme.getFilterator());
        assertTrue(tcme.isLive());

        tcme.dispose();
        assertEquals(0, textComponent.getActionListeners().length);
        assertEquals(initialDocumentListenerCount, document.getDocumentListeners().length);
    }
View Full Code Here

        }
    }

    public void guiTestDocumentSwap() throws Exception {
        final JTextField textField = new JTextField();
        final AbstractDocument documentA = (AbstractDocument) textField.getDocument();
        documentA.insertString(0, "documentA", null);
        final AbstractDocument documentB = new PlainDocument();
        documentB.insertString(0, "documentB", null);

        final int originalDocumentAListenerCount = documentA.getDocumentListeners().length;
        final int originalDocumentBListenerCount = documentB.getDocumentListeners().length;

        // using the textField in a TextComponentMatcherEditor will install a DocumentListener
        TextComponentMatcherEditor<String> textMatcherEditor = new TextComponentMatcherEditor<String>(textField, GlazedLists.toStringTextFilterator(), true);
        assertEquals(originalDocumentAListenerCount+1, documentA.getDocumentListeners().length);
        assertEquals(originalDocumentBListenerCount, documentB.getDocumentListeners().length);
        TextMatcher textMatcher = (TextMatcher) textMatcherEditor.getMatcher();
        assertEquals("documentA", textMatcher.getSearchTerms()[0].getText());

        // replace DocumentA with DocumentB, which should update the filter with the text from DocumentB
        textField.setDocument(documentB);
        assertEquals(0, documentA.getDocumentListeners().length);
        assertEquals(originalDocumentBListenerCount+3, documentB.getDocumentListeners().length);
        textMatcher = (TextMatcher) textMatcherEditor.getMatcher();
        assertEquals("documentB", textMatcher.getSearchTerms()[0].getText());

        // changing the text in DocumentB should alter the filter
        documentB.replace(0, documentB.getLength(), "blah", null);
        textMatcher = (TextMatcher) textMatcherEditor.getMatcher();
        assertEquals("blah", textMatcher.getSearchTerms()[0].getText());
    }
View Full Code Here

        assertEquals("blah", textMatcher.getSearchTerms()[0].getText());
    }

    public void guiTestListeners() {
        final JTextField textField = new JTextField();
        final AbstractDocument document = (AbstractDocument) textField.getDocument();

        final int originalPropertyChangeListenerCount = textField.getPropertyChangeListeners().length;
        final int originalActionListenerCount = textField.getActionListeners().length;
        final int originalDocumentListenerCount = document.getDocumentListeners().length;

        // live
        TextComponentMatcherEditor<String> textMatcherEditor = new TextComponentMatcherEditor<String>(textField, GlazedLists.toStringTextFilterator(), true);
        assertEquals(originalPropertyChangeListenerCount+1, textField.getPropertyChangeListeners().length);
        assertEquals(originalActionListenerCount, textField.getActionListeners().length);
        assertEquals(originalDocumentListenerCount+1, document.getDocumentListeners().length);

        textMatcherEditor.dispose();
        assertEquals(originalPropertyChangeListenerCount, textField.getPropertyChangeListeners().length);
        assertEquals(originalActionListenerCount, textField.getActionListeners().length);
        assertEquals(originalDocumentListenerCount, document.getDocumentListeners().length);

        // not live
        textMatcherEditor = new TextComponentMatcherEditor<String>(textField, GlazedLists.toStringTextFilterator(), false);
        assertEquals(originalPropertyChangeListenerCount+1, textField.getPropertyChangeListeners().length);
        assertEquals(originalActionListenerCount+1, textField.getActionListeners().length);
        assertEquals(originalDocumentListenerCount, document.getDocumentListeners().length);

        textMatcherEditor.dispose();
        assertEquals(originalPropertyChangeListenerCount, textField.getPropertyChangeListeners().length);
        assertEquals(originalActionListenerCount, textField.getActionListeners().length);
        assertEquals(originalDocumentListenerCount, document.getDocumentListeners().length);
    }
View Full Code Here

    }

    public void testGetRootView() {
        BasicTextUI ui = getBasicTextUI(jta);
        View rootView = ui.getRootView(jta);
        AbstractDocument doc = (AbstractDocument) jta.getDocument();
        Element rootElement = jta.getDocument().getDefaultRootElement();
        assertEquals(1, rootView.getViewCount());
        View sonRootView = rootView.getView(0);
        assertNotNull(sonRootView);
        assertEquals(0, sonRootView.getViewCount());
        assertEquals(rootElement, rootView.getElement());
        assertEquals(sonRootView.getElement(), rootElement);
        assertEquals(rootView.getView(0).getElement(), rootElement);
        assertEquals(doc, rootView.getDocument());
        assertEquals(jta, rootView.getContainer());
        assertEquals(doc.getLength() + 1, rootView.getEndOffset());
        assertEquals(ui, rootView.getViewFactory());
        assertNull(rootView.getParent());
        /*
         * Next Functionality is not required try { rootView.setParent(new
         * PlainView(rootElement)); } catch (Error error) { bWasException =
View Full Code Here

    public void testReplaceSelectionWithAttributes() {
        if (true) {
            throw new UnsupportedOperationException("Not implemented");
        }
        AbstractDocument doc = new DefaultStyledDocument();
        SimpleAttributeSet as1 = new SimpleAttributeSet();
        as1.addAttribute("key1", "value1");
        SimpleAttributeSet as2 = new SimpleAttributeSet();
        as2.addAttribute("key2", "value2");
        try {
            doc.insertString(0, "testReplaceSelection", as1);
            doc.insertString(4, "INSERT", as2);
        } catch (final BadLocationException e) {
            assertFalse("unexpected exception :" + e.getMessage(), true);
        }
        //temporarily commented-out: HTMLEditorKit not implemented
        //jep.setEditorKit(new RTFEditorKit());
        jep.setEditorKit(new StyledEditorKit());
        jep.setDocument(doc);
        jep.setSelectionStart(6);
        jep.setSelectionEnd(7);
        jep.replaceSelection("YYY");
        for (int i = 0; i < doc.getLength(); i++) {
            AttributeSet as = getAttributeSetByIndex(doc, i);
            if (i > 3 && i < 12) {
                assertEquals(as2, as);
            } else {
                assertEquals(as1, as);
View Full Code Here

    }

    public void testGetRootView() {
        BasicTextUI ui = getBasicTextUI(jta);
        View rootView = ui.getRootView(jta);
        AbstractDocument doc = (AbstractDocument) jta.getDocument();
        Element rootElement = jta.getDocument().getDefaultRootElement();
        assertEquals(1, rootView.getViewCount());
        View sonRootView = rootView.getView(0);
        assertNotNull(sonRootView);
        assertEquals(0, sonRootView.getViewCount());
        assertEquals(rootElement, rootView.getElement());
        assertEquals(sonRootView.getElement(), rootElement);
        assertEquals(rootView.getView(0).getElement(), rootElement);
        assertEquals(doc, rootView.getDocument());
        assertEquals(jta, rootView.getContainer());
        assertEquals(doc.getLength() + 1, rootView.getEndOffset());
        assertEquals(ui, rootView.getViewFactory());
        assertNull(rootView.getParent());
        /*
         * Next Functionality is not required try { rootView.setParent(new
         * PlainView(rootElement)); } catch (Error error) { bWasException =
View Full Code Here

  }

  private void testDefault(TestHarness h)
  {
    AbstractDocument doc = new TestAbstractDocument();
    Dictionary props = doc.getDocumentProperties();
    Enumeration keys = props.keys();
    while (keys.hasMoreElements())
      {
        Object key = keys.nextElement();
      }
View Full Code Here

            }
        }

        private void enableInsertionFilter() {
            if (getDocument() instanceof AbstractDocument) {
                AbstractDocument ad = (AbstractDocument) getDocument();
                ad.setDocumentFilter(new TextInsertionFilter(attrAddedLocally));
            }
        }
View Full Code Here

     * paragraph element.
     */
    public static final Element getParagraphElement(final Document doc,
                                                    final int p) {
        if (doc instanceof AbstractDocument) {
            AbstractDocument abstrDoc = (AbstractDocument) doc;
            abstrDoc.readLock();
            Element elem = null;
            int length = 0;
            boolean incorrectPosition = false;
            try {
                length = doc.getLength();
                incorrectPosition = (p < 0 || p > length)
                        && (doc instanceof PlainDocument);
                if (!incorrectPosition) {
                    elem = abstrDoc.getParagraphElement(p);
                }
            } finally {
                abstrDoc.readUnlock();
            }
            return elem;
        }

        Element root = doc.getDefaultRootElement();
View Full Code Here

TOP

Related Classes of javax.swing.text.AbstractDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.