From 1b6ef110b75c295400cec73b59174ec081939ebf Mon Sep 17 00:00:00 2001 From: Timothy Leatherbarrow Date: Wed, 10 Oct 2018 16:02:50 +0100 Subject: [PATCH] Public Release commit V1.0 + Color input / output links (No nodes use these yet, but the plan will be for these to control gradient colors + Added css styling to the code with a default skin. New skins planned with different colour schemes in future +Added proper file save / load dialogue ~Fixed a ton of bugs, and made the core node functionality feel way nicer (this took the most work :P) --- PrimaPlay/PrimaPlay.iml | 1 + .../prima/primaplay/core/FileManager.java | 41 ++++- .../prima/primaplay/core/Main.java | 3 +- .../prima/primaplay/core/RenderParams.java | 14 +- .../prima/primaplay/graphics/ColorTools.java | 18 +- .../primaplay/graphics/SimpleGradient.java | 1 - .../node/implemented/BasicRenderNode.java | 12 +- .../primaplay/node/implemented/ConstNode.java | 2 +- .../node/implemented/MapGenNode.java | 2 +- .../node/implemented/io/AnimationNode.java | 4 +- .../node/implemented/io/CombineNode.java | 3 +- .../node/implemented/io/DualAnimateNode.java | 2 +- .../node/implemented/io/GradientNode.java | 3 +- .../node/implemented/io/ImageConvertNode.java | 3 - .../node/implemented/io/ImageListNode.java | 14 +- .../node/implemented/io/KaliedoNode.java | 2 +- .../node/implemented/io/TransformNode.java | 2 +- .../io/iterative/IterativeNode.java | 4 +- .../implemented/io/iterative/MandelNode.java | 2 +- .../implemented/output/ImageLoadNode.java | 2 +- .../output/MultiImageLoadNode.java | 2 +- .../prima/primaplay/node/link/InputLink.java | 10 +- .../prima/primaplay/node/link/Link.java | 1 + .../node/link/type/ColorArrayInputLink.java | 12 ++ .../node/link/type/ColorArrayOutputLink.java | 4 + .../node/link/type/ColorInputLink.java | 34 ++++ .../node/link/type/ColorOutputLink.java | 18 ++ .../node/link/type/ImageArrayInputLink.java | 12 +- .../node/link/type/ImageArrayOutputLink.java | 5 + .../node/link/type/ImageInputLink.java | 13 +- .../node/link/type/ImageOutputLink.java | 6 +- .../node/link/type/NumberArrayInputLink.java | 15 ++ .../node/link/type/NumberArrayOutputLink.java | 5 + .../node/link/type/VectorArrayInputLink.java | 13 +- .../node/link/type/VectorArrayOutputLink.java | 7 +- .../node/link/type/VectorInputLink.java | 13 +- .../node/link/type/VectorOutputLink.java | 7 +- PrimaUtils/PrimaUtils.iml | 1 + PrimaUtils/pom.xml | 6 + .../utils/calculation/ReflectionHelper.java | 1 - .../utils/calculation/Vector2.java | 8 + PrimaView/PrimaView.iml | 2 +- .../src/main/java/guinode/GUIInputLink.java | 27 +-- PrimaView/src/main/java/guinode/GUILink.java | 10 +- .../src/main/java/guinode/GUILinkLine.java | 12 +- PrimaView/src/main/java/guinode/GUINode.java | 121 +++++++------ .../src/main/java/guinode/GUIOutputLink.java | 29 +--- .../src/main/java/sample/MainController.java | 78 ++++++--- PrimaView/src/main/java/sample/NodePane.java | 17 +- .../src/main/java/sample/NodeReflection.java | 1 - .../src/main/java/sample/NodeSerializer.java | 49 +++++- PrimaView/src/main/java/sample/ViewMain.java | 19 ++- PrimaView/src/main/resources/default.css | 55 +++++- PrimaView/src/main/resources/sample.fxml | 159 +++++++++--------- lib/Loki-1.9.0.jar | Bin 38794 -> 0 bytes saves/ManChop.prim | 16 ++ saves/ManChop2.prim | 24 +++ 57 files changed, 660 insertions(+), 287 deletions(-) create mode 100644 PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorInputLink.java create mode 100644 PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorOutputLink.java delete mode 100644 lib/Loki-1.9.0.jar create mode 100644 saves/ManChop.prim create mode 100644 saves/ManChop2.prim diff --git a/PrimaPlay/PrimaPlay.iml b/PrimaPlay/PrimaPlay.iml index 0b01ecf..59e5d32 100644 --- a/PrimaPlay/PrimaPlay.iml +++ b/PrimaPlay/PrimaPlay.iml @@ -11,5 +11,6 @@ + \ No newline at end of file diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/FileManager.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/FileManager.java index 2c9ec46..6b03b35 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/FileManager.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/FileManager.java @@ -1,15 +1,18 @@ package com.tiggerbiggo.prima.primaplay.core; -import com.tiggerbiggo.prima.primaplay.graphics.ImageTools; import com.tiggerbiggo.prima.primaplay.graphics.SafeImage; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileNotFoundException; import java.io.FilenameFilter; import java.io.IOException; import java.util.Arrays; import java.util.Comparator; import java.util.List; +import javafx.stage.FileChooser; +import javafx.stage.FileChooser.ExtensionFilter; +import javafx.stage.Stage; import javax.imageio.ImageIO; import javax.imageio.stream.FileImageOutputStream; import javax.imageio.stream.ImageOutputStream; @@ -173,6 +176,42 @@ public static SafeImage safeGetImg(String filepath){ return new SafeImage(1, 1); } } + + private static final FileChooser fileChooser = new FileChooser(); + + public static File showOpenDialogue() throws IOException { + return showOpenDialogue(null); + } + + public static File showOpenDialogue(Stage stage) throws IOException { + new File("saves/").createNewFile(); + fileChooser.getExtensionFilters().clear(); + fileChooser.getExtensionFilters().add(new ExtensionFilter("Prima layout file", "*.prim")); + fileChooser.setTitle("Load"); + fileChooser.setInitialDirectory(new File("saves/")); + File file = fileChooser.showOpenDialog(stage); + if(file != null){ + return file; + } + throw new FileNotFoundException("User cancelled input, or file path invalid."); + } + + public static File showSaveDialogue() throws IOException{ + return showSaveDialogue(null); + } + + public static File showSaveDialogue(Stage stage) throws IOException { + new File("saves/").createNewFile(); + fileChooser.getExtensionFilters().clear(); + fileChooser.getExtensionFilters().add(new ExtensionFilter("Prima layout file", "*.prim")); + fileChooser.setTitle("Save"); + fileChooser.setInitialDirectory(new File("saves/")); + File file = fileChooser.showSaveDialog(stage); + if (file != null) { + return file; + } + throw new FileNotFoundException("User cancelled input, or file path invalid."); + } } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/Main.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/Main.java index da3aa9d..8b9dfb9 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/Main.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/Main.java @@ -1,8 +1,6 @@ package com.tiggerbiggo.prima.primaplay.core; -import com.tiggerbiggo.prima.primaplay.graphics.ImageTools; import com.tiggerbiggo.prima.primaplay.graphics.SafeImage; -import com.tiggerbiggo.utils.calculation.Vector2; import com.tiggerbiggo.prima.primaplay.graphics.SimpleGradient; import com.tiggerbiggo.prima.primaplay.node.core.INodeHasInput; import com.tiggerbiggo.prima.primaplay.node.core.INodeHasOutput; @@ -10,6 +8,7 @@ import com.tiggerbiggo.prima.primaplay.node.implemented.MapGenNode; import com.tiggerbiggo.prima.primaplay.node.implemented.io.AnimationNode; import com.tiggerbiggo.prima.primaplay.node.implemented.io.GradientNode; +import com.tiggerbiggo.utils.calculation.Vector2; import java.awt.Color; public class Main { diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/RenderParams.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/RenderParams.java index 5f9ad6d..71ee5ad 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/RenderParams.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/core/RenderParams.java @@ -2,14 +2,14 @@ public class RenderParams { - private int width, height, x, y, n; + private int width, height, x, y, frameNum; - public RenderParams(int width, int height, int x, int y, int n) { + public RenderParams(int width, int height, int x, int y, int frameNum) { this.width = width; this.height = height; this.x = x; this.y = y; - this.n = n; + this.frameNum = frameNum; } public int width() { @@ -29,7 +29,7 @@ public int y() { } public int frameNum() { - return n; + return frameNum; } public void setWidth(int width) { @@ -48,12 +48,12 @@ public void setY(int y) { this.y = y; } - public void setN(int n) { - this.n = n; + public void setFrameNum(int frameNum) { + this.frameNum = frameNum; } @Override public RenderParams clone() { - return new RenderParams(width, height, x, y, n); + return new RenderParams(width, height, x, y, frameNum); } } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/graphics/ColorTools.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/graphics/ColorTools.java index 1ead61a..0b625cf 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/graphics/ColorTools.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/graphics/ColorTools.java @@ -2,7 +2,6 @@ import com.tiggerbiggo.utils.calculation.Calculation; import java.awt.Color; -import java.util.function.Function; /** * Contains various static methods for calculating things like Hue, Saturation, Brightness, etc. @@ -150,6 +149,23 @@ public static Color multiply(Color in, double toMul){ Math.min(255, Math.max((int)(in.getBlue() * toMul), 0)) ); } + + /**Generates an array of Color.BLACK with length n + * + * @param n + * @return + * @throws ArrayIndexOutOfBoundsException if n < 0 + */ + public static Color[] blankArray(int n) throws ArrayIndexOutOfBoundsException{ + if(n < 0){ + throw new ArrayIndexOutOfBoundsException("Error in ColorTools.blankArray: Number given was < 0, n: " + n); + } + Color[] toReturn = new Color[n]; + for (int i=0 ;i extends Link{ protected OutputLink currentLink; @@ -15,12 +11,14 @@ public void unlink() { currentLink = null; } - public T get(RenderParams p) throws NotLinkedException { + public T get(RenderParams p){ if (currentLink == null) { - throw new NotLinkedException("InputLink: " + this.getClass().getName()); + return defaultValue(p); } return currentLink.get(p); } + public abstract T defaultValue(RenderParams p); + } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/Link.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/Link.java index a4bb0b5..f92137b 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/Link.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/Link.java @@ -2,4 +2,5 @@ public abstract class Link { public abstract boolean canLink(Link other); + public abstract String getStyleClass(); } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorArrayInputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorArrayInputLink.java index 4d365c2..c486e54 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorArrayInputLink.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorArrayInputLink.java @@ -1,5 +1,7 @@ package com.tiggerbiggo.prima.primaplay.node.link.type; +import com.tiggerbiggo.prima.primaplay.core.RenderParams; +import com.tiggerbiggo.prima.primaplay.graphics.ColorTools; import com.tiggerbiggo.prima.primaplay.node.link.InputLink; import com.tiggerbiggo.prima.primaplay.node.link.Link; import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; @@ -16,9 +18,19 @@ public boolean link(OutputLink toLink) { return false; } + @Override + public Color[] defaultValue(RenderParams p) { + return ColorTools.blankArray(p.frameNum()); + } + @Override public boolean canLink(Link other) { if(other == null) return false; return other instanceof ColorArrayOutputLink; } + + @Override + public String getStyleClass() { + return "ColorArrayLink"; + } } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorArrayOutputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorArrayOutputLink.java index 8bf5c3a..aab1c62 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorArrayOutputLink.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorArrayOutputLink.java @@ -10,4 +10,8 @@ public boolean canLink(Link other) { if(other == null) return false; return other instanceof ColorArrayInputLink; } + @Override + public String getStyleClass() { + return "ColorArrayLink"; + } } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorInputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorInputLink.java new file mode 100644 index 0000000..ff28e10 --- /dev/null +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorInputLink.java @@ -0,0 +1,34 @@ +package com.tiggerbiggo.prima.primaplay.node.link.type; + +import com.tiggerbiggo.prima.primaplay.core.RenderParams; +import com.tiggerbiggo.prima.primaplay.node.link.InputLink; +import com.tiggerbiggo.prima.primaplay.node.link.Link; +import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; +import java.awt.Color; + +public class ColorInputLink extends InputLink { + + @Override + public boolean link(OutputLink toLink) { + if (canLink(toLink)) { + currentLink = (ColorOutputLink) toLink; + return true; + } + return false; + } + + @Override + public Color defaultValue(RenderParams p) { + return Color.BLACK; + } + + @Override + public boolean canLink(Link other) { + if(other == null) return false; + return other instanceof ColorArrayOutputLink; + } + @Override + public String getStyleClass() { + return "ColorLink"; + } +} diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorOutputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorOutputLink.java new file mode 100644 index 0000000..c4e31c1 --- /dev/null +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ColorOutputLink.java @@ -0,0 +1,18 @@ +package com.tiggerbiggo.prima.primaplay.node.link.type; + +import com.tiggerbiggo.prima.primaplay.node.link.Link; +import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; +import java.awt.Color; + +public abstract class ColorOutputLink extends OutputLink { + @Override + public boolean canLink(Link other) { + if(other == null) return false; + return other instanceof ColorInputLink; + } + + @Override + public String getStyleClass() { + return "ColorLink"; + } +} diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageArrayInputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageArrayInputLink.java index be709f1..b44d51b 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageArrayInputLink.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageArrayInputLink.java @@ -1,10 +1,11 @@ package com.tiggerbiggo.prima.primaplay.node.link.type; +import com.tiggerbiggo.prima.primaplay.core.RenderParams; +import com.tiggerbiggo.prima.primaplay.graphics.ImageTools; import com.tiggerbiggo.prima.primaplay.graphics.SafeImage; import com.tiggerbiggo.prima.primaplay.node.link.InputLink; import com.tiggerbiggo.prima.primaplay.node.link.Link; import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; -import java.awt.Color; public class ImageArrayInputLink extends InputLink { @@ -17,8 +18,17 @@ public boolean link(OutputLink toLink) { return false; } + @Override + public SafeImage[] defaultValue(RenderParams p) { + return ImageTools.blankArray(); + } + @Override public boolean canLink(Link other) { return other != null && other instanceof ImageArrayOutputLink; } + @Override + public String getStyleClass() { + return "ImageArrayLink"; + } } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageArrayOutputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageArrayOutputLink.java index 3bd9a24..542e54f 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageArrayOutputLink.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageArrayOutputLink.java @@ -10,4 +10,9 @@ public abstract class ImageArrayOutputLink extends OutputLink{ public boolean canLink(Link other) { return other != null && other instanceof ImageArrayInputLink; } + + @Override + public String getStyleClass() { + return "ImageArrayLink"; + } } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageInputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageInputLink.java index fb86968..c0ea502 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageInputLink.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageInputLink.java @@ -1,10 +1,11 @@ package com.tiggerbiggo.prima.primaplay.node.link.type; +import com.tiggerbiggo.prima.primaplay.core.RenderParams; +import com.tiggerbiggo.prima.primaplay.graphics.ImageTools; import com.tiggerbiggo.prima.primaplay.graphics.SafeImage; import com.tiggerbiggo.prima.primaplay.node.link.InputLink; import com.tiggerbiggo.prima.primaplay.node.link.Link; import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; -import java.awt.Color; public class ImageInputLink extends InputLink { @@ -17,8 +18,18 @@ public boolean link(OutputLink toLink) { return false; } + @Override + public SafeImage defaultValue(RenderParams p) { + return ImageTools.blankImage(); + } + @Override public boolean canLink(Link other) { return other != null && other instanceof ImageOutputLink; } + + @Override + public String getStyleClass() { + return "ImageLink"; + } } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageOutputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageOutputLink.java index c068b19..75c8109 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageOutputLink.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/ImageOutputLink.java @@ -5,9 +5,13 @@ import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; public abstract class ImageOutputLink extends OutputLink{ - @Override public boolean canLink(Link other) { return other != null && other instanceof ImageInputLink; } + + @Override + public String getStyleClass() { + return "ImageLink"; + } } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/NumberArrayInputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/NumberArrayInputLink.java index 49e113e..b35c064 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/NumberArrayInputLink.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/NumberArrayInputLink.java @@ -1,5 +1,6 @@ package com.tiggerbiggo.prima.primaplay.node.link.type; +import com.tiggerbiggo.prima.primaplay.core.RenderParams; import com.tiggerbiggo.prima.primaplay.node.link.InputLink; import com.tiggerbiggo.prima.primaplay.node.link.Link; import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; @@ -19,4 +20,18 @@ public boolean canLink(Link other) { if(other == null) return false; return other instanceof NumberArrayOutputLink; } + + @Override + public Double[] defaultValue(RenderParams p) { + Double[] toReturn = new Double[p.frameNum()]; + for(int i=0; i { @@ -21,6 +22,16 @@ public boolean canLink(Link other) { if(other == null) return false; return other instanceof VectorArrayOutputLink; } + + @Override + public Vector2[] defaultValue(RenderParams p) { + return Vector2.blankArray(p.frameNum()); + } + + @Override + public String getStyleClass() { + return "VectorArrayLink"; + } } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorArrayOutputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorArrayOutputLink.java index 2b04bc9..2ffd1c5 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorArrayOutputLink.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorArrayOutputLink.java @@ -1,8 +1,8 @@ package com.tiggerbiggo.prima.primaplay.node.link.type; -import com.tiggerbiggo.utils.calculation.Vector2; import com.tiggerbiggo.prima.primaplay.node.link.Link; import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; +import com.tiggerbiggo.utils.calculation.Vector2; public abstract class VectorArrayOutputLink extends OutputLink { @Override @@ -10,4 +10,9 @@ public boolean canLink(Link other) { if(other == null) return false; return other instanceof VectorArrayInputLink; } + + @Override + public String getStyleClass() { + return "VectorArrayLink"; + } } \ No newline at end of file diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorInputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorInputLink.java index acbbb55..2501779 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorInputLink.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorInputLink.java @@ -1,9 +1,10 @@ package com.tiggerbiggo.prima.primaplay.node.link.type; -import com.tiggerbiggo.utils.calculation.Vector2; +import com.tiggerbiggo.prima.primaplay.core.RenderParams; import com.tiggerbiggo.prima.primaplay.node.link.InputLink; import com.tiggerbiggo.prima.primaplay.node.link.Link; import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; +import com.tiggerbiggo.utils.calculation.Vector2; public class VectorInputLink extends InputLink { @@ -21,5 +22,15 @@ public boolean canLink(Link other) { if(other == null) return false; return other instanceof VectorOutputLink; } + + @Override + public Vector2 defaultValue(RenderParams p) { + return Vector2.ZERO; + } + + @Override + public String getStyleClass() { + return "VectorLink"; + } } diff --git a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorOutputLink.java b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorOutputLink.java index 374669e..d866e68 100644 --- a/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorOutputLink.java +++ b/PrimaPlay/src/main/java/com/tiggerbiggo/prima/primaplay/node/link/type/VectorOutputLink.java @@ -1,8 +1,8 @@ package com.tiggerbiggo.prima.primaplay.node.link.type; -import com.tiggerbiggo.utils.calculation.Vector2; import com.tiggerbiggo.prima.primaplay.node.link.Link; import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; +import com.tiggerbiggo.utils.calculation.Vector2; public abstract class VectorOutputLink extends OutputLink { @Override @@ -10,4 +10,9 @@ public boolean canLink(Link other) { if(other == null) return false; return other instanceof VectorInputLink; } + + @Override + public String getStyleClass() { + return "VectorLink"; + } } \ No newline at end of file diff --git a/PrimaUtils/PrimaUtils.iml b/PrimaUtils/PrimaUtils.iml index 8611f6a..d8a6a84 100644 --- a/PrimaUtils/PrimaUtils.iml +++ b/PrimaUtils/PrimaUtils.iml @@ -10,5 +10,6 @@ + \ No newline at end of file diff --git a/PrimaUtils/pom.xml b/PrimaUtils/pom.xml index 5264b64..ce8267c 100644 --- a/PrimaUtils/pom.xml +++ b/PrimaUtils/pom.xml @@ -41,5 +41,11 @@ Loki v1.9.0-SNAPSHOT --> + + + com.github.tiggerbiggo + loki + d09238dfeb + \ No newline at end of file diff --git a/PrimaUtils/src/main/java/com/tiggerbiggo/utils/calculation/ReflectionHelper.java b/PrimaUtils/src/main/java/com/tiggerbiggo/utils/calculation/ReflectionHelper.java index c29001c..e96e52c 100644 --- a/PrimaUtils/src/main/java/com/tiggerbiggo/utils/calculation/ReflectionHelper.java +++ b/PrimaUtils/src/main/java/com/tiggerbiggo/utils/calculation/ReflectionHelper.java @@ -1,7 +1,6 @@ package com.tiggerbiggo.utils.calculation; import java.lang.reflect.Field; -import java.util.Objects; public class ReflectionHelper { diff --git a/PrimaUtils/src/main/java/com/tiggerbiggo/utils/calculation/Vector2.java b/PrimaUtils/src/main/java/com/tiggerbiggo/utils/calculation/Vector2.java index 6aae23f..240b79e 100644 --- a/PrimaUtils/src/main/java/com/tiggerbiggo/utils/calculation/Vector2.java +++ b/PrimaUtils/src/main/java/com/tiggerbiggo/utils/calculation/Vector2.java @@ -352,6 +352,14 @@ public boolean equals(Object o) { Double.compare(vector2.y, y) == 0; } + public static Vector2[] blankArray(int n){ + Vector2[] toReturn = new Vector2[n]; + for(int i=0; i - + diff --git a/PrimaView/src/main/java/guinode/GUIInputLink.java b/PrimaView/src/main/java/guinode/GUIInputLink.java index e9369b6..7a1f52e 100644 --- a/PrimaView/src/main/java/guinode/GUIInputLink.java +++ b/PrimaView/src/main/java/guinode/GUIInputLink.java @@ -1,16 +1,7 @@ package guinode; -import com.tiggerbiggo.prima.primaplay.node.link.type.ImageArrayInputLink; -import com.tiggerbiggo.prima.primaplay.node.link.type.ImageInputLink; -import com.tiggerbiggo.utils.calculation.Vector2; import com.tiggerbiggo.prima.primaplay.node.link.InputLink; -import com.tiggerbiggo.prima.primaplay.node.link.type.ColorArrayInputLink; -import com.tiggerbiggo.prima.primaplay.node.link.type.NumberArrayInputLink; -import com.tiggerbiggo.prima.primaplay.node.link.type.VectorArrayInputLink; -import com.tiggerbiggo.prima.primaplay.node.link.type.VectorInputLink; import java.util.Objects; -import javafx.scene.layout.Pane; -import javafx.scene.paint.Color; public class GUIInputLink extends GUILink { @@ -21,27 +12,15 @@ public class GUIInputLink extends GUILink { private int index; public GUIInputLink(InputLink in, GUINode owner, int index, double yOffset) { + super(); + link = in; this.owner = Objects.requireNonNull(owner); this.index = index; setCenterY(yOffset); - if (link instanceof ColorArrayInputLink) { - setFill(Color.YELLOW); - } else if (link instanceof NumberArrayInputLink) { - setFill(Color.GREY); - } else if (link instanceof VectorArrayInputLink) { - setFill(Color.BLUE); - } else if (link instanceof VectorInputLink) { - setFill(Color.AQUA); - } else if (link instanceof ImageInputLink) { - setFill(Color.GREEN); - } else if (link instanceof ImageArrayInputLink) { - setFill(Color.DARKGREEN); - } else { - System.out.println("ERR: " + link); - } + getStyleClass().addAll("GUILink", link.getStyleClass()); setOnDragDropped(event -> { GUIOutputLink source; diff --git a/PrimaView/src/main/java/guinode/GUILink.java b/PrimaView/src/main/java/guinode/GUILink.java index 03f1eda..979cfe7 100644 --- a/PrimaView/src/main/java/guinode/GUILink.java +++ b/PrimaView/src/main/java/guinode/GUILink.java @@ -1,6 +1,7 @@ package guinode; import com.tiggerbiggo.utils.calculation.Vector2; +import javafx.event.Event; import javafx.geometry.Bounds; import javafx.scene.effect.Bloom; import javafx.scene.input.ClipboardContent; @@ -8,7 +9,6 @@ import javafx.scene.input.MouseButton; import javafx.scene.input.TransferMode; import javafx.scene.shape.Circle; -import javafx.scene.transform.Transform; public abstract class GUILink extends Circle { @@ -17,6 +17,7 @@ public abstract class GUILink extends Circle { public GUILink() { //extends Circle super(10); + getStyleClass().add("GUILink"); last = Vector2.ZERO; setOnDragDetected(event -> { @@ -35,12 +36,17 @@ public GUILink() { //extends Circle setOnDragOver(event -> event.acceptTransferModes(TransferMode.MOVE)); - setOnMouseClicked(event -> { + setOnMouseDragged(Event::consume); + + setOnMousePressed(event -> { if (event.getButton().equals(MouseButton.SECONDARY)) { triggerUnlink(); } + System.out.println("Clicked"); + event.consume(); }); setManaged(false); + toFront(); } public abstract void unlink(); diff --git a/PrimaView/src/main/java/guinode/GUILinkLine.java b/PrimaView/src/main/java/guinode/GUILinkLine.java index 2866dcf..0587adb 100644 --- a/PrimaView/src/main/java/guinode/GUILinkLine.java +++ b/PrimaView/src/main/java/guinode/GUILinkLine.java @@ -1,11 +1,8 @@ package guinode; -import com.tiggerbiggo.utils.calculation.Vector2; import java.util.Objects; import javafx.beans.binding.Bindings; import javafx.beans.binding.DoubleBinding; -import javafx.geometry.Bounds; -import javafx.scene.paint.Color; import javafx.scene.shape.CubicCurve; public class GUILinkLine extends CubicCurve { @@ -22,10 +19,11 @@ public GUILinkLine(GUIInputLink _input, GUIOutputLink _output) { output.addLine(this); input.setLine(this); - setStroke(Color.BLACK); - setFill(Color.TRANSPARENT); + + getStyleClass().add("LinkLine"); setManaged(false); + setMouseTransparent(true); doBindings(); } @@ -38,7 +36,7 @@ private void doBindings(){ output.getCenterX(), output.getCenterY() ) - ).getX(), + ).getX() + output.getRadius(), output.getOwner().layoutXProperty(), input.getOwner().layoutXProperty(), output.centerXProperty()); @@ -61,7 +59,7 @@ private void doBindings(){ input.getCenterX(), input.getCenterY() ) - ).getX(); + ).getX() - input.getRadius(); }, input.getOwner().layoutXProperty(), output.getOwner().layoutXProperty(), diff --git a/PrimaView/src/main/java/guinode/GUINode.java b/PrimaView/src/main/java/guinode/GUINode.java index 495a44e..af99553 100644 --- a/PrimaView/src/main/java/guinode/GUINode.java +++ b/PrimaView/src/main/java/guinode/GUINode.java @@ -2,23 +2,22 @@ import ch.hephaistos.utilities.loki.ReflectorGrid; import ch.hephaistos.utilities.loki.util.interfaces.ChangeListener; -import com.tiggerbiggo.prima.primaplay.node.implemented.BasicRenderNode; -import com.tiggerbiggo.utils.calculation.Vector2; import com.tiggerbiggo.prima.primaplay.node.core.INode; import com.tiggerbiggo.prima.primaplay.node.core.INodeHasInput; import com.tiggerbiggo.prima.primaplay.node.core.INodeHasOutput; +import com.tiggerbiggo.prima.primaplay.node.implemented.BasicRenderNode; import com.tiggerbiggo.prima.primaplay.node.link.InputLink; import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; +import com.tiggerbiggo.utils.calculation.Vector2; import java.util.ArrayList; import java.util.List; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; -import javafx.scene.layout.Pane; -import javafx.scene.text.Text; +import sample.NodePane; public class GUINode extends AnchorPane { @@ -32,13 +31,17 @@ public class GUINode extends AnchorPane { private double offsetX, offsetY; - public GUINode(int width, int height, int x, int y, INode node, Pane parent, ChangeListener listener) { + private NodePane parent; + + public GUINode(int width, int height, int x, int y, INode node, NodePane _parent, ChangeListener listener) { //super(); //setHeight(50); //setWidth(50); //setFill(Color.WHITE); + parent = _parent; + this.node = node; setMinWidth(width); @@ -46,25 +49,60 @@ public GUINode(int width, int height, int x, int y, INode node, Pane parent, Cha setMinHeight(height); setHeight(height); - setStyle("-fx-background-color: #888888"); + this.getStyleClass().add("GUINode"); setLayoutX(x); setLayoutY(y); + addEventHandler(MouseEvent.ANY, event -> { + if(event.getButton() != MouseButton.MIDDLE) event.consume(); + }); - setOnMousePressed(new EventHandler() { - @Override - public void handle(MouseEvent event) { - offsetX = getLayoutX() - event.getSceneX(); - offsetY = getLayoutY() - event.getSceneY(); - } + setOnMousePressed(event -> { + if(event.getButton() != MouseButton.PRIMARY) + return; + + offsetX = getLayoutX() - event.getSceneX(); + offsetY = getLayoutY() - event.getSceneY(); + System.out.println("Other Clicked"); + event.consume(); }); setOnMouseDragged(e -> { - setLayoutX(e.getSceneX() + offsetX); - setLayoutY(e.getSceneY() + offsetY); + if(e.getButton() != MouseButton.PRIMARY) + return; + if(e.getSceneX() + offsetX >= 0) + setLayoutX(e.getSceneX() + offsetX); + else + setLayoutX(0); + + if(e.getSceneY() + offsetY >= 0) + setLayoutY(e.getSceneY() + offsetY); + else + setLayoutY(0); + e.consume(); }); if (node != null) { + reflectorGrid = new ReflectorGrid(); + reflectorGrid.transfromIntoGrid(node); + + if(node instanceof ChangeListener){ + reflectorGrid.addChangeListener((ChangeListener)node); + } + + if(listener != null){ + reflectorGrid.addChangeListener(listener); + } + + GridPane layoutGrid = new GridPane(); + + setTopAnchor(layoutGrid, 0.0); + setLeftAnchor(layoutGrid, 0.0); + setBottomAnchor(layoutGrid, 0.0); + setRightAnchor(layoutGrid, 0.0); + + getChildren().add(layoutGrid); + inputs = new ArrayList<>(); if (node instanceof INodeHasInput) { InputLink[] inputs = ((INodeHasInput) node).getInputs(); @@ -89,44 +127,25 @@ public void handle(MouseEvent event) { } } - reflectorGrid = new ReflectorGrid(); - reflectorGrid.transfromIntoGrid(node); - - if(node instanceof ChangeListener){ - reflectorGrid.addChangeListener((ChangeListener)node); - } - - if(listener != null){ - reflectorGrid.addChangeListener(listener); - } - - GridPane layoutGrid = new GridPane(); - - setTopAnchor(layoutGrid, 0.0); - setLeftAnchor(layoutGrid, 0.0); - setBottomAnchor(layoutGrid, 0.0); - setRightAnchor(layoutGrid, 0.0); - - getChildren().add(layoutGrid); GUINode thisNode = this; Button delete = new Button("Delete"); - delete.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - for (GUIInputLink i : inputs) { - i.unlink(); - } - getChildren().removeAll(inputs); - getChildren().removeAll(outputs); - parent.getChildren().remove(thisNode); + delete.setOnAction(event -> { + for (GUIInputLink i : inputs) { + i.triggerUnlink(); } + for(GUIOutputLink o : outputs){ + o.triggerUnlink(); + } + getChildren().removeAll(inputs); + getChildren().removeAll(outputs); + parent.deleteNode(thisNode); }); if (!(node instanceof BasicRenderNode)) { - layoutGrid.addColumn(0, new Text(node.getName()), reflectorGrid, delete); + layoutGrid.addColumn(0, new Label(node.getName()), reflectorGrid, delete); } else { - layoutGrid.addColumn(0, new Text(node.getName()), reflectorGrid); + layoutGrid.addColumn(0, new Label(node.getName()), reflectorGrid); } toBack(); @@ -140,15 +159,15 @@ public void refreshGrid(){ reflectorGrid.redoGrid(); } - public GUINode(int x, int y, INode node, Pane parent, ChangeListener listener){ + public GUINode(int x, int y, INode node, NodePane parent, ChangeListener listener){ this(50, 50, x, y, node, parent, listener); } - public GUINode(INode node, Pane parent, ChangeListener listener){ + public GUINode(INode node, NodePane parent, ChangeListener listener){ this(0, 0, node, parent, listener); } - public GUINode(INode node, Pane parent) { + public GUINode(INode node, NodePane parent) { this(node, parent, null); } @@ -167,4 +186,8 @@ public List getOutputs() { public INode getNode() { return node; } + + public NodePane getParentPane() { + return parent; + } } diff --git a/PrimaView/src/main/java/guinode/GUIOutputLink.java b/PrimaView/src/main/java/guinode/GUIOutputLink.java index ddbda43..9d1e84f 100644 --- a/PrimaView/src/main/java/guinode/GUIOutputLink.java +++ b/PrimaView/src/main/java/guinode/GUIOutputLink.java @@ -1,18 +1,9 @@ package guinode; -import com.tiggerbiggo.prima.primaplay.node.link.type.ImageArrayOutputLink; -import com.tiggerbiggo.prima.primaplay.node.link.type.ImageOutputLink; -import com.tiggerbiggo.utils.calculation.Vector2; import com.tiggerbiggo.prima.primaplay.node.link.OutputLink; -import com.tiggerbiggo.prima.primaplay.node.link.type.ColorArrayOutputLink; -import com.tiggerbiggo.prima.primaplay.node.link.type.NumberArrayOutputLink; -import com.tiggerbiggo.prima.primaplay.node.link.type.VectorArrayOutputLink; -import com.tiggerbiggo.prima.primaplay.node.link.type.VectorOutputLink; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import javafx.scene.layout.Pane; -import javafx.scene.paint.Color; public class GUIOutputLink extends GUILink { @@ -24,6 +15,8 @@ public class GUIOutputLink extends GUILink { private int index; public GUIOutputLink(OutputLink in, GUINode owner, int index, double yOffset) { + super(); + link = in; lineList = new ArrayList<>(); @@ -32,19 +25,7 @@ public GUIOutputLink(OutputLink in, GUINode owner, int index, double yOffset) setCenterY(yOffset); - if (link instanceof ColorArrayOutputLink) { - setFill(Color.YELLOW); - } else if (link instanceof NumberArrayOutputLink) { - setFill(Color.GREY); - } else if (link instanceof VectorArrayOutputLink) { - setFill(Color.BLUE); - } else if (link instanceof VectorOutputLink) { - setFill(Color.AQUA); - }else if (link instanceof ImageOutputLink) { - setFill(Color.GREEN); - }else if (link instanceof ImageArrayOutputLink) { - setFill(Color.DARKGREEN); - } + getStyleClass().addAll("GUILink", link.getStyleClass()); GUIOutputLink thisLink = this; @@ -82,13 +63,13 @@ public void addLine(GUIInputLink link){ public void addLine(GUILinkLine line) { lineList.add(line); - owner.getChildren().add(line); + owner.getParentPane().getChildren().add(line); } public void forgetLine(GUILinkLine toForget) { toForget = Objects.requireNonNull(toForget); lineList.remove(toForget); - owner.getChildren().remove(toForget); + owner.getParentPane().getChildren().remove(toForget); } public void deleteAllLines() { diff --git a/PrimaView/src/main/java/sample/MainController.java b/PrimaView/src/main/java/sample/MainController.java index fd6a2e6..b31f7de 100644 --- a/PrimaView/src/main/java/sample/MainController.java +++ b/PrimaView/src/main/java/sample/MainController.java @@ -5,36 +5,37 @@ import com.tiggerbiggo.prima.primaplay.core.FileManager; import com.tiggerbiggo.prima.primaplay.graphics.ImageTools; import com.tiggerbiggo.prima.primaplay.node.core.INode; -import com.tiggerbiggo.prima.primaplay.node.implemented.BasicRenderNode; import guinode.GUILink; -import guinode.GUINode; - -import java.awt.*; +import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; import java.lang.reflect.Field; import java.net.URL; -import java.util.ArrayList; -import java.util.List; import java.util.ResourceBundle; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import javafx.animation.Animation; import javafx.animation.KeyFrame; import javafx.animation.Timeline; -import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.scene.control.*; import javafx.scene.control.Button; +import javafx.scene.control.ComboBox; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.Spinner; +import javafx.scene.control.SpinnerValueFactory; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.TransferMode; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.Pane; import javafx.util.Duration; import javafx.util.StringConverter; @@ -43,7 +44,7 @@ public class MainController implements Initializable, ChangeListener { public NodePane nodePane; @FXML - public AnchorPane nodeContainer; + public Pane nodeContainer; @FXML private ImageView imgView; @FXML @@ -58,6 +59,10 @@ public class MainController implements Initializable, ChangeListener { private ComboBox> comboNodeList; @FXML private TextArea txtSavedText; + @FXML + private BorderPane pannableContainer; + @FXML + private ScrollPane scrollPane; private String DEFAULT = "0@com.tiggerbiggo.prima.primaplay.node.implemented.MapGenNode@{\"aX\":0.0,\"aY\":0.0,\"dx\":1.0,\"dy\":1.0}@35@29\n" @@ -96,6 +101,9 @@ public void initialize(URL url, ResourceBundle rb) { timer.setCycleCount(Animation.INDEFINITE); timer.setOnFinished(e -> imgView.setImage(null)); + pannableContainer.minWidthProperty().bind(scrollPane.widthProperty()); + pannableContainer.minHeightProperty().bind(scrollPane.heightProperty()); + nodePane = new NodePane(this); nodePane = NodeSerializer.parseNodes(DEFAULT, this); AnchorPane.setBottomAnchor(nodePane, 0.0); @@ -178,35 +186,54 @@ private void onBtnSave(ActionEvent e) { @FXML private void onBtnSaveLayout(ActionEvent e){ + String ser; - //purge deleted entries before save - nodePane.purgeNodes(); + try{ + File chosen = FileManager.showSaveDialogue(); - String ser = NodeSerializer.SerializeNodePane(nodePane); - System.out.println(ser); + ser = NodeSerializer.saveToFile(nodePane, chosen); - txtSavedText.setText(ser); + ViewMain.setTitleToFile(chosen); + }catch(IOException ex){ + return; + } StringSelection stringSelection = new StringSelection(ser); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); - - //NodeSerializer.parseNodes(ser, this); } @FXML private void onBtnLoadLayout(ActionEvent e){ try{ - NodePane tmpPane = NodeSerializer.parseNodes(txtSavedText.getText(), this); - if(tmpPane != null){ - nodeContainer.getChildren().clear(); - nodeContainer.getChildren().add(tmpPane); - nodePane.clearNodes(); - nodePane = tmpPane; - } + File chosen = FileManager.showOpenDialogue(); + + NodePane tmpPane = NodeSerializer.parseFromFile(chosen, this); + //Open file dialogue + + //NodeSerializer.parseNodes(txtSavedText.getText(), this); + nodeContainer.getChildren().clear(); + nodePane.clearNodes(); + nodePane = tmpPane; + + AnchorPane.setBottomAnchor(nodePane, 0.0); + AnchorPane.setTopAnchor(nodePane, 0.0); + AnchorPane.setLeftAnchor(nodePane, 0.0); + AnchorPane.setRightAnchor(nodePane, 0.0); + + nodeContainer.getChildren().add(nodePane); + + ViewMain.setTitleToFile(chosen); + + startPreviewRender(); + timer.stop(); + timer.play(); } catch(NodeParseException ex){ + System.out.println("oh dear: " + ex.getMessage()); //oh dear, display error message + } catch (IOException e1) { + // nothing } } @@ -222,7 +249,10 @@ private void onBtnAddNode(ActionEvent e) { } @Override - public void onObjectValueChanged(Field field, Object object) { + public void onObjectValueChanged(Field field, Object oldValue, Object newValue, Object object) { + System.out.println("OLD VALUE: " + oldValue.toString()); + System.out.println("NEW VALUE: " + newValue.toString()); + System.out.println("-----------------------------------"); startPreviewRender(); } } diff --git a/PrimaView/src/main/java/sample/NodePane.java b/PrimaView/src/main/java/sample/NodePane.java index 894fc71..01822af 100644 --- a/PrimaView/src/main/java/sample/NodePane.java +++ b/PrimaView/src/main/java/sample/NodePane.java @@ -10,7 +10,6 @@ import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import javafx.application.Platform; import javafx.scene.layout.Pane; public class NodePane extends Pane { @@ -22,6 +21,8 @@ public NodePane(ChangeListener _listener){ listener = _listener; renderNode = null;//new BasicRenderNode(); + getStyleClass().add("NodePane"); + nodeList = new ArrayList<>(); //addNode(new GUINode(renderNode, this)); } @@ -50,7 +51,10 @@ public void addNode(GUINode node){ nodeList.add(node); } - + public void deleteNode(GUINode node){ + getChildren().remove(node); + nodeList.remove(node); + } public Future renderAsync(int w, int h, int n) throws NullPointerException{ return renderNode.renderAsync(w, h, n); @@ -70,13 +74,4 @@ public void clearNodes(){ getChildren().clear(); } - public void purgeNodes(){ - List toDelete = new ArrayList<>(); - for(GUINode n : nodeList){ - if(!getChildren().contains(n)){ - toDelete.add(n); - } - } - getChildren().removeAll(toDelete); - } } diff --git a/PrimaView/src/main/java/sample/NodeReflection.java b/PrimaView/src/main/java/sample/NodeReflection.java index 97d682a..5dddba2 100644 --- a/PrimaView/src/main/java/sample/NodeReflection.java +++ b/PrimaView/src/main/java/sample/NodeReflection.java @@ -1,7 +1,6 @@ package sample; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.tiggerbiggo.prima.primaplay.node.core.INode; import java.lang.reflect.Modifier; import java.util.ArrayList; diff --git a/PrimaView/src/main/java/sample/NodeSerializer.java b/PrimaView/src/main/java/sample/NodeSerializer.java index f2ffc56..ce57333 100644 --- a/PrimaView/src/main/java/sample/NodeSerializer.java +++ b/PrimaView/src/main/java/sample/NodeSerializer.java @@ -6,15 +6,20 @@ import com.google.gson.FieldAttributes; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.sun.deploy.util.StringUtils; import com.tiggerbiggo.prima.primaplay.node.core.INode; import guinode.GUIInputLink; -import guinode.GUIOutputLink; import guinode.GUINode; - +import guinode.GUIOutputLink; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.lang.annotation.Annotation; +import java.nio.charset.Charset; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; -import javafx.application.Platform; +import java.util.Objects; public class NodeSerializer { @@ -199,4 +204,42 @@ public static int[] parseLinks(String str){ } return toReturn; } + + public static NodePane parseFromFile(File file, ChangeListener listener) throws NodeParseException{ + try { + List lines = Files.readAllLines(file.toPath(), Charset.defaultCharset()); + String result = StringUtils.join(lines, "\n"); + System.out.println("------------------"); + System.out.println(result); + System.out.println("------------------"); + return parseNodes(result, listener); + } catch (IOException e) { + return null; + } + } + + public static String saveToFile(NodePane pane, File toWrite) throws IOException { + Objects.requireNonNull(pane); + Objects.requireNonNull(toWrite); + + if(!toWrite.exists()) + { + try { + toWrite.createNewFile(); + } catch (IOException e) { + throw e; + } + } + + String ser = SerializeNodePane(pane); + + System.out.println(ser); + + try(FileWriter fw = new FileWriter(toWrite)) { + fw.append(ser); + } catch (IOException e) { + throw e; + } + return ser; + } } diff --git a/PrimaView/src/main/java/sample/ViewMain.java b/PrimaView/src/main/java/sample/ViewMain.java index 0287794..74886b1 100644 --- a/PrimaView/src/main/java/sample/ViewMain.java +++ b/PrimaView/src/main/java/sample/ViewMain.java @@ -1,5 +1,6 @@ package sample; +import java.io.File; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; @@ -8,16 +9,30 @@ public class ViewMain extends Application { + private static Stage mainStage; + @Override public void start(Stage primaryStage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("/sample.fxml")); - primaryStage.setTitle("Hello World"); + primaryStage.setTitle("Prima: No file Loaded"); + mainStage = primaryStage; + + Scene s = new Scene(root, 600, 500); + s.getStylesheets().add(getClass().getResource("/default.css").toString()); + + primaryStage.setOnCloseRequest(event -> System.exit(0)); - primaryStage.setScene(new Scene(root, 600, 500)); + primaryStage.setScene(s); primaryStage.show(); } public static void main(String[] args) { launch(args); } + + public static void setTitleToFile(File f){ + if(f != null){ + mainStage.setTitle("Prima: " + f.getName()); + } + } } diff --git a/PrimaView/src/main/resources/default.css b/PrimaView/src/main/resources/default.css index 8420bb2..3806044 100644 --- a/PrimaView/src/main/resources/default.css +++ b/PrimaView/src/main/resources/default.css @@ -1,7 +1,54 @@ -#LinkLine{ - -fx-stroke:'#ffffff'; +.LinkLine{ + -fx-stroke: '#f4b700'; -fx-fill:transparent; } -#NodePane{ - -fx-background-color:'#0a0649'; +.NodePane{ + -fx-background-color:'#333333'; +} +.label{ + -fx-text-fill: '#eeeeee'; +} +.GUINode{ + -fx-border-color: '#f4b700'; + -fx-border-radius: 10; + -fx-background-color:'#777777'; + -fx-background-radius: 10; + -fx-padding: 10; +} +.button{ + -fx-background-color: '#825636'; + -fx-text-fill: '#ffd700'; + -fx-border-color: '#f4b700'; + -fx-border-radius: 60; + -fx-background-radius: 60; +} + +.split-pane-divider { + -fx-background-color: '#f4b700'; +} + +.GUILink{ + -fx-stroke: '#f4b700'; + -fx-stroke-width: 2; +} +.ColorArrayLink{ + -fx-fill: yellow; +} +.NumberArrayLink{ + -fx-fill: grey; +} +.VectorArrayLink{ + -fx-fill: blue; +} +.VectorLink{ + -fx-fill: aqua; +} +.ImageLink{ + -fx-fill: green; +} +.ImageArrayLink{ + -fx-fill: '#00ff00'; +} +.ColorLink{ + -fx-fill: '#ffffff'; } \ No newline at end of file diff --git a/PrimaView/src/main/resources/sample.fxml b/PrimaView/src/main/resources/sample.fxml index a3911f7..d2eff75 100644 --- a/PrimaView/src/main/resources/sample.fxml +++ b/PrimaView/src/main/resources/sample.fxml @@ -1,93 +1,96 @@ + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -