From 08719db537fae3645ca86f9ee6f8deba4dadf4f4 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Mon, 11 Jul 2022 22:14:30 +0300 Subject: [PATCH] Code refactoring. --- ...nuPanel.java => ApplicationListPanel.java} | 8 ++--- .../sixth/e3d/examples/launcher/Main.java | 33 ++++++++----------- .../examples/{life => life_demo}/Cell.java | 2 +- .../examples/{life => life_demo}/Main.java | 2 +- .../examples/{life => life_demo}/Matrix.java | 2 +- .../examples/{life => life_demo}/Star.java | 4 +-- 6 files changed, 23 insertions(+), 28 deletions(-) rename src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/{MenuPanel.java => ApplicationListPanel.java} (94%) rename src/main/java/eu/svjatoslav/sixth/e3d/examples/{life => life_demo}/Cell.java (98%) rename src/main/java/eu/svjatoslav/sixth/e3d/examples/{life => life_demo}/Main.java (98%) rename src/main/java/eu/svjatoslav/sixth/e3d/examples/{life => life_demo}/Matrix.java (98%) rename src/main/java/eu/svjatoslav/sixth/e3d/examples/{life => life_demo}/Star.java (95%) diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/MenuPanel.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/ApplicationListPanel.java similarity index 94% rename from src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/MenuPanel.java rename to src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/ApplicationListPanel.java index e620649..2b3b643 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/MenuPanel.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/ApplicationListPanel.java @@ -11,10 +11,10 @@ import eu.svjatoslav.sixth.e3d.examples.*; import javax.swing.*; import java.awt.event.ActionEvent; -class MenuPanel extends JPanel { +class ApplicationListPanel extends JPanel { private static final long serialVersionUID = 2012721856427052560L; - MenuPanel() { + ApplicationListPanel() { final GroupLayout groupLayout = new GroupLayout(this); GroupLayout.SequentialGroup sequentialGroup = groupLayout.createSequentialGroup(); sequentialGroup.addComponent(new JLabel("Choose an example to launch:")); @@ -64,7 +64,7 @@ class MenuPanel extends JPanel { private static class ShowPointCloud extends AbstractAction { ShowPointCloud() { - putValue(NAME, "Pointcloud galaxy"); + putValue(NAME, "Point cloud galaxy"); } @Override @@ -113,7 +113,7 @@ class MenuPanel extends JPanel { @Override public void actionPerformed(final ActionEvent e) { - eu.svjatoslav.sixth.e3d.examples.life.Main.main(null); + eu.svjatoslav.sixth.e3d.examples.life_demo.Main.main(null); } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java index 4d090f8..07e5c39 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java @@ -9,29 +9,24 @@ package eu.svjatoslav.sixth.e3d.examples.launcher; import javax.swing.*; import java.awt.*; -class Main extends javax.swing.JFrame { - - private static final long serialVersionUID = -3679656169594556137L; - - private Main() { - super(); - initGUI(); - } +class Main { public static void main(final String[] args) { - SwingUtilities.invokeLater(() -> { - final Main inst = new Main(); - final BorderLayout instLayout = new BorderLayout(); - inst.setLocationRelativeTo(null); - inst.setVisible(true); - inst.getContentPane().setLayout(instLayout); - }); + buildAndShowGuiWindow(); } - private void initGUI() { - getContentPane().add(new MenuPanel()); - pack(); - setSize(390, 300); + private static void buildAndShowGuiWindow() { + JFrame frame = new JFrame("Sixth 3D engine demos"); + + // Keep application running until last frame is closed. + frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + + frame.getContentPane().setLayout(new BorderLayout()); + frame.getContentPane().add(new ApplicationListPanel(), BorderLayout.CENTER); + frame.setSize(400, 300); + + frame.setLocationRelativeTo(null); // center frame on screen + frame.setVisible(true); } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Cell.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java similarity index 98% rename from src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Cell.java rename to src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java index fb78e4b..6b1ee8e 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Cell.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java @@ -1,4 +1,4 @@ -package eu.svjatoslav.sixth.e3d.examples.life; +package eu.svjatoslav.sixth.e3d.examples.life_demo; import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController; diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Main.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Main.java similarity index 98% rename from src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Main.java rename to src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Main.java index afc0e1c..cf47e7f 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Main.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Main.java @@ -1,4 +1,4 @@ -package eu.svjatoslav.sixth.e3d.examples.life; +package eu.svjatoslav.sixth.e3d.examples.life_demo; import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.geometry.Rectangle; diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Matrix.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Matrix.java similarity index 98% rename from src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Matrix.java rename to src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Matrix.java index ee7b0aa..8736b96 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Matrix.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Matrix.java @@ -1,4 +1,4 @@ -package eu.svjatoslav.sixth.e3d.examples.life; +package eu.svjatoslav.sixth.e3d.examples.life_demo; import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape; diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Star.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Star.java similarity index 95% rename from src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Star.java rename to src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Star.java index ad242d0..6f5edaa 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Star.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Star.java @@ -1,4 +1,4 @@ -package eu.svjatoslav.sixth.e3d.examples.life; +package eu.svjatoslav.sixth.e3d.examples.life_demo; import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.renderer.raster.Color; @@ -14,7 +14,7 @@ class Star extends GlowingPoint { private static final List uniqueStarColors = new ArrayList<>(); - /** + /* * A little hack to save RAM. We are going to have potentially lot of stars. * Instead of creating new individual texture for each star, Sixth 3D engine * uses internal optimization and reuses existing star textures, if star with -- 2.20.1