Package javax.swing.text

Examples of javax.swing.text.Segment


        h.check("cp\n", sc.getString(0, sc.length()),
                "StringContent.remove(): should be 'cp' is '"
                + sc.getString(0, sc.length()) + "'");
        h.checkPoint("StringContent -- getChars()");
        char[] ctab = { 'c', 'p' , '\n'};
        Segment s = new Segment(ctab, 0, 3);
        Segment s2 = new Segment();
        sc.getChars(0, sc.length(), s2);
        h.check(s.toString(), s2.toString(),
                "StringContent.getChars(): "
                + "compare to javax.swing.text.Segment "
                + "(first Segment: " + s + "; second Segment: " + s2 + ")");
        h.checkPoint("StringContent -- StringContent()");
        sc = new StringContent(100);
View Full Code Here


   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    char[] ch = new char[] {'A', 'B', 'C'};
    Segment s1 = new Segment(ch, 0, 3);
    harness.check(s1.isPartialReturn(), false);
    s1.setPartialReturn(true);
    harness.check(s1.isPartialReturn(), true);
  }
View Full Code Here

   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    char[] ch = new char[] {'A', 'B', 'C', 'D', 'E', 'F', 'G'};
    Segment s = new Segment(ch, 0, 7);
    harness.check(s.getBeginIndex(), 0);
   
    // try results for a subset of the characters
    s = new Segment(ch, 3, 3);
    harness.check(s.getBeginIndex(), 3);
  }
View Full Code Here

   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    char[] ch = new char[] {'A', 'B', 'C', 'D', 'E', 'F', 'G'};
    Segment s = new Segment(ch, 0, 7);
    s.last();
    harness.check(s.previous(), 'F');
    harness.check(s.previous(), 'E');
    harness.check(s.previous(), 'D');
    harness.check(s.previous(), 'C');
    harness.check(s.previous(), 'B');
    harness.check(s.previous(), 'A');
    harness.check(s.previous(), CharacterIterator.DONE);
    harness.check(s.previous(), CharacterIterator.DONE);
   
    // try results for a subset of the characters
    s = new Segment(ch, 3, 3);
    s.last();
    harness.check(s.previous(), 'E');
    harness.check(s.previous(), 'D');
    harness.check(s.previous(), CharacterIterator.DONE);
    harness.check(s.previous(), CharacterIterator.DONE);
  }
View Full Code Here

  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
  {   
    int newLines = 0;
    h2.check (ev.getLength() == 134);
    h2.check (ev.getOffset() == 0);
    Segment txt = new Segment();
    try
      {
        getText(ev.getOffset(), ev.getLength() + 1, txt);
      }
    catch (BadLocationException ble)
View Full Code Here

   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    char[] ch = new char[] {'A', 'B', 'C', 'D', 'E', 'F', 'G'};
    Segment s = new Segment(ch, 0, 7);
    harness.check(s.current(), 'A');
    s.last();
    harness.check(s.current(), 'G');
    s.next();
    harness.check(s.current(), CharacterIterator.DONE);
    s.first();
    harness.check(s.current(), 'A');
    s.previous();
    harness.check(s.current(), 'A');
   
    // try results for a subset of the characters
    s = new Segment(ch, 3, 3);
    harness.check(s.current(), 'A');
    s.last();
    harness.check(s.current(), 'F');
    s.next();
    harness.check(s.current(), CharacterIterator.DONE);
    s.first();
    harness.check(s.current(), 'D');
    s.previous();
    harness.check(s.current(), 'D');
  }
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);
View Full Code Here

    return (index + 5)/10;
  }

  static Segment createSegment(String foo)
  {
    return new Segment(foo.toCharArray(), 0, foo.length());
  }
View Full Code Here

   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    char[] ch = new char[] {'A', 'B', 'C'};
    Segment s1 = new Segment(ch, 0, 3);
    harness.check(s1.toString(), "ABC");
    Segment s2 = new Segment(ch, 1, 1);
    harness.check(s2.toString(), "B");
    Segment s3 = new Segment(ch, 2, 0);
    harness.check(s3.toString(), "");
    Segment s4 = new Segment(null, 0, 0);
    harness.check(s4.toString(), "");
  }
View Full Code Here

  }
 
  public void testConstructor1(TestHarness harness)
  {
    harness.checkPoint("()");
    Segment s = new Segment();
    harness.check(s.offset, 0);
    harness.check(s.count, 0);
    harness.check(s.array, null);
    harness.check(s.toString(), "");
  }
View Full Code Here

TOP

Related Classes of javax.swing.text.Segment

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.