Java 8 AttributedString - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 AttributedString class.

This code example shows how to use the following methods:getIterator
	/** 
	 * @tests java.text.AttributedCharacterIterator#last() 
	 */ 
	public void test_last() { 
		String test = "Test 23ring";
		AttributedString attrString = new AttributedString(test);
		AttributedCharacterIterator it = attrString.getIterator();
		assertEquals("Wrong last1", 'g', it.last());
		it = attrString.getIterator(null, 0, 3);
		assertEquals("Wrong last2", 's', it.last());
		it = attrString.getIterator(null, 2, 8);
		assertEquals("Wrong last3", 'r', it.last());
		it = attrString.getIterator(null, 0, 0);
		assertTrue("Wrong last4", it.last() == CharacterIterator.DONE);
	} 
 
	/** 
	 * @tests java.text.AttributedCharacterIterator#next() 
	 */ 
	public void test_next() { 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addAttribute, getIterator
        String str = "If this text is >" + target + "< the test passed.";
        int length = str.length();
        int start = str.indexOf(target);
        int limit = start + target.length();
 
        AttributedString astr = new AttributedString(str);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
 
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
                         new Integer(-3),
                         start,
                         limit);
 
        Bidi bidi = new Bidi(astr.getIterator());
 
        if (bidi.getRunCount() != 6) { // runs of spaces and angles at embedding bound,s and final period, each get level 1
            throw new Error("Bidi embedding processing failed");
        } 
    } 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addAttribute
 
    } 
 
    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();
    } 
 
    protected void tearDown() { 
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getIterator
	/** 
	 * @tests java.text.AttributedCharacterIterator#last() 
	 */ 
	public void test_last() { 
		String test = "Test 23ring";
		AttributedString attrString = new AttributedString(test);
		AttributedCharacterIterator it = attrString.getIterator();
		assertEquals("Wrong last1", 'g', it.last());
		it = attrString.getIterator(null, 0, 3);
		assertEquals("Wrong last2", 's', it.last());
		it = attrString.getIterator(null, 2, 8);
		assertEquals("Wrong last3", 'r', it.last());
		it = attrString.getIterator(null, 0, 0);
		assertTrue("Wrong last4", it.last() == CharacterIterator.DONE);
	} 
 
	/** 
	 * @tests java.text.AttributedCharacterIterator#next() 
	 */ 
	public void test_next() { 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addAttribute
     * java.text.AttributedString.addAttribute(AttributedCharacterIterator, 
     *        Object) 
     */ 
    public void test_addAttributeLjava_text_AttributedCharacterIterator$AttributeLjava_lang_Object() { 
        // regression for Harmony-1244 
        AttributedString as = new AttributedString("123", new WeakHashMap());
 
        as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "english");
        as.addAttribute(AttributedCharacterIterator.Attribute.INPUT_METHOD_SEGMENT,
                                                                "input method"); 
        as.addAttribute(AttributedCharacterIterator.Attribute.READING, "reading");
 
        try { 
            as.addAttribute(null, new TreeSet());
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected 
        } 
        try { 
            as.addAttribute(null, null);

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addAttribute, getIterator
    public void paint(Graphics2D g) {
        String fontName = "Arial";
        int fontSize = 15;
 
        String text = "Attributed Strings are fun !";
        AttributedString styledText = new AttributedString(text);
 
        // 
        // Set font family for the whole string 
        // 
        Font font = new Font(fontName, Font.PLAIN, fontSize);
        styledText.addAttribute(TextAttribute.FAMILY, font.getFamily());
        styledText.addAttribute(TextAttribute.SIZE, new Float(font.getSize()));
        styledText.addAttribute(TextAttribute.FOREGROUND, Color.black);
 
        // 
        // Set font style attributes for different part of the string 
        // 
 
        // "Attributed" is in Bold 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addAttribute
     * java.text.AttributedString.addAttribute(AttributedCharacterIterator, 
     *        Object) 
     */ 
    public void test_addAttributeLjava_text_AttributedCharacterIterator$AttributeLjava_lang_Object() { 
        // regression for Harmony-1244 
        AttributedString as = new AttributedString("123", new WeakHashMap());
 
        as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "english");
        as.addAttribute(AttributedCharacterIterator.Attribute.INPUT_METHOD_SEGMENT,
                                                                "input method"); 
        as.addAttribute(AttributedCharacterIterator.Attribute.READING, "reading");
 
        try { 
            as.addAttribute(null, new TreeSet());
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected 
        } 
        try { 
            as.addAttribute(null, null);

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addAttribute
     * Some checks for the equal(AttributedString, AttributedString) method. 
     */ 
    public void testEqual() { 
        assertTrue(AttributedStringUtilities.equal(null, null));
   
        AttributedString s1 = new AttributedString("ABC");
        assertFalse(AttributedStringUtilities.equal(s1, null));
        assertFalse(AttributedStringUtilities.equal(null, s1));
         
        AttributedString s2 = new AttributedString("ABC");
        assertTrue(AttributedStringUtilities.equal(s1, s2));
         
        s1.addAttribute(TextAttribute.BACKGROUND, Color.blue, 1, 2);
        assertFalse(AttributedStringUtilities.equal(s1, s2));
        s2.addAttribute(TextAttribute.BACKGROUND, Color.blue, 1, 2);
        assertTrue(AttributedStringUtilities.equal(s1, s2));
    } 
 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addAttribute
 
    } 
 
    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();
    } 
 
    protected void tearDown() { 
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addAttribute, getIterator
	String str = "If this text is >" + target + "< the test passed.";
	int length = str.length();
	int start = str.indexOf(target);
	int limit = start + target.length();
 
	AttributedString astr = new AttributedString(str);
	astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
	 
	astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
			 new Integer(-3),
			 start,
			 limit);
 
	Bidi bidi = new Bidi(astr.getIterator());
 
	if (bidi.getRunCount() != 6) { // runs of spaces and angles at embedding bound,s and final period, each get level 1
	    throw new Error("Bidi embedding processing failed");
	} 
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 AttributedString Methods: