URL url = program.getClass().getResource(program.getClass().getSimpleName() + ".fxml");
if (url == null) {
url = this.getClass().getResource(this.getClass().getSimpleName() + ".fxml");
}
Parent root = FXMLLoader.load(url, null, new ProgramBuilderFactory());
browseButton = lookupNode(root, "#fileButton", Button.class, browseActionHandler);
levelTextField = lookupNode(root, "#levelTextField", TextInputControl.class, levelTextActionHandler);
if (levelTextField != null && level != null) {
levelTextField.setText(level);
}
startButton = lookupNode(root, "#startButton", Button.class, levelTextActionHandler);
inputTextField = lookupNode(root, "#inputTextField", TextInputControl.class, inputTextActionHandler);
inputButton = lookupNode(root, "#inputButton", Button.class, inputTextActionHandler);
messageText = lookupNode(root, "#messageText", Text.class);
gridPane = lookupNode(root, "#gridPane", GameGridPane.class);
if (gridPane != null) {
gridPane.setFocusTraversable(true);
keyCombinationNodes = new HashMap<KeyCombination, Node>();
for (Node node : root.lookupAll(".keyCombinationId")) {
keyCombinationNodes.put(KeyCombination.valueOf(node.getId().replace('_', '+')), node);
}
for (Node node : root.lookupAll(".inputTextButton")) {
if (node instanceof Labeled) {
char firstChar = ((Labeled) node).getText().charAt(0);
KeyCharacterCombination kc = new KeyCharacterCombination(String.valueOf(firstChar));
keyCombinationNodes.put(kc, node);
}
}
gridPane.setOnKeyTyped(keyCombinationHandler);
gridPane.setOnKeyPressed(keyCombinationHandler);
gridPane.setOnKeyPressed(directionKeyHandler);
gridPane.setOnMouseClicked(graphicsNodeMouseHandler);
}
for (Node node : root.lookupAll(".inputTextButton")) {
setActionHandler(node, inputTextActionHandler);
}
stage.setScene(new Scene(root));
stage.show();