Search in sources :

Example 41 with AttributedCharacterIterator

use of java.text.AttributedCharacterIterator in project robovm by robovm.

the class OldAttributedStringTest method test_getIterator.

/**
     * java.text.AttributedString#getIterator() Test of method
     *        java.text.AttributedString#getIterator().
     */
public void test_getIterator() {
    String test = "Test string";
    try {
        AttributedString attrString = new AttributedString(test);
        AttributedCharacterIterator it = attrString.getIterator();
        assertEquals("Incorrect iteration on AttributedString", it.first(), test.charAt(0));
    } catch (Exception e) {
        fail("Unexpected exceptiption " + e.toString());
    }
}
Also used : AttributedString(java.text.AttributedString) AttributedString(java.text.AttributedString) AttributedCharacterIterator(java.text.AttributedCharacterIterator)

Example 42 with AttributedCharacterIterator

use of java.text.AttributedCharacterIterator in project robovm by robovm.

the class OldAttributedStringTest method test_ConstructorLAttributedCharacterIterator_2.

public void test_ConstructorLAttributedCharacterIterator_2() {
    String testString = "Test string";
    AttributedString attrString = new AttributedString(testString);
    AttributedCharacterIterator iter = attrString.getIterator();
    AttributedString attrString2 = new AttributedString(iter, 2, 7);
    assertEqualString("String must match!", "st st", attrString2);
}
Also used : AttributedString(java.text.AttributedString) AttributedString(java.text.AttributedString) AttributedCharacterIterator(java.text.AttributedCharacterIterator)

Example 43 with AttributedCharacterIterator

use of java.text.AttributedCharacterIterator in project robovm by robovm.

the class OldAttributedStringTest method test_ConstructorLjava_lang_StringLjava_util_Map.

/**
     * java.text.AttributedString#AttributedString(AttributedCharacterIterator,
     *        int, int, Map<? extends AttributedCharacterIterator.Attribute,?>)
     *        Test of method
     *        java.text.AttributedString#AttributedString(AttributedCharacterIterator,
     *        int, int, Map<? extends
     *        AttributedCharacterIterator.Attribute,?>). Case 1: Try to
     *        construct AttributedString. Case 2: Try to construct
     *        AttributedString using 0-length text and not an empty Map
     *        attributes.
     */
public void test_ConstructorLjava_lang_StringLjava_util_Map() {
    String test = "Test string";
    // case 1: Try to construct AttributedString
    try {
        AttributedString attrString = new AttributedString(test, new WeakHashMap<AttributedCharacterIterator.Attribute, String>());
        AttributedCharacterIterator it = attrString.getIterator();
        StringBuffer buf = new StringBuffer();
        buf.append(it.first());
        char ch;
        while ((ch = it.next()) != CharacterIterator.DONE) buf.append(ch);
        assertTrue("Wrong string: " + buf, buf.toString().equals(test));
    } catch (Exception e) {
        fail("Unexpected exception " + e.toString());
    }
    // not an empty Map attributes.
    try {
        Map<AttributedCharacterIterator.Attribute, String> whm = new WeakHashMap<AttributedCharacterIterator.Attribute, String>();
        whm.put(new TestAttributedCharacterIteratorAttribute("test"), "value");
        new AttributedString("", whm);
        fail("Expected IllegalArgumentException was not thrown");
    } catch (Exception e) {
    // expected
    }
}
Also used : AttributedString(java.text.AttributedString) AttributedString(java.text.AttributedString) AttributedCharacterIterator(java.text.AttributedCharacterIterator) WeakHashMap(java.util.WeakHashMap)

Example 44 with AttributedCharacterIterator

use of java.text.AttributedCharacterIterator in project robovm by robovm.

the class OldAttributedCharacterIteratorTest method test_getAllAttributeKeys.

public void test_getAllAttributeKeys() {
    AttributedString as = new AttributedString("test");
    AttributedCharacterIterator it = as.getIterator();
    Set<AttributedCharacterIterator.Attribute> emptyAttributes = it.getAllAttributeKeys();
    assertTrue(emptyAttributes.isEmpty());
    int attrCount = 10;
    for (int i = 0; i < attrCount; i++) {
        as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a");
    }
    it = as.getIterator();
    Set<AttributedCharacterIterator.Attribute> attributes = it.getAllAttributeKeys();
    for (AttributedCharacterIterator.Attribute attr : attributes) {
        assertEquals(AttributedCharacterIterator.Attribute.LANGUAGE, attr);
    }
}
Also used : AttributedString(java.text.AttributedString) AttributedCharacterIterator(java.text.AttributedCharacterIterator)

Example 45 with AttributedCharacterIterator

use of java.text.AttributedCharacterIterator in project robovm by robovm.

the class OldAttributedCharacterIteratorTest method test_getRunStart.

public void test_getRunStart() {
    assertEquals(0, it.getRunStart());
    AttributedString as = new AttributedString("");
    assertEquals(0, as.getIterator().getRunStart());
    as = new AttributedString(new AttributedString("test text").getIterator(), 2, 7);
    AttributedCharacterIterator it = as.getIterator();
    assertEquals(0, it.getRunStart());
    as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "GERMAN", 1, 2);
    as.addAttribute(AttributedCharacterIterator.Attribute.READING, "READ", 1, 3);
    assertEquals(0, as.getIterator().getRunStart());
}
Also used : AttributedString(java.text.AttributedString) AttributedCharacterIterator(java.text.AttributedCharacterIterator)

Aggregations

AttributedCharacterIterator (java.text.AttributedCharacterIterator)57 AttributedString (java.text.AttributedString)35 TextLayout (java.awt.font.TextLayout)17 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)15 Point (java.awt.Point)8 Font (java.awt.Font)7 Paint (java.awt.Paint)7 FontRenderContext (java.awt.font.FontRenderContext)7 Graphics2D (java.awt.Graphics2D)6 Color (java.awt.Color)5 ArrayList (java.util.ArrayList)5 WeakHashMap (java.util.WeakHashMap)5 Rectangle (java.awt.Rectangle)4 Attribute (java.text.AttributedCharacterIterator.Attribute)4 DecimalFormat (java.text.DecimalFormat)4 BigDecimal (java.math.BigDecimal)3 BigInteger (java.math.BigInteger)3 HashSet (java.util.HashSet)3 Dimension (java.awt.Dimension)2 Image (java.awt.Image)2