Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3507 Members - Latest Member: PienueDut

26. May 2012, 12:20:49 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Passing mouse events to the HUD system with a Swing Panel
Pages: [1]
Print
Author Topic: Passing mouse events to the HUD system with a Swing Panel  (Read 853 times)
ford.304
Enjoying the stay
*
Offline Offline

Posts: 30


View Profile Email
« on: 19. August 2009, 04:36:32 pm »

So, the application situation is:

A complex Swing application with Xith3D running in an embedded JPanel. Currently the mouse input and control in the JPanel is handled by a Swing MouseAdapter because when I switched to Swing instead of AWT, the xith input system stopped receiving events.

I would like to add xith HUD objects to the view as well, for zoom and rotate buttons similar to google earth. However, since I am not using the xith input system, I'm unsure how to pass mouse events into the HUD to interact with those elements. In my quick survey of the HUD class, all of the mouse handling callbacks are private methods.

Is there something extra setup needed to use the xith input system with a Swing panel? I tested it in one of the xith-tk tests, and with exactly the same setup code it works properly with the AWT panel and fails with the swing.

From a slightly modified HUDConsoleTest2.java:
Code:
    public HUDConsoleTest2( BasicApplicationArguments arguments ) throws Throwable
    {
        super( arguments.getMaxFPS() );
       
        Xith3DEnvironment env = new Xith3DEnvironment( this );
       
        ResourceLocator resLoc = TestUtils.createResourceLocator();
       
        resLoc.createAndAddTSL( "textures" );
       
        createHUD( env, arguments.getResolution() );
       
        Canvas3DJPanel canvas = new Canvas3DJPanel(new CanvasConstructionInfo( OpenGLLayer.JOGL_AWT, DisplayMode.WINDOWED, true, FSAA.ON_2X, "3D View" ));
        env.addCanvas( canvas );
       
        canvas.getCanvas().addWindowClosingListener( new WindowClosingRenderLoopEnder( this ) );
        this.addFPSListener( new CanvasFPSListener( canvas.getCanvas() ) );
       
        InputSystem.getInstance().registerNewKeyboardAndMouse( canvas.getCanvas().getPeer() );
//        Frame window = new();
        JFrame window = new JFrame();
        window.setSize(800, 600);
        window.add(canvas);
        window.setVisible(true);
    }

That code will set up the input system and work fine, allowing you to drag the HUD around. Changing the OpenGLLayer to OpenGLLayer.JOGL_SWING will still show the HUD, but all input is now ignored.

Any suggestions on where to start? I need a way to either call the HUD mouse handlers from the Swing inputhandler, or to connect the xith inputhandlers so they work when used in a swing environment.

Thanks,
-Mike Ford
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 19. August 2009, 09:09:57 pm »

I don't know why. But the Canvas3DJPanel needs a call to requestFocus(). Then it will work.

Marvin
Logged
ford.304
Enjoying the stay
*
Offline Offline

Posts: 30


View Profile Email
« Reply #2 on: 20. August 2009, 03:42:47 pm »

Thanks!
Logged
asbms
Just dropped in

Offline Offline

Posts: 1


View Profile
« Reply #3 on: 21. March 2011, 03:44:01 pm »

I don't know why. But the Canvas3DJPanel needs a call to requestFocus(). Then it will work.


I know this might sound like a silly questions, but I'm having the same problem and I need to know WHERE you suggest having the Canvas3DJPanel call requestFocus().  I tried just after initialization, but then the focus was immediately lost.

Thanks.

Ben



Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #4 on: 21. March 2011, 08:32:18 pm »

Hmm... I don't remember. Try to do it on a mouse clicked event. I'm pretty shure, that wasn't my situation. But that should work at loast.
Logged
jaytourist
Just dropped in

Offline Offline

Posts: 1


View Profile
« Reply #5 on: 09. April 2011, 03:16:12 am »

ford, thank's for the tip. let me try to do that one. keep up the good work dude. thumbs-up! Smiley
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic