Merge branch 'master' of https://forge.info.unicaen.fr/git/l-system
This commit is contained in:
commit
8c1fe66ce6
@ -6,10 +6,17 @@ import lsystem.engine.Rewrite;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import lsystem.screen.MainFrame;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
MainFrame frame = new MainFrame();
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
|
||||
|
||||
final Scanner scanner = new Scanner(System.in);
|
||||
String axiom = null;
|
||||
Parser parser = null;
|
||||
|
15
src/lsystem/screen/Help.java
Normal file
15
src/lsystem/screen/Help.java
Normal 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)));
|
||||
|
||||
}
|
||||
}
|
@ -4,21 +4,11 @@ package lsystem.screen;
|
||||
import lsystem.screen.listener.HelpListener;
|
||||
import lsystem.screen.listener.NewGenListener;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.JButton;
|
||||
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;
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
public class MainFrame extends JFrame {
|
||||
@ -30,10 +20,11 @@ public class MainFrame extends JFrame {
|
||||
private JTabbedPane tabs;
|
||||
private JButton newGen;
|
||||
private JButton help;
|
||||
private JButton close;
|
||||
private int nbRules;
|
||||
public HashMap<Integer,Component> componentList;
|
||||
|
||||
public MainFrame(){
|
||||
componentList = new HashMap<>();
|
||||
nbRules = 1;
|
||||
nbTabs = 0;
|
||||
basePanel = new JPanel();
|
||||
@ -54,46 +45,28 @@ public class MainFrame extends JFrame {
|
||||
this.setLocationRelativeTo(null);
|
||||
this.add(tabs);
|
||||
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() {
|
||||
JPanel helpTab = new JPanel();
|
||||
JTextArea helpText = new JTextArea();
|
||||
helpText.setText(Constants.HELP);
|
||||
helpText.setEditable(false);
|
||||
helpTab.add(helpText);
|
||||
tabs.addTab("Aide",(new JScrollPane(helpTab)));
|
||||
|
||||
new Help(tabs);
|
||||
}
|
||||
public void newTab() {
|
||||
nbTabs ++;
|
||||
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);
|
||||
|
||||
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);
|
||||
if(nbTabs>2)
|
||||
JOptionPane.showMessageDialog(null, "Nombre maximal de générations atteintes");
|
||||
else {
|
||||
nbTabs++;
|
||||
new Tab(this, nbTabs, nbRules, tabs);
|
||||
}
|
||||
|
||||
}
|
||||
public void closeTab() {
|
||||
//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) {
|
||||
switch(messageType) {
|
||||
case 0:
|
||||
@ -104,7 +77,7 @@ public class MainFrame extends JFrame {
|
||||
throw new IllegalArgumentException("Wrong argument given to method changeList");
|
||||
}
|
||||
}else{
|
||||
list.append("-> "+stringToAdd + "\n");
|
||||
list.append(String.valueOf(stringToAdd));
|
||||
}
|
||||
}
|
||||
public String getAxiom(){
|
||||
|
40
src/lsystem/screen/Tab.java
Normal file
40
src/lsystem/screen/Tab.java
Normal 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);
|
||||
}
|
||||
}
|
34
src/lsystem/screen/listener/AxiomFieldListener.java
Normal file
34
src/lsystem/screen/listener/AxiomFieldListener.java
Normal 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) {
|
||||
|
||||
}
|
||||
}
|
@ -9,11 +9,13 @@ public class HelpListener implements ActionListener {
|
||||
|
||||
MainFrame frame;
|
||||
public HelpListener(MainFrame frame) {
|
||||
|
||||
this.frame = frame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
frame.newHelp();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user