From a2d3dd398849ed0d352a7d94d7d05a60477556bd Mon Sep 17 00:00:00 2001 From: Inaba Kazuhiro Date: Sun, 30 Oct 2016 07:53:53 +0800 Subject: [PATCH] Navigate panels with tab and shift + tab --- .../java/seedu/taskman/ui/MainWindow.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/seedu/taskman/ui/MainWindow.java b/src/main/java/seedu/taskman/ui/MainWindow.java index 97e95bcfcda0..0f0726b0b569 100644 --- a/src/main/java/seedu/taskman/ui/MainWindow.java +++ b/src/main/java/seedu/taskman/ui/MainWindow.java @@ -1,8 +1,12 @@ package seedu.taskman.ui; +import java.util.ArrayList; + import javafx.fxml.FXML; import javafx.scene.Node; +import javafx.scene.Parent; import javafx.scene.Scene; +import javafx.scene.control.ListView; import javafx.scene.control.MenuItem; import javafx.scene.input.KeyCombination; import javafx.scene.layout.AnchorPane; @@ -119,6 +123,7 @@ void fillInnerParts() { resultDisplay = ResultDisplay.load(primaryStage, getResultDisplayPlaceholder()); statusBarFooter = StatusBarFooter.load(primaryStage, getStatusbarPlaceholder(), config.getTaskManFilePath()); commandBox = CommandBox.load(primaryStage, getCommandBoxPlaceholder(), resultDisplay, logic); + configureFocus(); } private AnchorPane getCommandBoxPlaceholder() { @@ -232,6 +237,31 @@ public void show() { private void handleExit() { raise(new ExitAppRequestEvent()); } + + private void configureFocus() { + ArrayList nodes = getAllNodes(); + for (Node node : nodes) { + if (node.getClass().equals(ListView.class)) { + node.setFocusTraversable(true); + } else { + node.setFocusTraversable(false); + } + } + } + + private ArrayList getAllNodes() { + ArrayList nodes = new ArrayList(); + addAllDescendents(rootLayout, nodes); + return nodes; + } + + private void addAllDescendents(Parent parent, ArrayList nodes) { + for (Node node : parent.getChildrenUnmodifiable()) { + nodes.add(node); + if (node instanceof Parent) + addAllDescendents((Parent)node, nodes); + } + } }