Fix issue with startAlgoButton when enabling the ShortestPathPanel.
This commit is contained in:
parent
592ef40e54
commit
575eb71e64
1 changed files with 15 additions and 9 deletions
|
@ -94,6 +94,8 @@ public class ShortestPathPanel extends JPanel {
|
||||||
// Component that can be enabled/disabled.
|
// Component that can be enabled/disabled.
|
||||||
private ArrayList<JComponent> components = new ArrayList<>();
|
private ArrayList<JComponent> components = new ArrayList<>();
|
||||||
|
|
||||||
|
private JButton startAlgoButton;
|
||||||
|
|
||||||
// Start listeners
|
// Start listeners
|
||||||
List<ActionListener> startActionListeners = new ArrayList<>();
|
List<ActionListener> startActionListeners = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -157,7 +159,8 @@ public class ShortestPathPanel extends JPanel {
|
||||||
// Bottom panel
|
// Bottom panel
|
||||||
JPanel bottomPanel = new JPanel();
|
JPanel bottomPanel = new JPanel();
|
||||||
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.LINE_AXIS));
|
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.LINE_AXIS));
|
||||||
JButton startAlgoButton = new JButton("Start");
|
|
||||||
|
startAlgoButton = new JButton("Start");
|
||||||
startAlgoButton.setEnabled(false);
|
startAlgoButton.setEnabled(false);
|
||||||
startAlgoButton.addActionListener(new ActionListener() {
|
startAlgoButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -187,7 +190,6 @@ public class ShortestPathPanel extends JPanel {
|
||||||
bottomPanel.add(Box.createHorizontalGlue());
|
bottomPanel.add(Box.createHorizontalGlue());
|
||||||
bottomPanel.add(hideButton);
|
bottomPanel.add(hideButton);
|
||||||
|
|
||||||
components.add(startAlgoButton);
|
|
||||||
components.add(hideButton);
|
components.add(hideButton);
|
||||||
|
|
||||||
bottomPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
bottomPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||||
|
@ -199,13 +201,7 @@ public class ShortestPathPanel extends JPanel {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
InputChangedEvent evt = (InputChangedEvent) e;
|
InputChangedEvent evt = (InputChangedEvent) e;
|
||||||
boolean allNotNull = true;
|
startAlgoButton.setEnabled(allNotNull(evt.getNodes()));
|
||||||
for (Node node: evt.getNodes()) {
|
|
||||||
if (node == null) {
|
|
||||||
allNotNull = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
startAlgoButton.setEnabled(allNotNull);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -228,6 +224,14 @@ public class ShortestPathPanel extends JPanel {
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean allNotNull(List<Node> nodes) {
|
||||||
|
boolean allNotNull = true;
|
||||||
|
for (Node node: nodes) {
|
||||||
|
allNotNull = allNotNull && node != null;
|
||||||
|
}
|
||||||
|
return allNotNull;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
super.setEnabled(enabled);
|
super.setEnabled(enabled);
|
||||||
|
@ -235,6 +239,8 @@ public class ShortestPathPanel extends JPanel {
|
||||||
for (JComponent component: components) {
|
for (JComponent component: components) {
|
||||||
component.setEnabled(enabled);
|
component.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
enabled = enabled && allNotNull(this.nodesInputPanel.getNodeForInputs());
|
||||||
|
startAlgoButton.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue