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