From 7df2358aa06230ec2aaeaf6bf5ffc8f228226532 Mon Sep 17 00:00:00 2001 From: Yannick Date: Fri, 16 Jun 2017 11:54:40 +0200 Subject: [PATCH 1/2] MiniMap and Merge --- .../controller/MiniMapController.java | 77 ++++++++++ .../gui/controller/GraphController.java | 12 +- .../gui/controller/GuiController.java | 17 ++- src/main/resources/Basic_Gui.fxml | 138 ++++++++++-------- 4 files changed, 175 insertions(+), 69 deletions(-) create mode 100644 src/main/java/programminglife/controller/MiniMapController.java diff --git a/src/main/java/programminglife/controller/MiniMapController.java b/src/main/java/programminglife/controller/MiniMapController.java new file mode 100644 index 0000000..5895d61 --- /dev/null +++ b/src/main/java/programminglife/controller/MiniMapController.java @@ -0,0 +1,77 @@ +package programminglife.controller; + +import javafx.scene.canvas.Canvas; +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; +import programminglife.gui.controller.GuiController; + +/** + * Controller that shows a miniMap in the gui. + */ +public class MiniMapController { + + private GuiController guiController; + private Canvas miniMap; + private int size; + + private boolean visible = false; + + /** + * Constructor for the miniMap. + * @param miniMap Canvas of the miniMap to be used. + * @param size int Size of the graph. + */ + public MiniMapController(Canvas miniMap, int size) { + this.miniMap = miniMap; + miniMap.setVisible(visible); + this.size = size; + } + + /** + * Draws the MiniMap on the screen. + */ + private void drawMiniMap() { + GraphicsContext gc = miniMap.getGraphicsContext2D(); + gc.setFill(Color.LIGHTGRAY); + gc.fillRect(0, 0, miniMap.getWidth(), 50); + + gc.setStroke(Color.BLACK); + gc.setLineWidth(2); + gc.strokeLine(0, 25, miniMap.getWidth(), 25); + } + + /** + * Toggle the visibility of the MiniMap. + */ + public void toggleVisibility() { + visible = !visible; + this.miniMap.setVisible(visible); + if (visible) { + drawMiniMap(); + } + } + + /** + * Shows the position of where you are in the graph (on the screen). + * It does not handle panning as of now! + * @param centerNode int of the centernode currently at. + */ + public void showPosition(int centerNode) { + GraphicsContext gc = miniMap.getGraphicsContext2D(); + gc.clearRect(0, 0, miniMap.getWidth(), miniMap.getHeight()); + drawMiniMap(); + gc.setFill(Color.RED); + System.out.println(centerNode); + System.out.println(size); + System.out.println(miniMap.getWidth()); + gc.fillOval((centerNode / (double) size) * miniMap.getWidth(), 20, 10, 10); + } + + /** + * Sets the guicontroller for controlling the menu. + * @param guiController The gui controller + */ + public void setGuiController(GuiController guiController) { + this.guiController = guiController; + } +} diff --git a/src/main/java/programminglife/gui/controller/GraphController.java b/src/main/java/programminglife/gui/controller/GraphController.java index ed570f9..78c53b6 100644 --- a/src/main/java/programminglife/gui/controller/GraphController.java +++ b/src/main/java/programminglife/gui/controller/GraphController.java @@ -7,12 +7,8 @@ import javafx.scene.layout.AnchorPane; import javafx.scene.paint.Color; import javafx.scene.text.Text; -import programminglife.model.drawing.DrawableDummy; import programminglife.model.GenomeGraph; -import programminglife.model.drawing.DrawableEdge; -import programminglife.model.drawing.DrawableNode; -import programminglife.model.drawing.DrawableSegment; -import programminglife.model.drawing.SubGraph; +import programminglife.model.drawing.*; import programminglife.utility.Console; import java.util.Collection; @@ -34,6 +30,7 @@ public class GraphController { private SubGraph subGraph; private AnchorPane anchorGraphInfo; private LinkedList oldGenomeList = new LinkedList<>(); + private int centerNodeInt; /** * Initialize controller object. @@ -47,6 +44,10 @@ public GraphController(GenomeGraph graph, Group grpDrawArea, AnchorPane anchorGr this.anchorGraphInfo = anchorGraphInfo; } + public int getCenterNodeInt() { + return this.centerNodeInt; + } + /** * Method to draw the subGraph decided by a center node and radius. * @param center the node of which the radius starts. @@ -55,6 +56,7 @@ public GraphController(GenomeGraph graph, Group grpDrawArea, AnchorPane anchorGr public void draw(int center, int radius) { long startTimeProgram = System.nanoTime(); DrawableSegment centerNode = new DrawableSegment(graph, center); + centerNodeInt = centerNode.getIdentifier(); subGraph = new SubGraph(centerNode, radius); long startLayoutTime = System.nanoTime(); diff --git a/src/main/java/programminglife/gui/controller/GuiController.java b/src/main/java/programminglife/gui/controller/GuiController.java index a3352e7..41c045b 100644 --- a/src/main/java/programminglife/gui/controller/GuiController.java +++ b/src/main/java/programminglife/gui/controller/GuiController.java @@ -25,6 +25,7 @@ import javafx.stage.Stage; import jp.uphy.javafx.console.ConsoleView; import programminglife.ProgrammingLife; +import programminglife.controller.MiniMapController; import programminglife.controller.RecentFileController; import programminglife.model.GenomeGraph; import programminglife.parser.GraphParser; @@ -36,7 +37,9 @@ import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; -import java.io.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import java.nio.charset.Charset; import java.util.Observable; import java.util.Observer; @@ -60,6 +63,7 @@ public class GuiController implements Observer { @FXML private MenuItem btnInstructions; @FXML private Menu menuRecent; @FXML private RadioMenuItem btnToggle; + @FXML private RadioMenuItem btnMiniMap; @FXML private Button btnZoomReset; @FXML private Button btnTranslateReset; @FXML private Button btnDraw; @@ -77,12 +81,14 @@ public class GuiController implements Observer { @FXML private AnchorPane anchorLeftControlPanel; @FXML private AnchorPane anchorGraphPanel; @FXML private AnchorPane anchorGraphInfo; + @FXML private javafx.scene.canvas.Canvas miniMap; private double orgSceneX, orgSceneY; private double orgTranslateX, orgTranslateY; private double scale; private GraphController graphController; private RecentFileController recentFileController; + private MiniMapController miniMapController; private File file; private File recentFile = new File("Recent.txt"); private Thread parseThread; @@ -196,6 +202,10 @@ public void setGraph(GenomeGraph graph) { }); if (graph != null) { + this.miniMapController = new MiniMapController(this.miniMap, graph.size()); + this.miniMapController.setGuiController(this); + miniMap.setWidth(anchorGraphPanel.getWidth()); + miniMap.setHeight(50.d); Console.println("[%s] Graph was set to %s.", Thread.currentThread().getName(), graph.getID()); Console.println("[%s] The graph has %d nodes", Thread.currentThread().getName(), graph.size()); } @@ -248,8 +258,10 @@ private void initMenuBar() { Alerts.error("This GFF file can't be opened"); } }); - btnOpenGFA.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCodeCombination.CONTROL_DOWN)); + + btnMiniMap.setOnAction(event -> miniMapController.toggleVisibility()); + btnMiniMap.setAccelerator(new KeyCodeCombination(KeyCode.M, KeyCodeCombination.CONTROL_DOWN)); btnQuit.setOnAction(event -> Alerts.quitAlert()); btnQuit.setAccelerator(new KeyCodeCombination(KeyCode.E, KeyCodeCombination.CONTROL_DOWN)); btnAbout.setOnAction(event -> Alerts.infoAboutAlert()); @@ -358,6 +370,7 @@ void draw() { if (graphController.getGraph().contains(centerNode)) { this.graphController.clear(); this.graphController.draw(centerNode, maxDepth); + this.miniMapController.showPosition(centerNode); Console.println("[%s] Graph drawn.", Thread.currentThread().getName()); } else { Alerts.warning("The centernode is not a existing node, try again with a number that exists as a node."); diff --git a/src/main/resources/Basic_Gui.fxml b/src/main/resources/Basic_Gui.fxml index 7461a77..d02292e 100644 --- a/src/main/resources/Basic_Gui.fxml +++ b/src/main/resources/Basic_Gui.fxml @@ -1,70 +1,84 @@ + + - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - -