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:
Brendan Robert 2015-03-08 22:05:00 -05:00
parent 36173ab5f4
commit ecf1a9c98f
7 changed files with 117 additions and 22 deletions

View File

@ -67,6 +67,30 @@ public class Configuration implements Reconfigurable {
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
public String getName() {
return "Configuration";
@ -95,8 +119,8 @@ public class Configuration implements Reconfigurable {
public transient ConfigNode parent;
private ObservableList<ConfigNode> children;
public transient Reconfigurable subject;
private Map<String, Serializable> settings;
private Map<String, String[]> hotkeys;
public Map<String, Serializable> settings;
public Map<String, String[]> hotkeys;
private boolean changed = true;
@Override
@ -514,13 +538,8 @@ public class Configuration implements Reconfigurable {
boolean found = false;
List<String> shortFieldNames = new ArrayList<>();
for (String longName : n.getAllSettingNames()) {
ConfigurableField f = null;
try {
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;
ConfigurableField f = getConfigurableFieldInfo(n.subject, longName);
String shortName = getShortName(f, longName);
shortFieldNames.add(shortName);
if (fieldName.equalsIgnoreCase(longName) || fieldName.equalsIgnoreCase(shortName)) {

View File

@ -1,18 +1,23 @@
package jace.config;
import jace.Emulator;
import jace.JaceApplication;
import jace.config.Configuration.ConfigNode;
import java.io.Serializable;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
public class ConfigurationUIController {
@FXML
private ResourceBundle resources;
@ -29,7 +34,7 @@ public class ConfigurationUIController {
private ScrollPane settingsScroll;
@FXML
private TreeView<?> deviceTree;
private TreeView<ConfigNode> deviceTree;
@FXML
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 treeScroll != null : "fx:id=\"treeScroll\" was not injected: check your FXML file 'Configuration.fxml'.";
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;
}
}

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
@ -7,12 +8,12 @@
<?import javafx.scene.control.*?>
<?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>
<URL value="@/styles/configuration.css" />
<URL value="@/styles/style.css" />
</stylesheets>
<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>
<Button mnemonicParsing="false" onMouseClicked="#reloadConfig" text="Reload" />
<Button mnemonicParsing="false" onMouseClicked="#saveConfig" text="Save" />
@ -20,17 +21,20 @@
<Button mnemonicParsing="false" onMouseClicked="#cancelConfig" text="Cancel" />
</items>
</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>
<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>
<TreeView fx:id="deviceTree" prefHeight="359.0" prefWidth="233.0" />
</content>
</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>
<VBox fx:id="settingsVbox" prefHeight="360.0" prefWidth="354.0" />
</content>
<padding>
<Insets right="3.0" />
</padding>
</ScrollPane>
</items>
</SplitPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

View File

@ -1,3 +0,0 @@
.button {
-fx-font-weight: bold;
}

View File

@ -5,3 +5,9 @@
.mainFxmlClass {
}
.keyboard-shortcut {
margin-left:20px;
background-image: "../jace/data/icon_keyboard.gif";
background-repeat: no-repeat;
}

View 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;
}