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