Examples of PlainDocument


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();
    Element[] e = d.getRootElements();
    harness.check(e.length, 2);
    harness.check(e[0], d.getDefaultRootElement());
  }
View Full Code Here

Examples of javax.swing.text.PlainDocument

  }
 
  public void testMethod1(TestHarness harness)
  {
    harness.checkPoint("(int, int)");
    PlainDocument d = new PlainDocument();
   
    // check default result
    try
    {
      d.insertString(0, "XYZ", null);
      harness.check(d.getText(0, 3).equals("XYZ"));
    }
    catch (BadLocationException e)
    {
      harness.fail(e.toString());
    }
   
    // get the implicit newline
    try
    {
      harness.check(d.getText(0, 4).equals("XYZ\n"));
    }
    catch (BadLocationException e)
    {
      harness.fail(e.toString());
    }   

    // fail on next char
    try
    {
      d.getText(0, 5);
      harness.check(false);
    }
    catch (BadLocationException e)
    {
      harness.check(true);
    }   

    // add some more text
    try
    {
      d.insertString(0, "ABCDEFG", null);
    }
    catch (BadLocationException e)
    {
    }
    harness.check(d.getLength(), 10);
   
    // if index < 0 should get BadLocationException
    boolean pass = false;
    try
    {
      d.getText(-1, 3);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if index > end of text should get BadLocationException
    pass = false;
    try
    {
      d.getText(99, 1);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if len goes past end of range, should get BadLocationException
    pass = false;
    try
    {
      d.getText(0, 99);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try a zero length string
    try
    {
      harness.check(d.getText(1, 0).equals(""));
    }
    catch (BadLocationException e)
    {
      harness.fail(e.toString());
    }
View Full Code Here

Examples of javax.swing.text.PlainDocument

  }

  public void testMethod2(TestHarness harness)
  {
    harness.checkPoint("(int, int, Segment)");
    PlainDocument d = new PlainDocument();
    Segment seg = new Segment();
   
    // check default result
    try
    {
      d.getText(0, 1, seg);
    }
    catch (BadLocationException e)
    {
      // ignore - tests below will fail if this happens
    }
    harness.check(seg.offset, 0);
    harness.check(seg.count, 1);
    harness.check(seg.array[0], '\n');

    // if len goes past end of range, should get BadLocationException
    boolean pass = false;
    try
    {
      d.getText(0, 2, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);

    // add some more text
    try
    {
      d.insertString(0, "ABCDEFG", null);
    }
    catch (BadLocationException e)
    {
    }
    harness.check(d.getLength(), 7);
   
    // if index < 0 should get BadLocationException
    pass = false;
    try
    {
      d.getText(-1, 3, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if index > end of text should get BadLocationException
    pass = false;
    try
    {
      d.getText(99, 1, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if len goes past end of range, should get BadLocationException
    pass = false;
    try
    {
      d.getText(0, 99, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try a zero length string
    try
    {
      d.getText(1, 0, seg);
    }
    catch (BadLocationException e)
    {
    }
    harness.check(seg.offset, 1);
    harness.check(seg.count, 0);
   
    // what happens for null Segment
    pass = false;
    try
    {
      d.getText(0, 1, null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    catch (BadLocationException e)
    {
      // ignore
    }
    harness.check(pass);
   
    // what happens if we update the Segment array, does that change the
    // StringContent
    Segment seg2 = new Segment();
    Segment seg3 = new Segment();
    PlainDocument d2 = new PlainDocument();
    try
    {
      d2.insertString(0, "XYZ", null);
      d2.getText(0, 3, seg2);
      seg2.array[1] = '5';
      d2.getText(0, 3, seg3);
    }
    catch (BadLocationException e)
    {
      // ignore
    }
View Full Code Here

Examples of javax.swing.text.PlainDocument

        c.insertString(5, "12345");
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 21);
       
        PlainDocument doc = new PlainDocument();
        doc.insertString(0, "cdefgh", null);
        Position s = doc.createPosition(1);
        harness.check(s.getOffset(), 1);

        doc.insertString(0, "a", null);
        harness.check(s.getOffset(), 2);
        Position a = doc.createPosition(1);
        harness.check(a.getOffset(), 1);

        doc.insertString(1, "b", null);
        harness.check(s.getOffset(), 3);
        harness.check(a.getOffset(), 2);
      }
    catch (BadLocationException ex)
      {
View Full Code Here

Examples of javax.swing.text.PlainDocument

  void testBorderCase(TestHarness h)
  {
    h.checkPoint("border case");
    try
      {
        PlainDocument doc = new PlainDocument();
        doc.insertString(0, "One Three Four", null);
        Position pos = doc.createPosition(4);
        doc.insertString(4, "Two ", null);
        h.check(pos.getOffset(), 8);
      }
    catch (BadLocationException ex)
      {
        h.fail("BadLocationException thrown")
View Full Code Here

Examples of javax.swing.text.PlainDocument

   *
   * @param h the test harness to use
   */
  private void testEmptyBranchElement(TestHarness h)
  {
    PlainDocument doc = new PlainDocument();
    AbstractDocument.BranchElement b =
      doc.new BranchElement(null, null);
    try
      {
        b.getStartOffset();
View Full Code Here

Examples of javax.swing.text.PlainDocument

   *
   * @param h the test harness to use
   */
  private void testOneLeafElement(TestHarness h)
  {
    PlainDocument doc = new PlainDocument();
    AbstractDocument.BranchElement b =
      doc.new BranchElement(null, null);
    AbstractDocument.LeafElement l = doc.new LeafElement(b, null, 10, 20);
    b.replace(0, 0, new Element[] { l });
    h.check(b.getStartOffset(), 10);
View Full Code Here

Examples of javax.swing.text.PlainDocument

   *
   * @param h the test harness to use
   */
  private void testCachedValue(TestHarness h)
  {
    PlainDocument doc = new PlainDocument();
    AbstractDocument.BranchElement b =
      doc.new BranchElement(null, null);
    AbstractDocument.LeafElement l = doc.new LeafElement(b, null, 10, 20);
    b.replace(0, 0, new Element[] { l });
    h.check(b.getStartOffset(), 10);
View Full Code Here

Examples of javax.swing.text.PlainDocument

*/
public class getElementIndexNullPointer implements Testlet
{
  public void test(TestHarness h)
  {
    PlainDocument doc = new PlainDocument();
    AbstractDocument.BranchElement b =
      doc.new BranchElement(null, null);
    try
      {
        b.getElementIndex(0);
View Full Code Here

Examples of javax.swing.text.PlainDocument

   *
   * @param h
   */
  private void testBeyondBoundary(TestHarness h)
  {
    PlainDocument doc = new PlainDocument();
    try
      {
        doc.insertString(0, "hello\n", null);
      }
    catch (BadLocationException ex)
      {
         h.fail(ex.getMessage());
      }
    Element root = doc.getDefaultRootElement();
    h.check(root.getElementIndex(6), 1);
  }
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.