Search in sources :

Example 61 with AttributedString

use of java.text.AttributedString 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 62 with AttributedString

use of java.text.AttributedString 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 63 with AttributedString

use of java.text.AttributedString 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 64 with AttributedString

use of java.text.AttributedString 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 65 with AttributedString

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

the class OldAttributedCharacterIteratorTest method setUp.

protected void setUp() {
    AttributedString as = new AttributedString(string);
    as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "GERMAN");
    as.addAttribute(AttributedCharacterIterator.Attribute.READING, "READ");
    as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "ENGLISH");
    it = as.getIterator();
}
Also used : AttributedString(java.text.AttributedString)

Aggregations

AttributedString (java.text.AttributedString)86 AttributedCharacterIterator (java.text.AttributedCharacterIterator)37 TextLayout (java.awt.font.TextLayout)29 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)16 FontRenderContext (java.awt.font.FontRenderContext)13 Font (java.awt.Font)11 Point (java.awt.Point)11 Paint (java.awt.Paint)10 Graphics2D (java.awt.Graphics2D)9 WeakHashMap (java.util.WeakHashMap)8 Color (java.awt.Color)4 Bidi (java.text.Bidi)4 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)4 Rectangle (java.awt.Rectangle)3 HashSet (java.util.HashSet)3 Dimension (java.awt.Dimension)2 Insets (java.awt.Insets)2 AffineTransform (java.awt.geom.AffineTransform)2 Rectangle2D (java.awt.geom.Rectangle2D)2