Interface works
This commit is contained in:
parent
2b19f4a8be
commit
0bc81d70a5
@ -15,34 +15,8 @@ public class Main {
|
|||||||
|
|
||||||
MainFrame frame = new MainFrame();
|
MainFrame frame = new MainFrame();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
/*
|
|
||||||
SwingGLCanvas canvas = new SwingGLCanvas();
|
SwingGLCanvas canvas = new SwingGLCanvas();
|
||||||
|
|
||||||
final Scanner scanner = new Scanner(System.in);
|
|
||||||
String axiom = null;
|
|
||||||
Parser parser = null;
|
|
||||||
final List<String> rules = new ArrayList<>();
|
|
||||||
int nbIterations = 0;
|
|
||||||
while(parser == null || !parser.isCorrect()) {
|
|
||||||
if(parser != null)
|
|
||||||
System.out.println("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
|
|
||||||
System.out.println("Axiome: ");
|
|
||||||
axiom = scanner.next();
|
|
||||||
System.out.println("Règles: (\"finish\" quand vous avez fini): ");
|
|
||||||
while(rules.isEmpty() || !rules.get(rules.size() - 1).equals("finish")) {
|
|
||||||
rules.add(scanner.next());
|
|
||||||
}
|
|
||||||
rules.remove(rules.size() - 1);
|
|
||||||
System.out.println("Nombre d'itérations: ");
|
|
||||||
nbIterations = scanner.nextInt();
|
|
||||||
parser = new Parser(axiom, rules,nbIterations);
|
|
||||||
}
|
|
||||||
System.out.println("Réécriture, veuillez patientez...");
|
|
||||||
Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), nbIterations);
|
|
||||||
final String word = rewriter.rewrite();
|
|
||||||
System.out.println(word);
|
|
||||||
scanner.close();*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import lsystem.screen.listener.NewGenListener;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
@ -93,14 +94,19 @@ public class MainFrame extends JFrame {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public String getAxiom(){
|
public String getAxiom(int index){
|
||||||
String str = "";
|
String str = textAreaList.get(index).getText();
|
||||||
// TODO : return the axiom
|
str = str.substring(10,str.length());
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
public ArrayList<String> getRules(){
|
public List<String> getRules(int index){
|
||||||
ArrayList<String> list= new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
//TODO return the rules
|
String str = textAreaList.get(index).getText();
|
||||||
|
str = str.substring(10,str.length());
|
||||||
|
String[] strsplit = str.split("\n");
|
||||||
|
for(int y = 0;y<strsplit.length;y++){
|
||||||
|
list.add(strsplit[y]);
|
||||||
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package lsystem.screen;
|
|||||||
|
|
||||||
import lsystem.screen.listener.ClearListener;
|
import lsystem.screen.listener.ClearListener;
|
||||||
import lsystem.screen.listener.FieldListener;
|
import lsystem.screen.listener.FieldListener;
|
||||||
|
import lsystem.screen.listener.GenerateListener;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -41,6 +42,7 @@ public class Tab {
|
|||||||
JButton submitButton = new JButton("Générer");
|
JButton submitButton = new JButton("Générer");
|
||||||
JButton clearButton = new JButton("Clear");
|
JButton clearButton = new JButton("Clear");
|
||||||
clearButton.addActionListener(new ClearListener(frame,nbTabs));
|
clearButton.addActionListener(new ClearListener(frame,nbTabs));
|
||||||
|
submitButton.addActionListener(new GenerateListener(frame,nbTabs));
|
||||||
JPanel southComponents = subPanel(clearButton,submitButton,null);
|
JPanel southComponents = subPanel(clearButton,submitButton,null);
|
||||||
|
|
||||||
GridBagConstraints gc = new GridBagConstraints();
|
GridBagConstraints gc = new GridBagConstraints();
|
||||||
|
@ -13,7 +13,9 @@ public class ClearListener implements ActionListener {
|
|||||||
this.frame =frame;
|
this.frame =frame;
|
||||||
this.nbTabs = nbTabs;
|
this.nbTabs = nbTabs;
|
||||||
}
|
}
|
||||||
|
public void forceAction(){
|
||||||
|
actionPerformed(null);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
frame.textAreaList.get(nbTabs).setText("Axiome : \n");
|
frame.textAreaList.get(nbTabs).setText("Axiome : \n");
|
||||||
|
34
src/lsystem/screen/listener/GenerateListener.java
Normal file
34
src/lsystem/screen/listener/GenerateListener.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package lsystem.screen.listener;
|
||||||
|
|
||||||
|
import lsystem.engine.Parser;
|
||||||
|
import lsystem.engine.Rewrite;
|
||||||
|
import lsystem.screen.MainFrame;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GenerateListener implements ActionListener {
|
||||||
|
MainFrame frame;
|
||||||
|
int nbTabs;
|
||||||
|
public GenerateListener(MainFrame frame,int nbTabs) {
|
||||||
|
this.frame = frame;
|
||||||
|
this.nbTabs = nbTabs;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String axiom = frame.getAxiom(nbTabs);
|
||||||
|
List<String> rules = frame.getRules(nbTabs+10);
|
||||||
|
Parser parser = new Parser(axiom,rules,12);
|
||||||
|
if(!parser.isCorrect()) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
|
||||||
|
new ClearListener(frame,nbTabs).forceAction();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), 12);
|
||||||
|
final String word = rewriter.rewrite();
|
||||||
|
System.out.println(word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user