From 7de61ac27e52e1f56d97185f5e0f914c24ee6581 Mon Sep 17 00:00:00 2001 From: Holt59 Date: Mon, 26 Feb 2018 20:29:05 +0100 Subject: [PATCH] Fix visiblity issue with markers in NodesInputPanel. --- .../org/insa/graphics/NodesInputPanel.java | 21 +++++++++++++++++-- .../org/insa/graphics/ShortestPathPanel.java | 20 ++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/main/org/insa/graphics/NodesInputPanel.java b/src/main/org/insa/graphics/NodesInputPanel.java index 4aa8d40..7326798 100644 --- a/src/main/org/insa/graphics/NodesInputPanel.java +++ b/src/main/org/insa/graphics/NodesInputPanel.java @@ -91,6 +91,17 @@ public class NodesInputPanel extends JPanel inputChangeListeners.add(listener); } + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + for (JTextField input: nodeInputs) { + MarkerOverlay marker = markerTrackers.getOrDefault(input, null); + if (marker != null) { + marker.setVisible(visible && !input.getText().trim().isEmpty()); + } + } + } + @Override public void setEnabled(boolean enabled) { for (JComponent component: components) { @@ -285,7 +296,10 @@ public class NodesInputPanel extends JPanel */ protected void nextInputToFill() { boolean found = false; - for (int i = 1; i < nodeInputs.size() && !found; ++i) { + if (inputToFillIndex == -1) { + inputToFillIndex = 0; + } + for (int i = 0; i < nodeInputs.size() && !found; ++i) { int nextIndex = (i + inputToFillIndex) % nodeInputs.size(); JTextField input = nodeInputs.get(nextIndex); if (input.getText().trim().isEmpty()) { @@ -300,9 +314,9 @@ public class NodesInputPanel extends JPanel @Override public void mouseClicked(Point point) { - Node node = graph.findClosestNode(point); JTextField input = getInputToFill(); if (input != null) { + Node node = graph.findClosestNode(point); input.setText(String.valueOf(node.getId())); nextInputToFill(); } @@ -313,6 +327,9 @@ public class NodesInputPanel extends JPanel if (graph != this.graph) { this.clear(); this.graph = graph; + + // Disable if previously disabled... + setEnabled(this.isEnabled()); } } diff --git a/src/main/org/insa/graphics/ShortestPathPanel.java b/src/main/org/insa/graphics/ShortestPathPanel.java index 37b2bbf..a52c11c 100644 --- a/src/main/org/insa/graphics/ShortestPathPanel.java +++ b/src/main/org/insa/graphics/ShortestPathPanel.java @@ -5,6 +5,8 @@ import java.awt.Component; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; import java.util.ArrayList; import java.util.List; @@ -206,6 +208,24 @@ public class ShortestPathPanel extends JPanel { startAlgoButton.setEnabled(allNotNull); } }); + + addComponentListener(new ComponentAdapter() { + + @Override + public void componentShown(ComponentEvent e) { + setEnabled(true); + nodesInputPanel.setVisible(true); + } + + @Override + public void componentHidden(ComponentEvent e) { + setEnabled(false); + nodesInputPanel.setVisible(false); + } + + }); + + setEnabled(false); } @Override