Examples of PlainDocument


Examples of javax.swing.text.PlainDocument

   */
  private void testNewline(TestHarness harness)
  {
    harness.checkPoint("testNewline");

    PlainDocument doc = new PlainDocument();
    try
      {
        doc.insertString(0, "Hello\nWorld", new SimpleAttributeSet());
      }
    catch (BadLocationException ex)
      {
        harness.fail("BadLocationException");
      }
    Element root = doc.getRootElements()[0];
    harness.check(root instanceof AbstractDocument.BranchElement);
    harness.check(root.getElementCount(), 2);
    Element el1 = root.getElement(0);
    harness.check(el1 instanceof AbstractDocument.LeafElement);
    harness.check(el1.getStartOffset(), 0);
View Full Code Here

Examples of javax.swing.text.PlainDocument

   */
  private void testFilterNewline(TestHarness harness)
  {
    harness.checkPoint("testFilterNewline");

    PlainDocument doc = new PlainDocument();
    doc.putProperty("filterNewlines", Boolean.TRUE);
    try
      {
        doc.insertString(0, "Hello\nWorld", new SimpleAttributeSet());
      }
    catch (BadLocationException ex)
      {
        harness.fail("BadLocationException");
      }
    Element root = doc.getRootElements()[0];
    harness.check(root instanceof AbstractDocument.BranchElement);
    harness.check(root.getElementCount(), 1);
    Element el1 = root.getElement(0);
    harness.check(el1 instanceof AbstractDocument.LeafElement);
    harness.check(el1.getStartOffset(), 0);
View Full Code Here

Examples of javax.swing.text.PlainDocument

  }
 
  public void testArguments(TestHarness harness)
  {
    harness.checkPoint("testArguments");
    PlainDocument d = new PlainDocument();
   
    // negative index
    boolean pass = false;
    try
    {
      d.insertString(-1, "XYZ", SimpleAttributeSet.EMPTY);
    }
    catch (Exception e)
    {
      pass = e instanceof BadLocationException;
    }
    harness.check(pass);

    // index > length
    pass = false;
    try
    {
      d.insertString(2, "XYZ", SimpleAttributeSet.EMPTY);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
 
    // null string is OK (ignored)
    pass = true;
    try
    {
      d.insertString(0, null, SimpleAttributeSet.EMPTY);
    }
    catch (Exception e)
    {
      pass = false;
    }
    harness.check(pass);
   
    // null attribute set is OK
    pass = true;
    try
    {
      d.insertString(0, "ABC", null);
    }
    catch (Exception e)
    {
      pass = false;
    }
View Full Code Here

Examples of javax.swing.text.PlainDocument

  }
 
  public void testPositions(TestHarness harness)
  {
    harness.checkPoint("testPositions");
    PlainDocument d = new PlainDocument();
    try
      {
        d.insertString(0, "ABC", null);
        Position p0 = d.createPosition(0);
        harness.check(p0.getOffset(), 0);
        Position p1 = d.createPosition(1);
        harness.check(p1.getOffset(), 1);
        Position p2 = d.createPosition(3);
        harness.check(p2.getOffset(), 3);
        Position p3 = d.createPosition(4);
        harness.check(p3.getOffset(), 4);
        
        d.insertString(1, "XYZ", null);
        harness.check(p0.getOffset(), 0);
        harness.check(p1.getOffset(), 4);
        harness.check(p2.getOffset(), 6);
        harness.check(p3.getOffset(), 7);
        
        d.remove(2, 3);
        harness.check(p0.getOffset(), 0);
        harness.check(p1.getOffset(), 2);
        harness.check(p2.getOffset(), 3);
        harness.check(p3.getOffset(), 4);     
      }
View Full Code Here

Examples of javax.swing.text.PlainDocument

  }

  // Helper for testModifications.
  PlainDocument prepare(String initialContent)
  {
    PlainDocument pd = new PlainDocument();

    try
      {
        pd.insertString(0, initialContent, null);

        return pd;
      }
    catch (BadLocationException ble)
      {
View Full Code Here

Examples of javax.swing.text.PlainDocument

  void testModifications(TestHarness h)
  {
    // Test 1: Insert an "a" into before a "\n".
    h.checkPoint("modifications-insert char 1-pre");
    PlainDocument doc = new PlainDocument();;

    // Checks whether there is an Element at index 0 which has the
    // starting offset 0, end offset 1 and contains the text "\n".
    checkElement(h, doc, 0, 0, 1, "\n");
View Full Code Here

Examples of javax.swing.text.PlainDocument

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    PlainDocument d = new PlainDocument();
   
    harness.check(d.getLength(), 0);
    try
    {
      d.insertString(0, "ABC", null);
    }
    catch (BadLocationException e)
    {
      // ignore - checks will fail if this happens
    }
    harness.check(d.getLength(), 3);
   
    // try adding a string with a '\n'
    try
    {
      d.insertString(0, "ABC\n", null);
    }
    catch (BadLocationException e)
    {
      // ignore - checks will fail if this happens
    }
    harness.check(d.getLength(), 7);
  }
View Full Code Here

Examples of javax.swing.text.PlainDocument

  }

  private void testDefault(TestHarness h)
  {
    PlainDocument doc = new PlainDocument();
    Dictionary props = doc.getDocumentProperties();
    h.check(props.size(), 2);
    // This property is inherited from AbstractDocument.
    h.check(props.get("i18n"), Boolean.FALSE);
    h.check(props.get("tabSize"), new Integer(8));
  }
View Full Code Here

Examples of javax.swing.text.PlainDocument

  }

  private void test01(TestHarness h)
  {
    h.checkPoint("test01");
    PlainDocument doc = new PlainDocument();
    doc.addDocumentListener(new TestListener());

    try
      {
        doc.insertString(0, "abcde\nabcdef\nabcde\n", null);
        doc.insertString(15, "abcdefghijklmn\n", null);
      }
    catch (BadLocationException ex)
      {
        h.fail("Unexpected BadLocationException");
      }

    DocumentEvent.ElementChange change = ev.getChange(doc.getDefaultRootElement());

    h.check(change.getIndex(), 2);

    Element[] added = change.getChildrenAdded();
    h.check(added.length, 2);
View Full Code Here

Examples of javax.swing.text.PlainDocument

  }

  private void test02(TestHarness h)
  {
    h.checkPoint("test02");
    PlainDocument doc = new PlainDocument();
    doc.addDocumentListener(new TestListener());

    try
      {
        doc.insertString(0, "abcde\nabcdef\nabcde\n", null);
        doc.insertString(13, "\nabc", null);
      }
    catch (BadLocationException ex)
      {
        h.fail("Unexpected BadLocationException");
      }

    DocumentEvent.ElementChange change = ev.getChange(doc.getDefaultRootElement());

    h.check(change.getIndex(), 1);

    Element[] added = change.getChildrenAdded();
    h.check(added.length, 3);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.