|
|
|
@ -1,7 +1,6 @@
|
|
|
|
package visualiser.Controllers;
|
|
|
|
package visualiser.Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
import javafx.application.Platform;
|
|
|
|
import javafx.application.Platform;
|
|
|
|
import javafx.event.EventHandler;
|
|
|
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.scene.control.Button;
|
|
|
|
import javafx.scene.control.Button;
|
|
|
|
import javafx.scene.control.ListView;
|
|
|
|
import javafx.scene.control.ListView;
|
|
|
|
@ -49,7 +48,7 @@ public class KeyBindingsController extends Controller {
|
|
|
|
* Sets up table before populating it.
|
|
|
|
* Sets up table before populating it.
|
|
|
|
* Set up includes headings, CSS styling and modifying default properties.
|
|
|
|
* Set up includes headings, CSS styling and modifying default properties.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void initializeTable(){
|
|
|
|
private void initializeTable(){
|
|
|
|
// set the headings for each column
|
|
|
|
// set the headings for each column
|
|
|
|
lstKey.getItems().add("Key");
|
|
|
|
lstKey.getItems().add("Key");
|
|
|
|
lstControl.getItems().add("Command");
|
|
|
|
lstControl.getItems().add("Command");
|
|
|
|
@ -67,15 +66,15 @@ public class KeyBindingsController extends Controller {
|
|
|
|
|
|
|
|
|
|
|
|
// stop the columns from being selectable, so only the buttons are
|
|
|
|
// stop the columns from being selectable, so only the buttons are
|
|
|
|
lstKey.getSelectionModel().selectedItemProperty()
|
|
|
|
lstKey.getSelectionModel().selectedItemProperty()
|
|
|
|
.addListener((observable, oldvalue, newValue) ->
|
|
|
|
.addListener((observable, oldValue, newValue) ->
|
|
|
|
Platform.runLater(() ->
|
|
|
|
Platform.runLater(() ->
|
|
|
|
lstKey.getSelectionModel().select(0)));
|
|
|
|
lstKey.getSelectionModel().select(0)));
|
|
|
|
lstDescription.getSelectionModel().selectedItemProperty()
|
|
|
|
lstDescription.getSelectionModel().selectedItemProperty()
|
|
|
|
.addListener((observable, oldvalue, newValue) ->
|
|
|
|
.addListener((observable, oldValue, newValue) ->
|
|
|
|
Platform.runLater(() ->
|
|
|
|
Platform.runLater(() ->
|
|
|
|
lstDescription.getSelectionModel().select(0)));
|
|
|
|
lstDescription.getSelectionModel().select(0)));
|
|
|
|
lstControl.getSelectionModel().selectedItemProperty()
|
|
|
|
lstControl.getSelectionModel().selectedItemProperty()
|
|
|
|
.addListener((observable, oldvalue, newValue) ->
|
|
|
|
.addListener((observable, oldValue, newValue) ->
|
|
|
|
Platform.runLater(() ->
|
|
|
|
Platform.runLater(() ->
|
|
|
|
lstControl.getSelectionModel().select(0)));
|
|
|
|
lstControl.getSelectionModel().select(0)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -83,7 +82,7 @@ public class KeyBindingsController extends Controller {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Populates the table with commands and their key binding details.
|
|
|
|
* Populates the table with commands and their key binding details.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void populateTable(){
|
|
|
|
private void populateTable(){
|
|
|
|
// add each command to the table
|
|
|
|
// add each command to the table
|
|
|
|
for (Map.Entry<String, ControlKey> entry : newKeyFactory.getKeyState().entrySet()) {
|
|
|
|
for (Map.Entry<String, ControlKey> entry : newKeyFactory.getKeyState().entrySet()) {
|
|
|
|
// create button for command
|
|
|
|
// create button for command
|
|
|
|
@ -100,9 +99,9 @@ public class KeyBindingsController extends Controller {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Makes a copy of the {@link KeyFactory} that does not modify the original.
|
|
|
|
* Makes a copy of the {@link KeyFactory} that does not modify the original.
|
|
|
|
* @return new keyfactory to be modified
|
|
|
|
* @return new keyFactory to be modified
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public KeyFactory copyExistingFactory(){
|
|
|
|
private KeyFactory copyExistingFactory(){
|
|
|
|
newKeyFactory = new KeyFactory();
|
|
|
|
newKeyFactory = new KeyFactory();
|
|
|
|
Map<String, ControlKey> oldKeyState = existingKeyFactory.getKeyState();
|
|
|
|
Map<String, ControlKey> oldKeyState = existingKeyFactory.getKeyState();
|
|
|
|
Map<String, ControlKey> newKeyState = new HashMap<>();
|
|
|
|
Map<String, ControlKey> newKeyState = new HashMap<>();
|
|
|
|
@ -118,18 +117,16 @@ public class KeyBindingsController extends Controller {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Creates a listener for when a user tries to close the current window.
|
|
|
|
* Creates a listener for when a user tries to close the current window.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void setClosedListener(){
|
|
|
|
private void setClosedListener(){
|
|
|
|
anchor.sceneProperty().addListener((obsS, oldS, newS) -> {
|
|
|
|
anchor.sceneProperty().addListener((obsS, oldS, newS) -> {
|
|
|
|
if (newS != null) {
|
|
|
|
if (newS != null) {
|
|
|
|
newS.windowProperty().addListener((obsW, oldW, newW) -> {
|
|
|
|
newS.windowProperty().addListener((obsW, oldW, newW) -> {
|
|
|
|
if (newW != null) {
|
|
|
|
if (newW != null) {
|
|
|
|
Stage stage = (Stage)newW;
|
|
|
|
Stage stage = (Stage)newW;
|
|
|
|
// WE is processed by onExit method
|
|
|
|
// WE is processed by onExit method
|
|
|
|
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
|
|
|
|
stage.setOnCloseRequest(we -> {
|
|
|
|
public void handle(WindowEvent we) {
|
|
|
|
if (we.getEventType() == WindowEvent.WINDOW_CLOSE_REQUEST) {
|
|
|
|
if (we.getEventType() == WindowEvent.WINDOW_CLOSE_REQUEST) {
|
|
|
|
onExit(we);
|
|
|
|
onExit(we);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -139,11 +136,11 @@ public class KeyBindingsController extends Controller {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Creates a listener for the base anchorpane for key presses.
|
|
|
|
* Creates a listener for the base anchorPane for key presses.
|
|
|
|
* It updates the current key bindings of the {@link KeyFactory} if
|
|
|
|
* It updates the current key bindings of the {@link KeyFactory} if
|
|
|
|
* required.
|
|
|
|
* required.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void setKeyListener(){
|
|
|
|
private void setKeyListener(){
|
|
|
|
anchor.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
|
|
|
anchor.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
|
|
|
// if esc, cancel current button click
|
|
|
|
// if esc, cancel current button click
|
|
|
|
if (event.getCode() == KeyCode.ESCAPE){
|
|
|
|
if (event.getCode() == KeyCode.ESCAPE){
|
|
|
|
@ -218,10 +215,10 @@ public class KeyBindingsController extends Controller {
|
|
|
|
* commands are missing a key binding.
|
|
|
|
* commands are missing a key binding.
|
|
|
|
* @return True if valid, false if invalid
|
|
|
|
* @return True if valid, false if invalid
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Boolean isFactoryValid(){
|
|
|
|
private Boolean isFactoryValid(){
|
|
|
|
for (Map.Entry<String, ControlKey> entry : newKeyFactory.getKeyState().entrySet
|
|
|
|
for (Map.Entry<String, ControlKey> entry : newKeyFactory.getKeyState().entrySet
|
|
|
|
()) {
|
|
|
|
()) {
|
|
|
|
if (entry.getKey().toString()==entry.getValue().toString()){
|
|
|
|
if (entry.getKey().toString().equals(entry.getValue().toString())){
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -234,7 +231,7 @@ public class KeyBindingsController extends Controller {
|
|
|
|
* @param we {@link WindowEvent} close request to be consumed if settings
|
|
|
|
* @param we {@link WindowEvent} close request to be consumed if settings
|
|
|
|
* have not been successfully saved.
|
|
|
|
* have not been successfully saved.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void onExit(WindowEvent we){
|
|
|
|
private void onExit(WindowEvent we){
|
|
|
|
// if modified KeyFactory hasn't been saved
|
|
|
|
// if modified KeyFactory hasn't been saved
|
|
|
|
if (changed){
|
|
|
|
if (changed){
|
|
|
|
loadNotification("Please cancel or save your changes before exiting" +
|
|
|
|
loadNotification("Please cancel or save your changes before exiting" +
|
|
|
|
@ -248,7 +245,7 @@ public class KeyBindingsController extends Controller {
|
|
|
|
* @param message the message to be displayed to the user
|
|
|
|
* @param message the message to be displayed to the user
|
|
|
|
* @param warning true if the message to be displayed is due to user error
|
|
|
|
* @param warning true if the message to be displayed is due to user error
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void loadNotification(String message, Boolean warning){
|
|
|
|
private void loadNotification(String message, Boolean warning){
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
NotificationController nc = (NotificationController)
|
|
|
|
NotificationController nc = (NotificationController)
|
|
|
|
loadPopupScene("notification.fxml",
|
|
|
|
loadPopupScene("notification.fxml",
|
|
|
|
|