From 7271c2202960fa7d344117ac9d9873c534c9b44f Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 28 Feb 2021 11:17:16 +0100 Subject: [PATCH] ControlPanel Buttons are now disabled when they have no function --- .../TypeInferenceView.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java index 9ac60b7..733315d 100644 --- a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java +++ b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java @@ -42,6 +42,7 @@ public class TypeInferenceView extends VerticalLayout private MathjaxProofTree tree; private final transient LatexCreator lc; private final Div content; + private ControlPanel controlPanel; /** * Initializes the component. When initialization is complete, the first step of the type @@ -58,13 +59,15 @@ public class TypeInferenceView extends VerticalLayout error -> getTranslation("root." + error.toString().toLowerCase(Locale.ENGLISH))); content = new Div(); content.setId(CONTENT_ID); - ControlPanel controlPanel = new ControlPanel(this, this); + controlPanel = new ControlPanel(this, this); Scroller scroller = new Scroller(content); scroller.setId(SCROLLER_ID); scroller.setScrollDirection(Scroller.ScrollDirection.BOTH); add(scroller, controlPanel); treeNumbers = lc.getTreeNumbers(); setContent(); + controlPanel.setEnabledFirstStep(false); + controlPanel.setEnabledPreviousStep(false); } private void setContent() { @@ -91,6 +94,12 @@ public class TypeInferenceView extends VerticalLayout int treeEnd = treeNumbers.indexOf(tree.getStepCount() - 1); currentStep = currentStep > treeEnd && tree.getStepCount() > 0 ? treeEnd : 0; refreshElements(); + if (currentStep == 0) { + controlPanel.setEnabledFirstStep(false); + controlPanel.setEnabledPreviousStep(false); + } + controlPanel.setEnabledNextStep(true); + controlPanel.setEnabledLastStep(true); } @Override @@ -98,18 +107,37 @@ public class TypeInferenceView extends VerticalLayout int treeEnd = treeNumbers.indexOf(tree.getStepCount() - 1); currentStep = currentStep < treeEnd ? treeEnd : unification.getStepCount() - 1; refreshElements(); + if (currentStep == unification.getStepCount() - 1) { + controlPanel.setEnabledNextStep(false); + controlPanel.setEnabledLastStep(false); + } + controlPanel.setEnabledFirstStep(true); + controlPanel.setEnabledPreviousStep(true); + } @Override public void nextStepButton() { currentStep = currentStep < unification.getStepCount() - 1 ? currentStep + 1 : currentStep; refreshElements(); + if (currentStep == unification.getStepCount() - 1) { + controlPanel.setEnabledNextStep(false); + controlPanel.setEnabledLastStep(false); + } + controlPanel.setEnabledFirstStep(true); + controlPanel.setEnabledPreviousStep(true); } @Override public void previousStepButton() { currentStep = currentStep > 0 ? currentStep - 1 : currentStep; refreshElements(); + if (currentStep == 0) { + controlPanel.setEnabledFirstStep(false); + controlPanel.setEnabledPreviousStep(false); + } + controlPanel.setEnabledNextStep(true); + controlPanel.setEnabledLastStep(true); } @Override