Button for 2d and 3d generation

This commit is contained in:
Antonin Boyon 2021-03-30 16:34:17 +02:00
parent d50b4f0042
commit a83126e585
2 changed files with 63 additions and 20 deletions

View File

@ -54,26 +54,26 @@ public class Listener implements ActionListener, KeyListener, MouseWheelListener
break;
case "Generate":
String axiom = tab.getAxiom();
List<String> rules = tab.getRules();
Parser parser = new Parser(axiom, rules, tab.getNbIterations());
case "Generate 2D":
String axiom2D = tab.getAxiom();
List<String> rules2D = tab.getRules();
Parser parser2D = new Parser(axiom2D, rules2D, tab.getNbIterations());
if(Main.joglFrame.frame.isVisible()) {
openDialog("Veuillez fermer la fenêtre 3D avant de lancer une nouvelle génération");
openDialog("Veuillez fermer la fenêtre 2D ou 3D avant de lancer une nouvelle génération");
} else if(Main.joglFrame.parsedState == AbstractCanvas.State.LOAD) {
openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre");
openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre");
} else if (!parser.isCorrect()) {
} else if (!parser2D.isCorrect()) {
openDialog("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
} else {
tab.submitButton.setIcon(staticIcon);
tab.submitButton.setText("");
tab.submitButton2D.setIcon(staticIcon);
tab.submitButton2D.setText("");
parserThread = new Thread(() -> {
try {
List<Pair<String, String>> lSystemRules = parser.parseRules();
Main.joglFrame.setLSystem(axiom, lSystemRules, tab.getNbIterations());
List<Pair<String, String>> lSystemRules = parser2D.parseRules();
Main.joglFrame.setLSystem(axiom2D, lSystemRules, tab.getNbIterations());
StringBuilder message = new StringBuilder("L-System 3D - {axiom:\"").append(axiom).append("\",rules:[");
StringBuilder message = new StringBuilder("L-System 2D - {axiom:\"").append(axiom2D).append("\",rules:[");
for(int i = 0; i < lSystemRules.size(); ++i) {
Pair<String, String> rule = lSystemRules.get(i);
message.append("\"").append(rule.getLeft()).append("=").append(rule.getRight()).append("\"");
@ -87,8 +87,48 @@ public class Listener implements ActionListener, KeyListener, MouseWheelListener
Main.joglFrame.parsedState = AbstractCanvas.State.FINISH_OR_NULL;
openDialog("Une erreur de type " + err.getClass().getSimpleName() + " est survenue lors de l'execution du parser: " + err.getMessage());
}
tab.submitButton.setIcon(null);
tab.submitButton.setText("Générer");
tab.submitButton2D.setIcon(null);
tab.submitButton2D.setText("Générer");
});
parserThread.start();
}
break;
case "Generate 3D":
String axiom3D = tab.getAxiom();
List<String> rules3D = tab.getRules();
Parser parser3D = new Parser(axiom3D, rules3D, tab.getNbIterations());
if(Main.joglFrame.frame.isVisible()) {
openDialog("Veuillez fermer la fenêtre 2D ou 3D avant de lancer une nouvelle génération");
} else if(Main.joglFrame.parsedState == AbstractCanvas.State.LOAD) {
openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre");
openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre");
} else if (!parser3D.isCorrect()) {
openDialog("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
} else {
tab.submitButton2D.setIcon(staticIcon);
tab.submitButton2D.setText("");
parserThread = new Thread(() -> {
try {
List<Pair<String, String>> lSystemRules = parser3D.parseRules();
Main.joglFrame.setLSystem(axiom3D, lSystemRules, tab.getNbIterations());
StringBuilder message = new StringBuilder("L-System 3D - {axiom:\"").append(axiom3D).append("\",rules:[");
for(int i = 0; i < lSystemRules.size(); ++i) {
Pair<String, String> rule = lSystemRules.get(i);
message.append("\"").append(rule.getLeft()).append("=").append(rule.getRight()).append("\"");
if(i + 1 != lSystemRules.size())
message.append(",");
}
Main.joglFrame.frame.setTitle(message.append("]} - Nombres d'itérations: ").append(tab.getNbIterations()).toString());
Main.joglFrame.setVisible(true);
} catch (NumberFormatException err) {
Main.joglFrame.parsedState = AbstractCanvas.State.FINISH_OR_NULL;
openDialog("Une erreur de type " + err.getClass().getSimpleName() + " est survenue lors de l'execution du parser: " + err.getMessage());
}
tab.submitButton3D.setIcon(null);
tab.submitButton3D.setText("Générer");
});
parserThread.start();
}

View File

@ -11,7 +11,7 @@ public class Tab extends JPanel{
public JSpinner itSpinner;
JTextField axiomeField,rulesField;
JTextArea axiomList,rulesList;;
JButton submitButton, close;
JButton submitButton2D, submitButton3D, close;
public Tab(int nbTabs,int nbRules,JTabbedPane tabs,MainFrame frame) {
this.nbRules = nbRules;
@ -38,11 +38,14 @@ public class Tab extends JPanel{
rulesField.addKeyListener(new Listener(null,nbTabs+10,"Règles",this));
rulesField.setPreferredSize(new Dimension(120,20));
submitButton = new JButton("Générer");
submitButton2D = new JButton("Générer en 2D");
submitButton3D = new JButton("Générer en 3D");
JButton clearButton = new JButton("Clear");
clearButton.addActionListener(new Listener(null,nbTabs,"Clear",this));
submitButton.addActionListener(new Listener(null,nbTabs,"Generate",this));
JPanel southComponents = subPanel(clearButton,submitButton,null);
submitButton2D.addActionListener(new Listener(null,nbTabs,"Generate 2D",this));
submitButton3D.addActionListener(new Listener(null,nbTabs,"Generate 3D",this));
JPanel southComponents = subPanel(submitButton2D,submitButton3D, null);
JPanel southComponents2 = subPanel(clearButton, southComponents, null);
GridBagConstraints gc = new GridBagConstraints();
gc.gridx = 0;
@ -64,7 +67,7 @@ public class Tab extends JPanel{
aboveComponents.setLayout(new GridLayout(1,4));
tab.add(aboveComponents);
tab.add(southComponents);
tab.add(southComponents2);
tab.setLayout(new BoxLayout(tab,1));
close = new JButton("Close");