diff --git a/.gitignore b/.gitignore index ac30167e..fa8e9bb9 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ *.bak *.swp *~.nib - +*.idea # Created by https://www.toptal.com/developers/gitignore/api/eclipse,java # Edit at https://www.toptal.com/developers/gitignore?templates=eclipse,java diff --git a/sources/commons/src/main/resources/resources.properties b/sources/commons/src/main/resources/resources.properties index 83de1655..7836f218 100644 --- a/sources/commons/src/main/resources/resources.properties +++ b/sources/commons/src/main/resources/resources.properties @@ -7,7 +7,8 @@ rendering_prefix = Rendering: # Converter info converter_introduction = CodeMetropolis CDF Converter (c) University of Szeged, Department of Software Engineering -converter_usage = Usage: java -jar converter.jar -t -s [-o ] [-p ] +# overwrote [-s] to [-i], overwrote to +converter_usage = Usage: java -jar converter.jar -t -i [-o ] [-p ] # Converter notifications converting_to_cdf = Converting input to CDF format... 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..e2b0acee 100644 --- a/sources/gui/src/main/java/codemetropolis/toolchain/gui/CodeMetropolisGUI.java +++ b/sources/gui/src/main/java/codemetropolis/toolchain/gui/CodeMetropolisGUI.java @@ -7,8 +7,12 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.PipedOutputStream; -import java.util.Random; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.swing.ImageIcon; import javax.swing.JFileChooser; @@ -46,10 +50,12 @@ 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 List protips; private GUIController controller; private CMTextField projectName; + private CMTextField protipsField; private JTabbedPane metricTabbedPane; private CMTextField mappingPath; private CMTextField mcRootPath; @@ -70,6 +76,8 @@ public CodeMetropolisGUI(GUIController controller) { JPanel panel = createBasePanel(); addHeaderImages(panel); addTitle(panel); + addProTip(panel); + addProTipImage(panel); addProjectNameField(panel); addMetricTabs(panel); addMappingOptions(panel); @@ -157,7 +165,7 @@ private final void addTitle(JPanel panel) { JLabel title = new JLabel(Translations.t("gui_title")); title.setFont(new Font("Source Sans Pro", Font.BOLD, 26)); title.setHorizontalAlignment(SwingConstants.CENTER); - title.setBounds(0, 280, 500, 30); + title.setBounds(0, 270, 500, 30); panel.add(title); } @@ -175,6 +183,8 @@ private final void addProjectNameField(JPanel panel) { panel.add(projectName); } + + /** * Adds the metric generation tabbed pane to the {@code panel} * @@ -315,4 +325,64 @@ private final void fillOptions(ExecutionOptions executionOptions) { executionOptions.setMinecraftRoot(new File(mcRootPath.getText())); } + private final void readProTipsJSON() { + protips = new ArrayList<>(); + + try { + File myObj = new File("..\\src\\main\\resources\\protips.json"); + + Scanner myReader = new Scanner(myObj); + StringBuilder data = new StringBuilder(); + + while (myReader.hasNextLine()) { + data.append(myReader.nextLine()); + } + + Matcher m = Pattern.compile("\".+?\"").matcher(data.toString()); + while (m.find()) { + protips.add(m.group()); + } + + protips.remove(0); + + myReader.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + /** + * Adds the lightbulb image next to the pro tip. + * + * @param panel The {@link JPanel} to add the components to. + */ + private final void addProTipImage(JPanel panel) { + // Load the cover and logo images + ImageIcon bulbIcon = new ImageIcon(ClassLoader.getSystemResource("images/cm-lightbulb.png")); + Image bulbLogo = bulbIcon.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH); + + JLabel logoImageContainer = new JLabel(new ImageIcon(bulbLogo)); + logoImageContainer.setBounds(60, 290, 30, 30); + + panel.add(logoImageContainer); + } + + /** + * Adds a random pro tip to the {@code panel} + * + * @param panel The {@link JPanel} to add the components to. + */ + private final void addProTip(JPanel panel) { + readProTipsJSON(); + + JLabel tip = new JLabel(protips.get(rng.nextInt(protips.size()))); + tip.setFont(new Font("Source Sans Pro", Font.BOLD, 10)); + tip.setHorizontalAlignment(SwingConstants.CENTER); + tip.setBounds(100, 300, 300, 20); + tip.setOpaque(true); + tip.setBackground(Color.orange); + + panel.add(tip); + } + } diff --git a/sources/gui/src/main/resources/images/cm-lightbulb.png b/sources/gui/src/main/resources/images/cm-lightbulb.png new file mode 100644 index 00000000..ab134d2a Binary files /dev/null and b/sources/gui/src/main/resources/images/cm-lightbulb.png differ diff --git a/sources/gui/src/main/resources/protips.json b/sources/gui/src/main/resources/protips.json new file mode 100644 index 00000000..b262e728 --- /dev/null +++ b/sources/gui/src/main/resources/protips.json @@ -0,0 +1,3 @@ +{"tips": [ + "pro tip1", "pro tip2", "pro tip3" +]} diff --git a/sources/toolchain/converter/src/main/java/codemetropolis/toolchain/converter/CommandLineOptions.java b/sources/toolchain/converter/src/main/java/codemetropolis/toolchain/converter/CommandLineOptions.java index 39848d5e..105f2569 100644 --- a/sources/toolchain/converter/src/main/java/codemetropolis/toolchain/converter/CommandLineOptions.java +++ b/sources/toolchain/converter/src/main/java/codemetropolis/toolchain/converter/CommandLineOptions.java @@ -10,8 +10,12 @@ public class CommandLineOptions { @Option(name="-t", aliases = {"--type"}) private String type = null; - - @Option(name="-s", aliases = { "--source", "-i", "--input" }) + + /** + * @author Zsombor Szabolcs Berezvai + * Option [-i], input, the path of the input graph file. Required + */ + @Option(name="-i", aliases = { "--input" })//overwrote [-s] to [-i], delete "--source, -s" private String source = null; @Option(name="-o", aliases = {"--output"}) diff --git a/sources/toolchain/mapping/src/main/java/codemetropolis/toolchain/mapping/MappingExecutor.java b/sources/toolchain/mapping/src/main/java/codemetropolis/toolchain/mapping/MappingExecutor.java index 2df108a3..775a58ee 100644 --- a/sources/toolchain/mapping/src/main/java/codemetropolis/toolchain/mapping/MappingExecutor.java +++ b/sources/toolchain/mapping/src/main/java/codemetropolis/toolchain/mapping/MappingExecutor.java @@ -28,7 +28,11 @@ public boolean execute(ExecutorArgs args) { printError(null, Resources.get("invalid_scale_error"), MIN_SCALE, MAX_SCALE); return false; } - + /** + * try-catch blocks to handle invalid XML inputs. + * @param mapping XML file content + * @param MappingReaderException Invalid XML content + */ print(Resources.get("reading_mapping")); Mapping mapping; try { @@ -36,8 +40,8 @@ public boolean execute(ExecutorArgs args) { } catch (FileNotFoundException e) { printError(e, Resources.get("mapping_not_found_error")); return false; - } catch (MappingReaderException e) { - printError(e, e.getMessage()); + } catch (MappingReaderException e) { //we print a warning, instead of a long error message. + System.out.println("Sorry, the XML file's content is invalid."); return false; } print(Resources.get("reading_mapping_done")); diff --git a/sources/toolchain/placing/src/main/java/codemetropolis/toolchain/placing/PlacingExecutor.java b/sources/toolchain/placing/src/main/java/codemetropolis/toolchain/placing/PlacingExecutor.java index c6d40ff7..b87b70bf 100644 --- a/sources/toolchain/placing/src/main/java/codemetropolis/toolchain/placing/PlacingExecutor.java +++ b/sources/toolchain/placing/src/main/java/codemetropolis/toolchain/placing/PlacingExecutor.java @@ -29,8 +29,11 @@ public boolean execute(ExecutorArgs args) { } catch (IOException e) { printError(e, Resources.get("missing_input_xml_error")); return false; + } catch (CmxmlValidationFailedException e) { - printError(e, Resources.get("invalid_input_xml_error")); + // Warns the user that the input file content is invalid and exits normally without creating the output file. + printError(e, "\nmappingToPlacing.xml is invalid," + + " please check the content of the input file or generate new mappingToPlacing.xml."); return false; } diff --git a/sources/toolchain/rendering/src/main/java/codemetropolis/toolchain/rendering/Main.java b/sources/toolchain/rendering/src/main/java/codemetropolis/toolchain/rendering/Main.java index 2de98730..f274002a 100644 --- a/sources/toolchain/rendering/src/main/java/codemetropolis/toolchain/rendering/Main.java +++ b/sources/toolchain/rendering/src/main/java/codemetropolis/toolchain/rendering/Main.java @@ -12,7 +12,12 @@ public class Main { public static void main(String[] args) { - + int javaVersion = parseJavaVersion(System.getProperty("java.version")); + + if(javaVersion != 8) { // Works with only Java 8 version. + throw new RuntimeException("The required Java version is 8, you have Java " + javaVersion); // Warns the user if the Java version is not 8. + } + FileLogger.load(Settings.get("rendering_log_file")); CommandLineOptions options = new CommandLineOptions(); @@ -79,4 +84,23 @@ private void printProgress(String message, ProgressEvent event) { } + /** + * java.version is a system property that exists in every JVM. + * There are two possible formats for it, because the version format changed after Java 8: + * Java 8 or lower: 1.6.0_12, 1.7.0, 1.7.0_22, 1.8.0_201 + * Java 9 or higher: 9.0.1, 10.1.4, 12, 12.0.1 + * @param version string of version numbers formatted in 'x.y.z' or '1.x.y_z' + * @return parsed version number in integer + */ + private static int parseJavaVersion(String version) { + if(version.startsWith("1.")) { // Under Java 8 and Java 8 version. Parse 1.x.y_z format string. + version = version.substring(2, 3); + + } else { // After Java 8 version. Parse x.y.z format string. + int dot = version.indexOf("."); + if(dot != -1) { + version = version.substring(0, dot); + } + } return Integer.parseInt(version); + } }