diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/RootLayoutController.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/RootLayoutController.java index ed270fc9..df2e2112 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/RootLayoutController.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/RootLayoutController.java @@ -58,8 +58,8 @@ public class RootLayoutController implements @FXML private AnchorPane rootPane; - @FXML - private SelectionPaneController selectionPaneController; + // @FXML + // private SelectionPaneController selectionPaneController; @FXML private SplitPane mainPane; @FXML @@ -81,6 +81,9 @@ public class RootLayoutController implements @FXML private GraphPaneController graphPaneController; + @FXML + private SelectionPaneController selectionPaneController; + /** * Initializes the controller class. * @@ -97,7 +100,7 @@ public void initialize(URL location, ResourceBundle resources) { rootPane.sceneProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, Scene oldValue, - Scene newValue) { + Scene newValue) { if (newValue != null) { initializeSearchPaneController(); // fire this only once when scene is set. @@ -154,29 +157,20 @@ public Region getPane() { return rootPane; } - /** - * Draw two subgraphs. - * - * @param topGenomes the genomes of the top graph. - * @param bottomGenomes the genomes of the bottom graph. - */ - public void drawGraph(ArrayList topGenomes, ArrayList bottomGenomes) { - graphPaneController.compareTwoGraphs(topGenomes, bottomGenomes); - } - /** * Initialize the selection manager (which manages showing the description of selected objects). */ private void initializeSelectionManager() { - selectionManager = new SelectionManager(this, selectionPaneController); + selectionManager = new SelectionManager(); + treePaneController.setup(selectionManager, graphPaneController); + graphPaneController.setup(selectionManager); + selectionPaneController.setup(selectionManager); mainPane.setOnMouseClicked((MouseEvent event) -> { if (!event.isConsumed()) { selectionManager.deselect(); event.consume(); } }); - treePaneController.setup(selectionManager, graphPaneController); - graphPaneController.setup(selectionManager); } /** diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/SearchPaneController.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/SearchPaneController.java index 1e1ef4b2..a15a0d42 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/SearchPaneController.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/SearchPaneController.java @@ -259,5 +259,4 @@ public void setData(Collection metaDatas) { masterData.clear(); masterData.addAll(metaDatas); } - } diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/GraphPaneController.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/GraphPaneController.java index fbd36a61..135d20a4 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/GraphPaneController.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/GraphPaneController.java @@ -153,6 +153,13 @@ public void initialize(URL location, ResourceBundle resources) { initializeScrollbar(); initializeScrollEvent(); + initializeOnMouseEventHandler(); + } + + /** + * Initialize the mouse handlers. + */ + private void initializeOnMouseEventHandler() { mainPane.setOnMouseClicked(event -> { if (contextMenu != null) { contextMenu.hide(); @@ -708,7 +715,14 @@ private void drawNode(Pane pane, GraphNode node, HashSet drawnGraphNo height = width; } IViewGraphNode viewNode = ViewNodeBuilder.buildNode(node, - width, height, nestedDepth, selectionManager); + width, height, nestedDepth); + + viewNode.get().setOnMouseClicked(mouseEvent -> { + selectionManager.select(viewNode); + mouseEvent.consume(); + }); + // select when previously selected node is equal to this new one + selectionManager.checkSelected(viewNode); pane.getChildren().add(viewNode.get()); viewNode.centerXProperty().set(zoomFactor.get() * (node.getLevel() - startLevel - node.size() / 2.0)); @@ -926,6 +940,9 @@ private void deleteBottomGraph() { */ public void setup(SelectionManager selectionManager) { this.selectionManager = selectionManager; + selectionManager.addListener((observable, oldValue, newValue) -> { + graphUpdater.update(); + }); } /** diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewGraphNodeEllipse.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewGraphNodeEllipse.java index 6f5a5ff6..bac5f0d9 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewGraphNodeEllipse.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewGraphNodeEllipse.java @@ -3,8 +3,10 @@ import javafx.scene.Node; import javafx.scene.paint.Color; import javafx.scene.shape.Ellipse; +import nl.tudelft.pl2016gr2.gui.view.selection.GraphBubbleDescription; +import nl.tudelft.pl2016gr2.gui.view.selection.ISelectable; import nl.tudelft.pl2016gr2.gui.view.selection.ISelectionInfo; -import nl.tudelft.pl2016gr2.gui.view.selection.SelectionManager; +import nl.tudelft.pl2016gr2.model.graph.nodes.GraphNode; /** * An ellipse representation of a node, which can be drawn in the user interface. @@ -13,19 +15,19 @@ */ public class ViewGraphNodeEllipse extends Ellipse implements IViewGraphNode { - private final ISelectionInfo selectionInfo; + private final GraphNode dataNode; /** * Construct a node circle. * * @param width the width of the ellipse. * @param height the height of the ellipse. - * @param selectionInfo the select info for this node. + * @param dataNode the data node. */ - public ViewGraphNodeEllipse(double width, double height, ISelectionInfo selectionInfo) { + public ViewGraphNodeEllipse(double width, double height, GraphNode dataNode) { super(width * GraphPaneController.NODE_MARGIN / 2.0, height / 2.0); setStrokeWidth(height / 20.0d); - this.selectionInfo = selectionInfo; + this.dataNode = dataNode; } @Override @@ -54,7 +56,16 @@ public void deselect() { } @Override - public ISelectionInfo getSelectionInfo(SelectionManager selectionManager) { - return selectionInfo; + public ISelectionInfo getSelectionInfo() { + return new GraphBubbleDescription(dataNode.toString()); + } + + @Override + public boolean isEqualSelection(ISelectable other) { + if (other instanceof ViewGraphNodeEllipse) { + ViewGraphNodeEllipse that = (ViewGraphNodeEllipse) other; + return this.dataNode.getId() == that.dataNode.getId(); + } + return false; } } diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewGraphNodeRectangle.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewGraphNodeRectangle.java index 114b2a26..f0894ec9 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewGraphNodeRectangle.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewGraphNodeRectangle.java @@ -5,8 +5,10 @@ import javafx.scene.Node; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; +import nl.tudelft.pl2016gr2.gui.view.selection.GraphBubbleDescription; +import nl.tudelft.pl2016gr2.gui.view.selection.ISelectable; import nl.tudelft.pl2016gr2.gui.view.selection.ISelectionInfo; -import nl.tudelft.pl2016gr2.gui.view.selection.SelectionManager; +import nl.tudelft.pl2016gr2.model.graph.nodes.GraphNode; /** * A square representation of a node, which can be drawn in the user interface. @@ -17,23 +19,22 @@ public class ViewGraphNodeRectangle extends Rectangle implements IViewGraphNode private final DoubleProperty centerXProperty = new SimpleDoubleProperty(); private final DoubleProperty centerYProperty = new SimpleDoubleProperty(); - private final ISelectionInfo selectionInfo; + private final GraphNode dataNode; /** * Constructor. - * - * @param width the width of the rectangle. + * @param width the width of the rectangle. * @param height the height of the rectangle. - * @param selectionInfo the select info for this node. + * @param dataNode the data object. */ public ViewGraphNodeRectangle(double width, double height, - ISelectionInfo selectionInfo) { + GraphNode dataNode) { super(width/* * GraphPaneController.NODE_MARGIN*/, height); layoutXProperty().bind(centerXProperty.add(-width / 2.0)); layoutYProperty().bind(centerYProperty.add(-height / 2.0)); setFill(Color.ALICEBLUE); setStrokeWidth(height / 20.0d); - this.selectionInfo = selectionInfo; + this.dataNode = dataNode; } @Override @@ -62,7 +63,16 @@ public void deselect() { } @Override - public ISelectionInfo getSelectionInfo(SelectionManager selectionManager) { - return selectionInfo; + public ISelectionInfo getSelectionInfo() { + return new GraphBubbleDescription(dataNode.toString()); + } + + @Override + public boolean isEqualSelection(ISelectable other) { + if (other instanceof ViewGraphNodeRectangle) { + ViewGraphNodeRectangle that = (ViewGraphNodeRectangle) other; + return this.dataNode.getId() == that.dataNode.getId(); + } + return false; } } diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewNodeBuilder.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewNodeBuilder.java index 33b83367..52e1049f 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewNodeBuilder.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewNodeBuilder.java @@ -3,11 +3,7 @@ import static nl.tudelft.pl2016gr2.gui.view.graph.GraphPaneController.NO_OVERLAP_COLOR; import static nl.tudelft.pl2016gr2.gui.view.graph.GraphPaneController.OVERLAP_COLOR; -import javafx.event.EventHandler; -import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; -import nl.tudelft.pl2016gr2.gui.view.selection.GraphBubbleDescription; -import nl.tudelft.pl2016gr2.gui.view.selection.SelectionManager; import nl.tudelft.pl2016gr2.model.graph.nodes.GraphNode; import nl.tudelft.pl2016gr2.model.graph.nodes.IndelBubble; import nl.tudelft.pl2016gr2.model.graph.nodes.PhyloBubble; @@ -27,7 +23,6 @@ public class ViewNodeBuilder implements NodeVisitor { private final double width; private final double height; private final int nestedDepth; - private final SelectionManager selectionManager; private IViewGraphNode viewNode; /** @@ -37,14 +32,11 @@ public class ViewNodeBuilder implements NodeVisitor { * @param width the width of the node. * @param height the height of the node. * @param nestedDepth the amount of times this node is nested in a bubble. - * @param selectionManager The selection manager, used to select things. */ - private ViewNodeBuilder(double width, double height, int nestedDepth, - SelectionManager selectionManager) { + private ViewNodeBuilder(double width, double height, int nestedDepth) { this.width = width; this.height = height; this.nestedDepth = nestedDepth; - this.selectionManager = selectionManager; } /** @@ -54,37 +46,15 @@ private ViewNodeBuilder(double width, double height, int nestedDepth, * @param width the width of the node. * @param height the height of the node. * @param nestedDepth the amount of times this node is nested in a bubble. - * @param selectionManager The selection manager. Needed to select things. * @return the visual representation of the node. */ public static IViewGraphNode buildNode(GraphNode node, double width, double height, - int nestedDepth, SelectionManager selectionManager) { - ViewNodeBuilder builder = new ViewNodeBuilder(width, height, nestedDepth, selectionManager); + int nestedDepth) { + ViewNodeBuilder builder = new ViewNodeBuilder(width, height, nestedDepth); node.accept(builder); - - // select when previously selected node is equal to this new one - if (selectionManager.getSelectedGraphNodes().contains(node.getId())) { - selectionManager.select(builder.viewNode); - } - return builder.viewNode; } - /** - * Builds a mouse click event handler that selects the graphnode for the given id. - * - * @param id The id of the graph node to be selected. - * @return The event handler. - */ - private EventHandler buildOnMouseClickedHandler(int id) { - return mouseEvent -> { - selectionManager.getSelectedGraphNodes().clear(); - selectionManager.getSelectedGraphNodes().add(id); - selectionManager.select(viewNode); - mouseEvent.consume(); - }; - } - @Override public void visit(GraphNode node) { throw new UnsupportedOperationException("Unknown node, this node doesn't have a graphical" @@ -93,96 +63,56 @@ public void visit(GraphNode node) { @Override public void visit(PhyloBubble bubble) { - ViewGraphNodeRectangle rect = new ViewGraphNodeRectangle(width, height, - new GraphBubbleDescription() { - @Override - public String getText() { - return bubble.toString(); - } - } - ); + ViewGraphNodeRectangle rect = new ViewGraphNodeRectangle(width, height, bubble); Color fill = Color.ALICEBLUE; for (int i = 0; i < nestedDepth; i++) { fill = fill.deriveColor(0.0, 1.0, 0.9, 1.0); } rect.setFill(fill); - rect.setOnMouseClicked(buildOnMouseClickedHandler(bubble.getId())); viewNode = rect; } @Override public void visit(StraightSequenceBubble bubble) { - ViewGraphNodeRectangle rect = new ViewGraphNodeRectangle(width, height, - new GraphBubbleDescription() { - @Override - public String getText() { - return bubble.toString(); - } - } - ); + ViewGraphNodeRectangle rect = new ViewGraphNodeRectangle(width, height, bubble); Color fill = Color.LIGHTCORAL; for (int i = 0; i < nestedDepth; i++) { fill = fill.deriveColor(0.0, 1.0, 0.9, 1.0); } rect.setFill(fill); - rect.setOnMouseClicked(buildOnMouseClickedHandler(bubble.getId())); viewNode = rect; } @Override public void visit(IndelBubble bubble) { - ViewGraphNodeRectangle rect = new ViewGraphNodeRectangle(width, height, - new GraphBubbleDescription() { - @Override - public String getText() { - return bubble.toString(); - } - } - ); + ViewGraphNodeRectangle rect = new ViewGraphNodeRectangle(width, height, bubble); Color fill = Color.LIGHTSKYBLUE; for (int i = 0; i < nestedDepth; i++) { fill = fill.deriveColor(0.0, 1.0, 0.9, 1.0); } rect.setFill(fill); - rect.setOnMouseClicked(buildOnMouseClickedHandler(bubble.getId())); viewNode = rect; } @Override public void visit(PointMutationBubble bubble) { - ViewGraphNodeRectangle rect = new ViewGraphNodeRectangle(width, height, - new GraphBubbleDescription() { - @Override - public String getText() { - return bubble.toString(); - } - } - ); + ViewGraphNodeRectangle rect = new ViewGraphNodeRectangle(width, height, bubble); Color fill = Color.PLUM; for (int i = 0; i < nestedDepth; i++) { fill = fill.deriveColor(0.0, 1.0, 0.9, 1.0); } rect.setFill(fill); - rect.setOnMouseClicked(buildOnMouseClickedHandler(bubble.getId())); viewNode = rect; } @Override public void visit(SequenceNode node) { - ViewGraphNodeEllipse circle = new ViewGraphNodeEllipse(width, height, - new GraphBubbleDescription() { - @Override - public String getText() { - return node.toString(); - } - } - ); + ViewGraphNodeEllipse circle = new ViewGraphNodeEllipse(width, height, node); if (node.getGuiData().overlapping) { circle.setFill(OVERLAP_COLOR); } else { circle.setFill(NO_OVERLAP_COLOR); } - circle.setOnMouseClicked(buildOnMouseClickedHandler(node.getId())); viewNode = circle; } } diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/GraphBubbleDescription.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/GraphBubbleDescription.java index 08fdddbe..09ee3af6 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/GraphBubbleDescription.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/GraphBubbleDescription.java @@ -13,11 +13,14 @@ /** * Class can be used for simple text. */ -public abstract class GraphBubbleDescription implements ISelectionInfo { +public class GraphBubbleDescription implements ISelectionInfo { - public GraphBubbleDescription() { - } + private final String text; + public GraphBubbleDescription(String text) { + this.text = text; + } + @Override public Node getNode() { try { @@ -36,8 +39,14 @@ public Node getNode() { } } - public abstract String getText(); - + /** + * This class is the controller for the fxml used by {@link GraphBubbleDescription}. + * + *

