diff --git a/build.xml b/build.xml
index d08656a..31f62d8 100644
--- a/build.xml
+++ b/build.xml
@@ -20,6 +20,8 @@
+
+
diff --git a/src/lsystem/engine/Parser.java b/src/lsystem/engine/Parser.java
index ccfbd16..d0987ae 100644
--- a/src/lsystem/engine/Parser.java
+++ b/src/lsystem/engine/Parser.java
@@ -79,7 +79,7 @@ public class Parser {
}
/**
- * Used by {@link Rewrite#rewrite()}
+ * Used by {@link Rewrite#rewrite(String, List, int)} )}
* @return a list of rules with the left and right sides separated by a {@link lsystem.utils.Pair Pair}
*/
public List> parseRules() {
diff --git a/src/lsystem/engine/Rewrite.java b/src/lsystem/engine/Rewrite.java
index 81c8b43..3a2253a 100644
--- a/src/lsystem/engine/Rewrite.java
+++ b/src/lsystem/engine/Rewrite.java
@@ -6,18 +6,8 @@ import java.util.List;
public class Rewrite {
- private final String axiom;
- private final List> rules;
- private final int recurrences;
- public Rewrite(String axiom, List> rules, int recurrences) {
- this.axiom = axiom;
- this.rules = rules;
- this.recurrences = recurrences;
- }
-
-
- private String replaceRulesByID(final String rewritten) {
+ private static String replaceRulesByID(final String rewritten, List> rules) {
String toRewrite = rewritten;
for(int j = 0; j < rules.size(); ++j){
Pair pair = rules.get(j);
@@ -26,7 +16,7 @@ public class Rewrite {
return toRewrite;
}
- private String replaceIDByRuleApplication(final String toRewrite) {
+ private static String replaceIDByRuleApplication(final String toRewrite, List> rules) {
String rewritten = toRewrite;
for(int j = 0; j < rules.size(); ++j){
rewritten = rewritten.replace("${" + j + "}", rules.get(j).getRight());
@@ -34,11 +24,12 @@ public class Rewrite {
return rewritten;
}
- public String rewrite() {
+ public static String rewrite(String axiom, List> rules, int recurrences) {
String rewritten = axiom;
for(int i = 0; i < recurrences; ++i) {
- String toRewrite = replaceRulesByID(rewritten);
- rewritten = replaceIDByRuleApplication(toRewrite);
+ String toRewrite = replaceRulesByID(rewritten, rules);
+ rewritten = replaceIDByRuleApplication(toRewrite, rules);
+ System.out.println(i + " / " + recurrences + " : " + rewritten.length());
}
return rewritten.replace("[", "Y[");
}
diff --git a/src/lsystem/screen/AbstractCanvas.java b/src/lsystem/screen/AbstractCanvas.java
index da7fd69..0540ef9 100644
--- a/src/lsystem/screen/AbstractCanvas.java
+++ b/src/lsystem/screen/AbstractCanvas.java
@@ -36,6 +36,7 @@ public abstract class AbstractCanvas {
@Override
public void windowClosing(WindowEvent e) {
frame.dispose();
+ setVisible(false);
}
});
frame.getContentPane().add(glCanvas, BorderLayout.CENTER);
diff --git a/src/lsystem/screen/main/Listener.java b/src/lsystem/screen/main/Listener.java
index 3fa6219..7fe7948 100644
--- a/src/lsystem/screen/main/Listener.java
+++ b/src/lsystem/screen/main/Listener.java
@@ -1,6 +1,5 @@
package lsystem.screen.main;
-import lsystem.engine.Element;
import lsystem.engine.Parser;
import lsystem.engine.Rewrite;
import lsystem.screen.gl3d.GLCanvas;
@@ -53,14 +52,14 @@ public class Listener implements ActionListener, KeyListener {
JOptionPane.showMessageDialog(null, "Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
new Listener(null, index, "Clear",tab);
} else {
- new Thread(() -> {
- Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), tab.getNbIterations());
- final String word = rewriter.rewrite();
- System.out.println(word);
- final Element parsed = Parser.parse(word);
- GLCanvas canvas = new GLCanvas(parsed);
+ Thread thread = new Thread(() -> {
+ GLCanvas canvas = new GLCanvas(
+ Parser.parse(Rewrite.rewrite(axiom, parser.parseRules(), tab.getNbIterations()))
+ );
canvas.setVisible(true);
- }).start();
+ });
+ thread.setDaemon(true);
+ thread.start();
}
break;
diff --git a/src/lsystem/screen/main/Tab.java b/src/lsystem/screen/main/Tab.java
index 6c62f09..2c9f9df 100644
--- a/src/lsystem/screen/main/Tab.java
+++ b/src/lsystem/screen/main/Tab.java
@@ -29,7 +29,7 @@ public class Tab extends JPanel{
nbIterations.setModel(new SpinnerNumberModel(1, 1, 15, 1));
JLabel itLabel = new JLabel("Nombre d'itérations : ");
- itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 15, 1));
+ itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 30, 1));
((JSpinner.DefaultEditor) itSpinner.getEditor()).getTextField().setEditable(false);
JLabel axiome = new JLabel("Axiome :");
@@ -74,7 +74,7 @@ public class Tab extends JPanel{
tabs.addTab("Génération"+String.valueOf(nbTabs), tab);
}
- public JTextArea textArea(String texte,int nb){
+ public JTextArea textArea(String texte, int nb){
JTextArea res = new JTextArea();
res.setText(texte);
res.setEditable(false);