improve example tab + improve camera when generate l system
This commit is contained in:
parent
11529aaf18
commit
4b34a788b2
@ -65,6 +65,7 @@ public abstract class AbstractCanvas {
|
|||||||
// -XX:+UseG1GC to force jre 1.8 to use G1GC (G1GC is default on jre 11+), if you have jre 15+ you should use
|
// -XX:+UseG1GC to force jre 1.8 to use G1GC (G1GC is default on jre 11+), if you have jre 15+ you should use
|
||||||
// ZGC which is very quick compared to G1GC and have a lower CPU usage
|
// ZGC which is very quick compared to G1GC and have a lower CPU usage
|
||||||
System.gc();
|
System.gc();
|
||||||
|
camera = new float[]{0f, 1f, 5f, 0f, 0f, 0f}; // reset default camera position
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
frame.getContentPane().add(glCanvas, BorderLayout.CENTER);
|
frame.getContentPane().add(glCanvas, BorderLayout.CENTER);
|
||||||
|
@ -92,8 +92,8 @@ public class GLEventListener extends AbstractListener {
|
|||||||
|
|
||||||
if(element.property == ElementProperties.DRAW) {
|
if(element.property == ElementProperties.DRAW) {
|
||||||
if(firstGen) {
|
if(firstGen) {
|
||||||
canvas.camera[1] += 0.10f;
|
canvas.camera[1] = (float) Math.min(50f, canvas.camera[1] + 0.10f-Math.sin(element.rotation[1]));
|
||||||
canvas.camera[2] += 0.10f;
|
canvas.camera[2] = Math.min(50f, canvas.camera[2] + 0.10f);
|
||||||
}
|
}
|
||||||
glut.glutSolidCylinder(0.25f, 1f, 10, 10);
|
glut.glutSolidCylinder(0.25f, 1f, 10, 10);
|
||||||
gl.glTranslatef(0f, 0f, 1f);
|
gl.glTranslatef(0f, 0f, 1f);
|
||||||
|
17
src/lsystem/screen/main/AbstractListener.java
Normal file
17
src/lsystem/screen/main/AbstractListener.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package lsystem.screen.main;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public abstract class AbstractListener implements ActionListener {
|
||||||
|
|
||||||
|
protected final String type;
|
||||||
|
protected ImageIcon staticIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("./loading-gif.gif")));
|
||||||
|
|
||||||
|
public AbstractListener(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void openDialog(String message);
|
||||||
|
}
|
@ -1,37 +1,55 @@
|
|||||||
package lsystem.screen.main;
|
package lsystem.screen.main;
|
||||||
|
|
||||||
|
import lsystem.engine.Parser;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Example extends JPanel {
|
public class Example extends JPanel {
|
||||||
|
|
||||||
private final MainFrame frame;
|
private final MainFrame frame;
|
||||||
|
private final JButton a;
|
||||||
|
private final JButton b;
|
||||||
public Example(MainFrame frame) {
|
public Example(MainFrame frame) {
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
|
|
||||||
JPanel list = new JPanel();
|
a = new JButton("{axiom=\"Y\",rules:[\"Y=X+[[Y]-Y]-X[-XY]+Y\", \"X=XX\"]}");
|
||||||
list.setLayout(new GridBagLayout());
|
|
||||||
JButton a = new JButton("{axiom=\"Y\",rules:[\"Y=X+[[Y]-Y]-X[-XY]+Y\", \"X=XX\"]}");
|
|
||||||
a.addActionListener(new ExampleListener("a"));
|
a.addActionListener(new ExampleListener("a"));
|
||||||
JPanel aboveComponents = new JPanel();
|
this.add(a);
|
||||||
|
b = new JButton("{axiom=\"X\",rules:[\"X=XY\",\"Y=X\"]}");
|
||||||
|
b.addActionListener(new ExampleListener("b"));
|
||||||
|
this.add(b);
|
||||||
|
|
||||||
|
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ExampleListener implements ActionListener {
|
private class ExampleListener extends AbstractListener {
|
||||||
|
|
||||||
private final String type;
|
|
||||||
|
|
||||||
public ExampleListener(String type) {
|
public ExampleListener(String type) {
|
||||||
this.type = type;
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openDialog(String message) {
|
||||||
|
JOptionPane.showMessageDialog(null, message);
|
||||||
|
new ExampleListener("Clear");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Parser parser;
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case "a":
|
case "a":
|
||||||
|
parser = new Parser("Y", Arrays.asList("Y=X+[[Y]-Y]-X[-XY]+Y", "X=XX"), 5);
|
||||||
|
frame.generateLSystem(this, parser, a);
|
||||||
|
break;
|
||||||
|
case "b":
|
||||||
|
parser = new Parser("X", Arrays.asList("X=XY", "Y=X"), 5);
|
||||||
|
frame.generateLSystem(this, parser , b);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,20 +7,18 @@ import java.awt.*;
|
|||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Listener implements ActionListener, KeyListener, MouseWheelListener {
|
public class Listener extends AbstractListener implements KeyListener, MouseWheelListener {
|
||||||
Tab tab;
|
Tab tab;
|
||||||
MainFrame frame;
|
MainFrame frame;
|
||||||
Integer index;
|
Integer index;
|
||||||
String type;
|
|
||||||
Integer nbAxioms= 0;
|
Integer nbAxioms= 0;
|
||||||
ImageIcon staticIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("./loading-gif.gif")));
|
|
||||||
|
|
||||||
|
|
||||||
public Listener(MainFrame frame, Integer index, String type, Tab tab){
|
public Listener(MainFrame frame, Integer index, String type, Tab tab){
|
||||||
|
super(type);
|
||||||
this.tab = tab;
|
this.tab = tab;
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,7 +62,8 @@ public class Listener implements ActionListener, KeyListener, MouseWheelListener
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void openDialog(String message) {
|
@Override
|
||||||
|
public void openDialog(String message) {
|
||||||
JOptionPane.showMessageDialog(null, message);
|
JOptionPane.showMessageDialog(null, message);
|
||||||
new Listener(null, index, "Clear", tab);
|
new Listener(null, index, "Clear", tab);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ public class MainFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateLSystem(Listener listener, Parser parser, JButton submitButton) {
|
public void generateLSystem(AbstractListener listener, Parser parser, JButton submitButton) {
|
||||||
if(Main.joglFrame.frame.isVisible()) {
|
if(Main.joglFrame.frame.isVisible()) {
|
||||||
listener.openDialog("Veuillez fermer la fenêtre 2D ou 3D avant de lancer une nouvelle génération");
|
listener.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) {
|
} else if(Main.joglFrame.parsedState == AbstractCanvas.State.LOAD) {
|
||||||
|
@ -131,7 +131,7 @@ public class Tab extends JPanel{
|
|||||||
/**
|
/**
|
||||||
* @return A string which contains the axiom entered by the user.
|
* @return A string which contains the axiom entered by the user.
|
||||||
*/
|
*/
|
||||||
public String getAxiom(){
|
public String getAxiom() {
|
||||||
String str = axiomList.getText();
|
String str = axiomList.getText();
|
||||||
str = str.substring(10).replaceAll(";", "");
|
str = str.substring(10).replaceAll(";", "");
|
||||||
return str;
|
return str;
|
||||||
|
Loading…
Reference in New Issue
Block a user