Skip to content

Commit

Permalink
Merge pull request #78 from Asis2019/wip
Browse files Browse the repository at this point in the history
Wip
  • Loading branch information
Asis2019 authored Apr 21, 2021
2 parents aef1891 + 1e12246 commit 957a7d6
Show file tree
Hide file tree
Showing 23 changed files with 756 additions and 123 deletions.
71 changes: 23 additions & 48 deletions src/com/asis/controllers/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.asis.controllers.dialogs.DialogUnsavedChanges;
import com.asis.joi.JOIPackageManager;
import com.asis.joi.model.JOIPackage;
import com.asis.joi.model.entities.Group;
import com.asis.joi.model.entities.GroupBridge;
import com.asis.joi.model.entities.JOIComponent;
import com.asis.ui.InfinityPane;
import com.asis.ui.asis_node.node_functional_expansion.AddComponentNodeResolver;
Expand All @@ -19,12 +21,9 @@
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.MenuBar;
import javafx.scene.control.ToolBar;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
Expand All @@ -39,11 +38,10 @@

import static com.asis.controllers.dialogs.DialogUnsavedChanges.CHOICE_CANCEL;
import static com.asis.controllers.dialogs.DialogUnsavedChanges.CHOICE_SAVE;
import static com.asis.joi.model.entities.JOIComponent.NOT_GROUPED;

