Swing Integration

I’m working on an app for handling terrain creation… mostly done in Swing, which I know very well.



My terrain editing stuff aside, I’ve gotten it so I can click a button and launch a jME ‘game’ that just has the terrain in it. The newly launched jME window has mouse/keyboard focus. I’ve gotten it so I can escape out of it without closing my app… it just closes the 3D portion.



I like the navigation in the 3D window – I want the user to be able to move around and look at the terrain from different perspectives.



However… Ultimately, I’d like the user to edit things using my Swing-based editor. In essence, I want to be able to switch back and forth between having swing-based focus and jME/LWJGL focus.



I’ve used the particle editor for guidence, but I don’t think I can go much further with that because the GUI and 3D portion are inherrantly separate: You don’t seem to mess with the 3D portion directly.



Does anybody have any suggestions on how I can alternate focus/control? I don’t expect to be able to do them at the same time, but it would be nice if the user could click a button or press a key to go back and forth (or something like that).



So… any thoughts?





–K

If you copead GUIFrame than all you have to do is cheek if getMouseInput().isCursorVisible() is false, if it is than use the mouse to update.



public void update()
{
          ...
          if(!getMouseInput().isCursorVisible())
          {
                 use the mouse to update;
          }
          ...
}



You can use the cowd from the GUIFrame in your button to switch to the JME windo and use a key to switch back.


void onButton()
{
        getMouseInput().setCursorVisible(false);
        input.setUpdateMouseActionsEnabled(true);
        input.setUpdateKeyboardActionsEnabled(true);
}

void update()
{
          ...
          if( key to tourn back is down)
          {
                getMouseInput().setCursorVisible(true);
                input.setUpdateMouseActionsEnabled(false);
                input.setUpdateKeyboardActionsEnabled(false);
         }
         ...
}         
}

Thanks for the info, Badmi.



I was hoping to not do things the same way the particle editor was doing it (Ie, use the GUI Frame), because I didn’t want to start up the jME portion of things until the user requested it… Ie: letting the Swing-based terrain editor portion be independent.



Also… I’m using the frame-rate limiting version of the ‘game’ class in an attempt to throttle the speed and keep things perky… I’ve set it to 30fps… I’m wondering if that will have an effect on how fluid the input in the Swing portion of the app is? The two portions should ideally be independent, but if we’re counting on jME to catch events in the update method, that might not be the case.



I’ll have another look at it and play with it some more the next chance I get, which might not be until this weekend.





–K

We (user Graum and I) actually wrote a tool that does exactly what you are talking about for our game. I’ll have to have a look at it and see if it can be extracted from our toolset as a demo for jme.

That’d be great, renase.



Likewise, if I get this working, I’d be happy to do something similar.





–K



//Called when the button is down
void onSwingButton()
{
        if(JME window is not open)
         {
               open jme window
         }


        JMEWINDOW.GUIFRAME.getMouseInput().setCursorVisible(false);
        JMEWINDOW.GUIFRAME.input.setUpdateMouseActionsEnabled(true);
      JMEWINDOW.GUIFRAME.input.setUpdateKeyboardActionsEnabled(true);
}



//In the JME windo that is opend in onSwingButton()
void update()
{
          ...
          if( key to tourn back is down)
          {
                GUIFRAME.getMouseInput().setCursorVisible(true);
                GUIFRAME.input.setUpdateMouseActionsEnabled(false);
                GUIFRAME.input.setUpdateKeyboardActionsEnabled(false);
         }
         ...
}         
}



I think this would do what you want. The words in caps nead to be replased by your var names. Remove mouse up in the GUIFRAME. You can probily do this without GUIFRAME but I do not have JME in front of me to look up how.