custom event handling

For a number of reasons, I wish to handle input events myself in a CAD-type of system, without the ordinary generated objects like MouseEvent, KeyEvent, etc.

First, the stream of object creations incurs a fair amount of overhead, particularly for mousemoves.
Second, the arbitrary division between keyboard and different kinds of mouse events only makes it harder to uniformly process events. By the time I’m done, I’ve coalesced all the relevant information anyway regardless of which kind of event it was, so it is only increasing the amount of code.

My Viewer class extends from JPanel, and overriding processEvent gets a single event. the resize when I first start up, then nothing. I know there are problems playing nicely with swing, is the solution to use Frame and Panel instead? Inside my viewer is a GLCanvas. I will try to subclass that next, but I would hope that I can make the parent intercept the child’s events in any case, because of an annoying problem – the GLCanvas isn’t getting the focus and I have to click into it, despite the fact that there is nothing else in the window.

So to sum up, I have a JFrame, inside it a JPanel, and inside that a GLCanvas. Is there any convenient way to:

  1. intercept the events BEFORE they create those AWT events in a single routine (Swing must do it somewhere).
  2. Make the GLCanvas have the focus without clicking in.

Another detail to report. I can’t just subclass GLCanvas because it’s instantiated using a factory:

canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

I was wondering why and whether there is any way to create my own subclass. If the answer to the input event trapping is elsewhere, then I don’t need this, but I’m still curious why this is the way it is.

Please upgrade to the current version of JOGL, either JSR-231 beta 2 or the current nightly build. The APIs in this area have changed considerably and GLCanvas is now directly instantiatable and subclassable.

This still doesn’t answer the basic question, how to override events. Any ideas?

You may need to subclass GLCanvas and override processEvent, which you can’t do in the old version of JOGL you’re using.

See java.awt.Component.requestFocus() for programmatically changing the focus.

You may get better answers to your focus- and event-related questions on the Swing/AWT forum on javadesktop.org:
http://forums.java.net/jive/thread.jspa?threadID=12734&tstart=0