Skip to content

Commit

Permalink
Merge pull request #273 from ProgrammingLife2017/MiniMap
Browse files Browse the repository at this point in the history
Mini map
  • Loading branch information
toinehartman authored Jun 16, 2017
2 parents b5c17ff + 6490b7b commit 2adb080
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 68 deletions.
77 changes: 77 additions & 0 deletions src/main/java/programminglife/controller/MiniMapController.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +30,7 @@ public class GraphController {
private SubGraph subGraph;
private AnchorPane anchorGraphInfo;
private LinkedList<DrawableNode> oldGenomeList = new LinkedList<>();
private int centerNodeInt;

/**
* Initialize controller object.
Expand All @@ -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.
Expand All @@ -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();
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/programminglife/gui/controller/GuiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.Feature;
import programminglife.model.GenomeGraph;
Expand Down Expand Up @@ -65,6 +66,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;
Expand All @@ -82,12 +84,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 Map<String, Feature> features;
private File recentFile = new File("Recent.txt");
Expand Down Expand Up @@ -217,6 +221,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());
}
Expand Down Expand Up @@ -269,8 +277,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());
Expand Down Expand Up @@ -379,6 +389,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.");
Expand Down
138 changes: 76 additions & 62 deletions src/main/resources/Basic_Gui.fxml
Original file line number Diff line number Diff line change
@@ -1,70 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--suppress ALL -->

<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.Group?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.RadioMenuItem?>
<?import javafx.scene.control.SeparatorMenuItem?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>

<!--suppress ALL -->
<?import javafx.scene.layout.*?>

<AnchorPane prefHeight="500.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="programminglife.gui.controller.GuiController">
<MenuBar AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Menu fx:id="menuFile" mnemonicParsing="false" text="File">
<MenuItem fx:id="btnOpenGFA" mnemonicParsing="false" text="Open GFA" />
<MenuItem fx:id="btnOpenGFF" mnemonicParsing="false" text="Open GFF" />
<Menu fx:id="menuRecent" mnemonicParsing="false" text="Open Recent GFA" />
<SeparatorMenuItem mnemonicParsing="false" />
<RadioMenuItem fx:id="btnToggle" mnemonicParsing="false" text="Toggle Console" />
<MenuItem fx:id="btnQuit" mnemonicParsing="false" text="Quit" />
</Menu>
<Menu fx:id="menuHelp" mnemonicParsing="false" text="Help">
<MenuItem fx:id="btnAbout" mnemonicParsing="false" text="About" />
<MenuItem fx:id="btnInstructions" mnemonicParsing="false" text="Instructions" />
</Menu>
<Menu fx:id="menuBookmark" mnemonicParsing="false" text="Bookmarks">
<MenuItem fx:id="btnBookmarks" mnemonicParsing="false" text="Bookmarks" />
</Menu>
</MenuBar>
<SplitPane dividerPositions="0.14, 1.0" layoutY="29.0" prefHeight="200.0" prefWidth="500.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="29.0">
<AnchorPane fx:id="anchorLeftControlPanel" maxWidth="140.0" minHeight="0.0" minWidth="140.0" prefHeight="800.0" prefWidth="100.0" SplitPane.resizableWithParent="false">
<Button fx:id="btnZoomReset" layoutX="12.0" layoutY="20.0" minWidth="100.0" mnemonicParsing="false" text="Reset Zoom" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<Button fx:id="btnTranslateReset" layoutX="12.0" layoutY="50.0" minWidth="100.0" mnemonicParsing="false" text="Reset X/Y" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<TextField text="Center Node:" layoutX="20.0" layoutY="85.0" editable="false" style="-fx-text-box-border: transparent;-fx-background-color: none; -fx-background-insets: 0; -fx-padding: 1 3 1 3; -fx-focus-color: transparent; -fx-faint-focus-color: transparent;"/>
<TextField fx:id="txtCenterNode" layoutX="20.0" layoutY="100.0" minWidth="100.0" promptText="Origin node" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<TextField text="Radius:" layoutX="20.0" layoutY="130.0" editable="false" style="-fx-text-box-border: transparent;-fx-background-color: none; -fx-background-insets: 0; -fx-padding: 1 3 1 3; -fx-focus-color: transparent; -fx-faint-focus-color: transparent;"/>
<TextField fx:id="txtMaxDrawDepth" layoutX="20.0" layoutY="145.0" minWidth="100.0" promptText="Max depth" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<Button fx:id="btnDraw" layoutX="27.0" layoutY="180.0" minWidth="100.0" mnemonicParsing="false" text="Draw" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<Button fx:id="btnDrawRandom" layoutX="20.0" layoutY="210.0" minWidth="100.0" mnemonicParsing="false" text="Surprise me!" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<Button fx:id="btnBookmark" layoutX="20.0" layoutY="240.0" minWidth="100.0" mnemonicParsing="false" text="Bookmark" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
</AnchorPane>
<AnchorPane fx:id="anchorGraphPanel" minHeight="200" minWidth="200" prefHeight="Infinity" prefWidth="Infinity">
<Group fx:id="grpDrawArea" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<ProgressBar fx:id="progressBar" minHeight="18.0" minWidth="100.0" progress="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</AnchorPane>
<AnchorPane maxWidth="500.0" minWidth="140.0" prefHeight="800.0" prefWidth="Infinity">
<TabPane maxWidth="500.0" tabClosingPolicy="UNAVAILABLE" tabMaxHeight="100.0" tabMaxWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Tab text="Graph Info">
<AnchorPane fx:id="anchorGraphInfo" minWidth="50.0">
<Button fx:id="btnClipboard" layoutX="15.0" layoutY="15.0" mnemonicParsing="false" text="Copy to clipboard" />
<Button fx:id="btnClipboard2" layoutX="255.0" layoutY="15.0" mnemonicParsing="false" text="Copy to clipboard" />
</AnchorPane>
</Tab>
<Tab fx:id="searchTab" text="Search / Highlight" />
</TabPane>
</AnchorPane>
</SplitPane>
<?import javafx.scene.canvas.Canvas?>
<AnchorPane prefHeight="500.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="programminglife.gui.controller.GuiController">
<children>
<MenuBar AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<menus>
<Menu fx:id="menuFile" mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="btnOpenGFA" mnemonicParsing="false" text="Open GFA" />
<MenuItem fx:id="btnOpenGFF" mnemonicParsing="false" text="Open GFF" />
<Menu fx:id="menuRecent" mnemonicParsing="false" text="Open Recent GFA" />
<SeparatorMenuItem mnemonicParsing="false" />
<RadioMenuItem fx:id="btnToggle" mnemonicParsing="false" text="Toggle Console" />
<RadioMenuItem fx:id="btnMiniMap" mnemonicParsing="false" text="Toggle MiniMap" />
<MenuItem fx:id="btnQuit" mnemonicParsing="false" text="Quit" />
</items>
</Menu>
<Menu fx:id="menuHelp" mnemonicParsing="false" text="Help">
<items>
<MenuItem fx:id="btnAbout" mnemonicParsing="false" text="About" />
<MenuItem fx:id="btnInstructions" mnemonicParsing="false" text="Instructions" />
</items>
</Menu>
<Menu fx:id="menuBookmark" mnemonicParsing="false" text="Bookmarks">
<items>
<MenuItem fx:id="btnBookmarks" mnemonicParsing="false" text="Bookmarks" />
</items>
</Menu>
</menus>
</MenuBar>
<SplitPane dividerPositions="0.14, 1.0" layoutY="29.0" prefHeight="200.0" prefWidth="500.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="29.0">
<items>
<AnchorPane fx:id="anchorLeftControlPanel" maxWidth="140.0" minHeight="0.0" minWidth="140.0" prefHeight="800.0" prefWidth="100.0" SplitPane.resizableWithParent="false">
<children>
<Button fx:id="btnZoomReset" layoutX="12.0" layoutY="20.0" minWidth="100.0" mnemonicParsing="false" text="Reset Zoom" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<Button fx:id="btnTranslateReset" layoutX="12.0" layoutY="50.0" minWidth="100.0" mnemonicParsing="false" text="Reset X/Y" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<TextField editable="false" layoutX="20.0" layoutY="85.0" style="-fx-text-box-border: transparent;-fx-background-color: none; -fx-background-insets: 0; -fx-padding: 1 3 1 3; -fx-focus-color: transparent; -fx-faint-focus-color: transparent;" text="Center Node:" />
<TextField fx:id="txtCenterNode" layoutX="20.0" layoutY="100.0" minWidth="100.0" promptText="Origin node" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<TextField editable="false" layoutX="20.0" layoutY="130.0" style="-fx-text-box-border: transparent;-fx-background-color: none; -fx-background-insets: 0; -fx-padding: 1 3 1 3; -fx-focus-color: transparent; -fx-faint-focus-color: transparent;" text="Radius:" />
<TextField fx:id="txtMaxDrawDepth" layoutX="20.0" layoutY="145.0" minWidth="100.0" promptText="Max depth" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<Button fx:id="btnDraw" layoutX="27.0" layoutY="180.0" minWidth="100.0" mnemonicParsing="false" text="Draw" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<Button fx:id="btnDrawRandom" layoutX="20.0" layoutY="210.0" minWidth="100.0" mnemonicParsing="false" text="Surprise me!" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<Button fx:id="btnBookmark" layoutX="20.0" layoutY="240.0" minWidth="100.0" mnemonicParsing="false" text="Bookmark" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
</children>
</AnchorPane>
<AnchorPane fx:id="anchorGraphPanel" minHeight="200" minWidth="200" prefHeight="Infinity" prefWidth="Infinity">
<children>
<Canvas fx:id="miniMap" height="100" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
<Group fx:id="grpDrawArea" AnchorPane.bottomAnchor="100.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<ProgressBar fx:id="progressBar" minHeight="18.0" minWidth="100.0" progress="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane maxWidth="500.0" minWidth="140.0" prefHeight="800.0" prefWidth="Infinity">
<children>
<TabPane maxWidth="500.0" tabClosingPolicy="UNAVAILABLE" tabMaxHeight="100.0" tabMaxWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab text="Graph Info">
<content>
<AnchorPane fx:id="anchorGraphInfo" minWidth="50.0">
<children>
<Button fx:id="btnClipboard" layoutX="15.0" layoutY="15.0" mnemonicParsing="false" text="Copy to clipboard" />
<Button fx:id="btnClipboard2" layoutX="255.0" layoutY="15.0" mnemonicParsing="false" text="Copy to clipboard" />
</children>
</AnchorPane>
</content>
</Tab>
<Tab fx:id="searchTab" text="Search / Highlight" />
</tabs>
</TabPane>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>

0 comments on commit 2adb080

Please sign in to comment.