updates to create a core directory in users home, added options in ui to allow changes for shell command and xml directory
This commit is contained in:
parent
8864169683
commit
12681b6382
7 changed files with 135 additions and 11 deletions
|
@ -52,6 +52,7 @@ public class Controller implements Initializable {
|
||||||
|
|
||||||
private Application application;
|
private Application application;
|
||||||
private Stage window;
|
private Stage window;
|
||||||
|
private Properties properties;
|
||||||
|
|
||||||
// core client utilities
|
// core client utilities
|
||||||
private ICoreClient coreClient;
|
private ICoreClient coreClient;
|
||||||
|
@ -80,6 +81,7 @@ public class Controller implements Initializable {
|
||||||
private LocationDialog locationDialog = new LocationDialog(this);
|
private LocationDialog locationDialog = new LocationDialog(this);
|
||||||
private GeoDialog geoDialog = new GeoDialog(this);
|
private GeoDialog geoDialog = new GeoDialog(this);
|
||||||
private ConnectDialog connectDialog = new ConnectDialog(this);
|
private ConnectDialog connectDialog = new ConnectDialog(this);
|
||||||
|
private GuiPreferencesDialog guiPreferencesDialog = new GuiPreferencesDialog(this);
|
||||||
|
|
||||||
public Controller() {
|
public Controller() {
|
||||||
}
|
}
|
||||||
|
@ -141,6 +143,7 @@ public class Controller implements Initializable {
|
||||||
backgroundDialog.setOwner(window);
|
backgroundDialog.setOwner(window);
|
||||||
locationDialog.setOwner(window);
|
locationDialog.setOwner(window);
|
||||||
connectDialog.setOwner(window);
|
connectDialog.setOwner(window);
|
||||||
|
guiPreferencesDialog.setOwner(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -164,6 +167,11 @@ public class Controller implements Initializable {
|
||||||
locationDialog.showDialog();
|
locationDialog.showDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onOptionsMenuPreferences(ActionEvent event) {
|
||||||
|
guiPreferencesDialog.showDialog();
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onHelpMenuWebsite(ActionEvent event) {
|
private void onHelpMenuWebsite(ActionEvent event) {
|
||||||
application.getHostServices().showDocument("https://github.com/coreemu/core");
|
application.getHostServices().showDocument("https://github.com/coreemu/core");
|
||||||
|
@ -183,7 +191,8 @@ public class Controller implements Initializable {
|
||||||
private void onOpenXmlAction() {
|
private void onOpenXmlAction() {
|
||||||
FileChooser fileChooser = new FileChooser();
|
FileChooser fileChooser = new FileChooser();
|
||||||
fileChooser.setTitle("Open Session");
|
fileChooser.setTitle("Open Session");
|
||||||
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
String xmlPath = properties.getProperty(ConfigUtils.CORE_XML_PATH);
|
||||||
|
fileChooser.setInitialDirectory(new File(xmlPath));
|
||||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml"));
|
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml"));
|
||||||
File file = fileChooser.showOpenDialog(window);
|
File file = fileChooser.showOpenDialog(window);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
@ -201,7 +210,8 @@ public class Controller implements Initializable {
|
||||||
FileChooser fileChooser = new FileChooser();
|
FileChooser fileChooser = new FileChooser();
|
||||||
fileChooser.setTitle("Save Session");
|
fileChooser.setTitle("Save Session");
|
||||||
fileChooser.setInitialFileName("session.xml");
|
fileChooser.setInitialFileName("session.xml");
|
||||||
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
String xmlPath = properties.getProperty(ConfigUtils.CORE_XML_PATH);
|
||||||
|
fileChooser.setInitialDirectory(new File(xmlPath));
|
||||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml"));
|
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml"));
|
||||||
File file = fileChooser.showSaveDialog(window);
|
File file = fileChooser.showSaveDialog(window);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
@ -266,8 +276,8 @@ public class Controller implements Initializable {
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
coreClient = new CoreRestClient(this);
|
coreClient = new CoreRestClient(this);
|
||||||
coreWebSocket = new CoreWebSocket(this);
|
coreWebSocket = new CoreWebSocket(this);
|
||||||
Properties properties = ConfigUtils.load();
|
properties = ConfigUtils.load();
|
||||||
String coreUrl = properties.getProperty("core-rest");
|
String coreUrl = properties.getProperty(ConfigUtils.CORE_REST);
|
||||||
logger.info("core rest: {}", coreUrl);
|
logger.info("core rest: {}", coreUrl);
|
||||||
connectDialog.setCoreUrl(coreUrl);
|
connectDialog.setCoreUrl(coreUrl);
|
||||||
connectToCore(coreUrl);
|
connectToCore(coreUrl);
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.core.graph;
|
||||||
import com.core.Controller;
|
import com.core.Controller;
|
||||||
import com.core.data.*;
|
import com.core.data.*;
|
||||||
import com.core.ui.Toast;
|
import com.core.ui.Toast;
|
||||||
|
import com.core.utils.ConfigUtils;
|
||||||
import com.core.utils.IconUtils;
|
import com.core.utils.IconUtils;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import edu.uci.ics.jung.algorithms.layout.StaticLayout;
|
import edu.uci.ics.jung.algorithms.layout.StaticLayout;
|
||||||
|
@ -117,8 +118,9 @@ public class NetworkGraph {
|
||||||
|
|
||||||
if (mouseEvent.getClickCount() == 2 && controller.getCoreClient().isRunning()) {
|
if (mouseEvent.getClickCount() == 2 && controller.getCoreClient().isRunning()) {
|
||||||
try {
|
try {
|
||||||
|
String shellCommand = controller.getProperties().getProperty(ConfigUtils.SHELL_COMMAND);
|
||||||
String terminalCommand = controller.getCoreClient().getTerminalCommand(node);
|
String terminalCommand = controller.getCoreClient().getTerminalCommand(node);
|
||||||
terminalCommand = String.format("gnome-terminal -x %s", terminalCommand);
|
terminalCommand = String.format("%s %s", shellCommand, terminalCommand);
|
||||||
logger.info("launching node terminal: {}", terminalCommand);
|
logger.info("launching node terminal: {}", terminalCommand);
|
||||||
String[] commands = terminalCommand.split("\\s+");
|
String[] commands = terminalCommand.split("\\s+");
|
||||||
logger.info("launching node terminal: {}", Arrays.toString(commands));
|
logger.info("launching node terminal: {}", Arrays.toString(commands));
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.core.ui.dialogs;
|
||||||
|
|
||||||
|
import com.core.Controller;
|
||||||
|
import com.core.ui.Toast;
|
||||||
|
import com.core.utils.ConfigUtils;
|
||||||
|
import com.jfoenix.controls.JFXButton;
|
||||||
|
import com.jfoenix.controls.JFXTextField;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class GuiPreferencesDialog extends StageDialog {
|
||||||
|
private static final Logger logger = LogManager.getLogger();
|
||||||
|
private @FXML JFXTextField xmlFilePathTextField;
|
||||||
|
private @FXML JFXTextField shellCommandTextField;
|
||||||
|
private @FXML JFXButton saveButton;
|
||||||
|
|
||||||
|
public GuiPreferencesDialog(Controller controller) {
|
||||||
|
super(controller, "/fxml/gui_preferences.fxml");
|
||||||
|
setTitle("GUI Preferences");
|
||||||
|
saveButton = createButton("Save");
|
||||||
|
saveButton.setOnAction(onSave);
|
||||||
|
addCancelButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
private EventHandler<ActionEvent> onSave = event -> {
|
||||||
|
Properties properties = getController().getProperties();
|
||||||
|
properties.setProperty(ConfigUtils.CORE_XML_PATH, xmlFilePathTextField.getText());
|
||||||
|
properties.setProperty(ConfigUtils.SHELL_COMMAND, shellCommandTextField.getText());
|
||||||
|
try {
|
||||||
|
ConfigUtils.save(properties);
|
||||||
|
Toast.success("Updated preferences");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Toast.error("Failure to update preferences", ex);
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
};
|
||||||
|
|
||||||
|
public void showDialog() {
|
||||||
|
Properties properties = getController().getProperties();
|
||||||
|
xmlFilePathTextField.setText(properties.getProperty(ConfigUtils.CORE_XML_PATH));
|
||||||
|
shellCommandTextField.setText(properties.getProperty(ConfigUtils.SHELL_COMMAND));
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,24 +3,52 @@ package com.core.utils;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public final class ConfigUtils {
|
public final class ConfigUtils {
|
||||||
private static final Logger logger = LogManager.getLogger();
|
private static final Logger logger = LogManager.getLogger();
|
||||||
private static final String DEFAULT_CONFIG = "/config.properties";
|
private static final String DEFAULT_CONFIG = "/config.properties";
|
||||||
|
private static final Path CORE_HOME = Paths.get(System.getProperty("user.home"), ".core");
|
||||||
|
private static final Path CORE_PROPERTIES = Paths.get(CORE_HOME.toString(), "config.properties");
|
||||||
|
private static final Path CORE_XML_DIR = Paths.get(CORE_HOME.toString(), "xml");
|
||||||
|
// config fields
|
||||||
|
public static final String CORE_REST = "core-rest";
|
||||||
|
public static final String CORE_XML_PATH = "xml-path";
|
||||||
|
public static final String SHELL_COMMAND = "shell-command";
|
||||||
|
|
||||||
|
|
||||||
private ConfigUtils() {
|
private ConfigUtils() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Properties load() {
|
public static void save(Properties properties) throws IOException {
|
||||||
String filePath = System.getProperty("config.file", DEFAULT_CONFIG);
|
properties.store(new FileOutputStream(CORE_PROPERTIES.toFile()), null);
|
||||||
logger.info("loading config file: {}", filePath);
|
}
|
||||||
|
|
||||||
|
public static Properties load() {
|
||||||
try {
|
try {
|
||||||
|
if (!CORE_HOME.toFile().exists()) {
|
||||||
|
logger.info("creating core home directory");
|
||||||
|
Files.createDirectory(CORE_HOME);
|
||||||
|
Files.createDirectory(CORE_XML_DIR);
|
||||||
|
}
|
||||||
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.load(ConfigUtils.class.getResourceAsStream(filePath));
|
if (!CORE_PROPERTIES.toFile().exists()) {
|
||||||
|
logger.info("creating default configuration");
|
||||||
|
Files.copy(ConfigUtils.class.getResourceAsStream(DEFAULT_CONFIG), CORE_PROPERTIES);
|
||||||
|
properties.load(new FileInputStream(CORE_PROPERTIES.toFile()));
|
||||||
|
properties.setProperty(CORE_XML_PATH, CORE_XML_DIR.toString());
|
||||||
|
save(properties);
|
||||||
|
} else {
|
||||||
|
properties.load(new FileInputStream(CORE_PROPERTIES.toFile()));
|
||||||
|
}
|
||||||
|
|
||||||
// override values if provided
|
// override values if provided
|
||||||
for (String key : properties.stringPropertyNames()) {
|
for (String key : properties.stringPropertyNames()) {
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
core-rest=http://127.0.0.1:5000
|
core-rest=http://127.0.0.1:5000
|
||||||
|
shell-command=gnome-terminal --window --
|
||||||
|
|
32
corefx/src/main/resources/fxml/gui_preferences.fxml
Normal file
32
corefx/src/main/resources/fxml/gui_preferences.fxml
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import com.jfoenix.controls.JFXTextField?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.TitledPane?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
|
|
||||||
|
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" spacing="10.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<children>
|
||||||
|
<TitledPane animated="false" collapsible="false" text="XML">
|
||||||
|
<content>
|
||||||
|
<VBox spacing="5.0">
|
||||||
|
<children>
|
||||||
|
<Label text="File Path" />
|
||||||
|
<JFXTextField fx:id="xmlFilePathTextField" />
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
|
</content>
|
||||||
|
</TitledPane>
|
||||||
|
<TitledPane animated="false" collapsible="false" text="Programs">
|
||||||
|
<content>
|
||||||
|
<VBox spacing="5.0">
|
||||||
|
<children>
|
||||||
|
<Label text="Shell Command" />
|
||||||
|
<JFXTextField fx:id="shellCommandTextField" />
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
|
</content>
|
||||||
|
</TitledPane>
|
||||||
|
</children>
|
||||||
|
</VBox>
|
|
@ -33,14 +33,15 @@
|
||||||
<items>
|
<items>
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onJoinSessionMenu" text="Join" />
|
<MenuItem mnemonicParsing="false" onAction="#onJoinSessionMenu" text="Join" />
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onSessionHooksMenu" text="Hooks" />
|
<MenuItem mnemonicParsing="false" onAction="#onSessionHooksMenu" text="Hooks" />
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuLocation" text="Location" />
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onSessionOptionsMenu" text="Options" />
|
<MenuItem mnemonicParsing="false" onAction="#onSessionOptionsMenu" text="Options" />
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu mnemonicParsing="false" text="Options">
|
<Menu mnemonicParsing="false" text="Options">
|
||||||
<items>
|
<items>
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuNodeTypes" text="Nodes" />
|
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuNodeTypes" text="Nodes" />
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuLocation" text="Location" />
|
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuBackground" text="Background" />
|
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuBackground" text="Background" />
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuPreferences" text="Preferences" />
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu mnemonicParsing="false" text="Help">
|
<Menu mnemonicParsing="false" text="Help">
|
||||||
|
|
Loading…
Reference in a new issue