Added Game of Life demo to application launcher.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sat, 15 Jul 2017 10:10:08 +0000 (12:10 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sat, 15 Jul 2017 10:10:08 +0000 (12:10 +0200)
src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/MenuPanel.java
src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Main.java

index 1f868b9..10178e3 100644 (file)
@@ -11,8 +11,6 @@ package eu.svjatoslav.sixth.e3d.examples.launcher;
 import eu.svjatoslav.sixth.e3d.examples.*;
 
 import javax.swing.*;
-import javax.swing.GroupLayout.Alignment;
-import javax.swing.LayoutStyle.ComponentPlacement;
 import java.awt.event.ActionEvent;
 import java.io.IOException;
 
@@ -21,110 +19,19 @@ class MenuPanel extends JPanel {
 
     public MenuPanel() {
 
-        final JLabel chooseExample = new JLabel("Choose an example to launch.");
-
-        final JButton showTextEditors = new JButton(new ShowTextEditors());
-        final JButton showSinusMap = new JButton(new ShowSinusMap());
-        final JButton showRain = new JButton(new ShowRain());
-        final JButton showPointCloud = new JButton(new ShowPointcloud());
-        final JButton showMathGraphs = new JButton(new ShowMathGraphs());
-        final JButton showOctree = new JButton(new ShowOctree());
-
         final GroupLayout groupLayout = new GroupLayout(this);
-        groupLayout
-                .setHorizontalGroup(groupLayout
-                        .createParallelGroup(Alignment.LEADING)
-                        .addGroup(
-                                groupLayout
-                                        .createSequentialGroup()
-                                        .addContainerGap()
-                                        .addGroup(
-                                                groupLayout
-                                                        .createParallelGroup(
-                                                                Alignment.LEADING)
-                                                        .addGroup(
-                                                                Alignment.TRAILING,
-                                                                groupLayout
-                                                                        .createSequentialGroup()
-                                                                        .addComponent(
-                                                                                chooseExample,
-                                                                                GroupLayout.PREFERRED_SIZE,
-                                                                                426,
-                                                                                GroupLayout.PREFERRED_SIZE)
-                                                                        .addContainerGap(
-                                                                                GroupLayout.DEFAULT_SIZE,
-                                                                                Short.MAX_VALUE))
-                                                        .addGroup(
-                                                                Alignment.TRAILING,
-                                                                groupLayout
-                                                                        .createSequentialGroup()
-                                                                        .addGroup(
-                                                                                groupLayout
-                                                                                        .createParallelGroup(
-                                                                                                Alignment.TRAILING)
-                                                                                        .addComponent(
-                                                                                                showOctree,
-                                                                                                Alignment.LEADING,
-                                                                                                GroupLayout.DEFAULT_SIZE,
-                                                                                                331,
-                                                                                                Short.MAX_VALUE)
-                                                                                        .addComponent(
-                                                                                                showMathGraphs,
-                                                                                                Alignment.LEADING,
-                                                                                                GroupLayout.DEFAULT_SIZE,
-                                                                                                331,
-                                                                                                Short.MAX_VALUE)
-                                                                                        .addComponent(
-                                                                                                showPointCloud,
-                                                                                                Alignment.LEADING,
-                                                                                                GroupLayout.DEFAULT_SIZE,
-                                                                                                331,
-                                                                                                Short.MAX_VALUE)
-                                                                                        .addComponent(
-                                                                                                showRain,
-                                                                                                Alignment.LEADING,
-                                                                                                GroupLayout.DEFAULT_SIZE,
-                                                                                                331,
-                                                                                                Short.MAX_VALUE)
-                                                                                        .addComponent(
-                                                                                                showSinusMap,
-                                                                                                Alignment.LEADING,
-                                                                                                GroupLayout.DEFAULT_SIZE,
-                                                                                                GroupLayout.DEFAULT_SIZE,
-                                                                                                Short.MAX_VALUE)
-                                                                                        .addComponent(
-                                                                                                showTextEditors,
-                                                                                                GroupLayout.DEFAULT_SIZE,
-                                                                                                331,
-                                                                                                Short.MAX_VALUE))
-                                                                        .addGap(107)))));
-        groupLayout.setVerticalGroup(groupLayout.createParallelGroup(
-                Alignment.LEADING).addGroup(
-                groupLayout
-                        .createSequentialGroup()
-                        .addGap(7)
-                        .addComponent(chooseExample, GroupLayout.PREFERRED_SIZE,
-                                58, GroupLayout.PREFERRED_SIZE)
-                        .addPreferredGap(ComponentPlacement.RELATED)
-                        .addComponent(showTextEditors)
-                        .addPreferredGap(ComponentPlacement.RELATED)
-                        .addComponent(showSinusMap)
-                        .addPreferredGap(ComponentPlacement.RELATED)
-                        .addComponent(showRain)
-                        .addPreferredGap(ComponentPlacement.RELATED)
-                        .addComponent(showPointCloud)
-                        .addPreferredGap(ComponentPlacement.RELATED)
-                        .addComponent(showMathGraphs)
-                        .addPreferredGap(ComponentPlacement.RELATED)
-                        .addComponent(showOctree)
-                        .addContainerGap(137, Short.MAX_VALUE)));
-        setLayout(groupLayout);
-
+        GroupLayout.SequentialGroup sequentialGroup = groupLayout.createSequentialGroup();
+        sequentialGroup.addComponent(new JLabel("Choose an example to launch:"));
+        sequentialGroup.addComponent(new JButton(new ShowOctree()));
+        sequentialGroup.addComponent(new JButton(new ShowMathGraphs()));
+        sequentialGroup.addComponent(new JButton(new ShowPointcloud()));
+        sequentialGroup.addComponent(new JButton(new ShowRain()));
+        sequentialGroup.addComponent(new JButton(new ShowSinusMap()));
+        sequentialGroup.addComponent(new JButton(new ShowTextEditors()));
+        sequentialGroup.addComponent(new JButton(new ShowGameOfLife()));
     }
 
     private class ShowTextEditors extends AbstractAction {
-        private static final long serialVersionUID = 5197962166765841015L;
-
         public ShowTextEditors() {
             putValue(NAME, "Text editors");
         }
@@ -136,8 +43,6 @@ class MenuPanel extends JPanel {
     }
 
     private class ShowSinusMap extends AbstractAction {
-        private static final long serialVersionUID = -896479509963403828L;
-
         public ShowSinusMap() {
             putValue(NAME, "Wireframe sphere and ploygon landscape");
         }
@@ -149,8 +54,6 @@ class MenuPanel extends JPanel {
     }
 
     private class ShowRain extends AbstractAction {
-        private static final long serialVersionUID = 8566009849873897321L;
-
         public ShowRain() {
             putValue(NAME, "Raining numbers");
         }
@@ -166,8 +69,6 @@ class MenuPanel extends JPanel {
     }
 
     private class ShowPointcloud extends AbstractAction {
-        private static final long serialVersionUID = -5369105936409884389L;
-
         public ShowPointcloud() {
             putValue(NAME, "Pointcloud galaxy");
         }
@@ -179,8 +80,6 @@ class MenuPanel extends JPanel {
     }
 
     private class ShowMathGraphs extends AbstractAction {
-        private static final long serialVersionUID = -8486796142555764460L;
-
         public ShowMathGraphs() {
             putValue(NAME, "Mathematical graphs");
         }
@@ -196,8 +95,6 @@ class MenuPanel extends JPanel {
     }
 
     private class ShowOctree extends AbstractAction {
-        private static final long serialVersionUID = -6210703594848004946L;
-
         public ShowOctree() {
             putValue(NAME, "Volumetric Octree");
         }
@@ -211,4 +108,16 @@ class MenuPanel extends JPanel {
             }
         }
     }
+
+    private class ShowGameOfLife extends AbstractAction {
+        public ShowGameOfLife() {
+            putValue(NAME, "Game of Life");
+        }
+
+        @Override
+        public void actionPerformed(final ActionEvent e) {
+            eu.svjatoslav.sixth.e3d.examples.life.Main.main(null);
+        }
+    }
+
 }
index 527a6a2..539527d 100644 (file)
@@ -15,7 +15,7 @@ import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.Grid2D
 import java.awt.event.KeyEvent;
 
 
-class Main extends WorldNavigationTracker {
+public class Main extends WorldNavigationTracker {
 
     private static final Matrix MATRIX = new Matrix(
             new Point3D() // position matrix in the center of the scene