Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » CTRL+C, CTRL+V, CTRL+X in JFace dialogs
CTRL+C, CTRL+V, CTRL+X in JFace dialogs [message #447893] Tue, 21 December 2004 14:15
Stefan Junsved is currently offline Stefan JunsvedFriend
Messages: 56
Registered: July 2009
Member
This is a multi-part message in MIME format.

------=_NextPart_000_00FA_01C4E76F.E2DBD3A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

I have read almost every mail about how to work with key events but I =
still cannot get the hang of it.
I use A LOT of JFace dialogs with tree viewers over a GEF editor, and =
I'm desperatly trying to make
ctrl+c, ctrl+v, and ctrl+x to work.

I have done the following:
1. In the dialog constructor I have invoked:
parentShell.getDisplay().addFilter(SWT.KeyDown, new Listener() =
{
public void handleEvent(Event event) {
if( (event.keyCode =3D=3D 'c') && (event.stateMask =
=3D=3D SWT.CTRL) ) {
=
System.out.println("YES!!!!!=3D"+event.keyCode+"\nSTATE =
MASK=3D"+event.stateMask);
}
}});
This doesn't work as planned because when pressing the CTRL key, =
and still keeping it pressed down, the
CTRL event is caught, but the following 'C', 'V', or 'X' event =
is not.

2. I have added a KeyListener to the tree viewer in the dialog:
treeViewer.getControl().addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if( (event.keyCode =3D=3D 'c') && (event.stateMask =
=3D=3D SWT.CTRL) ) {
=
System.out.println("YES!!!!!=3D"+event.keyCode+"\nSTATE =
MASK=3D"+event.stateMask);
}
System.out.println("KEY=3D"+event.keyCode+"\nSTATE =
MASK=3D"+event.stateMask);
}
public void keyReleased(KeyEvent event) {
//System.out.println("KEY=3D"+event.keyCode+"\nSTATE =
MASK=3D"+event.stateMask);
}});
The result is exactly the same as in the earlier example.

Of course I=B4m missing something very central here and I would very =
much appreciate some help on this issue.
------=_NextPart_000_00FA_01C4E76F.E2DBD3A0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2523" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have read almost every mail about how =
to work=20
with key events but I still cannot get the hang of it.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I use A LOT of JFace dialogs with tree =
viewers over=20
a GEF editor, and I'm desperatly trying to make</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>ctrl+c, ctrl+v, and ctrl+x to =
work.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have done the following:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>1.&nbsp;&nbsp;&nbsp; In the dialog =
constructor I=20
have invoked:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;parentShell.getDisplay().addFilter(SWT.KeyDown, new Listener()=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
public void handleEvent(Event event)=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; if( (event.keyCode =3D=3D 'c') &amp;&amp; =
(event.stateMask =3D=3D=20
SWT.CTRL) )=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; =
System.out.println("YES!!!!!=3D"+event.keyCode+"\nSTATE=20
MASK=3D"+event.stateMask);<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
}<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
}});</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;This=20
doesn't work as planned because when pressing the CTRL key, and still =
keeping it=20
pressed down, the</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
CTRL event is=20
caught, but the following 'C', 'V', or 'X' event is not.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>2.&nbsp;&nbsp;&nbsp; I have added a =
KeyListener to=20
the tree viewer in the dialog:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;treeViewer.getControl().addKeyListener(n ew KeyListener()=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
public=20
void keyPressed(KeyEvent event)=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
if( (event.keyCode =3D=3D 'c') &amp;&amp; (event.stateMask =3D=3D =
SWT.CTRL) )=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;=20
System.out.println("YES!!!!!=3D"+event.keyCode+"\nSTATE=20
MASK=3D"+event.stateMask);<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;=20
}<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
System.out.println("KEY=3D"+event.keyCode+"\nSTATE=20
MASK=3D"+event.stateMask);<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
}<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
public=20
void keyReleased(KeyEvent event)=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
//System.out.println("KEY=3D"+event.keyCode+"\nSTATE=20
MASK=3D"+event.stateMask);<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
}});<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; The result is exactly the =
same as=20
in the earlier example.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Of course I=B4m missing something very =
central here=20
and I would very much appreciate some help on this=20
issue.</FONT></DIV></BODY></HTML>

------=_NextPart_000_00FA_01C4E76F.E2DBD3A0--
Previous Topic:Changing Mouse Cursor
Next Topic:embed a composite control in a table or list?
Goto Forum:
  


Current Time: Sat Oct 31 16:05:47 GMT 2020

Powered by FUDForum. Page generated in 0.01318 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top