diff --git a/src/lsystem/engine/Element.java b/src/lsystem/engine/Element.java index 8d5d544..1aed8ab 100644 --- a/src/lsystem/engine/Element.java +++ b/src/lsystem/engine/Element.java @@ -18,9 +18,5 @@ public class Element { this.parent = parent; this.rotation = rotation; } - - public int getRotation2D () { - return (int) rotation[0]; - } } diff --git a/src/lsystem/screen/gl3d/AbstractCanvas.java b/src/lsystem/screen/gl3d/AbstractCanvas.java index e9438ec..0d9ae9e 100644 --- a/src/lsystem/screen/gl3d/AbstractCanvas.java +++ b/src/lsystem/screen/gl3d/AbstractCanvas.java @@ -74,6 +74,6 @@ public abstract class AbstractCanvas { public enum State { LOAD, - FINISH_OR_NULL; + FINISH_OR_NULL } } diff --git a/src/lsystem/screen/gl3d/DrawHelper.java b/src/lsystem/screen/gl3d/DrawHelper.java index 54fd284..0053966 100644 --- a/src/lsystem/screen/gl3d/DrawHelper.java +++ b/src/lsystem/screen/gl3d/DrawHelper.java @@ -67,6 +67,7 @@ public class DrawHelper { } + @SuppressWarnings("unused") public static void drawDebugInformation(GL2 gl, GLUT glut, AbstractCanvas canvas) { gl.glRasterPos3f(canvas.camera[0], canvas.camera[1], canvas.camera[2] - 1); gl.glColor3f(1f, 1f, 1f); diff --git a/src/lsystem/screen/main/Listener.java b/src/lsystem/screen/main/Listener.java index a9d01b9..e999856 100644 --- a/src/lsystem/screen/main/Listener.java +++ b/src/lsystem/screen/main/Listener.java @@ -52,49 +52,7 @@ public class Listener implements ActionListener, KeyListener, MouseWheelListener tab.getTextField((byte) 1).setText(""); Listener kl = (Listener) tab.getTextField((byte) 0).getKeyListeners()[0]; kl.resetNbAxioms(); - - break; - - case "Generate 2D": - String axiom2D = tab.getAxiom(); - List rules2D = tab.getRules(); - Parser parser2D = new Parser(axiom2D, rules2D, tab.getNbIterations()); - if(Main.joglFrame.frame.isVisible()) { - openDialog("Veuillez fermer la fenêtre 2D ou 3D avant de lancer une nouvelle génération"); - } else if(Main.joglFrame.parsedState == AbstractCanvas.State.LOAD) { - openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre"); - openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre"); - } else if (!parser2D.isCorrect()) { - openDialog("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer"); - } else { - tab.submitButton2D.setIcon(staticIcon); - tab.submitButton2D.setText(""); - parserThread = new Thread(() -> { - try { - List> lSystemRules = parser2D.parseRules(); - Main.joglFrame.setLSystem(axiom2D, lSystemRules, tab.getNbIterations()); - - StringBuilder message = new StringBuilder("L-System 2D - {axiom:\"").append(axiom2D).append("\",rules:["); - for(int i = 0; i < lSystemRules.size(); ++i) { - Pair rule = lSystemRules.get(i); - message.append("\"").append(rule.getLeft()).append("=").append(rule.getRight()).append("\""); - if(i + 1 != lSystemRules.size()) - message.append(","); - } - Main.joglFrame.frame.setTitle(message.append("]} - Nombres d'itérations: ").append(tab.getNbIterations()).toString()); - - Main.joglFrame.setVisible(true); - } catch (NumberFormatException err) { - Main.joglFrame.parsedState = AbstractCanvas.State.FINISH_OR_NULL; - openDialog("Une erreur de type " + err.getClass().getSimpleName() + " est survenue lors de l'execution du parser: " + err.getMessage()); - } - tab.submitButton2D.setIcon(null); - tab.submitButton2D.setText("Générer en 2D"); - }); - parserThread.start(); - } break; - case "Generate 3D": String axiom3D = tab.getAxiom(); List rules3D = tab.getRules(); diff --git a/src/lsystem/screen/main/Tab.java b/src/lsystem/screen/main/Tab.java index dd93818..e3ace0b 100644 --- a/src/lsystem/screen/main/Tab.java +++ b/src/lsystem/screen/main/Tab.java @@ -1,9 +1,7 @@ package lsystem.screen.main; import javax.swing.*; -import javax.swing.plaf.basic.BasicButtonUI; import java.awt.*; -import java.awt.event.ActionListener; import java.util.Arrays; public class Tab extends JPanel{ @@ -12,8 +10,8 @@ public class Tab extends JPanel{ int nbRules; public JSpinner itSpinner; JTextField axiomeField,rulesField; - JTextArea axiomList,rulesList;; - JButton submitButton2D, submitButton3D, close; + JTextArea axiomList,rulesList; + JButton submitButton3D, close; public Tab(int nbTabs,int nbRules,JTabbedPane tabs,MainFrame frame) { this.nbRules = nbRules; @@ -39,15 +37,11 @@ public class Tab extends JPanel{ rulesField = new JTextField(); rulesField.addKeyListener(new Listener(null,nbTabs+10,"Règles",this)); rulesField.setPreferredSize(new Dimension(120,20)); - - submitButton2D = new JButton("Générer en 2D"); submitButton3D = new JButton("Générer en 3D"); JButton clearButton = new JButton("Clear"); clearButton.addActionListener(new Listener(null,nbTabs,"Clear",this)); - submitButton2D.addActionListener(new Listener(null,nbTabs,"Generate 2D",this)); submitButton3D.addActionListener(new Listener(null,nbTabs,"Generate 3D",this)); - JPanel southComponents = subPanel(submitButton2D,submitButton3D, null); - JPanel southComponents2 = subPanel(clearButton, southComponents, null); + JPanel southComponents2 = subPanel(clearButton, submitButton3D, null); GridBagConstraints gc = new GridBagConstraints(); gc.gridx = 0; @@ -71,10 +65,11 @@ public class Tab extends JPanel{ aboveComponents.setLayout(new GridLayout(1,4)); this.add(aboveComponents); this.add(southComponents2); - this.setLayout(new BoxLayout(this,1)); + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - tabs.addTab("Génération"+String.valueOf(nbTabs),this); + tabs.addTab("Génération" + nbTabs,this); } + public JTextArea textArea(String texte, int nb){ JTextArea res = new JTextArea(); res.setText(texte); @@ -83,6 +78,7 @@ public class Tab extends JPanel{ return res; } + public JPanel subPanel(Component a, Component b,GridBagConstraints gc){ JPanel res = new JPanel(); if(gc == null){ @@ -97,12 +93,15 @@ public class Tab extends JPanel{ gc.gridy = 0; return res; } + public JTextArea getTextArea(byte i){ return (i == 0) ? axiomList : rulesList; } + public JTextField getTextField(byte i){ return (i == 0) ? axiomeField : rulesField; } + public void changeList(String stringToAdd, JTextArea list, int nbAxioms) { if(nbAxioms > 0) JOptionPane.showMessageDialog(null, "Nombre maximal d'axiomes créés"); @@ -113,17 +112,20 @@ public class Tab extends JPanel{ } } + public String getAxiom(){ String str = axiomList.getText(); str = str.substring(10).replaceAll(";", ""); return str; } + public java.util.List getRules(){ String str = rulesList.getText(); str = str.substring(10).replaceAll(";", ""); String[] strsplit = str.split("\n"); return Arrays.asList(strsplit); } + public int getNbIterations(){ return (int) itSpinner.getValue(); }