Package javax.swing.text

Examples of javax.swing.text.Segment


   * @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.last(), 'G');
    harness.check(s.getIndex(), 6);
   
    // try results for a subset of the characters
    s = new Segment(ch, 3, 3);
    harness.check(s.last(), 'F');
    harness.check(s.getIndex(), 5);
  }
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.getEndIndex(), 7);
   
    // try results for a subset of the characters
    s = new Segment(ch, 3, 3);
    harness.check(s.getEndIndex(), 6);
  }
View Full Code Here

  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);
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);
    Segment s2 = (Segment) s1.clone();
    harness.check(!s1.equals(s2));
    harness.check(s2.offset, 0);
    harness.check(s2.count, 3);
    harness.check(s2.array, ch);
   
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.first();
    harness.check(s.next(), 'B');
    harness.check(s.next(), 'C');
    harness.check(s.next(), 'D');
    harness.check(s.next(), 'E');
    harness.check(s.next(), 'F');
    harness.check(s.next(), 'G');
    harness.check(s.next(), CharacterIterator.DONE);
    harness.check(s.next(), CharacterIterator.DONE);
   
    // try results for a subset of the characters
    s = new Segment(ch, 3, 3);
    s.first();
    harness.check(s.next(), 'E');
    harness.check(s.next(), 'F');
    harness.check(s.next(), CharacterIterator.DONE);
    harness.check(s.next(), CharacterIterator.DONE);
  }
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.getIndex(), 0);
    s.next();
    harness.check(s.getIndex(), 1);
    s.last();
    harness.check(s.getIndex(), 6);
    s.next();
    harness.check(s.getIndex(), 7);
   
    // try results for a subset of the characters
    s = new Segment(ch, 3, 3);
    harness.check(s.getIndex(), 0);
    s.first();
    harness.check(s.getIndex(), 3);
    s.next();
    harness.check(s.getIndex(), 4);
    s.last();
    harness.check(s.getIndex(), 5);
    s.next();
    harness.check(s.getIndex(), 6);
    s.first();
    harness.check(s.getIndex(), 3);
    s.previous();
    harness.check(s.getIndex(), 3);
  }
View Full Code Here

   */
  public void test(TestHarness harness)     
  {
    StringContent sc = new StringContent();
    char[] ch = new char[] { 'A', 'B', 'C' };
    Segment seg = new Segment(ch, 0, 3);
   
    // check default result
    try
    {
      sc.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 != ch);
    harness.check(seg.array[0], '\n');

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

    // add some more text
    try
    {
      sc.insertString(0, "ABCDEFG");
    }
    catch (BadLocationException e)
    {
    }
    harness.check(sc.length(), 8);
   
    // if index < 0 should get BadLocationException
    pass = false;
    try
    {
      sc.getChars(-1, 3, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if index > end of text should get BadLocationException
    pass = false;
    try
    {
      sc.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
    {
      sc.getChars(0, 99, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try a zero length string
    try
    {
      sc.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
    {
      sc.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();
    StringContent sc2 = new StringContent();
    try
    {
      sc2.insertString(0, "XYZ");
      sc2.getChars(0, 3, seg2);
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.first(), 'A');
    harness.check(s.getIndex(), 0);
    s.last();
    harness.check(s.getIndex(), 6);
    harness.check(s.first(), 'A');
    harness.check(s.getIndex(), 0);
   
    // try results for a subset of the characters
    s = new Segment(ch, 3, 3);
    harness.check(s.first(), 'D');
    harness.check(s.getIndex(), 3);
    s.last();
    harness.check(s.getIndex(), 5);
    harness.check(s.first(), 'D');
    harness.check(s.getIndex(), 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.setIndex(2);
    harness.check(s.current(), 'C');
    s.setIndex(6);
    harness.check(s.current(), 'G');
   
    // try bad indices
    boolean pass = false;
    try
    {
      s.setIndex(-1);
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    pass = false;
    try
    {
      s.setIndex(99);
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
   
    // try results for a subset of the characters
    s = new Segment(ch, 3, 3);
    s.setIndex(4);
    harness.check(s.current(), 'E');
    s.setIndex(5);
    harness.check(s.current(), 'F');
   
    pass = false;
    try
    {
      s.setIndex(-1);
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    pass = false;
    try
    {
      s.setIndex(1);
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    pass = false;
    try
    {
      s.setIndex(7);
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    pass = false;
    try
    {
      s.setIndex(99);
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
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.