public class Controller extends EditorWindow {
private static Controller instance = null;
private boolean snapToGrid = false;
private boolean showThumbnail = false;

private final SelectionModel selectionModel = new SelectionModel();
private JOIPackage joiPackage;
Expand All @@ -52,10 +50,6 @@ public class Controller extends EditorWindow {
private InfinityPane infinityPane;
@FXML
public MenuBar mainMenuBar;
@FXML
public ToolBar toolBar;
@FXML
private Button gridToggle, thumbnailToggle;

@Override
public void initialize() {
Expand Down Expand Up @@ -128,7 +122,7 @@ public void actionOpenTranslationEditor() {
}

public void actionExit() {
Stage stage = (Stage) getInfinityPane().getScene().getWindow();
Stage stage = getStage();
stage.fireEvent(new WindowEvent(stage, WindowEvent.WINDOW_CLOSE_REQUEST));
}

Expand Down Expand Up @@ -198,12 +192,29 @@ public boolean processLoadProject() throws IOException {
resetEditorWindow();

//Create component nodes
for (JOIComponent component : getJoiPackage().getJoi().getJoiComponents())
for (JOIComponent component : getJoiPackage().getJoi().getJoiComponents()) {
if (component.getGroupId() != NOT_GROUPED) continue;
component.accept(new AddComponentNodeResolver(this));
}

//Create connections
for (JOIComponent component : getJoiPackage().getJoi().getJoiComponents())
for (JOIComponent component : getJoiPackage().getJoi().getJoiComponents()) {
if (component.getGroupId() != NOT_GROUPED) continue;
component.accept(new CreateComponentConnectionsResolver(this));
}

// Linkup groups to there bridges
for(JOIComponent component : Controller.getInstance().getJoiPackage().getJoi().getJoiComponents()) {
if(component instanceof GroupBridge) {
GroupBridge groupBridge = (GroupBridge) component;

int groupId = component.getGroupId();
Group group = (Group) Controller.getInstance().getJoiPackage().getJoi().getComponent(groupId);

if(groupBridge.isInputBridge()) group.setInputNodeData(groupBridge);
else group.setOutputNodeData(groupBridge);
}
}

//Loading completed successfully
return true;
Expand Down Expand Up @@ -270,34 +281,6 @@ public void actionAddSceneButton() {
getNodeManager().addScene(false);
}

public void actionToggleGrid() {
snapToGrid = !snapToGrid;
ImageView imageView;
if (snapToGrid)
imageView = new ImageView(new Image(getClass().getResourceAsStream("/resources/images/ic_grid_on.png")));
else
imageView = new ImageView(new Image(getClass().getResourceAsStream("/resources/images/ic_grid_off.png")));

imageView.setFitHeight(20);
imageView.setFitWidth(20);
gridToggle.setGraphic(imageView);
}

public void actionToggleThumbnail() {
showThumbnail = !showThumbnail;
ImageView imageView;
if (showThumbnail)
imageView = new ImageView(new Image(getClass().getResourceAsStream("/resources/images/ic_thumbnail_on.png")));
else
imageView = new ImageView(new Image(getClass().getResourceAsStream("/resources/images/ic_thumbnail_off.png")));

toggleSceneThumbnails(showThumbnail);

imageView.setFitHeight(20);
imageView.setFitWidth(20);
thumbnailToggle.setGraphic(imageView);
}

//Getters and setters
@Override
public InfinityPane getInfinityPane() {
Expand All @@ -312,14 +295,6 @@ public void setJoiPackage(JOIPackage joiPackage) {
this.joiPackage = joiPackage;
}

public boolean isSnapToGrid() {
return snapToGrid;
}

public boolean isShowThumbnail() {
return showThumbnail;
}

public SelectionModel getSelectionModel() {
return selectionModel;
}
Expand Down
68 changes: 63 additions & 5 deletions src/com/asis/controllers/EditorWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import com.asis.ui.InfinityPane;
import com.asis.ui.asis_node.*;
import com.asis.utilities.StageManager;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public abstract class EditorWindow {

Expand All @@ -17,6 +19,14 @@ public abstract class EditorWindow {
protected ComponentNodeManager nodeManager = new ComponentNodeManager(this);
protected ComponentConnectionManager connectionManager = new ComponentConnectionManager(this);

protected boolean snapToGrid = false;
protected boolean showThumbnail = false;

@FXML
public ToolBar toolBar;
@FXML
protected Button gridToggle, thumbnailToggle;

public void initialize() {
getInfinityPane().setUserData(this);
setupInfinityPaneContextMenu();
Expand All @@ -34,17 +44,19 @@ protected void resetEditorWindow() {
/**
* Creates and sets the context menu for the editor windows infinity pane.
*/
protected void setupInfinityPaneContextMenu() {
private void setupInfinityPaneContextMenu() {
//Create items and add them to there menu
MenuItem newSceneItem = new MenuItem("New Scene");
MenuItem newVariableSetterItem = new MenuItem("New Variable");
MenuItem newConditionItem = new MenuItem("New Condition");
MenuItem newArithmeticItem = new MenuItem("New Arithmetic");
SeparatorMenuItem separatorMenuItem = new SeparatorMenuItem();
MenuItem newNodeGroupItem = new MenuItem("New Node Group");
SeparatorMenuItem separatorMenuItem2 = new SeparatorMenuItem();

MenuItem reset_view = new MenuItem("Reset view");
editorWindowContextMenu.getItems().addAll(newSceneItem, newVariableSetterItem, newConditionItem,
newArithmeticItem, separatorMenuItem, reset_view);
newArithmeticItem, separatorMenuItem, newNodeGroupItem, separatorMenuItem2, reset_view);

//Handle menu actions
newSceneItem.setOnAction(event -> {
Expand All @@ -63,6 +75,10 @@ protected void setupInfinityPaneContextMenu() {
getNodeManager().calledFromContextMenu = true;
getNodeManager().addJOIComponentNode(ArithmeticNode.class, Arithmetic.class);
});
newNodeGroupItem.setOnAction(actionEvent -> {
getNodeManager().calledFromContextMenu = true;
getNodeManager().addGroup();
});
reset_view.setOnAction(actionEvent -> getInfinityPane().resetPosition());

getInfinityPane().setContextMenu(editorWindowContextMenu);
Expand All @@ -87,6 +103,36 @@ public void toggleSceneThumbnails(boolean showThumbnail) {
});
}

@FXML
protected void actionToggleGrid() {
snapToGrid = !snapToGrid;
ImageView imageView;
if (snapToGrid)
imageView = new ImageView(new Image(getClass().getResourceAsStream("/resources/images/ic_grid_on.png")));
else
imageView = new ImageView(new Image(getClass().getResourceAsStream("/resources/images/ic_grid_off.png")));

imageView.setFitHeight(20);
imageView.setFitWidth(20);
gridToggle.setGraphic(imageView);
}

@FXML
protected void actionToggleThumbnail() {
showThumbnail = !showThumbnail;
ImageView imageView;
if (showThumbnail)
imageView = new ImageView(new Image(getClass().getResourceAsStream("/resources/images/ic_thumbnail_on.png")));
else
imageView = new ImageView(new Image(getClass().getResourceAsStream("/resources/images/ic_thumbnail_off.png")));

toggleSceneThumbnails(showThumbnail);

imageView.setFitHeight(20);
imageView.setFitWidth(20);
thumbnailToggle.setGraphic(imageView);
}

/**
* Forces all editor windows to have an infinity pane implementation.
* @return InfinityPane - the editor window's infinity pane
Expand All @@ -100,4 +146,16 @@ public ComponentConnectionManager getConnectionManager() {
public ComponentNodeManager getNodeManager() {
return nodeManager;
}

protected Stage getStage() {
return (Stage) getInfinityPane().getScene().getWindow();
}

public boolean isSnapToGrid() {
return snapToGrid;
}

public boolean isShowThumbnail() {
return showThumbnail;
}
}
106 changes: 106 additions & 0 deletions src/com/asis/controllers/NodeGroupWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.asis.controllers;

import com.asis.controllers.dialogs.DialogMessage;
import com.asis.joi.model.entities.Group;
import com.asis.joi.model.entities.GroupBridge;
import com.asis.joi.model.entities.JOIComponent;
import com.asis.ui.InfinityPane;
import com.asis.ui.asis_node.node_functional_expansion.AddComponentNodeResolver;
import com.asis.ui.asis_node.node_functional_expansion.CreateComponentConnectionsResolver;
import com.asis.utilities.Config;
import com.asis.utilities.StageManager;
import javafx.fxml.FXML;
import javafx.scene.control.MenuBar;
import javafx.stage.Stage;
import org.json.JSONObject;

public class NodeGroupWindow extends EditorWindow {

private Group group;

@FXML
private InfinityPane infinityPane;
@FXML
public MenuBar mainMenuBar;

public void initialize(Group group) {
this.group = group;

try {
JSONObject object = (JSONObject) Config.get("ZOOM");
if (object.has("minimum")) getInfinityPane().setMinimumScale(object.getDouble("minimum"));
if (object.has("maximum")) getInfinityPane().setMaximumScale(object.getDouble("maximum"));
} catch (ClassCastException ignore) {
}

loadNodes();
}

private void loadNodes() {
try {
resetEditorWindow();

//Create the input/output bridging nodes if needed
loadGroupInternals();

//Create component nodes
for (JOIComponent component : Controller.getInstance().getJoiPackage().getJoi().getJoiComponents()) {
if (component.getGroupId() != getGroup().getComponentId()) continue;

component.accept(new AddComponentNodeResolver(this));
}

//Create connections
for (JOIComponent component : Controller.getInstance().getJoiPackage().getJoi().getJoiComponents()) {
if (component.getGroupId() != getGroup().getComponentId()) continue;

component.accept(new CreateComponentConnectionsResolver(this));
}

} catch (RuntimeException e) {
e.printStackTrace();
DialogMessage.messageDialog("LOADING FAILED", "The editor was unable to load this group for the following reason:\n" + e.getMessage(), 600, 200);
}
}

private void loadGroupInternals() {
if (getGroup().getInputNodeData() == null) {
final int componentId = Controller.getInstance().getJoiPackage().getJoi().getSceneIdCounter() + 1;

Controller.getInstance().getJoiPackage().getJoi().addNewComponent(GroupBridge.class, componentId);
GroupBridge groupBridge = (GroupBridge) Controller.getInstance().getJoiPackage().getJoi().getComponent(componentId);

groupBridge.setInputBridge(true);
groupBridge.setGroupId(getGroup().getComponentId());
getGroup().setInputNodeData(groupBridge);
}

if (getGroup().getOutputNodeData() == null) {
final int componentId = Controller.getInstance().getJoiPackage().getJoi().getSceneIdCounter() + 1;

Controller.getInstance().getJoiPackage().getJoi().addNewComponent(GroupBridge.class, componentId);
GroupBridge groupBridge = (GroupBridge) Controller.getInstance().getJoiPackage().getJoi().getComponent(componentId);

groupBridge.setLayoutXPosition(400);
groupBridge.setInputBridge(false);
groupBridge.setGroupId(getGroup().getComponentId());
getGroup().setOutputNodeData(groupBridge);
}
}

@FXML
private void actionClose() {
Stage stage = (Stage) getInfinityPane().getScene().getWindow();
StageManager.getInstance().closeStage(stage);
}

// Getters and setters
@Override
public InfinityPane getInfinityPane() {
return infinityPane;
}

public Group getGroup() {
return group;
}
}
Loading

0 comments on commit 957a7d6

Please sign in to comment.