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: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion sources/commons/src/main/resources/resources.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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 <type> -s <source> [-o <outputFile>] [-p <parameters>]
# overwrote [-s] to [-i], overwrote <source> to <graphFile>
converter_usage = Usage: java -jar converter.jar -t <type> -i <graphFile> [-o <outputFile>] [-p <parameters>]

# Converter notifications
converting_to_cdf = Converting input to CDF format...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> protips;

private GUIController controller;

private CMTextField projectName;
private CMTextField protipsField;
private JTabbedPane metricTabbedPane;
private CMTextField mappingPath;
private CMTextField mcRootPath;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -175,6 +183,8 @@ private final void addProjectNameField(JPanel panel) {
panel.add(projectName);
}



/**
* Adds the metric generation tabbed pane to the {@code panel}
*
Expand Down Expand Up @@ -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);
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions sources/gui/src/main/resources/protips.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"tips": [
"pro tip1", "pro tip2", "pro tip3"
]}
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ 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 {
mapping = Mapping.readFromXML(mappingArgs.getMappingFile());
} 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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}