This commit is contained in:
Antonin Boyon 2021-02-16 16:20:30 +01:00
commit 8c1fe66ce6
6 changed files with 117 additions and 46 deletions

View File

@ -6,10 +6,17 @@ import lsystem.engine.Rewrite;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import lsystem.screen.MainFrame;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
MainFrame frame = new MainFrame();
frame.pack();
frame.setVisible(true);
final Scanner scanner = new Scanner(System.in); final Scanner scanner = new Scanner(System.in);
String axiom = null; String axiom = null;
Parser parser = null; Parser parser = null;

View File

@ -0,0 +1,15 @@
package lsystem.screen;
import javax.swing.*;
public class Help {
public Help(JTabbedPane tabs){
JPanel helpTab = new JPanel();
JTextArea helpText = new JTextArea();
helpText.setText(Constants.HELP);
helpText.setEditable(false);
helpTab.add(helpText);
tabs.addTab("Aide",(new JScrollPane(helpTab)));
}
}

View File

@ -4,21 +4,11 @@ package lsystem.screen;
import lsystem.screen.listener.HelpListener; import lsystem.screen.listener.HelpListener;
import lsystem.screen.listener.NewGenListener; import lsystem.screen.listener.NewGenListener;
import java.awt.BorderLayout; import java.awt.*;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.JButton; import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
public class MainFrame extends JFrame { public class MainFrame extends JFrame {
@ -30,10 +20,11 @@ public class MainFrame extends JFrame {
private JTabbedPane tabs; private JTabbedPane tabs;
private JButton newGen; private JButton newGen;
private JButton help; private JButton help;
private JButton close;
private int nbRules; private int nbRules;
public HashMap<Integer,Component> componentList;
public MainFrame(){ public MainFrame(){
componentList = new HashMap<>();
nbRules = 1; nbRules = 1;
nbTabs = 0; nbTabs = 0;
basePanel = new JPanel(); basePanel = new JPanel();
@ -54,46 +45,28 @@ public class MainFrame extends JFrame {
this.setLocationRelativeTo(null); this.setLocationRelativeTo(null);
this.add(tabs); this.add(tabs);
this.add(toolBar, BorderLayout.NORTH); this.add(toolBar, BorderLayout.NORTH);
this.setPreferredSize(new Dimension(640,600));
}
public void addToComponentList(Component c ,Integer i){
componentList.put(i,c);
} }
public void newHelp() { public void newHelp() {
JPanel helpTab = new JPanel(); new Help(tabs);
JTextArea helpText = new JTextArea();
helpText.setText(Constants.HELP);
helpText.setEditable(false);
helpTab.add(helpText);
tabs.addTab("Aide",(new JScrollPane(helpTab)));
} }
public void newTab() { public void newTab() {
if(nbTabs>2)
JOptionPane.showMessageDialog(null, "Nombre maximal de générations atteintes");
else {
nbTabs++; nbTabs++;
JPanel tab = new JPanel(); new Tab(this, nbTabs, nbRules, tabs);
}
JTextArea axiomList = new JTextArea();
axiomList.setText("Axiome : \n");
axiomList.setEditable(false);
JTextArea rulesList = new JTextArea();
rulesList.setText("Règles : \n");
rulesList.setEditable(false);
JLabel axiome = new JLabel("Axiome");
JLabel rules = new JLabel("Règle "+ nbRules);
JTextField axiomeField = new JTextField();
JTextField rulesField = new JTextField();
tab.add(axiome);
tab.add(axiomeField);
tab.add(axiomList);
tab.add(rules);
tab.add(rulesField);
tab.add(rulesList);
tab.setLayout(new GridLayout(2,3));
tabs.addTab("Génération"+String.valueOf(nbTabs), tab);
} }
public void closeTab() { public void closeTab() {
//TODO : Pour fermer un onglet, nécessite l'implémentation d'un button fermer grâce à la méthode newTab(). //TODO : Pour fermer un onglet, nécessite l'implémentation d'un button fermer grâce à la méthode newTab().
} }
public void changeList(String stringToAdd, byte messageType, JTextArea list) { public void changeList(Character stringToAdd, byte messageType, JTextArea list) {
if (stringToAdd == null) { if (stringToAdd == null) {
switch(messageType) { switch(messageType) {
case 0: case 0:
@ -104,7 +77,7 @@ public class MainFrame extends JFrame {
throw new IllegalArgumentException("Wrong argument given to method changeList"); throw new IllegalArgumentException("Wrong argument given to method changeList");
} }
}else{ }else{
list.append("-> "+stringToAdd + "\n"); list.append(String.valueOf(stringToAdd));
} }
} }
public String getAxiom(){ public String getAxiom(){

View File

@ -0,0 +1,40 @@
package lsystem.screen;
import javax.swing.*;
import java.awt.*;
import javax.swing.JTabbedPane;
public class Tab {
public Tab(MainFrame frame,int nbTabs,int nbRules,JTabbedPane tabs) {
JPanel tab = new JPanel();
JTextArea axiomList = new JTextArea();
axiomList.setText("Axiome : \n");
axiomList.setEditable(false);
JTextArea rulesList = new JTextArea();
rulesList.setText("Règles : \n");
rulesList.setEditable(false);
JButton closeButton = new JButton("x");
JLabel axiome = new JLabel("Axiome");
JLabel rules = new JLabel("Règle "+ nbRules);
JTextField axiomeField = new JTextField();
frame.addToComponentList(axiomeField,nbTabs);
axiomeField.setPreferredSize(new Dimension(20,20));
JTextField rulesField = new JTextField();
frame.addToComponentList(rulesField,nbTabs+10);
rulesField.setPreferredSize(new Dimension(20,20));
tab.add(axiome);
tab.add(axiomeField);
tab.add(axiomList);
tab.add(rules);
tab.add(rulesField);
tab.add(rulesList);
tab.setLayout(new GridLayout(2,3));
tabs.addTab("Génération"+String.valueOf(nbTabs), tab);
}
}

View File

@ -0,0 +1,34 @@
package lsystem.screen.listener;
import lsystem.screen.MainFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class AxiomFieldListener implements KeyListener {
private MainFrame frame;
private int index;
public AxiomFieldListener(MainFrame frame,int index){
this.frame = frame;
this.index = index;
}
@Override
public void keyTyped(KeyEvent ke) {
frame.changeList(ke.getKeyChar(),(byte)0, (JTextArea) frame.componentList.get(index));
}
@Override
public void keyPressed(KeyEvent ke) {
}
@Override
public void keyReleased(KeyEvent ke) {
}
}

View File

@ -9,11 +9,13 @@ public class HelpListener implements ActionListener {
MainFrame frame; MainFrame frame;
public HelpListener(MainFrame frame) { public HelpListener(MainFrame frame) {
this.frame = frame; this.frame = frame;
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
frame.newHelp(); frame.newHelp();
} }
} }