Package java.text

Examples of java.text.AttributedString


  }

  private void testConstructor2(TestHarness harness)
  {
    harness.checkPoint("AttributedString(AttributedCharacterIterator, int, int);");
    AttributedString source = new AttributedString("ABCDEFGHIJ");
    AttributedCharacterIterator sourceACI = source.getIterator();
   
    // should get an IllegalArgumentException if the start index is outside the
    // valid range
    boolean pass = false;
    try
    {
      /*AttributedString as =*/ new AttributedString(sourceACI, -1, 2);
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);

    // should get an IllegalArgumentException if the end index is outside the
    // valid range
    pass = false;
    try
    {
      /*AttributedString as =*/ new AttributedString(sourceACI, 2, 12);
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // it isn't specified, but we assume a NullPointerException if the iterator
    // is null
    pass = false;
    try
    {
      /* AttributedString as = */
          new AttributedString((AttributedCharacterIterator) null, 1, 5);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
View Full Code Here


  private void testConstructor3(TestHarness harness)
  {
    harness.checkPoint("AttributedString(AttributedCharacterIterator, int, int," +
                "AttributedCharacterIterator.Attribute[]);");
   
    AttributedString as0 = new AttributedString("ABCDEFGHIJ");
    as0.addAttribute(TextAttribute.LANGUAGE, "English");
    as0.addAttribute(TextAttribute.FOREGROUND, Color.red, 2, 4);
    as0.addAttribute(TextAttribute.BACKGROUND, Color.yellow, 3, 5);
   
    // try extracting no attributes...
    AttributedString as = new AttributedString(as0.getIterator(), 1, 8,
            new AttributedCharacterIterator.Attribute[] {});
    AttributedCharacterIterator aci = as.getIterator();
    harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 7);
    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 7);
    harness.check(aci.getRunLimit(TextAttribute.BACKGROUND), 7);
   
    // try extracting just one attribute...
    as = new AttributedString(as0.getIterator(), 1, 8,
            new AttributedCharacterIterator.Attribute[] {TextAttribute.FOREGROUND});
    aci = as.getIterator();
    harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 7);
    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 1);
    aci.setIndex(1);
    harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 7);
    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 3);
    aci.setIndex(3);
    harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 7);
    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 7);
   
    // null iterator should throw NullPointerException
    boolean pass = false;
    try
    {
      /*AttributedString as =*/ new AttributedString(null, 0, 3,
            new AttributedCharacterIterator.Attribute[] {TextAttribute.FONT});
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try start > string length
    AttributedString as1 = new AttributedString("ABC");
   
    pass = false;
    try
    {
      /*AttributedString as =*/ new AttributedString(as1.getIterator(), 3, 4,
            new AttributedCharacterIterator.Attribute[] {TextAttribute.FONT});
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);

    // try end > string length
    pass = false;
    try
    {
      /*AttributedString as =*/ new AttributedString(as1.getIterator(), 1, 4,
            new AttributedCharacterIterator.Attribute[] {TextAttribute.FONT});
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try start > end
    pass = false;
    try
    {
      /*AttributedString as =*/ new AttributedString(as1.getIterator(), 1, 0,
            new AttributedCharacterIterator.Attribute[] {TextAttribute.FONT});
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
View Full Code Here

   
    // try null argument - the API spec doesn't say what happens.
    boolean pass = false;
    try
    {
      /* AttributedString as = */ new AttributedString((String) null);  
    }
    catch (NullPointerException e)
    {
      pass = true;  
    }
View Full Code Here

  private void testConstructor5(TestHarness harness)
  {
    harness.checkPoint("AttributedString(String, map);");
    HashMap map = new HashMap();
    map.put(AttributedCharacterIterator.Attribute.LANGUAGE, "English");   
    AttributedString as = new AttributedString("ABC", map);
    AttributedCharacterIterator aci = as.getIterator();
    harness.check(aci.first() == 'A');
    harness.check(aci.getAttribute(AttributedCharacterIterator.Attribute.LANGUAGE).equals("English"));
    harness.check(aci.getRunLimit() == 3);
    harness.check(aci.getRunStart() == 0);
   
    // test null string - not specified, assuming NullPointerException
    boolean pass = false;
    try
    {
      /* AttributedString as = */ new AttributedString(null, new HashMap());  
    }
    catch (NullPointerException e)
    {
      pass = true;  
    }
    harness.check(pass);
   
    // test null map - not specified, assuming NullPointerException.
    pass = false;
    try
    {
      /* AttributedString as = */ new AttributedString("ABC", null);
    }
    catch (NullPointerException e)
    {
      pass = true;  
    }
    harness.check(true);
   
    // test empty string with non-empty map
    pass = false;
    try
    {
      /* AttributedString as = */ new AttributedString("", map);  
    }
    catch (IllegalArgumentException e)
    {
      pass = true;  
    }
View Full Code Here

   * @param harness  the test harness (<code>null</code> not allowed).
   */
  public void test(TestHarness harness)
  {
    harness.checkPoint("addAttributes(Map, int, int)");
    AttributedString as = new AttributedString("ABCDEFG");
    HashMap attributes = new HashMap();
    attributes.put(TextAttribute.BACKGROUND, Color.red);
    attributes.put(TextAttribute.FOREGROUND, Color.yellow);
    as.addAttributes(attributes, 2, 4);
    AttributedCharacterIterator aci = as.getIterator();
    aci.first();
    harness.check(aci.getRunStart(TextAttribute.BACKGROUND), 0);
    harness.check(aci.getRunLimit(TextAttribute.BACKGROUND), 2);
    aci.next();
    aci.next();
    harness.check(aci.getRunStart(TextAttribute.BACKGROUND), 2);
    harness.check(aci.getRunLimit(TextAttribute.BACKGROUND), 4);
    aci.next();
    aci.next();
    harness.check(aci.getRunStart(TextAttribute.BACKGROUND), 4);
    harness.check(aci.getRunLimit(TextAttribute.BACKGROUND), 7);

    // check null map
    boolean pass = false;
    try
    {
      as.addAttributes(null, 2, 4);  
    }
    catch (NullPointerException e)
    {
      pass = true;  
    }
    harness.check(pass);
   
    // check negative beginIndex
    pass = false;
    try
    {
      as.addAttributes(attributes, -1, 4);  
    }
    catch (IllegalArgumentException e)
    {
      pass = true;  
    }
    harness.check(pass);
   
    // check endIndex > string length
    pass = false;
    try
    {
      as.addAttributes(attributes, 2, 8);  
    }
    catch (IllegalArgumentException e)
    {
      pass = true;  
    }
    harness.check(pass);
   
    // check indices with zero range
    pass = false;
    try
    {
      as.addAttributes(attributes, 2, 2);
    }
    catch (IllegalArgumentException e)
    {
      pass = true;  
    }
View Full Code Here

   */
  public void test(TestHarness harness)
  {
    harness.checkPoint("getAttribute(AttributedCharacterIterator.Attribute);");

    AttributedString as = new AttributedString("ABCDEFG");
    as.addAttribute(TextAttribute.LANGUAGE, "English");
    AttributedCharacterIterator aci = as.getIterator();
   
    harness.check(aci.getAttribute(TextAttribute.LANGUAGE), "English");
    harness.check(aci.getAttribute(TextAttribute.FONT), null);
   
    // try null attribute
View Full Code Here

  }
 
  public void test1(TestHarness harness)
  {
    harness.checkPoint("getIterator()");
    AttributedString as = new AttributedString("ABC");
    AttributedCharacterIterator aci = as.getIterator();
    harness.check(aci.current() == 'A');
    harness.check(aci.next() == 'B');
    harness.check(aci.next() == 'C');
    harness.check(aci.next() == CharacterIterator.DONE);

    AttributedString as2 = new AttributedString("");
    AttributedCharacterIterator aci2 = as2.getIterator();
    harness.check(aci2.current() == CharacterIterator.DONE);
  }
View Full Code Here

  }

  public void test2(TestHarness harness)
  {
    harness.checkPoint("getIterator(AttributedCharacterIterator.Attribute[])");
    AttributedString as = new AttributedString("ABCDEF");
    as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, Locale.FRENCH);
    as.addAttribute(TextAttribute.BACKGROUND, Color.red, 0, 3);
    as.addAttribute(TextAttribute.FOREGROUND, Color.blue, 2, 4);
    AttributedCharacterIterator.Attribute[] attributes = new AttributedCharacterIterator.Attribute[2];
    attributes[0] = TextAttribute.BACKGROUND;
    attributes[1] = TextAttribute.FOREGROUND;
    AttributedCharacterIterator aci = as.getIterator(attributes);
    harness.check(aci.getAttribute(TextAttribute.BACKGROUND), Color.red);
    harness.check(aci.getAttribute(TextAttribute.FOREGROUND), null);
    harness.check(aci.next() == 'B');
    harness.check(aci.getAttribute(TextAttribute.BACKGROUND), Color.red);
    harness.check(aci.getAttribute(TextAttribute.FOREGROUND), null);
    harness.check(aci.next() == 'C');
    harness.check(aci.getAttribute(TextAttribute.BACKGROUND), Color.red);
    harness.check(aci.getAttribute(TextAttribute.FOREGROUND), Color.blue);
    harness.check(aci.next() == 'D');
    harness.check(aci.getAttribute(TextAttribute.BACKGROUND), null);
    harness.check(aci.getAttribute(TextAttribute.FOREGROUND), Color.blue);
    harness.check(aci.next() == 'E');
    harness.check(aci.getAttribute(TextAttribute.BACKGROUND), null);
    harness.check(aci.getAttribute(TextAttribute.FOREGROUND), null);
    harness.check(aci.next() == 'F');
    harness.check(aci.getAttribute(TextAttribute.BACKGROUND), null);
    harness.check(aci.getAttribute(TextAttribute.FOREGROUND), null);
   
    // a null argument is equivalent to a regular iterator
    AttributedString as2 = new AttributedString("ABC");
    AttributedCharacterIterator aci2 = as2.getIterator(null);
    harness.check(aci2.current() == 'A');
    harness.check(aci2.next() == 'B');
    harness.check(aci2.next() == 'C');
    harness.check(aci2.next() == CharacterIterator.DONE);

    AttributedString as3 = new AttributedString("");
    AttributedCharacterIterator aci3 = as3.getIterator(null);
    harness.check(aci3.current() == CharacterIterator.DONE);
  }
View Full Code Here

  }

  private void test1(TestHarness harness)
  {
    harness.checkPoint("getRunStart();");
    AttributedString as = new AttributedString("ABCDEFG");
    as.addAttribute(TextAttribute.LANGUAGE, "English");
    as.addAttribute(TextAttribute.FOREGROUND, Color.red, 2, 4);
    AttributedCharacterIterator aci = as.getIterator();
    harness.check(aci.getRunStart(), 0);
    aci.setIndex(3);
    harness.check(aci.getRunStart(), 2);
  }
View Full Code Here

   
    // if beginIndex < 0, there should be an IllegalArgumentException
    boolean pass = false;
    try
    {
      AttributedString as = new AttributedString("ABC");
      as.getIterator(null, -1, 1);
    }
    catch (IllegalArgumentException e)
    {
      pass = true
    }
    harness.check(pass);
   
    // if end index > length of string, there should be an
    // IllegalArgumentException
    pass = false;
    try
    {
      AttributedString as = new AttributedString("XYZ");
      as.getIterator(null, 2, 4);
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(true);
   
    // if start index > end index, there should be an IllegalArgumentException
    pass = false;
    try
    {
      AttributedString as = new AttributedString("123");
      as.getIterator(null, 2, 1);   
    }
    catch (IllegalArgumentException e)
    {
      pass = true
    }
View Full Code Here

TOP

Related Classes of java.text.AttributedString

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.