Skip to content
Snippets Groups Projects
Commit 904e9f9b authored by Dallin Nickel (djn011)'s avatar Dallin Nickel (djn011)
Browse files

Merge branch 'feature-implement-ui' into 'feature-rebind-keys'

Add UI to feature branch

See merge request !38
parents 4d82a6d9 555c110f
No related branches found
No related tags found
3 merge requests!45Prototype to Master for Milestone 5,!40Feature rebind keys,!38Add UI to feature branch
......@@ -14,7 +14,7 @@ public class Action extends Hotkey implements InputEmulator{
* @param id The unique ID of the hotkey.
* @param modifier The modifier of the hotkey.
*/
public Action(int keyCode, int id, Modifier modifier) throws AWTException {
public Action(int keyCode, int id, int modifier) throws AWTException {
super(keyCode, id, modifier);
this.robot = new Robot();
......
......@@ -14,7 +14,7 @@ public class Hotkey {
/**
* Modifier for the hotkey.
*/
protected final Modifier modifier;
protected final int modifier;
/**
* Constructs an immutable hotkey.
......@@ -22,7 +22,7 @@ public class Hotkey {
* @param id The unique ID of the hotkey.
* @param modifier The modifier of the hotkey.
*/
public Hotkey(int keyCode, int id, Modifier modifier) {
public Hotkey(int keyCode, int id, int modifier) {
this.keyCode = keyCode;
this.id = id;
this.modifier = modifier;
......@@ -45,7 +45,7 @@ public class Hotkey {
/**
* Get's the hotkey's modifier.
*/
public Modifier getModifier() {
public int getModifier() {
return modifier;
}
}
package ui;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import org.controlsfx.control.textfield.TextFields;
/**
* KeybindView is the view screen for adding a new keybind to the active profile.
* There are two fields to enter the details of the keybind, a back button to go
* back to the main UI, and a save button which writes the keybind to the profile.
*/
public class KeybindView extends Pane {
//The key to be pressed for the keybind action
TextField keyToBind = new TextField();
//The key action once the bound buttton is pressed
TextField keyAction = new TextField();
//Options for selecting keys
OptionsList lists = new OptionsList();
//Mapping of key selections and key code integers
keyValueMap keyValueMap = new keyValueMap();
public KeybindView() {
this.setStyle("-fx-background-color: #99aab5;");
keyToBind.setLayoutX(60);
keyToBind.setLayoutY(200);
keyToBind.setStyle("-fx-background-color: #2c2f33; -fx-text-fill: white; -fx-font-size: 30; " +
"-fx-pref-width: 400px; -fx-pref-height: 50px;");
keyAction.setLayoutX(60);
keyAction.setLayoutY(500);
keyAction.setStyle("-fx-background-color: #2c2f33; -fx-text-fill: white; -fx-font-size: 30; " +
"-fx-pref-width: 400px; -fx-pref-height: 50px;");
//Available options to select in the text fields
String[] keyToBindOptions = lists.getOptionstoPress();
String[] keyActionOptions = lists.getActionsPress();
//Labels for the text fields
Label keyToBindLabel = new Label("Key to Bind:");
keyToBindLabel.setLayoutX(60);
keyToBindLabel.setLayoutY(150);
keyToBindLabel.setStyle("-fx-text-fill: #2c2f33; -fx-font-size: 30;");
Label keyActionLabel = new Label("Assign Action:");
keyActionLabel.setLayoutX(60);
keyActionLabel.setLayoutY(450);
keyActionLabel.setStyle("-fx-text-fill: #2c2f33; -fx-font-size: 30;");
TextFields.bindAutoCompletion(keyToBind, keyToBindOptions);
TextFields.bindAutoCompletion(keyAction, keyActionOptions);
this.getChildren().addAll(keyToBind, keyAction, keyActionLabel, keyToBindLabel);
}
/**
* Returns an Integer value for the Windows key code for the string representation of a key.
* Corresponds to the key which is being bound
* @return an Integer value for the Windows key code for the string representation of a key
*/
public Integer getKeyToBind() {
return keyValueMap.getKeyCode(keyToBind.getText());
}
/**
* Returns an Integer value for the Windows key code for the string representation of a key.
* Corresponds to the resulting action when the bound key is pressed
* @return an Integer value for the Windows key code for the string representation of a key
*/
public Integer getKeyAction() {
return keyValueMap.getKeyCode(keyAction.getText());
}
}
package ui;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("ui/main.fxml"));
primaryStage.setTitle("Main Window");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
// Initialize at main UI screen
new mainScreen();
}
......
package ui;
/**
* OptionsList initializes a number of lists used in the UI views. All lists have a getter function to send to
* the different views.
*/
public class OptionsList {
String[] optionsPress;
String[] optionsActions;
public OptionsList() {
//List of options for the user to bind an action to
optionsPress = new String[] {
"Q ", "W ", "E ", "R ", "T ", "Y ", "U ", "I ", "O ", "P ", "A ", "S ", "D ", "F ",
"G ", "H ", "J ", "K ", "L ", "Z ", "X ", "C ", "V ", "B ", "N ", "M ", ". Period",
", Comma", "/ Back slash", "Right shift", "[ Left square bracket", "] Right square bracket",
"\\ Forward slash", "Esc", "F1 ", "F2 ", "F3 ", "F4 ", "F5 ", "F6 ", "F7 ", "F8 ", "F9 ", "F10 ", "F11 ", "F12 ", "` Tilde",
"1 ", "2 ", "3 ", "4 ", "5 ", "6 ", "7 ", "8 ", "9 ", "0 ", "- Dash", "= Equals", "Backspace", "Tab",
"Caps Lock", "Enter", "Left Shift", "Left Control", "Alt", "Insert", "Home",
"Page Up", "Delete", "End", "Page Down", "Left Arrow", "Up Arrow", "Down Arrow", "Right Arrow",
"Number Lock", "/ Numpad slash", "* Numpad asterisk", "- Numpad dash", "Numpad 7", "Numpad 8", "Numpad 9",
"+ Numpad plus", "Numpad 4", "Numpad 5", "Numpad 6", "Numpad 1", "Numpad 2", "Numpad 3",
"Numpad 0", ". Numpad period", "Mouse button 4", "Mouse button 5"
};
//List of options the user can select as actions for the keybind
optionsActions = new String[] {
"Q ", "W ", "E ", "R ", "T ", "Y ", "U ", "I ", "O ", "P ", "A ", "S ", "D ", "F ",
"G ", "H ", "J ", "K ", "L ", "Z ", "X ", "C ", "V ", "B ", "N ", "M ", ". Period",
", Comma", "/ Back slash", "Right shift", "[ Left square bracket", "] Right square bracket",
"\\ Forward slash", "Esc", "F1 ", "F2 ", "F3 ", "F4 ", "F5 ", "F6 ", "F7 ", "F8 ", "F9 ", "F10 ", "F11 ", "F12 ", "` Tilde",
"1 ", "2 ", "3 ", "4 ", "5 ", "6 ", "7 ", "8 ", "9 ", "0 ", "- Dash", "= Equals", "Backspace", "Tab",
"Caps Lock", "Enter", "Left Shift", "Left Control", "Alt", "Insert", "Home",
"Page Up", "Delete", "End", "Page Down", "Left Arrow", "Up Arrow", "Down Arrow", "Right Arrow",
"Number Lock", "/ Numpad slash", "* Numpad asterisk", "- Numpad dash", "Numpad 7", "Numpad 8", "Numpad 9",
"+ Numpad plus", "Numpad 4", "Numpad 5", "Numpad 6", "Numpad 1", "Numpad 2", "Numpad 3",
"Numpad 0", ". Numpad period", "Volume mute/unmute", "Media play/pause",
"Media next track", "Media previous track"
};
}
public String[] getOptionstoPress() {
return optionsPress;
}
public String[] getActionsPress() {
return optionsActions;
}
}
package ui;
import java.util.Hashtable;
/**
* keyValueMap initializes a Hashtable which maps the string value in the UI to a Windows Integer key code.
*/
public class keyValueMap {
Hashtable<String, Integer> matchKey;
public keyValueMap () {
matchKey = new Hashtable<String, Integer>();
//Add keys, codes
matchKey.put("Q ", 81);
matchKey.put("W ", 87);
matchKey.put("E ", 69);
matchKey.put("R ", 82);
matchKey.put("T ", 84);
matchKey.put("Y ", 89);
matchKey.put("U ", 85);
matchKey.put("I ", 73);
matchKey.put("O ", 79);
matchKey.put("P ", 80);
matchKey.put("A ", 65);
matchKey.put("S ", 83);
matchKey.put("D ", 68);
matchKey.put("F ", 70);
matchKey.put("G ", 71);
matchKey.put("H ", 72);
matchKey.put("J ", 74);
matchKey.put("K ", 75);
matchKey.put("L ", 76);
matchKey.put("Z ", 90);
matchKey.put("X ", 88);
matchKey.put("C ", 67);
matchKey.put("V ", 86);
matchKey.put("B ", 66);
matchKey.put("N ", 0x4E);
matchKey.put(". Period", 0xBE);
matchKey.put(", Comma", 0xBC);
matchKey.put("/ Back slash", 0xBF);
matchKey.put("Right shift", 0xA1);
matchKey.put("[ Left square bracket", 0xDB);
matchKey.put("] Right square bracket", 0xDD);
matchKey.put("\\ Forward slash", 0xDC);
matchKey.put("F1 ", 0x70);
matchKey.put("F2 ", 0x71);
matchKey.put("F3 ", 0x72);
matchKey.put("F4 ", 0x73);
matchKey.put("F5 ", 0x74);
matchKey.put("F6 ", 0x75);
matchKey.put("F7 ", 0x76);
matchKey.put("F8 ", 0x77);
matchKey.put("F9 ", 0x78);
matchKey.put("F10 ", 0x79);
matchKey.put("F11 ", 0x7A);
matchKey.put("F12 ", 0x7B);
matchKey.put("` Tilde", 0xC0);
matchKey.put("1 ", 0x31);
matchKey.put("2 ", 0x32);
matchKey.put("3 ", 0x33);
matchKey.put("4 ", 0x34);
matchKey.put("5 ", 0x35);
matchKey.put("6 ", 0x36);
matchKey.put("7 ", 0x37);
matchKey.put("8 ", 0x38);
matchKey.put("9 ", 0x39);
matchKey.put("0 ", 0x30);
matchKey.put("- Dash", 0xBD);
matchKey.put("= Equals", 0xBB);
matchKey.put("Backspace", 0x08);
matchKey.put("Tab", 0x09);
matchKey.put("Caps Lock", 0x14);
matchKey.put("Enter", 0x0D);
matchKey.put("Left Shift", 0xA0);
matchKey.put("Left Control", 0xA2);
matchKey.put("Alt", 0x12);
matchKey.put("Insert", 0x2D);
matchKey.put("Home", 0x24);
matchKey.put("Page Up", 0x21);
matchKey.put("Delete", 0x2E);
matchKey.put("End", 0x23);
matchKey.put("Page Down", 0x22);
matchKey.put("Left Arrow", 0x25);
matchKey.put("Up Arrow", 0x26);
matchKey.put("Down Arrow", 0x28);
matchKey.put("Right Arrow", 0x27);
matchKey.put("Number Lock", 0x90);
matchKey.put("/ Numpad slash", 0x6F);
matchKey.put("* Numpad asterisk", 0x6A);
matchKey.put("- Numpad dash", 0x6D);
matchKey.put("Numpad 7", 0x67);
matchKey.put("Numpad 8", 0x68);
matchKey.put("Numpad 9", 0x69);
matchKey.put("+ Numpad plus", 0x6B);
matchKey.put("Numpad 4", 0x64);
matchKey.put("Numpad 5", 0x65);
matchKey.put("Numpad 6", 0x66);
matchKey.put("Numpad 1", 0x61);
matchKey.put("Numpad 2", 0x62);
matchKey.put("Numpad 3", 0x63);
matchKey.put("Numpad 0", 0x60);
matchKey.put(". Numpad period", 0x6E);
matchKey.put("Mouse button 4", 0x05);
matchKey.put("Mouse button 5", 0x06);
matchKey.put("Volume mute/unmute", 0xAD);
matchKey.put("Media play/pause", 0xB3);
matchKey.put("Media next track", 0xB0);
matchKey.put("Media previous track", 0xB1);
}
/**
* Returns the integer keycode for a given string parameter
* @param keyPressed String parameter represetning a key
* @return Keycode in matchKey for String parameter keyPressed
*/
public Integer getKeyCode(String keyPressed) {
return matchKey.get(keyPressed);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="Main"
prefHeight="400.0" prefWidth="600.0">
</AnchorPane>
package ui;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
/**
* mainScreen is the main UI page for the program. All user functions start here.
*/
public class mainScreen extends Pane {
Stage primaryStage = new Stage();
Scene mainScreenScene = new Scene(this, 800, 800);
public mainScreen() {
this.setStyle("-fx-background-color: #99aab5;");
primaryStage.setTitle("");
primaryStage.setScene(mainScreenScene);
primaryStage.show();
/*
Button to send user to screen to set a new keybind.
*/
Button bKeybind = new Button("Set a Keybind");
bKeybind.setOnAction(e -> goToKeybind());
bKeybind.setStyle("-fx-background-color: #2c2f33; -fx-text-fill: white; -fx-font-size: 30; -fx-vertical-align: middle; " +
"-fx-pref-width: 260px; -fx-pref-height: 150px; -fx-text-align: center;");
bKeybind.setWrapText(true);
bKeybind.setLayoutX(89);
bKeybind.setLayoutY(200);
/*
Button to send user to screen to set a new macro
*/
Button bMacro = new Button("Bind a Key to Macro");
bMacro.setOnAction(e -> System.out.println("Set Macro"));
bMacro.setStyle("-fx-background-color: #2c2f33; -fx-text-fill: white; -fx-font-size: 30; -fx-vertical-align: middle; " +
"-fx-pref-width: 260px; -fx-pref-height: 150px; -fx-text-align: center;");
bMacro.setWrapText(true);
bMacro.setLayoutX(438);
bMacro.setLayoutY(200);
/*
Button to send user to screen to set a new keybind.
*/
Button bProgram = new Button("Bind a Key to Program");
bProgram.setOnAction(e -> System.out.println("Bind a Key to Program"));
bProgram.setStyle("-fx-background-color: #2c2f33; -fx-text-fill: white; -fx-font-size: 30; -fx-vertical-align: middle; " +
"-fx-pref-width: 260px; -fx-pref-height: 150px; -fx-text-align: center;");
bProgram.setWrapText(true);
bProgram.setLayoutX(89);
bProgram.setLayoutY(450);
/*
Button to send user to screen to change mouse sensitivity
*/
Button bMouseSens = new Button("Change Mouse Sensitivity");
bMouseSens.setOnAction(e -> System.out.println("Change Mouse Sensitivity"));
bMouseSens.setStyle("-fx-background-color: #2c2f33; -fx-text-fill: white; -fx-font-size: 30; -fx-vertical-align: middle; " +
"-fx-pref-width: 260px; -fx-pref-height: 150px; -fx-text-align: center;");
bMouseSens.setWrapText(true);
bMouseSens.setLayoutX(438);
bMouseSens.setLayoutY(450);
/*
Button to toggle keybinds on/off
*/
Button bToggle = new Button("Toggle Keybinds On/Off");
bToggle.setOnAction(e -> System.out.println("Toggle On/Off"));
bToggle.setStyle("-fx-background-color: #2c2f33; -fx-text-fill: white; -fx-font-size: 16; -fx-vertical-align: middle; " +
"-fx-pref-width: 200px; -fx-pref-height: 50px; -fx-text-align: center;");
bToggle.setWrapText(true);
bToggle.setLayoutX(520);
bToggle.setLayoutY(670);
/*
Drop down box to select profile
*/
ComboBox<String> profileSelector = new ComboBox<String>();
profileSelector.getItems().add("Profile 1");
profileSelector.getItems().add("Profile 2");
profileSelector.getItems().add("Profile 3");
profileSelector.setValue("Profile 1");
profileSelector.setStyle("-fx-background-color: lightgrey; -fx-text-fill: white; -fx-font-size: 20; -fx-vertical-align: middle; " +
"-fx-pref-width: 200px; -fx-pref-height: 50px; -fx-text-align: center;");
profileSelector.setLayoutX(89);
profileSelector.setLayoutY(45);
profileSelector.setOnAction(e -> System.out.println(profileSelector.getValue()));
/*
Button to add new profile
*/
Button bAddProfile = new Button("Add New Profile");
bAddProfile.setOnAction(e -> System.out.println("Add New Profile"));
bAddProfile.setStyle("-fx-background-color: #2c2f33; -fx-text-fill: white; -fx-font-size: 16; -fx-vertical-align: middle; " +
"-fx-pref-width: 200px; -fx-pref-height: 50px; -fx-text-align: center;");
bAddProfile.setWrapText(true);
bAddProfile.setLayoutX(315);
bAddProfile.setLayoutY(45);
/*
Button to delete the current profile
*/
Button bDelProfile = new Button("Delete Current Profile");
bDelProfile.setOnAction(e -> System.out.println("Delete Current Profile"));
bDelProfile.setStyle("-fx-background-color: #2c2f33; -fx-text-fill: white; -fx-font-size: 16; -fx-vertical-align: middle; " +
"-fx-pref-width: 200px; -fx-pref-height: 50px; -fx-text-align: center;");
bDelProfile.setWrapText(true);
bDelProfile.setLayoutX(541);
bDelProfile.setLayoutY(45);
this.getChildren().addAll(bKeybind, bMacro, bProgram, bMouseSens, bToggle, profileSelector, bAddProfile, bDelProfile);
}
/**
* Function called when user wishes to make a new keybind. Opens the KeybindView class in the stage.
*/
private void goToKeybind() {
KeybindView KBV = new KeybindView();
//Button to go back to main view
Button back = new Button("Back");
back.setLayoutX(510);
back.setLayoutY(700);
back.setStyle("-fx-background-color: #2c2f33; -fx-text-fill: white; -fx-font-size: 16; -fx-vertical-align: middle; " +
"-fx-pref-width: 100px; -fx-pref-height: 50px; -fx-text-align: center;");
back.setOnAction(e -> primaryStage.setScene(mainScreenScene));
//Button to save fields and enter keybind to profile
Button save = new Button("Save");
save.setLayoutX(640);
save.setLayoutY(700);
save.setStyle("-fx-background-color: #2c2f33; -fx-text-fill: white; -fx-font-size: 16; -fx-vertical-align: middle; " +
"-fx-pref-width: 100px; -fx-pref-height: 50px; -fx-text-align: center;");
save.setOnAction(e -> {
primaryStage.setScene(mainScreenScene);
System.out.println(KBV.getKeyToBind());
System.out.println(KBV.getKeyAction());
});
primaryStage.setTitle("Set a Keybind");
Scene testScene = new Scene(KBV, 800, 800);
primaryStage.setScene(testScene);
KBV.getChildren().addAll(back, save);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment