Skip to main content



      Home
Home » Eclipse Projects » GEF » ScrollableGraphicalViewer and key accelerations
ScrollableGraphicalViewer and key accelerations [message #87523] Wed, 16 July 2003 07:21 Go to next message
Eclipse UserFriend
Hello all!

I want to enable the arrow and page-up/down keys for my editor. This
appears to not be done by default for ScrollableGraphicalViewer. I do
not seem to be able to do so by adding key event listeners either. Has
someone done this successfully?

Here is what I tried:
protected void configureGraphicalViewer()
{
super.configureGraphicalViewer();
GraphicalViewer viewer = getGraphicalViewer();
viewer.setRootEditPart(new FreeformGraphicalRootEditPart());
viewer.setEditPartFactory(new CvsGraphEditPartFactory());

viewer.getControl().addKeyListener(
new KeyAdapter()
{
public void keyPressed(KeyEvent event)
{
if (event.character == SWT.PAGE_DOWN &&
event.stateMask == 0)
{
_logger.debug("Page Down pressed!");
}
else if (event.character == SWT.PAGE_UP &&
event.stateMask == 0)
{
_logger.debug("Page Up pressed!");
}
}
}
);
}

I get nothing in the log (yes, debug is enabled).

Thanx

jeff

--
Jeffrey Bonevich
Ann Arbor, Michigan
bonevich at covad dot net
jeff at bonevich dot com
http://www.bonevich.com

"Make me a fire and I'm warm for a night. Set me
on fire and I'm warm for the rest of my life."
- Ancient Didactical Saying
Re: ScrollableGraphicalViewer and key accelerations [message #87568 is a reply to message #87523] Wed, 16 July 2003 08:58 Go to previous messageGo to next message
Eclipse UserFriend
The logic example uses a GraphicalViewerKeyHandler (see
LogicEditor.configureGraphicalViewer()). This key handler uses the arrow keys
to navigate to the different edit parts in the viewer. The key handler also
checks for the Home, End, PgUp and PgDn key events, but then calls a method that
does nothing. I have opened a bug for this.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=40208



Jeffrey Bonevich wrote:

> Hello all!
>
> I want to enable the arrow and page-up/down keys for my editor. This
> appears to not be done by default for ScrollableGraphicalViewer. I do
> not seem to be able to do so by adding key event listeners either. Has
> someone done this successfully?
>
> Here is what I tried:
> protected void configureGraphicalViewer()
> {
> super.configureGraphicalViewer();
> GraphicalViewer viewer = getGraphicalViewer();
> viewer.setRootEditPart(new FreeformGraphicalRootEditPart());
> viewer.setEditPartFactory(new CvsGraphEditPartFactory());
>
> viewer.getControl().addKeyListener(
> new KeyAdapter()
> {
> public void keyPressed(KeyEvent event)
> {
> if (event.character == SWT.PAGE_DOWN &&
> event.stateMask == 0)
> {
> _logger.debug("Page Down pressed!");
> }
> else if (event.character == SWT.PAGE_UP &&
> event.stateMask == 0)
> {
> _logger.debug("Page Up pressed!");
> }
> }
> }
> );
> }
>
> I get nothing in the log (yes, debug is enabled).
>
> Thanx
>
> jeff
>
Re: ScrollableGraphicalViewer and key accelerations [message #87598 is a reply to message #87523] Wed, 16 July 2003 10:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

It sounds like there is an Action or MenuItem which has registered these
keystrokes as accelerators. Are you using a Multipage Editor? Do you have
a TextViewer somewhere at the same time?

"Jeffrey Bonevich" <jeff@bonevich.com> wrote in message
news:bf3cof$vcq$1@eclipse.org...
> Hello all!
>
> I want to enable the arrow and page-up/down keys for my editor. This
> appears to not be done by default for ScrollableGraphicalViewer. I do
> not seem to be able to do so by adding key event listeners either. Has
> someone done this successfully?
>
> Here is what I tried:
> protected void configureGraphicalViewer()
> {
> super.configureGraphicalViewer();
> GraphicalViewer viewer = getGraphicalViewer();
> viewer.setRootEditPart(new FreeformGraphicalRootEditPart());
> viewer.setEditPartFactory(new CvsGraphEditPartFactory());
>
> viewer.getControl().addKeyListener(
> new KeyAdapter()
> {
> public void keyPressed(KeyEvent event)
> {
> if (event.character == SWT.PAGE_DOWN &&
> event.stateMask == 0)
> {
> _logger.debug("Page Down pressed!");
> }
> else if (event.character == SWT.PAGE_UP &&
> event.stateMask == 0)
> {
> _logger.debug("Page Up pressed!");
> }
> }
> }
> );
> }
>
> I get nothing in the log (yes, debug is enabled).
>
> Thanx
>
> jeff
>
> --
> Jeffrey Bonevich
> Ann Arbor, Michigan
> bonevich at covad dot net
> jeff at bonevich dot com
> http://www.bonevich.com
>
> "Make me a fire and I'm warm for a night. Set me
> on fire and I'm warm for the rest of my life."
> - Ancient Didactical Saying
>
Re: ScrollableGraphicalViewer and key accelerations [message #87683 is a reply to message #87598] Wed, 16 July 2003 18:32 Go to previous messageGo to next message
Eclipse UserFriend
Nope to both questions. I did try the GraphicalViewerKeyHandler that
Eric suggested and got similar results to what he mentioned.

jeff

Randy Hudson wrote:
> It sounds like there is an Action or MenuItem which has registered these
> keystrokes as accelerators. Are you using a Multipage Editor? Do you have
> a TextViewer somewhere at the same time?
>
> "Jeffrey Bonevich" <jeff@bonevich.com> wrote in message
> news:bf3cof$vcq$1@eclipse.org...
>
>>Hello all!
>>
>>I want to enable the arrow and page-up/down keys for my editor. This
>>appears to not be done by default for ScrollableGraphicalViewer. I do
>>not seem to be able to do so by adding key event listeners either. Has
>>someone done this successfully?
>>
>>Here is what I tried:
>> protected void configureGraphicalViewer()
>> {
>>super.configureGraphicalViewer();
>>GraphicalViewer viewer = getGraphicalViewer();
>>viewer.setRootEditPart(new FreeformGraphicalRootEditPart());
>>viewer.setEditPartFactory(new CvsGraphEditPartFactory());
>>
>>viewer.getControl().addKeyListener(
>> new KeyAdapter()
>> {
>>public void keyPressed(KeyEvent event)
>>{
>> if (event.character == SWT.PAGE_DOWN &&
>>event.stateMask == 0)
>> {
>>_logger.debug("Page Down pressed!");
>> }
>> else if (event.character == SWT.PAGE_UP &&
>> event.stateMask == 0)
>> {
>>_logger.debug("Page Up pressed!");
>> }
>>}
>> }
>>);
>> }
>>
>>I get nothing in the log (yes, debug is enabled).
>>
>>Thanx
>>
>>jeff
>>
>>--
>>Jeffrey Bonevich
>>Ann Arbor, Michigan
>>bonevich at covad dot net
>>jeff at bonevich dot com
>>http://www.bonevich.com
>>
>>"Make me a fire and I'm warm for a night. Set me
>>on fire and I'm warm for the rest of my life."
>>- Ancient Didactical Saying
>>
>
>
>

--
Jeffrey Bonevich
Ann Arbor, Michigan
bonevich at covad dot net
jeff at bonevich dot com
http://www.bonevich.com

"Make me a fire and I'm warm for a night. Set me
on fire and I'm warm for the rest of my life."
- Ancient Didactical Saying
Re: ScrollableGraphicalViewer and key accelerations [message #87714 is a reply to message #87568] Wed, 16 July 2003 21:45 Go to previous message
Eclipse UserFriend
Success! I took a look at what LogicEditor was doing, and also
inspected source for GraphicalViewerKeyHandler, and I have resolved the
problem at least to my satisfaction for now. Inside my editor, I
declare the following inner class to use as a key handler:

class CvsGraphViewerKeyHandler extends GraphicalViewerKeyHandler
{
public CvsGraphViewerKeyHandler(GraphicalViewer viewer)
{
super(viewer);
}

public boolean keyPressed(KeyEvent event)
{
if (event.keyCode == SWT.PAGE_DOWN ||
event.keyCode == SWT.PAGE_UP ||
event.keyCode == SWT.HOME ||
event.keyCode == SWT.END )
{
ScrollingGraphicalViewer viewer = (ScrollingGraphicalViewer)
getGraphicalViewer();
FigureCanvas canvas = (FigureCanvas) viewer.getControl();

int x = canvas.getViewport().getViewLocation().x;
int y = canvas.getViewport().getViewLocation().y;
int dx = 0;
int dy = 0;

Dimension viewingArea =
canvas.getViewport().getClientArea().getSize();
Rectangle totalArea = canvas.getBounds();

switch (event.keyCode)
{
case SWT.PAGE_DOWN : dx = x; dy = y + viewingArea.height; break;
case SWT.PAGE_UP : dx = x; dy = y - viewingArea.height; break;
case SWT.HOME : dx = 0; dy = y; break;
case SWT.END : dx = totalArea.width; dy = y; break;
default: dx = x; dy = y; break;
}

canvas.scrollSmoothTo(dx, dy);
return true;
}
return super.keyPressed(event);
}
}

This does the trick! Helps that I changed "event.character ==
SWT.PAGE_DOWN" to "event.keyCode == SWT.PAGE_DOWN". I think that was
the main source of my problem. Then I just added the appropriate
scrolling behavior for the arrows, page up/down, home/end. Voila!

Thanx again!

jeff


Eric Bordeau wrote:
> The logic example uses a GraphicalViewerKeyHandler (see
> LogicEditor.configureGraphicalViewer()). This key handler uses the
> arrow keys to navigate to the different edit parts in the viewer. The
> key handler also checks for the Home, End, PgUp and PgDn key events, but
> then calls a method that does nothing. I have opened a bug for this.
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=40208
>
>
>
> Jeffrey Bonevich wrote:
>
>> Hello all!
>>
>> I want to enable the arrow and page-up/down keys for my editor. This
>> appears to not be done by default for ScrollableGraphicalViewer. I do
>> not seem to be able to do so by adding key event listeners either.
>> Has someone done this successfully?
>>
>> Here is what I tried:
>> protected void configureGraphicalViewer()
>> {
>> super.configureGraphicalViewer();
>> GraphicalViewer viewer = getGraphicalViewer();
>> viewer.setRootEditPart(new FreeformGraphicalRootEditPart());
>> viewer.setEditPartFactory(new CvsGraphEditPartFactory());
>>
>> viewer.getControl().addKeyListener(
>> new KeyAdapter()
>> {
>> public void keyPressed(KeyEvent event)
>> {
>> if (event.character == SWT.PAGE_DOWN &&
>> event.stateMask == 0)
>> {
>> _logger.debug("Page Down pressed!");
>> }
>> else if (event.character == SWT.PAGE_UP &&
>> event.stateMask == 0)
>> {
>> _logger.debug("Page Up pressed!");
>> }
>> }
>> }
>> );
>> }
>>
>> I get nothing in the log (yes, debug is enabled).
>>
>> Thanx
>>
>> jeff
>>
>

--
Jeffrey Bonevich
Ann Arbor, Michigan
bonevich at covad dot net
jeff at bonevich dot com
http://www.bonevich.com

"Make me a fire and I'm warm for a night. Set me
on fire and I'm warm for the rest of my life."
- Ancient Didactical Saying
Previous Topic:Creating connections
Next Topic:How to remove scrollbars from FigureCanvas?
Goto Forum:
  


Current Time: Thu May 01 03:24:06 EDT 2025

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

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

Back to the top