Hi there !
HybridJme
is a project aiming to provide jme-awt-swing-jfx
gui bindings, through the javafx.embed.swing.JFXPanel
& the NullLayout
or the absolute positioning of awt.Component
on other Container, So now jfxParentNodes can be inflated easily either from code or fxml
files, (you can use SceneBuilder freely for GUI) :
Controller
class of jfx can be used also without Platform.runLater()
if you are outside of jme-context.
Example 1, shows 3 UiStates at different positions in immersive mode & 1-pop-up UiScene:
Example 2, shows 3 UiStates & 1 inflated UiState from fxml (made with SceneBuilder) :
In code, i have made sure that the panels get managed by UiStateManager
class which is very similar to its relative on android, so coding stack is similar :
package test;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetKey;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.debug.WireSphere;
import core.uiStates.JfxUiState;
import core.uiStates.UiStateManager;
import core.window.HybridWindow;
import javafx.embed.swing.JFXPanel;
import java.io.IOException;
import java.nio.file.FileSystems;
/**
* Test Jme-Canvas inside a Hybrid Window. (WIP)
* @author pavl_g
*/
public class TestHybridWindow extends SimpleApplication {
@Override
public void simpleInitApp() {
flyCam.setDragToRotate(true);
WireSphere wireSphere=new WireSphere(50);
Geometry geometry = new Geometry("wireSphere", wireSphere);
geometry.setLocalScale(0.05f);
Material material = new Material(assetManager.loadAsset(new AssetKey<>("Common/MatDefs/Misc/Unshaded.j3md")));
material.setColor("Color", ColorRGBA.randomColor().mult(2f));
geometry.setMaterial(material);
rootNode.attachChild(geometry);
}
public static void main(String[] args) throws IOException {
HybridWindow hybridWindow = new HybridWindow(new TestHybridWindow());
UiStateManager uiStateManager = new UiStateManager(hybridWindow);
/*test immersive mode on the primary screen*/
hybridWindow.setImmersiveMode(0);
/*test attach UiStates*/
JFXPanel jfxUiState1 = uiStateManager.attachUiState(new TestCase().attachJfxTest(), 222);
JFXPanel jfxUiState2 = uiStateManager.attachUiState(new TestCase().attachJfxTest(), 223);
JFXPanel jfxUiState3 = uiStateManager.attachUiState(new TestCase().attachJfxTest(), 224);
/*test jfxUiStates, inflation from XML*/
JfxUiState jfxStateTest = new JfxUiState(uiStateManager.fromXML(FileSystems.getDefault().getPath("src/main/java/test/Options.fxml").toUri().toURL()) , 0,0,800,800);
uiStateManager.attachUiState(jfxStateTest, 225);
/*test change size on JFXPanels*/
jfxUiState1.setSize(200,200);
jfxUiState2.setSize(200,200);
jfxUiState3.setSize(200,500);
/*test initialize the hybrid window*/
hybridWindow.init(800,800, uiStateManager);
/*test setBounds, location, sizes*/
/*test immersion on upper-left corner*/
jfxUiState1.setBounds(uiStateManager.getWidth()-jfxUiState1.getWidth(),0,200,200);
/*full immersion on screen-end, lower-left corner*/
jfxUiState2.setBounds(uiStateManager.getWidth()-jfxUiState2.getWidth(),
uiStateManager.getHeight()-jfxUiState2.getHeight(),200,200);
/*test middle positioning*/
jfxUiState3.setBounds(uiStateManager.getWidth()/2 - jfxUiState3.getWidth()/2
,uiStateManager.getHeight()/2 - jfxUiState3.getHeight()/2,jfxUiState3.getWidth(),jfxUiState3.getHeight());
}
}
Current Features :
- Inflation of
AWT-Swing-Jfx
Ui is available. - Listeners & focus are working fine in both the GUI & Jme.
- No problems from threads incompatibility so far.
- Layout Inflating from XML for jfx is available.
- default null layout is guarded against Ui & window update.
- Swing LayoutManager is also accessible.
- Immersive mode is available for all screens connected to the laptop.
Current Limitations :
- No support for Lwjgl-3.
- Prolonged loading time if you are attaching too much UiStates at the start-up.
- Testing within jme3 update() & BaseAppState, Stills WIP.