Skip to content

Commit 2adb080

Browse files
authored
Merge pull request #273 from ProgrammingLife2017/MiniMap
Mini map
2 parents b5c17ff + 6490b7b commit 2adb080

File tree

4 files changed

+172
-68
lines changed

4 files changed

+172
-68
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package programminglife.controller;
2+
3+
import javafx.scene.canvas.Canvas;
4+
import javafx.scene.canvas.GraphicsContext;
5+
import javafx.scene.paint.Color;
6+
import programminglife.gui.controller.GuiController;
7+
8+
/**
9+
* Controller that shows a MiniMap in the gui.
10+
*/
11+
public class MiniMapController {
12+
13+
private GuiController guiController;
14+
private Canvas miniMap;
15+
private int size;
16+
17+
private boolean visible = false;
18+
19+
/**
20+
* Constructor for the miniMap.
21+
* @param miniMap Canvas of the miniMap to be used.
22+
* @param size int Size of the graph.
23+
*/
24+
public MiniMapController(Canvas miniMap, int size) {
25+
this.miniMap = miniMap;
26+
miniMap.setVisible(visible);
27+
this.size = size;
28+
}
29+
30+
/**
31+
* Draws the MiniMap on the screen.
32+
*/
33+
private void drawMiniMap() {
34+
GraphicsContext gc = miniMap.getGraphicsContext2D();
35+
gc.setFill(Color.LIGHTGRAY);
36+
gc.fillRect(0, 0, miniMap.getWidth(), 50);
37+
38+
gc.setStroke(Color.BLACK);
39+
gc.setLineWidth(2);
40+
gc.strokeLine(0, 25, miniMap.getWidth(), 25);
41+
}
42+
43+
/**
44+
* Toggle the visibility of the MiniMap.
45+
*/
46+
public void toggleVisibility() {
47+
visible = !visible;
48+
this.miniMap.setVisible(visible);
49+
if (visible) {
50+
drawMiniMap();
51+
}
52+
}
53+
54+
/**
55+
* Shows the position of where you are in the graph (on the screen).
56+
* It does not handle panning as of now!
57+
* @param centerNode int of the centernode currently at.
58+
*/
59+
public void showPosition(int centerNode) {
60+
GraphicsContext gc = miniMap.getGraphicsContext2D();
61+
gc.clearRect(0, 0, miniMap.getWidth(), miniMap.getHeight());
62+
drawMiniMap();
63+
gc.setFill(Color.RED);
64+
System.out.println(centerNode);
65+
System.out.println(size);
66+
System.out.println(miniMap.getWidth());
67+
gc.fillOval((centerNode / (double) size) * miniMap.getWidth(), 20, 10, 10);
68+
}
69+
70+
/**
71+
* Sets the guicontroller for controlling the menu.
72+
* @param guiController The gui controller
73+
*/
74+
public void setGuiController(GuiController guiController) {
75+
this.guiController = guiController;
76+
}
77+
}

src/main/java/programminglife/gui/controller/GraphController.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
import javafx.scene.layout.AnchorPane;
88
import javafx.scene.paint.Color;
99
import javafx.scene.text.Text;
10-
import programminglife.model.drawing.DrawableDummy;
1110
import programminglife.model.GenomeGraph;
12-
import programminglife.model.drawing.DrawableEdge;
13-
import programminglife.model.drawing.DrawableNode;
14-
import programminglife.model.drawing.DrawableSegment;
15-
import programminglife.model.drawing.SubGraph;
11+
import programminglife.model.drawing.*;
1612
import programminglife.utility.Console;
1713

