forked from Apple-2-Tools/jace
Starting to show all keyboard shortcuts and settings, still no edit/load/save of config but it's a big step!
This commit is contained in:
parent
36173ab5f4
commit
ecf1a9c98f
@ -67,6 +67,30 @@ public class Configuration implements Reconfigurable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ConfigurableField getConfigurableFieldInfo(Reconfigurable subject, String settingName) {
|
||||||
|
Field f;
|
||||||
|
try {
|
||||||
|
f = subject.getClass().getField(settingName);
|
||||||
|
} catch (NoSuchFieldException | SecurityException ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ConfigurableField annotation = f.getAnnotation(ConfigurableField.class);
|
||||||
|
return annotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getShortName(ConfigurableField f, String longName) {
|
||||||
|
return (f != null && !f.shortName().equals("")) ? f.shortName() : longName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InvokableAction getInvokableActionInfo(Reconfigurable subject, String actionName) {
|
||||||
|
for (Method m : subject.getClass().getMethods()) {
|
||||||
|
if (m.getName().equals(actionName) && m.isAnnotationPresent(InvokableAction.class)) {
|
||||||
|
return m.getAnnotation(InvokableAction.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Configuration";
|
return "Configuration";
|
||||||
@ -95,8 +119,8 @@ public class Configuration implements Reconfigurable {
|
|||||||
public transient ConfigNode parent;
|
public transient ConfigNode parent;
|
||||||
private ObservableList<ConfigNode> children;
|
private ObservableList<ConfigNode> children;
|
||||||
public transient Reconfigurable subject;
|
public transient Reconfigurable subject;
|
||||||
private Map<String, Serializable> settings;
|
public Map<String, Serializable> settings;
|
||||||
private Map<String, String[]> hotkeys;
|
public Map<String, String[]> hotkeys;
|
||||||
private boolean changed = true;
|
private boolean changed = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -514,13 +538,8 @@ public class Configuration implements Reconfigurable {
|
|||||||
boolean found = false;
|
boolean found = false;
|
||||||
List<String> shortFieldNames = new ArrayList<>();
|
List<String> shortFieldNames = new ArrayList<>();
|
||||||
for (String longName : n.getAllSettingNames()) {
|
for (String longName : n.getAllSettingNames()) {
|
||||||
ConfigurableField f = null;
|
ConfigurableField f = getConfigurableFieldInfo(n.subject, longName);
|
||||||
try {
|
String shortName = getShortName(f, longName);
|
||||||
f = n.subject.getClass().getField(longName).getAnnotation(ConfigurableField.class);
|
|
||||||
} catch (NoSuchFieldException | SecurityException ex) {
|
|
||||||
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
String shortName = (f != null && !f.shortName().equals("")) ? f.shortName() : longName;
|
|
||||||
shortFieldNames.add(shortName);
|
shortFieldNames.add(shortName);
|
||||||
|
|
||||||
if (fieldName.equalsIgnoreCase(longName) || fieldName.equalsIgnoreCase(shortName)) {
|
if (fieldName.equalsIgnoreCase(longName) || fieldName.equalsIgnoreCase(shortName)) {
|
||||||
|
@ -1,18 +1,23 @@
|
|||||||
package jace.config;
|
package jace.config;
|
||||||
|
|
||||||
import jace.Emulator;
|
import jace.config.Configuration.ConfigNode;
|
||||||
import jace.JaceApplication;
|
import java.io.Serializable;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.control.SplitPane;
|
import javafx.scene.control.SplitPane;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.control.TreeItem;
|
||||||
import javafx.scene.control.TreeView;
|
import javafx.scene.control.TreeView;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
public class ConfigurationUIController {
|
public class ConfigurationUIController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ResourceBundle resources;
|
private ResourceBundle resources;
|
||||||
|
|
||||||
@ -29,7 +34,7 @@ public class ConfigurationUIController {
|
|||||||
private ScrollPane settingsScroll;
|
private ScrollPane settingsScroll;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TreeView<?> deviceTree;
|
private TreeView<ConfigNode> deviceTree;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ScrollPane treeScroll;
|
private ScrollPane treeScroll;
|
||||||
@ -62,5 +67,56 @@ public class ConfigurationUIController {
|
|||||||
assert deviceTree != null : "fx:id=\"deviceTree\" was not injected: check your FXML file 'Configuration.fxml'.";
|
assert deviceTree != null : "fx:id=\"deviceTree\" was not injected: check your FXML file 'Configuration.fxml'.";
|
||||||
assert treeScroll != null : "fx:id=\"treeScroll\" was not injected: check your FXML file 'Configuration.fxml'.";
|
assert treeScroll != null : "fx:id=\"treeScroll\" was not injected: check your FXML file 'Configuration.fxml'.";
|
||||||
deviceTree.setRoot(Configuration.BASE);
|
deviceTree.setRoot(Configuration.BASE);
|
||||||
|
deviceTree.getSelectionModel().selectedItemProperty().addListener(this::selectionChanged);
|
||||||
|
deviceTree.maxWidthProperty().bind(treeScroll.widthProperty());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectionChanged(
|
||||||
|
ObservableValue<? extends TreeItem<ConfigNode>> observable,
|
||||||
|
TreeItem<ConfigNode> oldValue,
|
||||||
|
TreeItem<ConfigNode> newValue) {
|
||||||
|
clearForm();
|
||||||
|
buildForm((ConfigNode) newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearForm() {
|
||||||
|
settingsVbox.getChildren().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildForm(ConfigNode node) {
|
||||||
|
node.hotkeys.forEach((name, values) -> {
|
||||||
|
settingsVbox.getChildren().add(buildKeyShortcutRow(node, name, values));
|
||||||
|
});
|
||||||
|
node.settings.forEach((name, value) -> {
|
||||||
|
settingsVbox.getChildren().add(buildSettingRow(node, name, value));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node buildSettingRow(ConfigNode node, String settingName, Serializable value) {
|
||||||
|
ConfigurableField fieldInfo = Configuration.getConfigurableFieldInfo(node.subject, settingName);
|
||||||
|
if (fieldInfo == null) return null;
|
||||||
|
HBox row = new HBox();
|
||||||
|
Label label = new Label(fieldInfo.name());
|
||||||
|
label.getStyleClass().add("setting-label");
|
||||||
|
label.setMinWidth(150.0);
|
||||||
|
TextField widget = new TextField(String.valueOf(value));
|
||||||
|
label.setLabelFor(widget);
|
||||||
|
row.getChildren().add(label);
|
||||||
|
row.getChildren().add(widget);
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node buildKeyShortcutRow(ConfigNode node, String actionName, String[] values) {
|
||||||
|
InvokableAction actionInfo = Configuration.getInvokableActionInfo(node.subject, actionName);
|
||||||
|
if (actionInfo == null) return null;
|
||||||
|
HBox row = new HBox();
|
||||||
|
Label label = new Label(actionInfo.name());
|
||||||
|
label.getStyleClass().add("setting-keyboard-shortcut");
|
||||||
|
label.setMinWidth(150.0);
|
||||||
|
TextField widget = new TextField(String.valueOf(values));
|
||||||
|
label.setLabelFor(widget);
|
||||||
|
row.getChildren().add(label);
|
||||||
|
row.getChildren().add(widget);
|
||||||
|
return row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.*?>
|
||||||
<?import java.lang.*?>
|
<?import java.lang.*?>
|
||||||
<?import java.net.*?>
|
<?import java.net.*?>
|
||||||
<?import java.util.*?>
|
<?import java.util.*?>
|
||||||
@ -7,12 +8,12 @@
|
|||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="jace.config.ConfigurationUIController">
|
<AnchorPane id="AnchorPane" prefHeight="426.0" prefWidth="600.0" styleClass="mainFxmlClass" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jace.config.ConfigurationUIController">
|
||||||
<stylesheets>
|
<stylesheets>
|
||||||
<URL value="@/styles/configuration.css" />
|
<URL value="@/styles/style.css" />
|
||||||
</stylesheets>
|
</stylesheets>
|
||||||
<children>
|
<children>
|
||||||
<ToolBar prefHeight="40.0" prefWidth="600.0">
|
<ToolBar prefHeight="40.0" prefWidth="600.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<items>
|
<items>
|
||||||
<Button mnemonicParsing="false" onMouseClicked="#reloadConfig" text="Reload" />
|
<Button mnemonicParsing="false" onMouseClicked="#reloadConfig" text="Reload" />
|
||||||
<Button mnemonicParsing="false" onMouseClicked="#saveConfig" text="Save" />
|
<Button mnemonicParsing="false" onMouseClicked="#saveConfig" text="Save" />
|
||||||
@ -20,17 +21,20 @@
|
|||||||
<Button mnemonicParsing="false" onMouseClicked="#cancelConfig" text="Cancel" />
|
<Button mnemonicParsing="false" onMouseClicked="#cancelConfig" text="Cancel" />
|
||||||
</items>
|
</items>
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
<SplitPane fx:id="splitPane" dividerPositions="0.3979933110367893" layoutY="40.0" prefHeight="363.0" prefWidth="600.0">
|
<SplitPane fx:id="splitPane" dividerPositions="0.3979933110367893" layoutY="40.0" prefHeight="363.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0">
|
||||||
<items>
|
<items>
|
||||||
<ScrollPane fx:id="treeScroll" prefHeight="361.0" prefWidth="174.0">
|
<ScrollPane fx:id="treeScroll" fitToHeight="true" fitToWidth="true" prefHeight="361.0" prefWidth="174.0">
|
||||||
<content>
|
<content>
|
||||||
<TreeView fx:id="deviceTree" prefHeight="359.0" prefWidth="233.0" />
|
<TreeView fx:id="deviceTree" prefHeight="359.0" prefWidth="233.0" />
|
||||||
</content>
|
</content>
|
||||||
</ScrollPane>
|
</ScrollPane>
|
||||||
<ScrollPane fx:id="settingsScroll" prefHeight="361.0" prefWidth="416.0">
|
<ScrollPane fx:id="settingsScroll" fitToHeight="true" fitToWidth="true" prefHeight="361.0" prefWidth="416.0">
|
||||||
<content>
|
<content>
|
||||||
<VBox fx:id="settingsVbox" prefHeight="360.0" prefWidth="354.0" />
|
<VBox fx:id="settingsVbox" prefHeight="360.0" prefWidth="354.0" />
|
||||||
</content>
|
</content>
|
||||||
|
<padding>
|
||||||
|
<Insets right="3.0" />
|
||||||
|
</padding>
|
||||||
</ScrollPane>
|
</ScrollPane>
|
||||||
</items>
|
</items>
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
|
BIN
src/main/resources/jace/data/icon_keyboard.gif
Normal file
BIN
src/main/resources/jace/data/icon_keyboard.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 592 B |
@ -1,3 +0,0 @@
|
|||||||
.button {
|
|
||||||
-fx-font-weight: bold;
|
|
||||||
}
|
|
@ -5,3 +5,9 @@
|
|||||||
.mainFxmlClass {
|
.mainFxmlClass {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.keyboard-shortcut {
|
||||||
|
margin-left:20px;
|
||||||
|
background-image: "../jace/data/icon_keyboard.gif";
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
}
|
13
src/main/resources/styles/style.css
Normal file
13
src/main/resources/styles/style.css
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
.button {
|
||||||
|
-fx-font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-label, .setting-keyboard-shortcut {
|
||||||
|
-fx-padding: 5 0 0 4;
|
||||||
|
-fx-allignment: center-left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-keyboard-shortcut {
|
||||||
|
-fx-graphic: "/jace/data/icon_keyboard.gif";
|
||||||
|
-fx-graphic-text-gap: 2;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user