Button for 2d and 3d generation
This commit is contained in:
parent
d50b4f0042
commit
a83126e585
@ -52,28 +52,28 @@ public class Listener implements ActionListener, KeyListener, MouseWheelListener
|
|||||||
Listener kl = (Listener) tab.getTextField((byte) 0).getKeyListeners()[0];
|
Listener kl = (Listener) tab.getTextField((byte) 0).getKeyListeners()[0];
|
||||||
kl.resetNbAxioms();
|
kl.resetNbAxioms();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "Generate":
|
case "Generate 2D":
|
||||||
String axiom = tab.getAxiom();
|
String axiom2D = tab.getAxiom();
|
||||||
List<String> rules = tab.getRules();
|
List<String> rules2D = tab.getRules();
|
||||||
Parser parser = new Parser(axiom, rules, tab.getNbIterations());
|
Parser parser2D = new Parser(axiom2D, rules2D, tab.getNbIterations());
|
||||||
if(Main.joglFrame.frame.isVisible()) {
|
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) {
|
} 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");
|
||||||
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");
|
openDialog("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
|
||||||
} else {
|
} else {
|
||||||
tab.submitButton.setIcon(staticIcon);
|
tab.submitButton2D.setIcon(staticIcon);
|
||||||
tab.submitButton.setText("");
|
tab.submitButton2D.setText("");
|
||||||
parserThread = new Thread(() -> {
|
parserThread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
List<Pair<String, String>> lSystemRules = parser.parseRules();
|
List<Pair<String, String>> lSystemRules = parser2D.parseRules();
|
||||||
Main.joglFrame.setLSystem(axiom, lSystemRules, tab.getNbIterations());
|
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) {
|
for(int i = 0; i < lSystemRules.size(); ++i) {
|
||||||
Pair<String, String> rule = lSystemRules.get(i);
|
Pair<String, String> rule = lSystemRules.get(i);
|
||||||
message.append("\"").append(rule.getLeft()).append("=").append(rule.getRight()).append("\"");
|
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;
|
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());
|
openDialog("Une erreur de type " + err.getClass().getSimpleName() + " est survenue lors de l'execution du parser: " + err.getMessage());
|
||||||
}
|
}
|
||||||
tab.submitButton.setIcon(null);
|
tab.submitButton2D.setIcon(null);
|
||||||
tab.submitButton.setText("Générer");
|
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();
|
parserThread.start();
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ public class Tab extends JPanel{
|
|||||||
public JSpinner itSpinner;
|
public JSpinner itSpinner;
|
||||||
JTextField axiomeField,rulesField;
|
JTextField axiomeField,rulesField;
|
||||||
JTextArea axiomList,rulesList;;
|
JTextArea axiomList,rulesList;;
|
||||||
JButton submitButton, close;
|
JButton submitButton2D, submitButton3D, close;
|
||||||
|
|
||||||
public Tab(int nbTabs,int nbRules,JTabbedPane tabs,MainFrame frame) {
|
public Tab(int nbTabs,int nbRules,JTabbedPane tabs,MainFrame frame) {
|
||||||
this.nbRules = nbRules;
|
this.nbRules = nbRules;
|
||||||
@ -38,11 +38,14 @@ public class Tab extends JPanel{
|
|||||||
rulesField.addKeyListener(new Listener(null,nbTabs+10,"Règles",this));
|
rulesField.addKeyListener(new Listener(null,nbTabs+10,"Règles",this));
|
||||||
rulesField.setPreferredSize(new Dimension(120,20));
|
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");
|
JButton clearButton = new JButton("Clear");
|
||||||
clearButton.addActionListener(new Listener(null,nbTabs,"Clear",this));
|
clearButton.addActionListener(new Listener(null,nbTabs,"Clear",this));
|
||||||
submitButton.addActionListener(new Listener(null,nbTabs,"Generate",this));
|
submitButton2D.addActionListener(new Listener(null,nbTabs,"Generate 2D",this));
|
||||||
JPanel southComponents = subPanel(clearButton,submitButton,null);
|
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();
|
GridBagConstraints gc = new GridBagConstraints();
|
||||||
gc.gridx = 0;
|
gc.gridx = 0;
|
||||||
@ -64,7 +67,7 @@ public class Tab extends JPanel{
|
|||||||
|
|
||||||
aboveComponents.setLayout(new GridLayout(1,4));
|
aboveComponents.setLayout(new GridLayout(1,4));
|
||||||
tab.add(aboveComponents);
|
tab.add(aboveComponents);
|
||||||
tab.add(southComponents);
|
tab.add(southComponents2);
|
||||||
tab.setLayout(new BoxLayout(tab,1));
|
tab.setLayout(new BoxLayout(tab,1));
|
||||||
|
|
||||||
close = new JButton("Close");
|
close = new JButton("Close");
|
||||||
|
Loading…
Reference in New Issue
Block a user