diff --git a/app/src/main/java/xl/controller/EditorController.java b/app/src/main/java/xl/controller/EditorController.java new file mode 100644 index 0000000..7b4086e --- /dev/null +++ b/app/src/main/java/xl/controller/EditorController.java @@ -0,0 +1,59 @@ +package xl.controller; + +import xl.model.XLModel; +import xl.gui.Editor; +import xl.gui.SlotLabel; +import xl.gui.StatusLabel; + +/** + * The controller for the editor. + * + * The controller is responsible for handling the editor actions. + */ +public class EditorController { + private XLModel xlModel; + private Editor editor; + private SlotLabel currentSlot; + private StatusLabel statusLabel; + + public EditorController(XLModel xlModel, StatusLabel statusLabel) { + this.xlModel = xlModel; + this.statusLabel = statusLabel; + } + + public void setCurrentSlot(SlotLabel currentSlot) { + this.currentSlot = currentSlot; + } + + public void setEditor(Editor editor) { + this.editor = editor; + } + + public void handleEditorAction() { + String content = editor.getText(); + String address = currentSlot.getAddress(); + + if (content.isEmpty()) { + boolean isOkRemove = xlModel.remove(address); + if (isOkRemove) { + currentSlot.setText(""); + statusLabel.setText(""); + } else { + statusLabel.setText(xlModel.getStatus()); + } + } else if (content.charAt(0) == '#') { + xlModel.add(address, content); + currentSlot.setText(content.substring(1)); + statusLabel.setText(""); + } else { + xlModel.add(address, content); + if (xlModel.getStatus().equals("")) { + content = xlModel.getAddressValue(address); + currentSlot.setText(content); + } else { + statusLabel.setText(xlModel.getStatus()); + } + + } + } +} diff --git a/app/src/main/java/xl/controller/SlotLabelController.java b/app/src/main/java/xl/controller/SlotLabelController.java new file mode 100644 index 0000000..c555c65 --- /dev/null +++ b/app/src/main/java/xl/controller/SlotLabelController.java @@ -0,0 +1,60 @@ +package xl.controller; +import java.awt.Color; +import xl.model.XLModel; +import xl.gui.*; + +/** + * The controller for the slot labels. + * + * The controller is responsible for handling the slot label actions. + */ +public class SlotLabelController { + private XLModel xlModel; + private Editor editor; + private SlotLabel currentSlot; + private EditorController editorController; + private StatusLabel statusLabel; + private CurrentLabel currentLabel; + + public SlotLabelController(XLModel xlModel, Editor editor, StatusLabel statusLabel) { + this.xlModel = xlModel; + this.editor = editor; + this.statusLabel = statusLabel; + } + + public void setCurrentLabel(CurrentLabel currentLabel) { + this.currentLabel = currentLabel; + } + + public void setCurrentSlot(SlotLabel currentSlot) { + this.currentSlot = currentSlot; + } + + public void setEditorController(EditorController editorController) { + this.editorController = editorController; + } + + public void handleSlotClick(SlotLabel slotLabel) { + // Retrieve the address of the clicked slot + String address = slotLabel.getAddress(); + currentLabel.setText(address); + xlModel.setCurrentAddress(address); + + // Clear the status label + statusLabel.setText(""); + + // Reset the background color of the previous slot + currentSlot.setBackground(Color.WHITE); + + // Set the background color of the clicked slot + slotLabel.setBackground(Color.YELLOW); + currentSlot = slotLabel; + editorController.setCurrentSlot(currentSlot); + + // Retrieve the content of the clicked slot + String content = xlModel.getAddressContent(address); + + // Set the content of the clicked slot in the editor + editor.setText(content); + } +} \ No newline at end of file