From a168e308be57ccfc27ab1bf05286bb6836b79c0c Mon Sep 17 00:00:00 2001 From: Arthur <78031901+Arthur7770@users.noreply.github.com> Date: Tue, 16 Feb 2021 16:38:17 +0100 Subject: [PATCH] Adding some changes --- src/lsystem/screen/MainFrame.java | 17 +++++++++++------ src/lsystem/screen/Tab.java | 11 +++++++++-- .../screen/listener/AxiomFieldListener.java | 10 +++++++--- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/lsystem/screen/MainFrame.java b/src/lsystem/screen/MainFrame.java index 260f8b1..09c8577 100644 --- a/src/lsystem/screen/MainFrame.java +++ b/src/lsystem/screen/MainFrame.java @@ -21,10 +21,12 @@ public class MainFrame extends JFrame { private JButton newGen; private JButton help; private int nbRules; - public HashMap componentList; + public HashMap textAreaList; + public HashMap textFieldList; public MainFrame(){ - componentList = new HashMap<>(); + textAreaList = new HashMap<>(); + textFieldList = new HashMap<>(); nbRules = 1; nbTabs = 0; basePanel = new JPanel(); @@ -47,8 +49,11 @@ public class MainFrame extends JFrame { this.add(toolBar, BorderLayout.NORTH); this.setPreferredSize(new Dimension(640,600)); } - public void addToComponentList(Component c ,Integer i){ - componentList.put(i,c); + public void addToTextAreaList(JTextArea c ,Integer i){ + textAreaList.put(i,c); + } + public void addToTextFieldList(JTextField c ,Integer i){ + textFieldList.put(i,c); } public void newHelp() { @@ -66,7 +71,7 @@ public class MainFrame extends JFrame { 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(Character stringToAdd, byte messageType, JTextArea list) { + public void changeList(String stringToAdd, byte messageType, JTextArea list) { if (stringToAdd == null) { switch(messageType) { case 0: @@ -77,7 +82,7 @@ public class MainFrame extends JFrame { throw new IllegalArgumentException("Wrong argument given to method changeList"); } }else{ - list.append(String.valueOf(stringToAdd)); + list.append(stringToAdd); } } public String getAxiom(){ diff --git a/src/lsystem/screen/Tab.java b/src/lsystem/screen/Tab.java index 1058263..1fae1a9 100644 --- a/src/lsystem/screen/Tab.java +++ b/src/lsystem/screen/Tab.java @@ -1,5 +1,7 @@ package lsystem.screen; +import lsystem.screen.listener.AxiomFieldListener; + import javax.swing.*; import java.awt.*; import javax.swing.JTabbedPane; @@ -12,22 +14,27 @@ public class Tab { JTextArea axiomList = new JTextArea(); axiomList.setText("Axiome : \n"); axiomList.setEditable(false); + frame.addToTextAreaList(axiomList,nbTabs); JTextArea rulesList = new JTextArea(); rulesList.setText("Règles : \n"); rulesList.setEditable(false); + frame.addToTextAreaList(rulesList,nbTabs+10); 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.addKeyListener(new AxiomFieldListener(frame,nbTabs)); axiomeField.setPreferredSize(new Dimension(20,20)); + frame.addToTextFieldList(axiomeField,nbTabs); + JTextField rulesField = new JTextField(); - frame.addToComponentList(rulesField,nbTabs+10); rulesField.setPreferredSize(new Dimension(20,20)); + tab.add(axiome); tab.add(axiomeField); tab.add(axiomList); diff --git a/src/lsystem/screen/listener/AxiomFieldListener.java b/src/lsystem/screen/listener/AxiomFieldListener.java index e343261..7cc60b3 100644 --- a/src/lsystem/screen/listener/AxiomFieldListener.java +++ b/src/lsystem/screen/listener/AxiomFieldListener.java @@ -19,16 +19,20 @@ public class AxiomFieldListener implements KeyListener { } @Override public void keyTyped(KeyEvent ke) { - frame.changeList(ke.getKeyChar(),(byte)0, (JTextArea) frame.componentList.get(index)); + if(ke.getKeyCode() != 10) + frame.changeList(String.valueOf(ke.getKeyChar()),(byte)0, (JTextArea) frame.textAreaList.get(index)); + else{ + String str = ";\n"; + frame.changeList(str,(byte)0, (JTextArea) frame.textAreaList.get(index)); + frame.textFieldList.get(index).setText(""); + } } @Override public void keyPressed(KeyEvent ke) { - } @Override public void keyReleased(KeyEvent ke) { - } }