corefx - fixed issue with home directory creation due to log file, added configuration for node labels in preferences
This commit is contained in:
parent
fb71e55b0b
commit
9a2625e502
8 changed files with 72 additions and 15 deletions
|
@ -432,6 +432,9 @@ public class Controller implements Initializable {
|
||||||
logger.info("controller initialize");
|
logger.info("controller initialize");
|
||||||
swingNode.setContent(networkGraph.getGraphViewer());
|
swingNode.setContent(networkGraph.getGraphViewer());
|
||||||
|
|
||||||
|
// update graph preferences
|
||||||
|
networkGraph.updatePreferences(configuration);
|
||||||
|
|
||||||
// set node types / default services
|
// set node types / default services
|
||||||
graphToolbar.setupNodeTypes();
|
graphToolbar.setupNodeTypes();
|
||||||
defaultServices = configuration.getNodeTypeConfigs().stream()
|
defaultServices = configuration.getNodeTypeConfigs().stream()
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class Main extends Application {
|
||||||
System.setProperty("core_log", LOG_FILE.toString());
|
System.setProperty("core_log", LOG_FILE.toString());
|
||||||
|
|
||||||
// check for and create gui home directory
|
// check for and create gui home directory
|
||||||
ConfigUtils.checkForHomeDirectory();
|
ConfigUtils.checkHomeDirectory();
|
||||||
|
|
||||||
// load svg icons
|
// load svg icons
|
||||||
SVGGlyphLoader.loadGlyphsFont(getClass().getResourceAsStream("/icons/icomoon_material.svg"),
|
SVGGlyphLoader.loadGlyphsFont(getClass().getResourceAsStream("/icons/icomoon_material.svg"),
|
||||||
|
|
|
@ -7,19 +7,26 @@ import javax.swing.border.EmptyBorder;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class CoreVertexLabelRenderer extends DefaultVertexLabelRenderer {
|
public class CoreVertexLabelRenderer extends DefaultVertexLabelRenderer {
|
||||||
|
private Color foregroundColor = Color.WHITE;
|
||||||
|
private Color backgroundColor = Color.BLACK;
|
||||||
|
|
||||||
CoreVertexLabelRenderer(Color pickedVertexLabelColor) {
|
CoreVertexLabelRenderer() {
|
||||||
super(pickedVertexLabelColor);
|
super(Color.YELLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColors(Color foregroundColor, Color backgroundColor) {
|
||||||
|
this.foregroundColor = foregroundColor;
|
||||||
|
this.backgroundColor = backgroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <V> Component getVertexLabelRendererComponent(JComponent vv, Object value, Font font, boolean isSelected, V vertex) {
|
public <V> Component getVertexLabelRendererComponent(JComponent vv, Object value, Font font, boolean isSelected, V vertex) {
|
||||||
super.setForeground(Color.WHITE);
|
super.setForeground(foregroundColor);
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
this.setForeground(this.pickedVertexLabelColor);
|
this.setForeground(this.pickedVertexLabelColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
super.setBackground(Color.BLACK);
|
super.setBackground(backgroundColor);
|
||||||
if (font != null) {
|
if (font != null) {
|
||||||
this.setFont(font);
|
this.setFont(font);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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.Configuration;
|
||||||
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;
|
||||||
|
@ -56,6 +57,7 @@ public class NetworkGraph {
|
||||||
private CorePopupGraphMousePlugin customPopupPlugin;
|
private CorePopupGraphMousePlugin customPopupPlugin;
|
||||||
private CoreAnnotatingGraphMousePlugin<CoreNode, CoreLink> customAnnotatingPlugin;
|
private CoreAnnotatingGraphMousePlugin<CoreNode, CoreLink> customAnnotatingPlugin;
|
||||||
private BackgroundPaintable<CoreNode, CoreLink> backgroundPaintable;
|
private BackgroundPaintable<CoreNode, CoreLink> backgroundPaintable;
|
||||||
|
private CoreVertexLabelRenderer nodeLabelRenderer = new CoreVertexLabelRenderer();
|
||||||
|
|
||||||
public NetworkGraph(Controller controller) {
|
public NetworkGraph(Controller controller) {
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
|
@ -70,7 +72,7 @@ public class NetworkGraph {
|
||||||
|
|
||||||
// node render properties
|
// node render properties
|
||||||
renderContext.setVertexLabelTransformer(CoreNode::getName);
|
renderContext.setVertexLabelTransformer(CoreNode::getName);
|
||||||
renderContext.setVertexLabelRenderer(new CoreVertexLabelRenderer(Color.YELLOW));
|
renderContext.setVertexLabelRenderer(nodeLabelRenderer);
|
||||||
renderContext.setVertexShapeTransformer(node -> {
|
renderContext.setVertexShapeTransformer(node -> {
|
||||||
double offset = -(IconUtils.ICON_SIZE / 2.0);
|
double offset = -(IconUtils.ICON_SIZE / 2.0);
|
||||||
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
|
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
|
||||||
|
@ -171,6 +173,18 @@ public class NetworkGraph {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Color convertJfxColor(String hexValue) {
|
||||||
|
javafx.scene.paint.Color color = javafx.scene.paint.Color.web(hexValue);
|
||||||
|
return new Color((float) color.getRed(), (float) color.getGreen(), (float) color.getBlue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePreferences(Configuration configuration) {
|
||||||
|
Color nodeLabelColor = convertJfxColor(configuration.getNodeLabelColor());
|
||||||
|
Color nodeLabelBackgroundColor = convertJfxColor(configuration.getNodeLabelBackgroundColor());
|
||||||
|
nodeLabelRenderer.setColors(nodeLabelColor, nodeLabelBackgroundColor);
|
||||||
|
graphViewer.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
public void setBackground(String imagePath) {
|
public void setBackground(String imagePath) {
|
||||||
try {
|
try {
|
||||||
backgroundPaintable = new BackgroundPaintable<>(imagePath, graphViewer);
|
backgroundPaintable = new BackgroundPaintable<>(imagePath, graphViewer);
|
||||||
|
|
|
@ -5,10 +5,12 @@ import com.core.ui.Toast;
|
||||||
import com.core.utils.ConfigUtils;
|
import com.core.utils.ConfigUtils;
|
||||||
import com.core.utils.Configuration;
|
import com.core.utils.Configuration;
|
||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.JFXButton;
|
||||||
|
import com.jfoenix.controls.JFXColorPicker;
|
||||||
import com.jfoenix.controls.JFXTextField;
|
import com.jfoenix.controls.JFXTextField;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@ -20,6 +22,8 @@ public class GuiPreferencesDialog extends StageDialog {
|
||||||
@FXML private JFXTextField mobilityFilePathTextField;
|
@FXML private JFXTextField mobilityFilePathTextField;
|
||||||
@FXML private JFXTextField shellCommandTextField;
|
@FXML private JFXTextField shellCommandTextField;
|
||||||
@FXML private JFXTextField iconPathTextField;
|
@FXML private JFXTextField iconPathTextField;
|
||||||
|
@FXML private JFXColorPicker nodeLabelColorPicker;
|
||||||
|
@FXML private JFXColorPicker nodeLabelBackgroundColorPicker;
|
||||||
@FXML private JFXButton saveButton;
|
@FXML private JFXButton saveButton;
|
||||||
|
|
||||||
public GuiPreferencesDialog(Controller controller) {
|
public GuiPreferencesDialog(Controller controller) {
|
||||||
|
@ -36,6 +40,9 @@ public class GuiPreferencesDialog extends StageDialog {
|
||||||
configuration.setMobilityPath(mobilityFilePathTextField.getText());
|
configuration.setMobilityPath(mobilityFilePathTextField.getText());
|
||||||
configuration.setShellCommand(shellCommandTextField.getText());
|
configuration.setShellCommand(shellCommandTextField.getText());
|
||||||
configuration.setIconPath(iconPathTextField.getText());
|
configuration.setIconPath(iconPathTextField.getText());
|
||||||
|
configuration.setNodeLabelColor(nodeLabelColorPicker.getValue().toString());
|
||||||
|
configuration.setNodeLabelBackgroundColor(nodeLabelBackgroundColorPicker.getValue().toString());
|
||||||
|
getController().getNetworkGraph().updatePreferences(configuration);
|
||||||
try {
|
try {
|
||||||
ConfigUtils.save(configuration);
|
ConfigUtils.save(configuration);
|
||||||
Toast.success("Updated preferences");
|
Toast.success("Updated preferences");
|
||||||
|
@ -51,6 +58,8 @@ public class GuiPreferencesDialog extends StageDialog {
|
||||||
mobilityFilePathTextField.setText(configuration.getMobilityPath());
|
mobilityFilePathTextField.setText(configuration.getMobilityPath());
|
||||||
shellCommandTextField.setText(configuration.getShellCommand());
|
shellCommandTextField.setText(configuration.getShellCommand());
|
||||||
iconPathTextField.setText(configuration.getIconPath());
|
iconPathTextField.setText(configuration.getIconPath());
|
||||||
|
nodeLabelColorPicker.setValue(Color.web(configuration.getNodeLabelColor()));
|
||||||
|
nodeLabelBackgroundColorPicker.setValue(Color.web(configuration.getNodeLabelBackgroundColor()));
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.core.utils;
|
package com.core.utils;
|
||||||
|
|
||||||
import com.core.data.NodeType;
|
import com.core.data.NodeType;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@ -59,13 +60,19 @@ public final class ConfigUtils {
|
||||||
return new NodeTypeConfig(model, display, iconPath.toUri().toString(), services);
|
return new NodeTypeConfig(model, display, iconPath.toUri().toString(), services);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkForHomeDirectory() throws IOException {
|
private static void checkDirectory(Path path) throws IOException {
|
||||||
if (!HOME.toFile().exists()) {
|
if (!path.toFile().exists()) {
|
||||||
logger.info("creating core home directory");
|
Files.createDirectory(path);
|
||||||
Files.createDirectory(HOME);
|
}
|
||||||
Files.createDirectory(XML_DIR);
|
}
|
||||||
Files.createDirectory(MOBILITY_DIR);
|
|
||||||
Files.createDirectory(ICON_DIR);
|
public static void checkHomeDirectory() throws IOException {
|
||||||
|
logger.info("checking core home directory");
|
||||||
|
checkDirectory(HOME);
|
||||||
|
checkDirectory(XML_DIR);
|
||||||
|
checkDirectory(MOBILITY_DIR);
|
||||||
|
checkDirectory(ICON_DIR);
|
||||||
|
if (!CONFIG_FILE.toFile().exists()) {
|
||||||
createDefaultConfigFile();
|
createDefaultConfigFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +85,8 @@ public final class ConfigUtils {
|
||||||
configuration.setMobilityPath(MOBILITY_DIR.toString());
|
configuration.setMobilityPath(MOBILITY_DIR.toString());
|
||||||
configuration.setIconPath(ICON_DIR.toString());
|
configuration.setIconPath(ICON_DIR.toString());
|
||||||
configuration.setNodeTypeConfigs(createDefaults());
|
configuration.setNodeTypeConfigs(createDefaults());
|
||||||
|
configuration.setNodeLabelColor(Color.WHITE.toString());
|
||||||
|
configuration.setNodeLabelBackgroundColor(Color.BLACK.toString());
|
||||||
save(configuration);
|
save(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,8 +112,8 @@ public final class ConfigUtils {
|
||||||
|
|
||||||
return configuration;
|
return configuration;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.error("error reading config file");
|
logger.error("error reading config file", ex);
|
||||||
throw new RuntimeException("configuration file did not exist");
|
throw new RuntimeException("configuration file did not exist", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,4 +15,6 @@ public class Configuration {
|
||||||
private String iconPath;
|
private String iconPath;
|
||||||
private String shellCommand;
|
private String shellCommand;
|
||||||
private List<NodeTypeConfig> nodeTypeConfigs = new ArrayList<>();
|
private List<NodeTypeConfig> nodeTypeConfigs = new ArrayList<>();
|
||||||
|
private String nodeLabelColor;
|
||||||
|
private String nodeLabelBackgroundColor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import com.jfoenix.controls.JFXColorPicker?>
|
||||||
<?import com.jfoenix.controls.JFXTextField?>
|
<?import com.jfoenix.controls.JFXTextField?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.control.TitledPane?>
|
<?import javafx.scene.control.TitledPane?>
|
||||||
|
@ -21,6 +22,18 @@
|
||||||
</VBox>
|
</VBox>
|
||||||
</content>
|
</content>
|
||||||
</TitledPane>
|
</TitledPane>
|
||||||
|
<TitledPane animated="false" collapsible="false" text="Graph">
|
||||||
|
<content>
|
||||||
|
<VBox spacing="10.0">
|
||||||
|
<children>
|
||||||
|
<Label text="Node Label" />
|
||||||
|
<JFXColorPicker fx:id="nodeLabelColorPicker" maxWidth="1.7976931348623157E308" />
|
||||||
|
<Label text="Node Label Background" />
|
||||||
|
<JFXColorPicker fx:id="nodeLabelBackgroundColorPicker" maxWidth="1.7976931348623157E308" />
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
|
</content>
|
||||||
|
</TitledPane>
|
||||||
<TitledPane animated="false" collapsible="false" text="Programs">
|
<TitledPane animated="false" collapsible="false" text="Programs">
|
||||||
<content>
|
<content>
|
||||||
<VBox spacing="10.0">
|
<VBox spacing="10.0">
|
||||||
|
|
Loading…
Add table
Reference in a new issue