Fix visiblity issue with markers in NodesInputPanel.

This commit is contained in:
Holt59 2018-02-26 20:29:05 +01:00
parent 1a664b8a3c
commit 7de61ac27e
2 changed files with 39 additions and 2 deletions

View File

@ -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());
}
}

View File

@ -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