From 44da019d98b38bcc54f25d0b780a0fad0decf534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Balogh?= Date: Tue, 16 Aug 2022 16:38:06 +0200 Subject: [PATCH] feat: This is an automated commit from the student work uploader. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The content of this commit is the work of students. These changes was created during the System Development 2 course of the University of Szeged as a project assignment. The work was checked by the author (the tutor) of this commit. The original authors of this changes are: Horváth Bence , Irinyi Kabinet Magyar Nyelvű Felhasználó . --- README.md | 2 + .../toolchain/gui/CodeMetropolisGUI.java | 56 +++++++++++++++++++ .../main/resources/translations.properties | 4 ++ 3 files changed, 62 insertions(+) diff --git a/README.md b/README.md index 862217fd..5b4ab78a 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,5 @@ http://codemetropolis.github.io/CodeMetropolis/ 1. navigate to `sources` folder 1. `mvn clean package` 1. The current distribution will be aviable under `source/distro`. + +## Demo \ No newline at end of file diff --git a/sources/gui/src/main/java/codemetropolis/toolchain/gui/CodeMetropolisGUI.java b/sources/gui/src/main/java/codemetropolis/toolchain/gui/CodeMetropolisGUI.java index 7ef2ae8a..9996dea5 100644 --- a/sources/gui/src/main/java/codemetropolis/toolchain/gui/CodeMetropolisGUI.java +++ b/sources/gui/src/main/java/codemetropolis/toolchain/gui/CodeMetropolisGUI.java @@ -6,6 +6,8 @@ import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import java.io.File; import java.io.PipedOutputStream; import java.util.Random; @@ -46,6 +48,8 @@ public class CodeMetropolisGUI extends JFrame { private static final FileFilter XML_FILTER = new XmlFileFilter(); private static final int COVER_IMAGE_COUNT = 4; private static final Random rng = new Random(); + private static final Color colorGreen = Color.decode(Translations.t("color_green")); + private static final Color colorRed = Color.decode(Translations.t("color_red")); private GUIController controller; @@ -57,6 +61,8 @@ public class CodeMetropolisGUI extends JFrame { private CMCheckBox validateStructure; private CMSpinner scaleSpinner; private CMComboBox layoutSelector; + private FocusListener highlighter; + private CMLabel projectNameErrorMessage; /** * Instantiates the CodeMetropolis GUI. @@ -79,6 +85,56 @@ public CodeMetropolisGUI(GUIController controller) { initFields(); + projectNameErrorMessage = new CMLabel("", 205, 365, 300, 30); + highlighter = new FocusListener() { + /*** + * When the focus gained, this method checks the rules of the project name and shows if there are any problems. + * + * @param e The FocusEvent to modify the background of the textfield + */ + @Override + public void focusGained(FocusEvent e) { + ExecutionOptions executionOptions = controller.getExecutionOptions(); + fillOptions(executionOptions); + + if (executionOptions.getProjectName().isEmpty()) { + e.getComponent().setBackground(Color.WHITE); + projectNameErrorMessage.setText(""); + } else if (executionOptions.getProjectName().length() < 3) { + e.getComponent().setBackground(colorRed); + projectNameErrorMessage.setText("Project name must be at least three characters"); + } else { + e.getComponent().setBackground(colorGreen); + projectNameErrorMessage.setText(""); + } + } + + /*** + * When the focus gained, this method checks the rules of the project name and shows if there are any problems. + * + * @param e The FocusEvent to modify the background of the textfield + */ + @Override + public void focusLost(FocusEvent e) { + ExecutionOptions executionOptions = controller.getExecutionOptions(); + fillOptions(executionOptions); + + if (executionOptions.getProjectName().isEmpty()) { + e.getComponent().setBackground(Color.WHITE); + projectNameErrorMessage.setText(""); + } else if (executionOptions.getProjectName().length() < 3) { + e.getComponent().setBackground(colorRed); + projectNameErrorMessage.setText("Project name must be at least three characters"); + } else { + e.getComponent().setBackground(colorGreen); + projectNameErrorMessage.setText(""); + } + } + }; + + projectName.addFocusListener(highlighter); + panel.add(projectNameErrorMessage); + this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setContentPane(panel); diff --git a/sources/gui/src/main/resources/translations.properties b/sources/gui/src/main/resources/translations.properties index f56865a2..e17de867 100644 --- a/sources/gui/src/main/resources/translations.properties +++ b/sources/gui/src/main/resources/translations.properties @@ -61,3 +61,7 @@ gui_err_sm_run_failed = Failed to run SourceMeter! gui_err_unexpected_err = Unexpected error occured! gui_err_unhandled_metric_source = Unhandled metric source! gui_err_world_gen_failed = World generation failed! Check logs for details! + +#Colors +color_green = 0xA5FFB4 +color_red = 0xFF9C9C \ No newline at end of file