use of java.text.AttributedString in project jdk8u_jdk by JetBrains.
the class X11InputMethod method dispatchComposedText.
/**
* Updates composed text with XIM preedit information and
* posts composed text to the awt event queue. The args of
* this method correspond to the XIM preedit callback
* information. The XIM highlight attributes are translated via
* fixed mapping (i.e., independent from any underlying input
* method engine). This method is invoked in the AWT Toolkit
* (X event loop) thread context and thus inside the AWT Lock.
*/
// NOTE: This method may be called by privileged threads.
// This functionality is implemented in a package-private method
// to insure that it cannot be overridden by client subclasses.
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void dispatchComposedText(String chgText, int[] chgStyles, int chgOffset, int chgLength, int caretPosition, long when) {
if (disposed) {
return;
}
//Workaround for deadlock bug on solaris2.6_zh bug#4170760
if (chgText == null && chgStyles == null && chgOffset == 0 && chgLength == 0 && caretPosition == 0 && composedText == null && committedText == null)
return;
if (composedText == null) {
// TODO: avoid reallocation of those buffers
composedText = new StringBuffer(INITIAL_SIZE);
rawFeedbacks = new IntBuffer(INITIAL_SIZE);
}
if (chgLength > 0) {
if (chgText == null && chgStyles != null) {
rawFeedbacks.replace(chgOffset, chgStyles);
} else {
if (chgLength == composedText.length()) {
// optimization for the special case to replace the
// entire previous text
composedText = new StringBuffer(INITIAL_SIZE);
rawFeedbacks = new IntBuffer(INITIAL_SIZE);
} else {
if (composedText.length() > 0) {
if (chgOffset + chgLength < composedText.length()) {
String text;
text = composedText.toString().substring(chgOffset + chgLength, composedText.length());
composedText.setLength(chgOffset);
composedText.append(text);
} else {
// in case to remove substring from chgOffset
// to the end
composedText.setLength(chgOffset);
}
rawFeedbacks.remove(chgOffset, chgLength);
}
}
}
}
if (chgText != null) {
composedText.insert(chgOffset, chgText);
if (chgStyles != null)
rawFeedbacks.insert(chgOffset, chgStyles);
}
if (composedText.length() == 0) {
composedText = null;
rawFeedbacks = null;
// client component.
if (committedText != null) {
dispatchCommittedText(committedText, when);
committedText = null;
return;
}
// otherwise, send null text to delete client's composed
// text.
postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, null, 0, null, null, when);
return;
}
// Now sending the composed text to the client
int composedOffset;
AttributedString inputText;
// the composed text.
if (committedText != null) {
composedOffset = committedText.length();
inputText = new AttributedString(committedText + composedText);
committedText = null;
} else {
composedOffset = 0;
inputText = new AttributedString(composedText.toString());
}
int currentFeedback;
int nextFeedback;
int startOffset = 0;
int currentOffset;
int visiblePosition = 0;
TextHitInfo visiblePositionInfo = null;
rawFeedbacks.rewind();
currentFeedback = rawFeedbacks.getNext();
rawFeedbacks.unget();
while ((nextFeedback = rawFeedbacks.getNext()) != -1) {
if (visiblePosition == 0) {
visiblePosition = nextFeedback & XIMVisibleMask;
if (visiblePosition != 0) {
int index = rawFeedbacks.getOffset() - 1;
if (visiblePosition == XIMVisibleToBackward)
visiblePositionInfo = TextHitInfo.leading(index);
else
visiblePositionInfo = TextHitInfo.trailing(index);
}
}
nextFeedback &= ~XIMVisibleMask;
if (currentFeedback != nextFeedback) {
rawFeedbacks.unget();
currentOffset = rawFeedbacks.getOffset();
inputText.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, convertVisualFeedbackToHighlight(currentFeedback), composedOffset + startOffset, composedOffset + currentOffset);
startOffset = currentOffset;
currentFeedback = nextFeedback;
}
}
currentOffset = rawFeedbacks.getOffset();
if (currentOffset >= 0) {
inputText.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, convertVisualFeedbackToHighlight(currentFeedback), composedOffset + startOffset, composedOffset + currentOffset);
}
postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, inputText.getIterator(), composedOffset, TextHitInfo.leading(caretPosition), visiblePositionInfo, when);
}
use of java.text.AttributedString in project jdk8u_jdk by JetBrains.
the class X11InputMethod method dispatchCommittedText.
/**
* Dispatches committed text from XIM to the awt event queue. This
* method is invoked from the event handler in canvas.c in the
* AWT Toolkit thread context and thus inside the AWT Lock.
* @param str committed text
* @param long when
*/
// NOTE: This method may be called by privileged threads.
// This functionality is implemented in a package-private method
// to insure that it cannot be overridden by client subclasses.
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void dispatchCommittedText(String str, long when) {
if (str == null)
return;
if (composedText == null) {
AttributedString attrstr = new AttributedString(str);
postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, attrstr.getIterator(), str.length(), null, null, when);
} else {
// if there is composed text, wait until the preedit
// callback is invoked.
committedText = str;
}
}
use of java.text.AttributedString in project jdk8u_jdk by JetBrains.
the class InputMethodContext method dispatchCommittedText.
/**
* Dispatches committed text to a client component.
* Called by composition window.
*
* @param client The component that the text should get dispatched to.
* @param text The iterator providing access to the committed
* (and possible composed) text.
* @param committedCharacterCount The number of committed characters in the text.
*/
synchronized void dispatchCommittedText(Component client, AttributedCharacterIterator text, int committedCharacterCount) {
// the event was in the queue.
if (committedCharacterCount == 0 || text.getEndIndex() <= text.getBeginIndex()) {
return;
}
long time = System.currentTimeMillis();
dispatchingCommittedText = true;
try {
InputMethodRequests req = client.getInputMethodRequests();
if (req != null) {
// active client -> send text as InputMethodEvent
int beginIndex = text.getBeginIndex();
AttributedCharacterIterator toBeCommitted = (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();
InputMethodEvent inputEvent = new InputMethodEvent(client, InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, toBeCommitted, committedCharacterCount, null, null);
client.dispatchEvent(inputEvent);
} else {
// passive client -> send text as KeyEvents
char keyChar = text.first();
while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED, time, 0, KeyEvent.VK_UNDEFINED, keyChar);
client.dispatchEvent(keyEvent);
keyChar = text.next();
}
}
} finally {
dispatchingCommittedText = false;
}
}
use of java.text.AttributedString in project jdk8u_jdk by JetBrains.
the class BidiEmbeddingTest method test1.
static void test1() {
String target = "BACK WARDS";
String str = "If this text is >" + target + "< the test passed.";
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.BIDI_EMBEDDING, new Integer(-1), 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);
byte[] embs = new byte[str.length() + 3];
for (int i = start + 1; i < limit + 1; ++i) {
embs[i] = -1;
}
Bidi bidi2 = new Bidi(str.toCharArray(), 0, embs, 1, str.length(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
for (int i = 0; i < bidi2.getRunCount(); ++i) {
System.out.println("run " + i + " from " + bidi2.getRunStart(i) + " to " + bidi2.getRunLimit(i) + " at level " + bidi2.getRunLevel(i));
}
System.out.println(bidi2 + "\n");
if (bidi.getRunCount() != 3 || bidi2.getRunCount() != 3) {
throw new Error("Bidi run count incorrect");
} else {
System.out.println("test1() passed.\n");
}
}
use of java.text.AttributedString in project chipKIT32-MAX by chipKIT32.
the class CompositionTextManager method getTextLayout.
private TextLayout getTextLayout(AttributedCharacterIterator text, int committed_count) {
AttributedString composed = new AttributedString(text, committed_count, text.getEndIndex());
Font font = textArea.getPainter().getFont();
FontRenderContext context = ((Graphics2D) (textArea.getPainter().getGraphics())).getFontRenderContext();
composed.addAttribute(TextAttribute.FONT, font);
TextLayout layout = new TextLayout(composed.getIterator(), context);
return layout;
}
Aggregations