java - JtextPane with a touch interface -



java - JtextPane with a touch interface -

i'm developing touch based windows 7 app using tuio client-server setup , touch library extends multitouch 4 java. 1 of functionality i'm struggling enable text highlighting when using touch. display simple txt file using jtextpane display text, highlighting done through drag action. clicked position drag event starts , when stops , tried convert coordinates text panel's space different values ones should have, before actual text.

the code i'm using display document following:

//create jdialog container of window = new jdialog(parent); window.setundecorated(true); //create jtextpane text = new jtextpane(); text.setpage(newfile.touri().tourl()); text.seteditable(false); text.sethighlighter(null); //scrollpane used display text jscrollpane scroll = new jscrollpane(text); scroll.setpreferredsize(new dimension(500, 700)); window.getcontentpane().add(scroll, borderlayout.center); window.pack(); window.setvisible(true); window.validate();

where jdialog parent main display component used in app.

the drag handled follows:

@override public boolean processgestureevent(gestureevent ge) { if((ge instanceof dragevent) && this.component.ishighlight()) { tapcount=0; if(this.component.ishighlight()) { //do highlighting dragevent drag = (dragevent) ge; switch (drag.getid()) { case gestureevent.gesture_started: point start = drag.getfrom(); point calcstart = new point(start.x - compposition.x, start.y - compposition.y); startpos = this.textdisplay.viewtomodel(calcstart); break; case gestureevent.gesture_ended: point end = drag.getto(); point calcend = new point(end.x - compposition.x, end.y - compposition.y); endpos = this.textdisplay.viewtomodel(calcend); system.out.println("i have positions:" + startpos + "/" + endpos); system.out.println("should have " + this.textdisplay.getselectionstart() + "/" + this.textdisplay.getselectionend()); system.out.println("and text is: " + this.textdisplay.gettext().substring(startpos, endpos)); break; case gestureevent.gesture_canceled: startpos = 0; endpos = 0; break; } } homecoming true; }

in compposition jdialog's position holds text pane. i'm simulating touch mouse right text position highlighting i'm getting built-in highlighting functionality of text pane mouse.

is problem because of jdialog , jscroll pane somehow skews conversion? coordinate scheme point's touch origin in top left corner of screen , text pane's coordinate scheme origin in same top lef corner.

any ideas on how can solve problem? suggestions appreciated.

le: doing wrong in adding gesture processor when initialized component , it's position (0,0) , afterwards moved wanted to.

i changed position calculations follows:

point calcstart = new point(start.x - this.component.getlocation().x, start.y -this.component.getlocation().y);

passing instead reference actual component , getting location when needed.

try instead of

point calcstart = new point(start.x - compposition.x, start.y - compposition.y);

to use

point calcstart = new point(start.x, start.y);

i wonder how gonna end, give value of get

java touch highlighting mt4j

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -