Search in sources :

Example 71 with AttributedString

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

the class Util method getIterator.

//	initCap
/**************************************************************************
	 * Return a Iterator with only the relevant attributes.
	 * Fixes implementation in AttributedString, which returns everything
	 * @param aString attributed string
	 * @param relevantAttributes relevant attributes
	 * @return iterator
	 */
public static AttributedCharacterIterator getIterator(AttributedString aString, AttributedCharacterIterator.Attribute[] relevantAttributes) {
    AttributedCharacterIterator iter = aString.getIterator();
    Set set = iter.getAllAttributeKeys();
    //	System.out.println("AllAttributeKeys=" + set);
    if (set.size() == 0)
        return iter;
    //	Check, if there are unwanted attributes
    Set<AttributedCharacterIterator.Attribute> unwanted = new HashSet<AttributedCharacterIterator.Attribute>(iter.getAllAttributeKeys());
    for (int i = 0; i < relevantAttributes.length; i++) unwanted.remove(relevantAttributes[i]);
    if (unwanted.size() == 0)
        return iter;
    //	Create new String
    StringBuffer sb = new StringBuffer();
    for (char c = iter.first(); c != AttributedCharacterIterator.DONE; c = iter.next()) sb.append(c);
    aString = new AttributedString(sb.toString());
    //	copy relevant attributes
    Iterator it = iter.getAllAttributeKeys().iterator();
    while (it.hasNext()) {
        AttributedCharacterIterator.Attribute att = (AttributedCharacterIterator.Attribute) it.next();
        if (!unwanted.contains(att)) {
            for (char c = iter.first(); c != AttributedCharacterIterator.DONE; c = iter.next()) {
                Object value = iter.getAttribute(att);
                if (value != null) {
                    int start = iter.getRunStart(att);
                    int limit = iter.getRunLimit(att);
                    //	System.out.println("Attribute=" + att + " Value=" + value + " Start=" + start + " Limit=" + limit);
                    aString.addAttribute(att, value, start, limit);
                    iter.setIndex(limit);
                }
            }
        }
    //	else
    //		System.out.println("Unwanted: " + att);
    }
    return aString.getIterator();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AttributedString(java.text.AttributedString) TextAttribute(java.awt.font.TextAttribute) Iterator(java.util.Iterator) AttributedCharacterIterator(java.text.AttributedCharacterIterator) AttributedCharacterIterator(java.text.AttributedCharacterIterator) HashSet(java.util.HashSet)

Example 72 with AttributedString

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

the class WFNode method paintComponent.

//	getPreferredSize
/**
	 * 	Paint Component
	 *	@param g Graphics
	 */
protected void paintComponent(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    Rectangle bounds = getBounds();
    m_icon.paintIcon(this, g2D, 0, 0);
    //	Paint Text
    Color color = getForeground();
    g2D.setPaint(color);
    Font font = getFont();
    //
    AttributedString aString = new AttributedString(m_name);
    aString.addAttribute(TextAttribute.FONT, font);
    aString.addAttribute(TextAttribute.FOREGROUND, color);
    AttributedCharacterIterator iter = aString.getIterator();
    //
    LineBreakMeasurer measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
    float width = s_size.width - m_icon.getIconWidth() - 2;
    TextLayout layout = measurer.nextLayout(width);
    float xPos = m_icon.getIconWidth();
    float yPos = layout.getAscent() + 2;
    //
    layout.draw(g2D, xPos, yPos);
    //	2 pt 
    width = s_size.width - 4;
    while (measurer.getPosition() < iter.getEndIndex()) {
        layout = measurer.nextLayout(width);
        yPos += layout.getAscent() + layout.getDescent() + layout.getLeading();
        layout.draw(g2D, 2, yPos);
    }
}
Also used : AttributedString(java.text.AttributedString) Color(java.awt.Color) Rectangle(java.awt.Rectangle) LineBreakMeasurer(java.awt.font.LineBreakMeasurer) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) AttributedCharacterIterator(java.text.AttributedCharacterIterator) TextLayout(java.awt.font.TextLayout)

Example 73 with AttributedString

use of java.text.AttributedString in project jdk8u_jdk by JetBrains.

the class CodePointInputMethod method sendCommittedText.

/**
     * Send the committed text to the client.
     */
