Package javax.swing.text

Examples of javax.swing.text.GapContent


   */
  public void testGeneral(TestHarness harness)     
  {
    harness.checkPoint("testGeneral()");
   
    GapContent gc = new GapContent();
    // regular insert
    try
    {
      gc.insertString(0, "ABC");
      // ignoring undo/redo here - see insertUndo.java
    }
    catch (BadLocationException e)
    {
      // ignore - checks below will fail if this happens
    }
    harness.check(gc.length(), 4);
   
    // insert at location before start
    boolean pass = false;
    try
    {
      gc.insertString(-1, "XYZ");
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    catch (Exception _)
    {
      pass = false;
    }

    harness.check(pass);
   
    // insert at index of last character - this is OK
    try
    {
      gc.insertString(3, "XYZ");
    }
    catch (BadLocationException e)
    {
      // ignore
    }
    harness.check(gc.length(), 7);
   
    // Insert at index of last character + 1. This appends the new string to
    // the existing string. (This works since 1.5 of the RI)
    try
    {
      gc.insertString(7, "XYZ");
    }
    catch (BadLocationException e)
    {
      pass = false;
    }
    harness.check(gc.length(), 10);

    // insert at index of last character + 2
    pass = false;
    try
    {
      gc.insertString(gc.length() + 1, "XYZ");
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);

    // insert empty string
    int length = gc.length();
    try
    {
      gc.insertString(0, "");
    }
    catch (BadLocationException e)
    {
      // ignore
    }
    harness.check(gc.length(), length);
   
    // insert null string
    pass = false;
    try
    {
      gc.insertString(0, null);
    }
    catch (BadLocationException e)
    {
      // ignore
    }
View Full Code Here


      harness.checkPoint("specialInsert");
      int posValue = -1;

      try
        {
    GapContent gc = new GapContent();
      gc.insertString(0, "foo\nbar\n");
    gc.remove(0, 4);

          // Gap starts at 0 now and the following Position
          // instance is created at the end of the gap.
          Position pos = gc.createPosition(0);

          // This insertion should not move the offset
          // of the Position object.
    gc.insertString(0, "z");

    posValue = pos.getOffset();
        }
      catch(BadLocationException ble)
        {
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    GapContent gc = new GapContent();
    Segment seg = new Segment();
   
    // check default result
    try
    {
      gc.getChars(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
    {
      gc.getChars(0, 2, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);

    // add some more text
    try
    {
      gc.insertString(0, "ABCDEFG");
    }
    catch (BadLocationException e)
    {
    }
    harness.check(gc.length(), 8);
   
    // if index < 0 should get BadLocationException
    pass = false;
    try
    {
      gc.getChars(-1, 3, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if index > end of text should get BadLocationException
    pass = false;
    try
    {
      gc.getChars(99, 1, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if len goes past end of range, should get BadLocationException
    pass = false;
    try
    {
      gc.getChars(0, 99, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try a zero length string
    try
    {
      gc.getChars(1, 0, seg);
    }
    catch (BadLocationException e)
    {
    }
    harness.check(seg.offset, 1);
    harness.check(seg.count, 0);
   
    // what happens for null Segment
    pass = false;
    try
    {
      gc.getChars(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();
    GapContent gc2 = new GapContent();
    try
    {
      gc2.insertString(0, "XYZ");
      gc2.getChars(0, 3, seg2);
      seg2.array[1] = '5';
      gc2.getChars(0, 3, seg3);
    }
    catch (BadLocationException e)
    {
      // ignore
    }
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    GapContent gc = new GapContent();
   
    // check default result
    boolean pass = false;
    try
    {
      pass = gc.getString(0, 1).equals("\n");
    }
    catch (BadLocationException e)
    {
    }
    harness.check(pass);

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

    // add some more text
    try
    {
      gc.insertString(0, "ABCDEFG");
    }
    catch (BadLocationException e)
    {
    }
    harness.check(gc.length(), 8);
   
    // if index < 0 should get BadLocationException
    pass = false;
    try
    {
      /*String s =*/ gc.getString(-1, 3);
    }
    catch (StringIndexOutOfBoundsException e)
    {
      pass = false// JDK does this, API docs say it should be a
                     // BadLocationException
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if index > end of text should get BadLocationException
    pass = false;
    try
    {
      /*String s =*/ gc.getString(99, 1);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if len goes past end of range, should get BadLocationException
    pass = false;
    try
    {
      /* String s =*/ gc.getString(0, 99);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try a zero length string
    pass = false;
    try
    {
      pass = gc.getString(1, 0).equals("");
    }
    catch (BadLocationException e)
    {
    }
    harness.check(pass);
View Full Code Here

   * @param harness the test harness
   */
  void testSimple(TestHarness harness)
  {
    harness.checkPoint("testSimple");
    GapContent c = new GapContent();
    try
      {
        Position p1 = c.createPosition(0);
        Position p2 = c.createPosition(1);
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 1);

        c.insertString(0, "hello");
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 6);

        c.remove(0, 5);
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 1);
      }
    catch (BadLocationException ex)
      {
View Full Code Here

   * Tests a more complex situation.
   */
  void testComplex(TestHarness harness)
  {
    harness.checkPoint("testComplex");
    GapContent c = new GapContent();
    try
      {
        Position p1 = c.createPosition(0);
        Position p2 = c.createPosition(1);
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 1);

        c.insertString(0, "abcdefghijklmno");
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 16);

        c.insertString(5, "12345");
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 21);
       
        PlainDocument doc = new PlainDocument();
        doc.insertString(0, "cdefgh", null);
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    GapContent gc = new GapContent();
    harness.check(gc.length(), 1);
    try
    {
      gc.insertString(0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
      harness.check(gc.length(), 27);
      gc.remove(0, 3);
      harness.check(gc.length(), 24);
      gc.insertString(4, "123");
      harness.check(gc.length(), 27);
      gc.remove(20, 5);
      harness.check(gc.length(), 22)
    }
    catch (BadLocationException e)
    {
      harness.fail(e.toString())
    }
View Full Code Here

    testRemoveLast(harness);
  }
 
  public void testGeneral(TestHarness harness)
  {
    GapContent gc = new GapContent();
    // regular insert
    try
    {
      gc.insertString(0, "ABCDEFG");
      // ignoring undo/redo here
    }
    catch (BadLocationException e)
    {
      // ignore - checks below will fail if this happens
    }
    harness.check(gc.length(), 8);
   
    // remove from location before start
    boolean pass = false;
    try
    {
      gc.remove(-1, 3);
    }
    catch (BadLocationException e)
    {
      pass = true// Classpath does this
    }
    catch (StringIndexOutOfBoundsException e)
    {
      pass = false// JDK does this - it is a bug given the API spec
    }
    harness.check(pass);
   
    // remove from location after end
    pass = false;
    try
    {
      gc.remove(99, 1);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // doesn't allow removal of last char
    pass = false;
    try
    {
      gc.remove(7, 1);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
    harness.check(gc.length(), 8);

    // remove 0 chars
    pass = true;
    try
    {
      gc.remove(0, 0);
    }
    catch (BadLocationException e)
    {
      pass = false;
    }
    harness.check(pass);
    harness.check(gc.length(), 8);
   

    int offset = 0;
    try
    {
      gc = new GapContent();
      gc.insertString(0, "abc\ndef\n");

      // create position on the 'd'.
      Position pos = gc.createPosition(4);

      // remove the 'd'
      gc.remove(4, 1);

      offset = pos.getOffset();
    }
    catch(BadLocationException ble)
    {
View Full Code Here

public class TestAbstractDocument extends AbstractDocument
{

  public TestAbstractDocument()
  {
    super(new GapContent());
  }
View Full Code Here

public class BranchElementTest extends AbstractDocument
  implements Testlet
{
  public BranchElementTest()
  {
    super(new GapContent());
  }
View Full Code Here

TOP

Related Classes of javax.swing.text.GapContent

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.