Revision: 1793
http://svn.sourceforge.net/vexi/?rev=1793&view=rev
Author: mkpg2
Date: 2007-04-08 00:25:35 -0700 (Sun, 08 Apr 2007)
Log Message:
-----------
Feature. InputMethodListener (for languages which aren't trivial to type,
chinese, japanese ...etc.)
Modified Paths:
--------------
core/trunk/org.vexi.core/src/org/vexi/plat/AWT.java
Modified: core/trunk/org.vexi.core/src/org/vexi/plat/AWT.java
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/plat/AWT.java 2007-04-08 07:18:44 UTC
(rev 1792)
+++ core/trunk/org.vexi.core/src/org/vexi/plat/AWT.java 2007-04-08 07:25:35 UTC
(rev 1793)
@@ -31,6 +31,8 @@
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.InputEvent;
+import java.awt.event.InputMethodEvent;
+import java.awt.event.InputMethodListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
@@ -40,6 +42,8 @@
import java.awt.event.MouseWheelListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
+import java.awt.font.TextHitInfo;
+import java.awt.im.InputMethodRequests;
import java.awt.image.ColorModel;
import java.awt.image.DirectColorModel;
import java.awt.image.ImageObserver;
@@ -47,6 +51,8 @@
import java.awt.image.PixelGrabber;
import java.io.File;
import java.io.InputStream;
+import java.text.AttributedCharacterIterator;
+import java.text.AttributedCharacterIterator.Attribute;
import org.ibex.js.JS;
import org.ibex.util.InputStreamToByteArray;
@@ -319,7 +325,7 @@
protected static class AWTSurface extends Surface.DoubleBufferedSurface
- implements MouseListener, MouseMotionListener, MouseWheelListener,
KeyListener, ComponentListener, WindowListener {
+ implements MouseListener, MouseMotionListener, MouseWheelListener,
KeyListener, ComponentListener, WindowListener, InputMethodListener {
public void blit(PixelBuffer s, int sx, int sy, int dx, int dy, int
dx2, int dy2) {
discoverInsets();
@@ -375,6 +381,14 @@
refreshFromBackbuffer(r.x - leftInset, r.y - topInset,
r.width, r.height);
}
+
+ public InputMethodRequests getInputMethodRequests() {
+ // REMARK - Inexplicatbly, in the case of SKIM on kubuntu
+ // - at least - this cannot be the same object each time as it
+ // causes the scim input window to close and reopen
+ // everytime a key is typed
+ return new IMRequests();
+ }
}
class InnerWindow extends Window {
@@ -386,8 +400,30 @@
Rectangle r = gr.getClipBounds();
refreshFromBackbuffer(r.x - leftInset, r.y - topInset,
r.width, r.height);
}
+ public InputMethodRequests getInputMethodRequests() {
+ // REMARK - Inexplicatbly, in the case of SKIM on kubuntu
+ // - at least - this cannot be the same object each time as it
+ // causes the scim input window to close and reopen
+ // everytime a key is typed
+ return new IMRequests();//imRequests;
+ }
}
-
+
+ // REMARK
+ // A dummy implementation - doesn't do anything
+ // It is required for the InputMethodListening to work ...
+ //static InputMethodRequests imRequests = new IMRequests();
+
+ static class IMRequests implements InputMethodRequests{
+ public AttributedCharacterIterator
cancelLatestCommittedText(Attribute[] attributes) {return null;}
+ public AttributedCharacterIterator getCommittedText(int
beginIndex, int endIndex, Attribute[] attributes) {return null;}
+ public int getCommittedTextLength() {return 0;}
+ public int getInsertPositionOffset() {return 0;}
+ public TextHitInfo getLocationOffset(int x, int y)
{return null;}
+ public AttributedCharacterIterator
getSelectedText(Attribute[] attributes) {return null;}
+ public Rectangle getTextLocation(TextHitInfo offset)
{return null;}
+ }
+
private void discoverInsets() {
Insets i = (frame == null ? window : frame).getInsets();
if (leftInset == i.left && topInset == i.top && bottomInset ==
i.bottom && rightInset == i.right)
@@ -446,7 +482,10 @@
window.addMouseMotionListener(this);
window.addMouseWheelListener(this);
window.addWindowListener(this);
-
+ window.addInputMethodListener(this);
+ window.getInputContext().setCompositionEnabled(false);
+ //window.add
+
// IMPORTANT: this must be called before render() to ensure
// that our peer has been created
makeVisible();
@@ -464,6 +503,7 @@
window.removeComponentListener(this);
window.removeMouseMotionListener(this);
window.removeWindowListener(this);
+ window.removeInputMethodListener(this);
window.dispose();
}
@@ -590,6 +630,39 @@
// TODO Auto-generated method stub
throw new Error("FIXME: not yet implemented");
}
+ public void caretPositionChanged(InputMethodEvent event) {}
+ public void inputMethodTextChanged(InputMethodEvent event) {
+ AttributedCharacterIterator aci= event.getText();
+ if(aci==null)return;
+ char c = aci.first();
+
+ int limit = event.getCommittedCharacterCount();
+ // HACK - (skim on Kubuntu) the control that is pressed
to
+ // initiate the input when it is released no event is
ever
+ // sent as skim must be interfering with the
keylistening
+ if(limit>=1){
+ // TODO -Add a specific event type to do this
...
+ // as a single scheduled instance.
+ KeyReleased("control");
+ KeyReleased("shift");
+ }
+ for(int i=0; c!=aci.DONE && i<limit; i++){
+ //System.out.println(c);
+ String s = ""+c;
+ //System.out.println(s);
+ KeyPressed(s);
+ KeyReleased(s);
+ c = aci.next();
+ }
+
//System.out.println(window.getInputContext().getInputMethodControlObject().getClass());
+ //while(aci.)
+ /*AttributedCharacterIterator aci = event.getText();
+ for(int i=0; i<event.getCommittedCharacterCount(); i++){
+ aci.setIndex(i);
+ System.out.println(aci.next());
+ }*/
+ //System.out.println(event.paramString());
+ }
}
protected void _decodeJPEG(InputStream is, Picture p) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn