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();
}
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);
}
}
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;
}
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");
}
}
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);
}
}
Aggregations