Java 8 AttributedCharacterIterator - 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 AttributedCharacterIterator class.

This code example shows how to use the following methods:getBeginIndex, getEndIndex, setIndex, clone
     * @param stop the index of the first character after the subinterval 
     */ 
    public AttributedCharacterSpanIterator(AttributedCharacterIterator aci, 
                                           int start, int stop) {
        this.aci = aci;
        end = Math.min(aci.getEndIndex(), stop);
        begin = Math.max(aci.getBeginIndex(), start);
        this.aci.setIndex(begin);
    } 
 
    //From java.text.AttributedCharacterIterator 
 
    /** 
     * Get the keys of all attributes defined on the iterator's text range. 
     */ 
    public Set getAllAttributeKeys() {
        return aci.getAllAttributeKeys();
        // FIXME: not if there are atts outside the substring! 
    } 
 

6
CodeRank
This code example shows how to use the following methods:current, setIndex
	 */ 
	public void test_setIndexI() { 
		String test = "Test 23ring";
		AttributedString attrString = new AttributedString(test);
		AttributedCharacterIterator it = attrString.getIterator();
		it.setIndex(5);
		assertEquals("Wrong first", '2', it.current());
	} 
 
	/** 
	 * @tests java.text.AttributedCharacterIterator#getRunLimit(java.text.AttributedCharacterIterator$Attribute) 
	 */ 
	public void test_getRunLimitLjava_text_AttributedCharacterIterator$Attribute() { 
		AttributedString as = new AttributedString("test");
		as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2,
				3); 
		AttributedCharacterIterator it = as.getIterator();
		assertEquals("non-null value limit",
				2, it.getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE));
 
5
CodeRank
This code example shows how to use the following methods:toString
 
    public void testAttributeNames() { 
        assertEquals("java.awt.font.TextAttribute(kerning)",
                TextAttribute.KERNING.toString());
        assertEquals("java.awt.font.TextAttribute(ligatures)",
                TextAttribute.LIGATURES.toString());
        assertEquals("java.awt.font.TextAttribute(tracking)",
                TextAttribute.TRACKING.toString());
    } 
 
    public void testAttributeValues() { 
        assertEquals(new Integer(1), TextAttribute.KERNING_ON);
        assertEquals(new Integer(1), TextAttribute.LIGATURES_ON);
        assertEquals(new Float(0.04f), TextAttribute.TRACKING_LOOSE);
        assertEquals(new Float(-0.04f), TextAttribute.TRACKING_TIGHT);
    } 
} 
4
CodeRank
This code example shows how to use the following methods:getBeginIndex, getEndIndex
                     new Object[] {s, new Float(x), new Float(y)}); 
    } 
 
    public void drawString(AttributedCharacterIterator iterator,
                           int x, int y) {
        Rectangle2D r2d =
            getFontMetrics(getFont() 
                           ).getStringBounds(iterator,
                                             iterator.getBeginIndex(),
                                             iterator.getEndIndex(),
                                             this);
 
        r2d.setRect(x, y - r2d.getHeight() + 1,
                    r2d.getWidth(), r2d.getHeight());
 
        doGraphicsOp(r2d,
                     "drawString", 
                     new Class[] {java.text.AttributedCharacterIterator.class,
                                      int.class, int.class}, 
                     new Object[] {iterator, new Integer(x), new Integer(y)}); 
5
CodeRank
This code example shows how to use the following methods:getAttribute, getRunLimit, setIndex
            // the current char. 
            ret = lineBreakCount;
 
            // Update the lineBreakRunLimit, this is a bit tricky since 
            // The attribute doesn't change until the next glyph... 
            aci.setIndex(aciIdx+charCount);
            lineBreakRunLimit = aci.getRunLimit(FLOW_LINE_BREAK);
            aci.setIndex(aciIdx);  // Restore location...
 
            Object o = aci.getAttribute(FLOW_LINE_BREAK);
            lineBreakCount = (o == null)?0:1;
        } 
        return ret;
    } 
 
    /** 
     * Move iterator to the next char. 
     */ 
    public void nextChar() { 
        if ((ch == SOFT_HYPHEN)      ||
5
CodeRank
This code example shows how to use the following methods:current, setIndex
	 */ 
	public void test_setIndexI() { 
		String test = "Test 23ring";
		AttributedString attrString = new AttributedString(test);
		AttributedCharacterIterator it = attrString.getIterator();
		it.setIndex(5);
		assertEquals("Wrong first", '2', it.current());
	} 
 
	/** 
	 * @tests java.text.AttributedCharacterIterator#getRunLimit(java.text.AttributedCharacterIterator$Attribute) 
	 */ 
	public void test_getRunLimitLjava_text_AttributedCharacterIterator$Attribute() { 
		AttributedString as = new AttributedString("test");
		as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2,
				3); 
		AttributedCharacterIterator it = as.getIterator();
		assertEquals("non-null value limit",
				2, it.getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE));
 
5
CodeRank
This code example shows how to use the following methods:getBeginIndex, getEndIndex
This code example shows how to use the following methods:getAttribute
        } 
    } 
 
    public void test_getAttributeLAttributedCharacterIterator_Attribute() { 
 
        Object attribute =
            it.getAttribute(AttributedCharacterIterator.Attribute.LANGUAGE);
        assertEquals("ENGLISH", attribute);
 
        attribute =
            it.getAttribute(AttributedCharacterIterator.Attribute.READING);
        assertEquals("READ", attribute);
 
        assertNull(it.getAttribute(AttributedCharacterIterator.
                Attribute.INPUT_METHOD_SEGMENT));
    } 
 
    public void test_getAttributes() { 
        Map<AttributedCharacterIterator.Attribute, Object> attributes =
            it.getAttributes();
4
CodeRank
This code example shows how to use the following methods:getBeginIndex, getEndIndex
  } 
 
  private boolean isInputProcess(AttributedCharacterIterator text){
    if(text == null)
      return false; 
    return (text.getEndIndex() - (text.getBeginIndex() + committed_count) > 0);
  } 
 
  public void caretPositionChanged(InputMethodEvent event) {
    event.consume();
  } 
} 
4
CodeRank
This code example shows how to use the following methods:getRunLimit
        AttributedString as = new AttributedString("test");
        as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2,
                3); 
        AttributedCharacterIterator it = as.getIterator();
        assertEquals("non-null value limit", 2, it
                .getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE));
 
        as = new AttributedString("test");
        as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, null,
                2, 3); 
        it = as.getIterator();
        assertEquals("null value limit", 4, it
                .getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE));
 
        try { 
            as = new AttributedString("test");
            as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE,
                    null, -1, 3); 
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException e) {
4
CodeRank
See Code Examples for Java 8 AttributedCharacterIterator Methods: