Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -57,6 +61,8 @@ public class CodeMetropolisGUI extends JFrame {
private CMCheckBox validateStructure;
private CMSpinner scaleSpinner;
private CMComboBox<LayoutAlgorithm> layoutSelector;
private FocusListener highlighter;
private CMLabel projectNameErrorMessage;

/**
* Instantiates the CodeMetropolis GUI.
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions sources/gui/src/main/resources/translations.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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