private void sendCommittedText() {
    AttributedString as = new AttributedString(buffer.toString());
    context.dispatchInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, as.getIterator(), buffer.length(), TextHitInfo.leading(insertionPoint), null);
    buffer.setLength(0);
    insertionPoint = 0;
    format = UNSET;
}
Also used : AttributedString(java.text.AttributedString)

Example 74 with AttributedString

use of java.text.AttributedString in project jdk8u_jdk by JetBrains.

the class BidiEmbeddingTest method test2.

// make sure BIDI_EMBEDDING values of 0 are mapped to base run direction, instead of flagging an error.
static void test2() {
    String target = "BACK WARDS";
    String str = "If this text is >" + target + "< the test passed.";
    int length = str.length();
    int start = str.indexOf(target);
    int limit = start + target.length();
    System.out.println("start: " + start + " limit: " + limit);
    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());
    for (int i = 0; i < bidi.getRunCount(); ++i) {
        System.out.println("run " + i + " from " + bidi.getRunStart(i) + " to " + bidi.getRunLimit(i) + " at level " + bidi.getRunLevel(i));
    }
    System.out.println(bidi + "\n");
    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");
    } else {
        System.out.println("test2() passed.\n");
    }
}
Also used : AttributedString(java.text.AttributedString) Bidi(java.text.Bidi) AttributedString(java.text.AttributedString)

Example 75 with AttributedString

use of java.text.AttributedString in project jdk8u_jdk by JetBrains.

the class BidiConformance method testMethods4Constructor1.

private void testMethods4Constructor1() {
    System.out.println("*** Test methods for constructor 1");
    String paragraph;
    Bidi bidi;
    NumericShaper ns = NumericShaper.getShaper(NumericShaper.ARABIC);
    for (int textNo = 0; textNo < data4Constructor1.length; textNo++) {
        paragraph = data4Constructor1[textNo][0];
        int start = paragraph.indexOf('<') + 1;
        int limit = paragraph.indexOf('>');
        int testNo;
        System.out.println("*** Test textNo=" + textNo + ": Bidi(AttributedCharacterIterator\"" + toReadableString(paragraph) + "\") " + "  start=" + start + ", limit=" + limit);
        // Test 0
        testNo = 0;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_LTR");
        AttributedString astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 1
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_LTR, BIDI_EMBEDDING(1)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(1), start, limit);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 2
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIERCTION_LTR, BIDI_EMBEDDING(2)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(2), start, limit);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 3
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTIOIN_LTR, BIDI_EMBEDDING(-3)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-3), start, limit);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 4
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_LTR, BIDI_EMBEDDING(-4)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-4), start, limit);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 5
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 6
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL, BIDI_EMBEDDING(1)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(1), start, limit);
        try {
            bidi = new Bidi(astr.getIterator());
            callTestEachMethod4Constructor1(textNo, testNo, bidi);
        } catch (IllegalArgumentException e) {
            errorHandling("  Unexpected exception: " + e);
        }
        // Test 7
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL, BIDI_EMBEDDING(2)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(2), start, limit);
        try {
            bidi = new Bidi(astr.getIterator());
            callTestEachMethod4Constructor1(textNo, testNo, bidi);
        } catch (IllegalArgumentException e) {
            errorHandling("  Unexpected exception: " + e);
        }
        // Test 8
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL, BIDI_EMBEDDING(-3)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-3), start, limit);
        try {
            bidi = new Bidi(astr.getIterator());
            callTestEachMethod4Constructor1(textNo, testNo, bidi);
        } catch (IllegalArgumentException e) {
            errorHandling("  Unexpected exception: " + e);
        }
        // Test 9
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL, BIDI_EMBEDDING(-4)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-4), start, limit);
        try {
            bidi = new Bidi(astr.getIterator());
            callTestEachMethod4Constructor1(textNo, testNo, bidi);
        } catch (IllegalArgumentException e) {
            errorHandling("  Unexpected exception: " + e);
        }
        // Test 10
        ++testNo;
        System.out.println(" Test#" + testNo + ": TextAttribute not specified");
        astr = new AttributedString(paragraph);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 11
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_LTR, NUMERIC_SHAPING(ARABIC)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        astr.addAttribute(TextAttribute.NUMERIC_SHAPING, ns);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 12
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL, NUMERIC_SHAPING(ARABIC)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        astr.addAttribute(TextAttribute.NUMERIC_SHAPING, ns);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
    }
}
Also used : Bidi(java.text.Bidi) NumericShaper(java.awt.font.NumericShaper) AttributedString(java.text.AttributedString) 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