initial basics for working with mobility scripts
This commit is contained in:
parent
1d73f28248
commit
2815554487
11 changed files with 182 additions and 33 deletions
|
@ -1,9 +1,13 @@
|
||||||
package com.core;
|
package com.core;
|
||||||
|
|
||||||
import com.core.client.ICoreClient;
|
import com.core.client.ICoreClient;
|
||||||
import com.core.client.rest.*;
|
import com.core.client.rest.ConfigOption;
|
||||||
|
import com.core.client.rest.CoreRestClient;
|
||||||
|
import com.core.client.rest.GetConfig;
|
||||||
|
import com.core.client.rest.SetConfig;
|
||||||
import com.core.data.CoreLink;
|
import com.core.data.CoreLink;
|
||||||
import com.core.data.CoreNode;
|
import com.core.data.CoreNode;
|
||||||
|
import com.core.data.MobilityConfig;
|
||||||
import com.core.graph.NetworkGraph;
|
import com.core.graph.NetworkGraph;
|
||||||
import com.core.ui.*;
|
import com.core.ui.*;
|
||||||
import com.core.utils.ConfigUtils;
|
import com.core.utils.ConfigUtils;
|
||||||
|
@ -16,6 +20,7 @@ import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -59,6 +64,7 @@ public class Controller implements Initializable {
|
||||||
private NodeDetails nodeDetails = new NodeDetails();
|
private NodeDetails nodeDetails = new NodeDetails();
|
||||||
private LinkDetails linkDetails = new LinkDetails(networkGraph);
|
private LinkDetails linkDetails = new LinkDetails(networkGraph);
|
||||||
private GraphToolbar graphToolbar = new GraphToolbar(this);
|
private GraphToolbar graphToolbar = new GraphToolbar(this);
|
||||||
|
private MobilityPlayer mobilityPlayer = new MobilityPlayer(this);
|
||||||
|
|
||||||
// dialogs
|
// dialogs
|
||||||
private SessionsDialog sessionsDialog = new SessionsDialog(this);
|
private SessionsDialog sessionsDialog = new SessionsDialog(this);
|
||||||
|
@ -96,6 +102,32 @@ public class Controller implements Initializable {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sessionStarted() {
|
||||||
|
// configure and add mobility player
|
||||||
|
VBox vBox = (VBox) borderPane.getTop();
|
||||||
|
CoreNode node = mobilityDialog.getNode();
|
||||||
|
if (node != null) {
|
||||||
|
MobilityConfig mobilityConfig = mobilityDialog.getMobilityScripts().get(node.getId());
|
||||||
|
if (mobilityConfig != null) {
|
||||||
|
mobilityPlayer.show(node, mobilityConfig);
|
||||||
|
vBox.getChildren().add(mobilityPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sessionStopped() {
|
||||||
|
VBox vBox = (VBox) borderPane.getTop();
|
||||||
|
vBox.getChildren().remove(mobilityPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteNode(CoreNode node) {
|
||||||
|
networkGraph.removeNode(node);
|
||||||
|
CoreNode mobilityNode = mobilityDialog.getNode();
|
||||||
|
if (mobilityNode != null && mobilityNode.getId().equals(node.getId())) {
|
||||||
|
mobilityDialog.setNode(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setWindow(Stage window) {
|
public void setWindow(Stage window) {
|
||||||
this.window = window;
|
this.window = window;
|
||||||
sessionsDialog.setOwner(window);
|
sessionsDialog.setOwner(window);
|
||||||
|
|
|
@ -350,6 +350,6 @@ public class CoreRestClient implements ICoreClient {
|
||||||
@Override
|
@Override
|
||||||
public boolean mobilityAction(CoreNode node, String action) throws IOException {
|
public boolean mobilityAction(CoreNode node, String action) throws IOException {
|
||||||
String url = getUrl(String.format("sessions/%s/nodes/%s/mobility/%s", sessionId, node.getId(), action));
|
String url = getUrl(String.format("sessions/%s/nodes/%s/mobility/%s", sessionId, node.getId(), action));
|
||||||
return WebUtils.putJson(url, null);
|
return WebUtils.putJson(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class CorePopupGraphMousePlugin<V, E> extends EditingPopupGraphMousePlugi
|
||||||
|
|
||||||
if (!isRunning) {
|
if (!isRunning) {
|
||||||
menuItems.add(createMenuItem("Delete Node",
|
menuItems.add(createMenuItem("Delete Node",
|
||||||
event -> networkGraph.removeNode(node)));
|
event -> controller.deleteNode(node)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return menuItems;
|
return menuItems;
|
||||||
|
|
|
@ -58,6 +58,7 @@ public class NetworkGraph {
|
||||||
private Set<NodeType> nodeTypes = new HashSet<>();
|
private Set<NodeType> nodeTypes = new HashSet<>();
|
||||||
private CorePopupGraphMousePlugin customPopupPlugin;
|
private CorePopupGraphMousePlugin customPopupPlugin;
|
||||||
private CoreAnnotatingGraphMousePlugin<CoreNode, CoreLink> customAnnotatingPlugin;
|
private CoreAnnotatingGraphMousePlugin<CoreNode, CoreLink> customAnnotatingPlugin;
|
||||||
|
private RadioIcon radioIcon = new RadioIcon();
|
||||||
|
|
||||||
public NetworkGraph(Controller controller) {
|
public NetworkGraph(Controller controller) {
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
|
@ -77,12 +78,13 @@ public class NetworkGraph {
|
||||||
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
|
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
|
||||||
});
|
});
|
||||||
renderContext.setVertexIconTransformer(vertex -> {
|
renderContext.setVertexIconTransformer(vertex -> {
|
||||||
LayeredIcon layeredIcon = IconUtils.getIcon(vertex.getIcon());
|
LayeredIcon icon = IconUtils.getIcon(vertex.getIcon());
|
||||||
if (hasWirelessLink(vertex)) {
|
if (hasWirelessLink(vertex)) {
|
||||||
RadioIcon radioIcon = new RadioIcon();
|
icon.add(radioIcon);
|
||||||
layeredIcon.add(radioIcon);
|
} else {
|
||||||
|
icon.remove(radioIcon);
|
||||||
}
|
}
|
||||||
return layeredIcon;
|
return icon;
|
||||||
});
|
});
|
||||||
|
|
||||||
// edge render properties
|
// edge render properties
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.core.ui;
|
package com.core.ui;
|
||||||
|
|
||||||
import com.core.Controller;
|
import com.core.Controller;
|
||||||
|
import com.core.data.CoreNode;
|
||||||
|
import com.core.data.MobilityConfig;
|
||||||
import com.core.data.NodeType;
|
import com.core.data.NodeType;
|
||||||
import com.core.data.SessionState;
|
import com.core.data.SessionState;
|
||||||
import com.core.utils.IconUtils;
|
import com.core.utils.IconUtils;
|
||||||
|
@ -252,6 +254,7 @@ public class GraphToolbar extends VBox {
|
||||||
|
|
||||||
boolean result = controller.getCoreClient().start();
|
boolean result = controller.getCoreClient().start();
|
||||||
if (result) {
|
if (result) {
|
||||||
|
controller.sessionStarted();
|
||||||
Toast.success("Session Started");
|
Toast.success("Session Started");
|
||||||
setRunButton(true);
|
setRunButton(true);
|
||||||
}
|
}
|
||||||
|
@ -266,6 +269,7 @@ public class GraphToolbar extends VBox {
|
||||||
try {
|
try {
|
||||||
boolean result = controller.getCoreClient().setState(SessionState.SHUTDOWN);
|
boolean result = controller.getCoreClient().setState(SessionState.SHUTDOWN);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
controller.sessionStopped();
|
||||||
Toast.success("Session Stopped");
|
Toast.success("Session Stopped");
|
||||||
setRunButton(false);
|
setRunButton(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,16 @@ import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
|
import lombok.Data;
|
||||||
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.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class MobilityDialog extends StageDialog {
|
public class MobilityDialog extends StageDialog {
|
||||||
private static final Logger logger = LogManager.getLogger();
|
private static final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
@ -43,6 +47,7 @@ public class MobilityDialog extends StageDialog {
|
||||||
@FXML
|
@FXML
|
||||||
private JFXTextField stopTextField;
|
private JFXTextField stopTextField;
|
||||||
|
|
||||||
|
private Map<Integer, MobilityConfig> mobilityScripts = new HashMap<>();
|
||||||
private CoreNode node;
|
private CoreNode node;
|
||||||
|
|
||||||
public MobilityDialog(Controller controller) {
|
public MobilityDialog(Controller controller) {
|
||||||
|
@ -65,9 +70,9 @@ public class MobilityDialog extends StageDialog {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
controller.getCoreClient().setMobilityConfig(node, mobilityConfig);
|
controller.getCoreClient().setMobilityConfig(node, mobilityConfig);
|
||||||
|
mobilityScripts.put(node.getId(), mobilityConfig);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.error("error setting mobility configuration", ex);
|
Toast.error("error setting mobility configuration", ex);
|
||||||
Toast.error("error setting mobility configuration");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close();
|
close();
|
||||||
|
@ -108,8 +113,7 @@ public class MobilityDialog extends StageDialog {
|
||||||
pauseTextField.setText(mobilityConfig.getPauseScript());
|
pauseTextField.setText(mobilityConfig.getPauseScript());
|
||||||
stopTextField.setText(mobilityConfig.getStopScript());
|
stopTextField.setText(mobilityConfig.getStopScript());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.error("error getting mobility config", ex);
|
Toast.error("error getting mobility config", ex);
|
||||||
Toast.error("error getting mobility config");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
show();
|
show();
|
||||||
|
|
65
corefx/src/main/java/com/core/ui/MobilityPlayer.java
Normal file
65
corefx/src/main/java/com/core/ui/MobilityPlayer.java
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
package com.core.ui;
|
||||||
|
|
||||||
|
import com.core.Controller;
|
||||||
|
import com.core.data.CoreNode;
|
||||||
|
import com.core.data.MobilityConfig;
|
||||||
|
import com.jfoenix.controls.JFXButton;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class MobilityPlayer extends HBox {
|
||||||
|
private static final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label label;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXButton playButton;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXButton pauseButton;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXButton stopButton;
|
||||||
|
|
||||||
|
private Controller controller;
|
||||||
|
private CoreNode node;
|
||||||
|
private MobilityConfig mobilityConfig;
|
||||||
|
|
||||||
|
public MobilityPlayer(Controller controller) {
|
||||||
|
this.controller = controller;
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/mobility_player.fxml"));
|
||||||
|
loader.setRoot(this);
|
||||||
|
loader.setController(this);
|
||||||
|
|
||||||
|
try {
|
||||||
|
loader.load();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
playButton.setOnAction(event -> action("start"));
|
||||||
|
pauseButton.setOnAction(event -> action("pause"));
|
||||||
|
stopButton.setOnAction(event -> action("stop"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void action(String action) {
|
||||||
|
try {
|
||||||
|
controller.getCoreClient().mobilityAction(node, action);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Toast.error(String.format("mobility error: %s", action), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void show(CoreNode node, MobilityConfig mobilityConfig) {
|
||||||
|
this.node = node;
|
||||||
|
this.mobilityConfig = mobilityConfig;
|
||||||
|
label.setText(String.format("%s - %s", node.getName(), mobilityConfig.getFile()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,6 +37,13 @@ public final class Toast {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void error(String message) {
|
public static void error(String message) {
|
||||||
|
error(message, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(String message, Exception ex) {
|
||||||
|
if (ex != null) {
|
||||||
|
logger.error(message, ex);
|
||||||
|
}
|
||||||
JFXSnackbar.SnackbarEvent snackbarEvent = new JFXSnackbar.SnackbarEvent(message,
|
JFXSnackbar.SnackbarEvent snackbarEvent = new JFXSnackbar.SnackbarEvent(message,
|
||||||
"toast-error", "X", TIMEOUT, true, event -> snackbar.close());
|
"toast-error", "X", TIMEOUT, true, event -> snackbar.close());
|
||||||
snackbar.enqueue(snackbarEvent);
|
snackbar.enqueue(snackbarEvent);
|
||||||
|
|
|
@ -98,6 +98,18 @@ public final class WebUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean putJson(String url) throws IOException {
|
||||||
|
logger.debug("put json: {}", url);
|
||||||
|
RequestBody body = new FormBody.Builder().build();
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.put(body)
|
||||||
|
.build();
|
||||||
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
return response.isSuccessful();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean putJson(String url, String json) throws IOException {
|
public static boolean putJson(String url, String json) throws IOException {
|
||||||
logger.debug("put json: {} - {}", url, json);
|
logger.debug("put json: {} - {}", url, json);
|
||||||
RequestBody body = RequestBody.create(JSON, json);
|
RequestBody body = RequestBody.create(JSON, json);
|
||||||
|
|
|
@ -7,35 +7,40 @@
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
<?import javafx.scene.layout.BorderPane?>
|
<?import javafx.scene.layout.BorderPane?>
|
||||||
<?import javafx.scene.layout.StackPane?>
|
<?import javafx.scene.layout.StackPane?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
<StackPane fx:id="stackPane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.core.Controller">
|
<StackPane fx:id="stackPane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.core.Controller">
|
||||||
<children>
|
<children>
|
||||||
<BorderPane fx:id="borderPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0">
|
<BorderPane fx:id="borderPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0">
|
||||||
<top>
|
<top>
|
||||||
<MenuBar BorderPane.alignment="CENTER">
|
<VBox BorderPane.alignment="CENTER">
|
||||||
<menus>
|
<children>
|
||||||
<Menu mnemonicParsing="false" text="File">
|
<MenuBar>
|
||||||
|
<menus>
|
||||||
|
<Menu mnemonicParsing="false" text="File">
|
||||||
|
<items>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#onOpenXmlAction" text="Open XML" />
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#onSaveXmlAction" text="Save XML" />
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
|
<Menu mnemonicParsing="false" text="Session">
|
||||||
<items>
|
<items>
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onOpenXmlAction" text="Open XML" />
|
<MenuItem mnemonicParsing="false" onAction="#onJoinSessionMenu" text="Join" />
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onSaveXmlAction" text="Save XML" />
|
<MenuItem mnemonicParsing="false" onAction="#onSessionHooksMenu" text="Hooks" />
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#onSessionOptionsMenu" text="Options" />
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu mnemonicParsing="false" text="Session">
|
<Menu mnemonicParsing="false" text="Help">
|
||||||
<items>
|
<items>
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onJoinSessionMenu" text="Join" />
|
<MenuItem mnemonicParsing="false" onAction="#onHelpMenuWebsite" text="CORE Website" />
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onSessionHooksMenu" text="Hooks" />
|
<MenuItem mnemonicParsing="false" onAction="#onHelpMenuDocumentation" text="CORE Documentation" />
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onSessionOptionsMenu" text="Options" />
|
<MenuItem mnemonicParsing="false" onAction="#onHelpMenuMailingList" text="CORE Mailing List" />
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu mnemonicParsing="false" text="Help">
|
</menus>
|
||||||
<items>
|
</MenuBar>
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onHelpMenuWebsite" text="CORE Website" />
|
</children>
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onHelpMenuDocumentation" text="CORE Documentation" />
|
</VBox>
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onHelpMenuMailingList" text="CORE Mailing List" />
|
|
||||||
</items>
|
|
||||||
</Menu>
|
|
||||||
</menus>
|
|
||||||
</MenuBar>
|
|
||||||
</top>
|
</top>
|
||||||
<center>
|
<center>
|
||||||
<AnchorPane>
|
<AnchorPane>
|
||||||
|
|
18
corefx/src/main/resources/fxml/mobility_player.fxml
Normal file
18
corefx/src/main/resources/fxml/mobility_player.fxml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import com.jfoenix.controls.JFXButton?>
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
|
||||||
|
<fx:root alignment="CENTER" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" spacing="10.0" type="HBox" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="label" maxHeight="1.7976931348623157E308" text="Label" />
|
||||||
|
<JFXButton fx:id="playButton" styleClass="core-button" text="Play" />
|
||||||
|
<JFXButton fx:id="pauseButton" styleClass="core-button" text="Pause" />
|
||||||
|
<JFXButton fx:id="stopButton" styleClass="core-button" text="Stop" />
|
||||||
|
</children>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||||
|
</padding>
|
||||||
|
</fx:root>
|
Loading…
Add table
Add a link
Reference in a new issue