|
|
|
|
@ -3,9 +3,6 @@ package visualiser.Controllers;
|
|
|
|
|
import javafx.application.Platform;
|
|
|
|
|
import javafx.event.EventHandler;
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
|
import javafx.fxml.FXMLLoader;
|
|
|
|
|
import javafx.scene.Parent;
|
|
|
|
|
import javafx.scene.Scene;
|
|
|
|
|
import javafx.scene.control.Button;
|
|
|
|
|
import javafx.scene.control.ListView;
|
|
|
|
|
import javafx.scene.input.KeyCode;
|
|
|
|
|
@ -21,12 +18,10 @@ import java.io.IOException;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import static visualiser.app.App.keyFactory;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Controller for the scene used to display and update current key bindings.
|
|
|
|
|
*/
|
|
|
|
|
public class KeyBindingsController extends Controller2 {
|
|
|
|
|
public class KeyBindingsController extends Controller {
|
|
|
|
|
private @FXML Button btnSave;
|
|
|
|
|
private @FXML Button btnCancel;
|
|
|
|
|
private @FXML Button btnReset;
|
|
|
|
|
@ -34,12 +29,15 @@ public class KeyBindingsController extends Controller2 {
|
|
|
|
|
private @FXML ListView lstKey;
|
|
|
|
|
private @FXML ListView lstDescription;
|
|
|
|
|
private @FXML AnchorPane anchor;
|
|
|
|
|
private KeyFactory existingKeyFactory;
|
|
|
|
|
private KeyFactory newKeyFactory;
|
|
|
|
|
private Boolean changed = false; // keyBindings have been modified
|
|
|
|
|
private Button currentButton = null; // last button clicked
|
|
|
|
|
|
|
|
|
|
public void initialize(){
|
|
|
|
|
// create new key factory to modify, keeping the existing one safe
|
|
|
|
|
existingKeyFactory = new KeyFactory();
|
|
|
|
|
existingKeyFactory.load();
|
|
|
|
|
newKeyFactory = copyExistingFactory();
|
|
|
|
|
initializeTable();
|
|
|
|
|
populateTable();
|
|
|
|
|
@ -106,7 +104,7 @@ public class KeyBindingsController extends Controller2 {
|
|
|
|
|
*/
|
|
|
|
|
public KeyFactory copyExistingFactory(){
|
|
|
|
|
newKeyFactory = new KeyFactory();
|
|
|
|
|
Map<String, ControlKey> oldKeyState = keyFactory.getKeyState();
|
|
|
|
|
Map<String, ControlKey> oldKeyState = existingKeyFactory.getKeyState();
|
|
|
|
|
Map<String, ControlKey> newKeyState = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
// copy over commands and their keys
|
|
|
|
|
@ -204,10 +202,10 @@ public class KeyBindingsController extends Controller2 {
|
|
|
|
|
*/
|
|
|
|
|
public void save(){
|
|
|
|
|
if (isFactoryValid()) {
|
|
|
|
|
keyFactory = newKeyFactory;
|
|
|
|
|
existingKeyFactory = newKeyFactory;
|
|
|
|
|
newKeyFactory = new KeyFactory();
|
|
|
|
|
changed = false;
|
|
|
|
|
keyFactory.save(); // save persistently
|
|
|
|
|
existingKeyFactory.save(); // save persistently
|
|
|
|
|
loadNotification("Key bindings were successfully saved.", false);
|
|
|
|
|
} else {
|
|
|
|
|
loadNotification("One or more key bindings are missing. " +
|
|
|
|
|
@ -251,22 +249,14 @@ public class KeyBindingsController extends Controller2 {
|
|
|
|
|
* @param warning true if the message to be displayed is due to user error
|
|
|
|
|
*/
|
|
|
|
|
public void loadNotification(String message, Boolean warning){
|
|
|
|
|
Parent root = null;
|
|
|
|
|
FXMLLoader loader = new FXMLLoader(getClass().getResource
|
|
|
|
|
("/visualiser/scenes/notification.fxml"));
|
|
|
|
|
try {
|
|
|
|
|
root = loader.load();
|
|
|
|
|
NotificationController nc = (NotificationController)
|
|
|
|
|
loadPopupScene("notification.fxml",
|
|
|
|
|
"", Modality.APPLICATION_MODAL);
|
|
|
|
|
nc.setMessage(message, warning);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
NotificationController controller = loader.getController();
|
|
|
|
|
Stage stage = new Stage();
|
|
|
|
|
stage.setScene(new Scene(root));
|
|
|
|
|
stage.centerOnScreen();
|
|
|
|
|
stage.initModality(Modality.APPLICATION_MODAL);
|
|
|
|
|
stage.show();
|
|
|
|
|
// displays given message in the window
|
|
|
|
|
controller.setMessage(message, warning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|