+ * The controller can be setup with an {@link GraphBubbleDescription} instance to + * display the text in a simple TextArea. + *

+ */ public static class GraphNodeRectangleDescriptionController implements Initializable { @FXML @@ -50,7 +59,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) { void setup(GraphBubbleDescription graphBubbleDescription) { - textArea.setText(graphBubbleDescription.getText()); + textArea.setText(graphBubbleDescription.text); } } } diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/ISelectable.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/ISelectable.java index 629b15cd..32faa37d 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/ISelectable.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/ISelectable.java @@ -20,8 +20,21 @@ public interface ISelectable { /** * Get the {@link ISelectionInfo}. * - * @param selectionManager the {@link SelectionManager} which is requesting the selection info. * @return the {@link ISelectionInfo}. */ - ISelectionInfo getSelectionInfo(SelectionManager selectionManager); + ISelectionInfo getSelectionInfo(); + + /** + * Like Object.equals, but for selections + * + *

+ * Should return true when the other selection would be corresponding + * to the same conceptual selection. + *

+ * + * @param other object to check against. + * @return true when equal + */ + boolean isEqualSelection(ISelectable other); + } diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/SelectionManager.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/SelectionManager.java index c89c4472..37dbe7d8 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/SelectionManager.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/SelectionManager.java @@ -1,13 +1,13 @@ package nl.tudelft.pl2016gr2.gui.view.selection; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ChangeListener; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import javafx.collections.ObservableSet; -import javafx.scene.Node; -import nl.tudelft.pl2016gr2.gui.view.RootLayoutController; -import nl.tudelft.pl2016gr2.thirdparty.testing.utility.TestId; +import javafx.geometry.Pos; +import javafx.scene.control.TextArea; +import javafx.scene.layout.StackPane; -import java.util.ArrayList; /** * This class manages the currently selected node. It makes sure the correct data is displayed and @@ -17,100 +17,107 @@ */ public class SelectionManager { - private final RootLayoutController rootLayoutController; - @TestId(id = "selectionPaneController") - private final SelectionPaneController selectionPaneController; - @TestId(id = "selected") - private ISelectable selected; + private final ObservableList searchBoxSelectedGenomes + = FXCollections.observableArrayList(); + private final SimpleObjectProperty selection; /** - * The selected nodes in the graph. -1 means no genome is selected. + * This Selectable represents no selection. + * + *

+ * This makes sure that there will not be unexpected null-references + * when doing stuff with selections. + *

*/ - private final ObservableSet graphSelectedNodes - = FXCollections.observableSet(); + public static final ISelectable NO_SELECTION = new ISelectable() { + @Override + public void select() { - /** - * The selected genome in the search box. -1 means no genome is selected. - */ - private final ObservableList searchBoxSelectedGenomes - = FXCollections.observableArrayList(); + } + + @Override + public void deselect() { + + } + + @Override + public ISelectionInfo getSelectionInfo() { + return () -> { + TextArea textArea = new TextArea("Nothing selected"); + + textArea.setWrapText(true); + + StackPane.setAlignment(textArea, Pos.CENTER); + + return new StackPane(textArea); + }; + } + + @Override + public boolean isEqualSelection(ISelectable other) { + return false; + } + }; /** * Create a selection manager. - * - * @param rootLayoutController the root layout controller class. - * @param selectionPaneController the controller of the selectionPane. */ - public SelectionManager(RootLayoutController rootLayoutController, - SelectionPaneController selectionPaneController) { - this.rootLayoutController = rootLayoutController; - this.selectionPaneController = selectionPaneController; + public SelectionManager() { + this.selection = new SimpleObjectProperty<>(); } /** - * Request the selection manager to select the given object. + * Get the observable list of genomes which is selected in the search box. * - * @param selected the object to select. + * @return the observable list of genomes which is selected in the search box. */ - public void select(ISelectable selected) { - if (selected.equals(this.selected)) { - return; - } - deselect(); - this.selected = selected; - selected.select(); - createDescription(selected); + public ObservableList getSearchBoxSelectedGenomes() { + return searchBoxSelectedGenomes; } - /** - * Deselect the selected object. If no object is selected calling this method will have no effect. - */ - public void deselect() { - if (selected != null) { - selected.deselect(); - selected = null; - clearDescription(); - } + public void addListener(ChangeListener listener) { + selection.addListener(listener); } - /** - * Draw the two given graphs. - * - * @param topGenomes the genomes to draw in the top graph. - * @param bottomGenomes the genomes to draw in the bottom graph. - */ - protected void drawGraph(ArrayList topGenomes, ArrayList bottomGenomes) { - rootLayoutController.drawGraph(topGenomes, bottomGenomes); + public void deselect() { + selection.set(NO_SELECTION); } /** - * Set the content of the selection description pane. + * Returns the selected item * - * @param selected the currently selected object. + * @return the currently selected item. */ - private void createDescription(ISelectable selected) { - Node description = selected.getSelectionInfo(this).getNode(); - selectionPaneController.setContent(description); + public ISelectable getSelection() { + return selection.get(); } /** - * Clear the description pane. + * Select the given selectable. + * + * @param selectable the item to be "selected" */ - private void clearDescription() { - selectionPaneController.clearContent(); + public void select(ISelectable selectable) { + if (!isSelected(selectable)) { + selection.set(selectable); + } } /** - * Get the observable list of genomes which is selected in the search box. + * This method calls select or deselect depending on the state of viewNode. * - * @return the observable list of genomes which is selected in the search box. + * @param selectable the selectable in question */ - public ObservableList getSearchBoxSelectedGenomes() { - return searchBoxSelectedGenomes; + public void checkSelected(ISelectable selectable) { + if (isSelected(selectable)) { + selectable.select(); + } else { + selectable.deselect(); + } } - public ObservableSet getSelectedGraphNodes() { - return graphSelectedNodes; + private boolean isSelected(ISelectable selectable) { + return selectable.isEqualSelection(selection.get()); } } diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/SelectionPaneController.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/SelectionPaneController.java index 52ce4233..8b10cd13 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/SelectionPaneController.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/SelectionPaneController.java @@ -1,56 +1,141 @@ package nl.tudelft.pl2016gr2.gui.view.selection; +import javafx.beans.property.SimpleObjectProperty; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.geometry.Insets; import javafx.scene.Node; +import javafx.scene.control.Button; +import javafx.scene.control.TextArea; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import java.net.URL; import java.util.ResourceBundle; +/** + * Right now this class mainly just shows the selection(s). + * + *

+ * It has some code ready for doing a comparison, but consider this more of a + * proof of concept. There has to be an easy way for the user to compare the two + * selections he has made. + *

+ * + */ public class SelectionPaneController implements Initializable { private static final Color BACKGROUND_COLOR = new Color(0.4, 0.4, 0.45, 1); @FXML - public AnchorPane rootPane; + private Pane rootPane; + @FXML + private AnchorPane primarySelectionPane; + @FXML + private AnchorPane secondarySelectionPane; + @FXML + private AnchorPane compareSelectionPane; + + private Button setSecondaryButton = new Button("Copy over from left to right"); + private Button compareButton = new Button("Compare left to right"); + // Add compareButton when wanting to do the actual comparison! + private Pane buttonContainer = new VBox(setSecondaryButton); + + { + AnchorPane.setLeftAnchor(buttonContainer, 5.0d); + AnchorPane.setRightAnchor(buttonContainer, 5.0d); + setSecondaryButton.setWrapText(true); + compareButton.setWrapText(true); + } + + private SimpleObjectProperty primarySelection; + private SimpleObjectProperty secondarySelection; @Override public void initialize(URL url, ResourceBundle resourceBundle) { + this.primarySelection = new SimpleObjectProperty<>(); + this.secondarySelection = new SimpleObjectProperty<>(); + + primarySelection.addListener((observable, oldValue, newValue) -> { + expandInAnchorPane(newValue.getSelectionInfo().getNode(), primarySelectionPane); + }); + secondarySelection.addListener((observable, oldValue, newValue) -> { + expandInAnchorPane(newValue.getSelectionInfo().getNode(), secondarySelectionPane); + }); + + primarySelection.set(SelectionManager.NO_SELECTION); + secondarySelection.set(SelectionManager.NO_SELECTION); + + resetCompare(); + rootPane.setBackground(new Background( new BackgroundFill(BACKGROUND_COLOR, null, Insets.EMPTY))); } /** - * Sets the content of the selectionPane. - * - *

- * This removes previous shown content, - * call with null to clear. - *

+ * Sets up this controller. * - * @param content new content, may be null + * @param selectionManager a selection manager is needed. */ - public void setContent(Node content) { - clearContent(); + public void setup(SelectionManager selectionManager) { + selectionManager.addListener((observable, oldValue, newValue) -> { + primarySelection.set(newValue); + }); + + setSecondaryButton.setOnAction(actionEvent -> { + System.out.println("clicked (onAction)"); + secondarySelection.set(primarySelection.getValue()); + }); + compareButton.setOnAction(actionEvent -> { + Pane pane = startCompare(); + pane.setMaxWidth(150); + expandInAnchorPane(pane, compareSelectionPane); + }); + } + + /** + * Removes the visual comparison and puts button back. + */ + private void resetCompare() { + compareSelectionPane.getChildren().clear(); + compareSelectionPane.getChildren().add(buttonContainer); + } + + /** + * This method is not used yet. It is called when + * the compare button (now hidden) is pressed. + * @return A pane that should contain a visual comparison of primary and secondary. + */ + private Pane startCompare() { + Button cancelButton = new Button("Cancel"); + cancelButton.setOnAction(actionEvent1 -> { + resetCompare(); + }); + + TextArea textArea = new TextArea(String.format("Compare %s to %s", + primarySelection.get().getSelectionInfo(), + secondarySelection.get().getSelectionInfo())); + textArea.setWrapText(true); + + return new VBox(textArea, cancelButton); + } + + /** + * Sets all anchors to 0 and adds. + */ + private void expandInAnchorPane(Node content, AnchorPane anchorPane) { + anchorPane.getChildren().clear(); if (content != null) { AnchorPane.setTopAnchor(content, 0.0d); AnchorPane.setBottomAnchor(content, 0.0d); AnchorPane.setLeftAnchor(content, 0.0d); AnchorPane.setRightAnchor(content, 0.0d); - rootPane.getChildren().add(content); + anchorPane.getChildren().add(content); } } - /** - * Clears the pane of information. - */ - public void clearContent() { - rootPane.getChildren().clear(); - } - } diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/TreeNodeDescription.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/TreeNodeDescription.java index 0cd3a8bf..33e280ca 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/TreeNodeDescription.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/selection/TreeNodeDescription.java @@ -7,6 +7,7 @@ import javafx.scene.control.TextArea; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; +import nl.tudelft.pl2016gr2.gui.view.graph.GraphPaneController; import nl.tudelft.pl2016gr2.model.GenomeMap; import nl.tudelft.pl2016gr2.model.phylogenetictree.IPhylogeneticTreeNode; @@ -18,24 +19,25 @@ public class TreeNodeDescription implements ISelectionInfo { private final IPhylogeneticTreeNode treeNode; - private final SelectionManager selectionManager; + private final GraphPaneController graphPaneController; private final EventHandler buttonClicked = new EventHandler() { @Override public void handle(ActionEvent event) { IPhylogeneticTreeNode topNode = treeNode.getChild(0); IPhylogeneticTreeNode bottomNode = treeNode.getChild(1); - selectionManager.drawGraph(topNode.getGenomeIds(), bottomNode.getGenomeIds()); + graphPaneController.compareTwoGraphs(topNode.getGenomeIds(), bottomNode.getGenomeIds()); } }; /** * Construct a tree node description. * - * @param selectionManager a reference to the selection manager. + * @param graphPaneController a reference to the graphpane controller. * @param treeNode the tree node to describe. */ - public TreeNodeDescription(SelectionManager selectionManager, IPhylogeneticTreeNode treeNode) { - this.selectionManager = selectionManager; + public TreeNodeDescription(GraphPaneController graphPaneController, + IPhylogeneticTreeNode treeNode) { + this.graphPaneController = graphPaneController; this.treeNode = treeNode; } diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/tree/TreeNodeCircle.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/tree/TreeNodeCircle.java index 3a2f9b4f..cba6d8bd 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/tree/TreeNodeCircle.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/tree/TreeNodeCircle.java @@ -22,7 +22,6 @@ import nl.tudelft.pl2016gr2.gui.view.graph.GraphPaneController; import nl.tudelft.pl2016gr2.gui.view.selection.ISelectable; import nl.tudelft.pl2016gr2.gui.view.selection.ISelectionInfo; -import nl.tudelft.pl2016gr2.gui.view.selection.SelectionManager; import nl.tudelft.pl2016gr2.gui.view.selection.TreeLeafDescription; import nl.tudelft.pl2016gr2.gui.view.selection.TreeNodeDescription; import nl.tudelft.pl2016gr2.model.GenomeMap; @@ -71,7 +70,7 @@ public class TreeNodeCircle extends Circle implements ISelectable { @TestId(id = "children") private final ArrayList children = new ArrayList<>(); private final Area area; - private final SelectionManager selectionManager; + private final TreePaneController treePaneController; private boolean isLeaf; private final Line edge = new Line(); private Rectangle highlightArea; @@ -81,15 +80,15 @@ public class TreeNodeCircle extends Circle implements ISelectable { * * @param dataNode the data of the node. * @param graphArea the graph area in which the node has to be drawn. - * @param selectionManager the selection manager. + * @param treePaneController the selection manager. */ private TreeNodeCircle(IPhylogeneticTreeNode dataNode, Area graphArea, - SelectionManager selectionManager) { + TreePaneController treePaneController) { super(NODE_RADIUS); setStrokeWidth(NODE_BORDER_WIDTH); this.dataNode = dataNode; this.area = graphArea; - this.selectionManager = selectionManager; + this.treePaneController = treePaneController; setColor(); resetBorderColor(); @@ -126,7 +125,7 @@ private void initializeNodeListeners() { */ private void initializeClickedEvent() { this.setOnMouseClicked((MouseEvent event) -> { - selectionManager.select(this); + treePaneController.getSelectionManager().select(this); event.consume(); }); } @@ -196,18 +195,19 @@ public IPhylogeneticTreeNode getDataNode() { * @param dataNode the data of the node to draw. * @param graphArea the area in which the node should be drawn. * @param graphPane the pane in which to draw the node. - * @param selectionManager the selection manager. + * @param treePaneController the treePane controller. * @return the drawn nl.tudelft.pl2016gr2.gui.view node. */ protected static TreeNodeCircle drawNode(IPhylogeneticTreeNode dataNode, Area graphArea, - Pane graphPane, SelectionManager selectionManager) { + Pane graphPane, TreePaneController treePaneController) { if (graphArea.getWidth() < NODE_DIAMETER || graphArea.getHeight() < NODE_DIAMETER || dataNode == null) { return null; // not enough space to draw the tree node. } - TreeNodeCircle node = new TreeNodeCircle(dataNode, graphArea, selectionManager); + TreeNodeCircle node = new TreeNodeCircle(dataNode, graphArea, treePaneController); graphPane.getChildren().add(node); - drawChildren(node, dataNode, graphArea, graphPane, selectionManager); + drawChildren(node, dataNode, graphArea, graphPane); + treePaneController.getSelectionManager().checkSelected(node); return node; } @@ -218,10 +218,9 @@ protected static TreeNodeCircle drawNode(IPhylogeneticTreeNode dataNode, Area gr * @param dataNode the data node. * @param area the graph area of the node. * @param graphPane the pane in which to draw the node. - * @param selectionManager the selection manager. */ private static void drawChildren(TreeNodeCircle node, IPhylogeneticTreeNode dataNode, Area area, - Pane graphPane, SelectionManager selectionManager) { + Pane graphPane) { if (dataNode.isLeaf()) { node.isLeaf = true; return; @@ -238,7 +237,7 @@ private static void drawChildren(TreeNodeCircle node, IPhylogeneticTreeNode data double nextEndY = nextStartY + ySize; double nextEndX = area.getEndX() - calculateEdgeLength(dataNode.getChild(i)); Area childArea = new Area(area.getStartX(), nextEndX, nextStartY, nextEndY); - TreeNodeCircle child = drawNode(childDataNode, childArea, graphPane, selectionManager); + TreeNodeCircle child = drawNode(childDataNode, childArea, graphPane, node.treePaneController); node.children.add(child); child.drawEdge(node, child, graphPane); } @@ -419,6 +418,10 @@ public ArrayList getCurrentLeaves() { return res; } + public List getChildren() { + return children; + } + /** * Get the closest parent node to the given x and y coordinates. Parent nodes contain the given x * and y coordinates in their {@code area}. The node which is the deepest in the tree and contains @@ -478,10 +481,19 @@ public void deselect() { } @Override - public ISelectionInfo getSelectionInfo(SelectionManager selectionManager) { + public ISelectionInfo getSelectionInfo() { if (dataNode.getChildCount() != 0) { - return new TreeNodeDescription(selectionManager, dataNode); + return new TreeNodeDescription(treePaneController.getGraphPaneController(), dataNode); } return new TreeLeafDescription(dataNode); } + + @Override + public boolean isEqualSelection(ISelectable other) { + if (other instanceof TreeNodeCircle) { + TreeNodeCircle that = (TreeNodeCircle) other; + return this.dataNode == that.dataNode; + } + return false; + } } diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/tree/TreePaneController.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/tree/TreePaneController.java index 451570b1..25563f81 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/tree/TreePaneController.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/tree/TreePaneController.java @@ -1,5 +1,6 @@ package nl.tudelft.pl2016gr2.gui.view.tree; + import javafx.animation.Timeline; import javafx.collections.ListChangeListener; import javafx.collections.SetChangeListener; @@ -9,8 +10,8 @@ import javafx.scene.input.ScrollEvent; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Pane; -import javafx.scene.layout.Region; import nl.tudelft.pl2016gr2.gui.view.graph.GraphPaneController; +import nl.tudelft.pl2016gr2.gui.view.selection.ISelectable; import nl.tudelft.pl2016gr2.gui.view.selection.SelectionManager; import nl.tudelft.pl2016gr2.gui.view.tree.heatmap.HeatmapManager; import nl.tudelft.pl2016gr2.model.phylogenetictree.IPhylogeneticTreeNode; @@ -74,6 +75,9 @@ public void initialize(URL location, ResourceBundle resources) { public void setup(SelectionManager selectionManager, GraphPaneController graphPaneController) { this.selectionManager = selectionManager; this.graphPaneController = graphPaneController; + selectionManager.addListener((observable, oldValue, newValue) -> { + checkSelectedForNodeAndLeaves(currentRoot); + }); initializeTopGraphSelectionManger(); initializeBottomGraphSelectionManger(); initializeSearchBoxSelectionManager(); @@ -247,7 +251,7 @@ private void initializeGraphSizeListeners() { @TestId(id = "setRoot") private void setCurrentRoot(IPhylogeneticTreeNode root) { treePane.getChildren().clear(); - currentRoot = TreeNodeCircle.drawNode(root, getGraphPaneArea(), treePane, selectionManager); + currentRoot = TreeNodeCircle.drawNode(root, getGraphPaneArea(), treePane, this); childLeaveObservers.forEach((Observer observer) -> { observer.update(null, null); }); @@ -314,21 +318,35 @@ private ArrayList getCurrentLeaves() { } /** - * Get the pane in which the tree is drawn. + * Recursively iterate the given node and its children and check Selection. * - * @return the pane in which the tree is drawn. + *

+ * This method will call {@link SelectionManager#checkSelected(ISelectable)} for + * each child. + *

+ * + * @param node check for this node. */ - public Region getTreePane() { - return mainPane; + private void checkSelectedForNodeAndLeaves(TreeNodeCircle node) { + if (node != null) { + selectionManager.checkSelected(node); + node.getChildren().forEach(this::checkSelectedForNodeAndLeaves); + } } /** - * Get the root of the tree. - * - * @return the root of the tree. + * Getter for the selectionManager + * @return the selectionManager. */ - public IPhylogeneticTreeRoot getTreeRoot() { - return rootNode; + public SelectionManager getSelectionManager() { + return selectionManager; } + /** + * Getter for the graphPaneController. + * @return the graphPaneController. + */ + public GraphPaneController getGraphPaneController() { + return graphPaneController; + } } diff --git a/PL2/PL2-gui/src/main/resources/pages/RootLayout.fxml b/PL2/PL2-gui/src/main/resources/pages/RootLayout.fxml index 9f067db8..78349e47 100644 --- a/PL2/PL2-gui/src/main/resources/pages/RootLayout.fxml +++ b/PL2/PL2-gui/src/main/resources/pages/RootLayout.fxml @@ -11,7 +11,7 @@ - + diff --git a/PL2/PL2-gui/src/main/resources/pages/selectionPane.fxml b/PL2/PL2-gui/src/main/resources/pages/selectionPane.fxml index b9a9f1f1..f6694ec4 100644 --- a/PL2/PL2-gui/src/main/resources/pages/selectionPane.fxml +++ b/PL2/PL2-gui/src/main/resources/pages/selectionPane.fxml @@ -2,8 +2,8 @@ - - - - - + + + + + diff --git a/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/IntegrationTest.java b/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/IntegrationTest.java index 4d5c3bf3..736206ef 100644 --- a/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/IntegrationTest.java +++ b/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/IntegrationTest.java @@ -1,26 +1,16 @@ package nl.tudelft.pl2016gr2.gui; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.scene.Node; -import javafx.scene.control.Button; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; -import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.Pane; import javafx.stage.Stage; -import nl.tudelft.pl2016gr2.core.algorithms.subgraph.OrderedGraph; import nl.tudelft.pl2016gr2.gui.javafxrunner.JavaFxIntegrationTestRunner; import nl.tudelft.pl2016gr2.gui.javafxrunner.JavaFxRealApplication; import nl.tudelft.pl2016gr2.gui.view.RootLayoutController; import nl.tudelft.pl2016gr2.gui.view.graph.GraphPaneController; -import nl.tudelft.pl2016gr2.gui.view.selection.ISelectable; import nl.tudelft.pl2016gr2.gui.view.selection.SelectionManager; import nl.tudelft.pl2016gr2.gui.view.selection.SelectionPaneController; -import nl.tudelft.pl2016gr2.gui.view.tree.TreeNodeCircle; import nl.tudelft.pl2016gr2.gui.view.tree.TreePaneController; import nl.tudelft.pl2016gr2.model.GenomeMap; import nl.tudelft.pl2016gr2.parser.controller.GfaReader; @@ -54,60 +44,6 @@ public void launchApplicationTest() { assertNotEquals(null, getPrimaryStage().getScene()); } - /** - * Test if a tree node is correctly selected when it is clicked. - */ - @Test - public void selectTreeNodeTest() { - loadFiles(); - TreeNodeCircle root = AccessPrivate.getFieldValue("currentRoot", TreePaneController.class, - getTreeManager()); - root.getOnMouseClicked().handle(SOME_MOUSE_EVENT); - SelectionManager selectionManager = getSelectionManager(); - ISelectable selected = AccessPrivate.getFieldValue("selected", SelectionManager.class, - selectionManager); - assertEquals(selected, root); - } - - /** - * Check if two graphs are drawn when the compare children button is clicked. - */ - @Test - public void compareChildrenButtonTest() { - drawGraph(); - SimpleIntegerProperty drawnLevels - = AccessPrivate.getFieldValue("amountOfLevels", GraphPaneController.class, - getDrawComparedGraphs()); - assertTrue(drawnLevels.get() > 0); - OrderedGraph topGraph = AccessPrivate.getFieldValue("topGraph", GraphPaneController.class, - getDrawComparedGraphs()); - OrderedGraph bottomGraph = AccessPrivate.getFieldValue("bottomGraph", GraphPaneController.class, - getDrawComparedGraphs()); - assertTrue(topGraph.getGraphOrder().size() > 0); - assertTrue(bottomGraph.getGraphOrder().size() > 0); - } - - /** - * Click through the application, select a tree node and click the "compare children" button. - */ - private void drawGraph() { - loadFiles(); - TreeNodeCircle root = AccessPrivate.getFieldValue("currentRoot", TreePaneController.class, - getTreeManager()); - root.getOnMouseClicked().handle( - new MouseEvent(null, 0, 0, 0, 0, MouseButton.NONE, 0, true, true, true, true, true, true, - true, true, true, true, null)); - AnchorPane rootPane = getSelectionController().rootPane; - Button compareButton = null; - for (Node node : rootPane.getChildren()) { - if (node instanceof Pane) { - compareButton = (Button) ((Pane) node).getChildren().get(0); - } - } - assertNotEquals(null, compareButton); - compareButton.fire(); - } - /** * Load the tree, graph and metadata files. */ diff --git a/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/view/selection/SelectionManagerTest.java b/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/view/selection/SelectionManagerTest.java deleted file mode 100644 index 3e281ecc..00000000 --- a/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/view/selection/SelectionManagerTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package nl.tudelft.pl2016gr2.gui.view.selection; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import javafx.scene.Scene; -import javafx.scene.layout.Pane; -import nl.tudelft.pl2016gr2.gui.javafxrunner.JavaFxIntegrationTestRunner; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; - -/** - * This class tests the {@link SelectionManager} class. - * - * @author Faris - */ -@RunWith(JavaFxIntegrationTestRunner.class) -public class SelectionManagerTest { - - private SelectionManager selectionManager; - private ISelectable selectable; - - /** - * Initialize and mock the variables which are used by the tests. - */ - @Before - public void initializeVariables() { - Pane pane = new Pane(); - SelectionPaneController selectionPaneController = mock(SelectionPaneController.class); - selectionManager = new SelectionManager(null, selectionPaneController); - selectable = mock(ISelectable.class); - ISelectionInfo selectionInfo = mock(ISelectionInfo.class); - - when(selectable.getSelectionInfo(selectionManager)).thenReturn(selectionInfo); - when(selectionInfo.getNode()).thenReturn(new Pane()); - } - - /** - * Test of select method, of class SelectionManager. - */ - @Test - public void testSelect() { - selectionManager.select(selectable); - verify(selectable, times(1)).select(); - } - - /** - * Test of select method, of class SelectionManager. - */ - @Test - public void testSelectTwice() { - selectionManager.select(selectable); - selectionManager.select(selectable); - verify(selectable, times(1)).select(); - } - - /** - * Test of deselect method, of class SelectionManager. - */ - @Test - public void testDeselect() { - selectionManager.select(selectable); - selectionManager.deselect(); - verify(selectable, times(1)).deselect(); - } - - /** - * Test of deselect method, of class SelectionManager. - */ - @Test - public void testDeselectTwice() { - selectionManager.select(selectable); - selectionManager.deselect(); - selectionManager.deselect(); - verify(selectable, times(1)).deselect(); - } - -} diff --git a/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/view/tree/TreeNodeCircleTest.java b/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/view/tree/TreeNodeCircleTest.java index a1e6c899..d74ebbd0 100644 --- a/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/view/tree/TreeNodeCircleTest.java +++ b/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/view/tree/TreeNodeCircleTest.java @@ -1,6 +1,8 @@ package nl.tudelft.pl2016gr2.gui.view.tree; import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -55,6 +57,8 @@ public class TreeNodeCircleTest { @Mock private SelectionManager selectionManager; + @Mock + private TreePaneController treePaneController; private TreeNodeCircle viewNode; private final Area area = new Area(0, 50, 100, 200); private Pane graphPaneSpy; @@ -70,7 +74,8 @@ public void loadTree() { mockLeafLr(); mockLeafLl(); graphPaneSpy = Mockito.spy(new Pane()); - viewNode = TreeNodeCircle.drawNode(root, area, graphPaneSpy, selectionManager); + when(treePaneController.getSelectionManager()).thenReturn(selectionManager); + viewNode = TreeNodeCircle.drawNode(root, area, graphPaneSpy, treePaneController); } /** @@ -238,7 +243,8 @@ public void testZoomIn() { @Test public void testZoomOut() { Timeline timeline = new Timeline(); - TreeNodeCircle zoomLeafL = TreeNodeCircle.drawNode(leafL, area, graphPaneSpy, selectionManager); + TreeNodeCircle zoomLeafL = + TreeNodeCircle.drawNode(leafL, area,graphPaneSpy, treePaneController); zoomLeafL.zoomOut(timeline); assertEquals(3, timeline.getKeyFrames().size()); } diff --git a/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/view/tree/TreePaneControllerTest.java b/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/view/tree/TreePaneControllerTest.java index e6df5ef9..68c74ca7 100644 --- a/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/view/tree/TreePaneControllerTest.java +++ b/PL2/PL2-gui/src/test/java/nl/tudelft/pl2016gr2/gui/view/tree/TreePaneControllerTest.java @@ -89,10 +89,9 @@ private void initializeTreeManager() { AccessPrivate.setFieldValue("mainPane", TreePaneController.class, treePaneController, new AnchorPane()); - SelectionPaneController mockedSelectionPaneController = mock(SelectionPaneController.class); GraphPaneController mockedGraphPaneController = spy(new GraphPaneController()); SelectionManager mockedSelectionManager = - spy(new SelectionManager(null, mockedSelectionPaneController)); + spy(new SelectionManager()); treePaneController.setup(mockedSelectionManager, mockedGraphPaneController); mockedGraphPaneController.getBottomGraphGenomes().addAll(root.getGenomes());