- Current key bindings are shown on buttons - Added button action events to store the clicked button - Added key press event to entire pane - Button text is updated to display its key - Added functionality to keyFactory to update key bindings - CSS styling for some components #story[1197]main
parent
7086af6057
commit
ad0e26e882
@ -0,0 +1,116 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import visualiser.gameController.Keys.ControlKey;
|
||||
import visualiser.gameController.Keys.KeyFactory;
|
||||
import java.util.Map;
|
||||
|
||||
public class KeyBindingsController {
|
||||
@FXML Button btnSave;
|
||||
@FXML Button btnCancel;
|
||||
@FXML Button btnReset;
|
||||
@FXML ListView lstControl;
|
||||
@FXML ListView lstKey;
|
||||
@FXML ListView lstDescription;
|
||||
@FXML Label lblTitle;
|
||||
String currentButton = null;
|
||||
KeyFactory keyFactory = KeyFactory.getFactory();
|
||||
|
||||
public void initialize(){
|
||||
|
||||
lstKey.getItems().add("Key");
|
||||
lstControl.getItems().add("Command");
|
||||
lstDescription.getItems().add("Description");
|
||||
|
||||
|
||||
|
||||
for (Map.Entry<String, ControlKey> entry : keyFactory.getKeyState().entrySet()) {
|
||||
Button button = new Button(entry.getKey());
|
||||
button.setMinWidth(120);
|
||||
button.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override public void handle(ActionEvent e) {
|
||||
currentButton = button.getText();
|
||||
System.out.println("Button clicked");
|
||||
}
|
||||
});
|
||||
lstKey.getItems().add(button);
|
||||
lstControl.getItems().add(entry.getValue());
|
||||
lstDescription.getItems().add(entry.getValue().getProtocolCode());
|
||||
}
|
||||
|
||||
lstKey.getSelectionModel().select(0);
|
||||
lstControl.getSelectionModel().select(0);
|
||||
lstDescription.getSelectionModel().select(0);
|
||||
|
||||
lstKey.getSelectionModel().selectedItemProperty()
|
||||
.addListener((observable, oldvalue, newValue) -> {
|
||||
Platform.runLater(new Runnable() {
|
||||
public void run() {
|
||||
lstKey.getSelectionModel().select(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
lstDescription.getSelectionModel().selectedItemProperty()
|
||||
.addListener((observable, oldvalue, newValue) -> {
|
||||
Platform.runLater(new Runnable() {
|
||||
public void run() {
|
||||
lstDescription.getSelectionModel().select(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
lstControl.getSelectionModel().selectedItemProperty()
|
||||
.addListener((observable, oldvalue, newValue) -> {
|
||||
Platform.runLater(new Runnable() {
|
||||
public void run() {
|
||||
lstControl.getSelectionModel().select(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
lstKey.sceneProperty().addListener((obs, oldScene, newScene) -> {
|
||||
if (newScene != null) {
|
||||
newScene.getStylesheets().add("/css/keyBindings.css");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void cancel(){
|
||||
System.out.println("cancel clicked");
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
System.out.println("reset clicked");
|
||||
}
|
||||
|
||||
public void save(){
|
||||
System.out.println("save clicked");
|
||||
}
|
||||
|
||||
public void onKey(KeyEvent e){
|
||||
System.out.println("key pressed");
|
||||
// if a button was clicked
|
||||
if (currentButton!=null){
|
||||
// update text on the button
|
||||
ObservableList buttons = lstKey.getItems();
|
||||
for (int i = 1; i < buttons.size(); i++) {
|
||||
if (currentButton == ((Button)buttons.get(i)).getText()) {
|
||||
((Button)buttons.get(i)).setText(e.getCode().toString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
// update the control key
|
||||
keyFactory.updateKey(currentButton, e.getCode().toString());
|
||||
// remove current button selection
|
||||
currentButton = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
.list-view .list-cell {
|
||||
-fx-cell-size: 40;
|
||||
-fx-font-family: "Tahoma";
|
||||
-fx-background-color: #fffff0;
|
||||
-fx-alignment: center;
|
||||
}
|
||||
|
||||
.list-view .list-cell:even {
|
||||
-fx-background-color: #ffffdc;
|
||||
}
|
||||
|
||||
.list-view .list-cell:selected {
|
||||
-fx-background-color: #f9e5c3;
|
||||
-fx-font-family: "Comic Sans MS";
|
||||
-fx-font-weight: bold;
|
||||
-fx-font-size: 18;
|
||||
}
|
||||
|
||||
.button {
|
||||
-fx-background-color: linear-gradient(#acdeff 50%, #a9c8ff 100%);
|
||||
-fx-background-radius: 4px;
|
||||
-fx-border-radius: 4px;
|
||||
-fx-text-fill: #242d35;
|
||||
-fx-font-size: 12px;
|
||||
-fx-font-family: "Courier New";
|
||||
}
|
||||
|
||||
.button:focused {
|
||||
-fx-background-color: white;
|
||||
-fx-border-color: #0056bd;
|
||||
}
|
||||
|
||||
#anchor {
|
||||
-fx-background-color: #fdfac3;
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<AnchorPane id="anchor" maxHeight="-Infinity" maxWidth="-Infinity"
|
||||
minHeight="-Infinity"
|
||||
minWidth="-Infinity" onKeyPressed="#onKey" prefHeight="471.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.KeyBindingsController">
|
||||
<children>
|
||||
<Label fx:id="lblTitle" layoutX="172.0" layoutY="14.0" text="Key Bindings">
|
||||
<font>
|
||||
<Font name="Comic Sans MS" size="44.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Button fx:id="btnCancel" layoutX="430.0" layoutY="428.0" mnemonicParsing="false" onAction="#cancel" prefWidth="160.0" text="Cancel" AnchorPane.bottomAnchor="18.0" AnchorPane.rightAnchor="20.0" />
|
||||
<ListView fx:id="lstControl" focusTraversable="false" layoutX="27.0" layoutY="88.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="322.0" prefWidth="150.0" />
|
||||
<ListView fx:id="lstKey" focusTraversable="false" layoutX="176.0" layoutY="88.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="322.0" prefWidth="150.0" />
|
||||
<ListView fx:id="lstDescription" focusTraversable="false" layoutX="325.0" layoutY="88.0" prefHeight="322.0" prefWidth="250.0" />
|
||||
<Button fx:id="btnSave" layoutX="220.0" layoutY="428.0" mnemonicParsing="false" onAction="#save" prefWidth="160.0" text="Save" AnchorPane.bottomAnchor="18.0" />
|
||||
<Button fx:id="btnReset" layoutX="20.0" layoutY="428.0" mnemonicParsing="false" onAction="#reset" prefWidth="160.0" text="Reset to Default" AnchorPane.bottomAnchor="18.0" AnchorPane.leftAnchor="20.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
Loading…
Reference in new issue