1814
import java.util.Collection;
@@ -34,6 +30,7 @@ public class GraphController {
3430
private SubGraph subGraph;
3531
private AnchorPane anchorGraphInfo;
3632
private LinkedList<DrawableNode> oldGenomeList = new LinkedList<>();
33+
private int centerNodeInt;
3734

3835
/**
3936
* Initialize controller object.
@@ -47,6 +44,10 @@ public GraphController(GenomeGraph graph, Group grpDrawArea, AnchorPane anchorGr
4744
this.anchorGraphInfo = anchorGraphInfo;
4845
}
4946

47+
public int getCenterNodeInt() {
48+
return this.centerNodeInt;
49+
}
50+
5051
/**
5152
* Method to draw the subGraph decided by a center node and radius.
5253
* @param center the node of which the radius starts.
@@ -55,6 +56,7 @@ public GraphController(GenomeGraph graph, Group grpDrawArea, AnchorPane anchorGr
5556
public void draw(int center, int radius) {
5657
long startTimeProgram = System.nanoTime();
5758
DrawableSegment centerNode = new DrawableSegment(graph, center);
59+
centerNodeInt = centerNode.getIdentifier();
5860
subGraph = new SubGraph(centerNode, radius);
5961

6062
long startLayoutTime = System.nanoTime();

src/main/java/programminglife/gui/controller/GuiController.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javafx.stage.Stage;
2626
import jp.uphy.javafx.console.ConsoleView;
2727
import programminglife.ProgrammingLife;
28+
import programminglife.controller.MiniMapController;
2829
import programminglife.controller.RecentFileController;
2930
import programminglife.model.Feature;
3031
import programminglife.model.GenomeGraph;
@@ -65,6 +66,7 @@ public class GuiController implements Observer {
6566
@FXML private MenuItem btnInstructions;
6667
@FXML private Menu menuRecent;
6768
@FXML private RadioMenuItem btnToggle;
69+
@FXML private RadioMenuItem btnMiniMap;
6870
@FXML private Button btnZoomReset;
6971
@FXML private Button btnTranslateReset;
7072
@FXML private Button btnDraw;
@@ -82,12 +84,14 @@ public class GuiController implements Observer {
8284
@FXML private AnchorPane anchorLeftControlPanel;
8385
@FXML private AnchorPane anchorGraphPanel;
8486
@FXML private AnchorPane anchorGraphInfo;
87+
@FXML private javafx.scene.canvas.Canvas miniMap;
8588

8689
private double orgSceneX, orgSceneY;
8790
private double orgTranslateX, orgTranslateY;
8891
private double scale;
8992
private GraphController graphController;
9093
private RecentFileController recentFileController;
94+
private MiniMapController miniMapController;
9195
private File file;
9296
private Map<String, Feature> features;
9397
private File recentFile = new File("Recent.txt");
@@ -217,6 +221,10 @@ public void setGraph(GenomeGraph graph) {
217221
});
218222

219223
if (graph != null) {
224+
this.miniMapController = new MiniMapController(this.miniMap, graph.size());
225+
this.miniMapController.setGuiController(this);
226+
miniMap.setWidth(anchorGraphPanel.getWidth());
227+
miniMap.setHeight(50.d);
220228
Console.println("[%s] Graph was set to %s.", Thread.currentThread().getName(), graph.getID());
221229
Console.println("[%s] The graph has %d nodes", Thread.currentThread().getName(), graph.size());
222230
}
@@ -269,8 +277,10 @@ private void initMenuBar() {
269277
Alerts.error("This GFF file can't be opened");
270278
}
271279
});
272-
273280
btnOpenGFA.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCodeCombination.CONTROL_DOWN));
281+
282+
btnMiniMap.setOnAction(event -> miniMapController.toggleVisibility());
283+
btnMiniMap.setAccelerator(new KeyCodeCombination(KeyCode.M, KeyCodeCombination.CONTROL_DOWN));
274284
btnQuit.setOnAction(event -> Alerts.quitAlert());
275285
btnQuit.setAccelerator(new KeyCodeCombination(KeyCode.E, KeyCodeCombination.CONTROL_DOWN));
276286
btnAbout.setOnAction(event -> Alerts.infoAboutAlert());
@@ -379,6 +389,7 @@ void draw() {
379389
if (graphController.getGraph().contains(centerNode)) {
380390
this.graphController.clear();
381391
this.graphController.draw(centerNode, maxDepth);
392+
this.miniMapController.showPosition(centerNode);
382393
Console.println("[%s] Graph drawn.", Thread.currentThread().getName());
383394
} else {
384395
Alerts.warning("The centernode is not a existing node, try again with a number that exists as a node.");

src/main/resources/Basic_Gui.fxml

+76-62
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,84 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3+
<!--suppress ALL -->
4+
35
<?import java.lang.*?>
46
<?import javafx.scene.*?>
57
<?import javafx.scene.control.*?>
6-
<?import javafx.scene.layout.*?>
78
<?import javafx.scene.Group?>
8-
<?import javafx.scene.control.Button?>
9-
<?import javafx.scene.control.Menu?>
10-
<?import javafx.scene.control.MenuBar?>
11-
<?import javafx.scene.control.MenuItem?>
12-
<?import javafx.scene.control.ProgressBar?>
13-
<?import javafx.scene.control.RadioMenuItem?>
14-
<?import javafx.scene.control.SeparatorMenuItem?>
15-
<?import javafx.scene.control.SplitPane?>
16-
<?import javafx.scene.control.Tab?>
17-
<?import javafx.scene.control.TabPane?>
18-
<?import javafx.scene.control.TextField?>
19-
<?import javafx.scene.layout.AnchorPane?>
20-
<?import javafx.scene.layout.VBox?>
21-
22-
<!--suppress ALL -->
9+
<?import javafx.scene.layout.*?>
2310

24-
<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">
25-
<MenuBar AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
26-
<Menu fx:id="menuFile" mnemonicParsing="false" text="File">
27-
<MenuItem fx:id="btnOpenGFA" mnemonicParsing="false" text="Open GFA" />
28-
<MenuItem fx:id="btnOpenGFF" mnemonicParsing="false" text="Open GFF" />
29-
<Menu fx:id="menuRecent" mnemonicParsing="false" text="Open Recent GFA" />
30-
<SeparatorMenuItem mnemonicParsing="false" />
31-
<RadioMenuItem fx:id="btnToggle" mnemonicParsing="false" text="Toggle Console" />
32-
<MenuItem fx:id="btnQuit" mnemonicParsing="false" text="Quit" />
33-
</Menu>
34-
<Menu fx:id="menuHelp" mnemonicParsing="false" text="Help">
35-
<MenuItem fx:id="btnAbout" mnemonicParsing="false" text="About" />
36-
<MenuItem fx:id="btnInstructions" mnemonicParsing="false" text="Instructions" />
37-
</Menu>
38-
<Menu fx:id="menuBookmark" mnemonicParsing="false" text="Bookmarks">
39-
<MenuItem fx:id="btnBookmarks" mnemonicParsing="false" text="Bookmarks" />
40-
</Menu>
41-
</MenuBar>
42-
<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">
43-
<AnchorPane fx:id="anchorLeftControlPanel" maxWidth="140.0" minHeight="0.0" minWidth="140.0" prefHeight="800.0" prefWidth="100.0" SplitPane.resizableWithParent="false">
44-
<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" />
45-
<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" />
46-
<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;"/>
47-
<TextField fx:id="txtCenterNode" layoutX="20.0" layoutY="100.0" minWidth="100.0" promptText="Origin node" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
48-
<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;"/>
49-
<TextField fx:id="txtMaxDrawDepth" layoutX="20.0" layoutY="145.0" minWidth="100.0" promptText="Max depth" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
50-
<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" />
51-
<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" />
52-
<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" />
53-
</AnchorPane>
54-
<AnchorPane fx:id="anchorGraphPanel" minHeight="200" minWidth="200" prefHeight="Infinity" prefWidth="Infinity">
55-
<Group fx:id="grpDrawArea" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
56-
<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" />
57-
</AnchorPane>
58-
<AnchorPane maxWidth="500.0" minWidth="140.0" prefHeight="800.0" prefWidth="Infinity">
59-
<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">
60-
<Tab text="Graph Info">
61-
<AnchorPane fx:id="anchorGraphInfo" minWidth="50.0">
62-
<Button fx:id="btnClipboard" layoutX="15.0" layoutY="15.0" mnemonicParsing="false" text="Copy to clipboard" />
63-
<Button fx:id="btnClipboard2" layoutX="255.0" layoutY="15.0" mnemonicParsing="false" text="Copy to clipboard" />
64-
</AnchorPane>
65-
</Tab>
66-
<Tab fx:id="searchTab" text="Search / Highlight" />
67-
</TabPane>
68-
</AnchorPane>
69-
</SplitPane>
11+
<?import javafx.scene.canvas.Canvas?>
12+
<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">
13+
<children>
14+
<MenuBar AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
15+
<menus>
16+
<Menu fx:id="menuFile" mnemonicParsing="false" text="File">
17+
<items>
18+
<MenuItem fx:id="btnOpenGFA" mnemonicParsing="false" text="Open GFA" />
19+
<MenuItem fx:id="btnOpenGFF" mnemonicParsing="false" text="Open GFF" />
20+
<Menu fx:id="menuRecent" mnemonicParsing="false" text="Open Recent GFA" />
21+
<SeparatorMenuItem mnemonicParsing="false" />
22+
<RadioMenuItem fx:id="btnToggle" mnemonicParsing="false" text="Toggle Console" />
23+
<RadioMenuItem fx:id="btnMiniMap" mnemonicParsing="false" text="Toggle MiniMap" />
24+
<MenuItem fx:id="btnQuit" mnemonicParsing="false" text="Quit" />
25+
</items>
26+
</Menu>
27+
<Menu fx:id="menuHelp" mnemonicParsing="false" text="Help">
28+
<items>
29+
<MenuItem fx:id="btnAbout" mnemonicParsing="false" text="About" />
30+
<MenuItem fx:id="btnInstructions" mnemonicParsing="false" text="Instructions" />
31+
</items>
32+
</Menu>
33+
<Menu fx:id="menuBookmark" mnemonicParsing="false" text="Bookmarks">
34+
<items>
35+
<MenuItem fx:id="btnBookmarks" mnemonicParsing="false" text="Bookmarks" />
36+
</items>
37+
</Menu>
38+
</menus>
39+
</MenuBar>
40+
<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">
41+
<items>
42+
<AnchorPane fx:id="anchorLeftControlPanel" maxWidth="140.0" minHeight="0.0" minWidth="140.0" prefHeight="800.0" prefWidth="100.0" SplitPane.resizableWithParent="false">
43+
<children>
44+
<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" />
45+
<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" />
46+
<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:" />
47+
<TextField fx:id="txtCenterNode" layoutX="20.0" layoutY="100.0" minWidth="100.0" promptText="Origin node" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
48+
<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:" />
49+
<TextField fx:id="txtMaxDrawDepth" layoutX="20.0" layoutY="145.0" minWidth="100.0" promptText="Max depth" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
50+
<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" />
51+
<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" />
52+
<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" />
53+
</children>
54+
</AnchorPane>
55+
<AnchorPane fx:id="anchorGraphPanel" minHeight="200" minWidth="200" prefHeight="Infinity" prefWidth="Infinity">
56+
<children>
57+
<Canvas fx:id="miniMap" height="100" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
58+
<Group fx:id="grpDrawArea" AnchorPane.bottomAnchor="100.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
59+
<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" />
60+
</children>
61+
</AnchorPane>
62+
<AnchorPane maxWidth="500.0" minWidth="140.0" prefHeight="800.0" prefWidth="Infinity">
63+
<children>
64+
<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">
65+
<tabs>
66+
<Tab text="Graph Info">
67+
<content>
68+
<AnchorPane fx:id="anchorGraphInfo" minWidth="50.0">
69+
<children>
70+
<Button fx:id="btnClipboard" layoutX="15.0" layoutY="15.0" mnemonicParsing="false" text="Copy to clipboard" />
71+
<Button fx:id="btnClipboard2" layoutX="255.0" layoutY="15.0" mnemonicParsing="false" text="Copy to clipboard" />
72+
</children>
73+
</AnchorPane>
74+
</content>
75+
</Tab>
76+
<Tab fx:id="searchTab" text="Search / Highlight" />
77+
</tabs>
78+
</TabPane>
79+
</children>
80+
</AnchorPane>
81+
</items>
82+
</SplitPane>
83+
</children>
7084
</AnchorPane>

0 commit comments

Comments
 (0)