From 96f76bab30b47db83a1c9061b8916c69657f1e13 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 14 Jul 2018 00:56:07 +0300 Subject: [PATCH] Removed ViewListener interface. Renamed View to ViewPanel. --- .../svjatoslav/sixth/e3d/gui/ViewContext.java | 10 +++--- .../svjatoslav/sixth/e3d/gui/ViewFrame.java | 31 +++++++++---------- .../sixth/e3d/gui/ViewListener.java | 16 ---------- .../e3d/gui/{View.java => ViewPanel.java} | 17 +++------- .../sixth/e3d/gui/ViewUpdateTimerTask.java | 8 ++--- .../e3d/gui/humaninput/UserInputTracker.java | 14 ++++----- .../renderer/octree/raytracer/RayTracer.java | 12 +++---- 7 files changed, 40 insertions(+), 68 deletions(-) delete mode 100644 src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewListener.java rename src/main/java/eu/svjatoslav/sixth/e3d/gui/{View.java => ViewPanel.java} (94%) diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewContext.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewContext.java index 0afa0de..be949c8 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewContext.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewContext.java @@ -22,12 +22,12 @@ public class ViewContext { private final Avatar avatar = new Avatar(); - private final View view; + private final ViewPanel viewPanel; private final ShapeCollection rootShapeCollection = new ShapeCollection(); - public ViewContext(final View view) { - this.view = view; + public ViewContext(final ViewPanel viewPanel) { + this.viewPanel = viewPanel; } public Avatar getAvatar() { @@ -46,8 +46,8 @@ public class ViewContext { return userInputTracker; } - public View getView() { - return view; + public ViewPanel getViewPanel() { + return viewPanel; } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewFrame.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewFrame.java index bdfe765..874673f 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewFrame.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewFrame.java @@ -16,11 +16,11 @@ import java.awt.event.ComponentListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; -public class ViewFrame extends JFrame implements ViewListener, WindowListener { +public class ViewFrame extends JFrame implements WindowListener { private static final long serialVersionUID = -7037635097739548470L; - private final View view; + private final ViewPanel viewPanel; public ViewFrame() { setTitle("3D engine"); @@ -32,11 +32,9 @@ public class ViewFrame extends JFrame implements ViewListener, WindowListener { } }); - view = new View(); + viewPanel = new ViewPanel(); - add(getView()); - - getView().addViewListener(this); + add(getViewPanel()); setSize(800, 600); @@ -86,18 +84,17 @@ public class ViewFrame extends JFrame implements ViewListener, WindowListener { @Override public void componentShown(final ComponentEvent e) { - view.repaintDuringNextViewUpdate(); + viewPanel.repaintDuringNextViewUpdate(); } }); } - @Override public void exit() { - if (getView() != null) { - getView().stop(); - getView().setEnabled(false); - getView().setVisible(false); + if (getViewPanel() != null) { + getViewPanel().stop(); + getViewPanel().setEnabled(false); + getViewPanel().setVisible(false); } dispose(); } @@ -110,13 +107,13 @@ public class ViewFrame extends JFrame implements ViewListener, WindowListener { /** * @return the view */ - public View getView() { - return view; + public ViewPanel getViewPanel() { + return viewPanel; } @Override public void windowActivated(final WindowEvent e) { - view.repaintDuringNextViewUpdate(); + viewPanel.repaintDuringNextViewUpdate(); } @Override @@ -133,7 +130,7 @@ public class ViewFrame extends JFrame implements ViewListener, WindowListener { @Override public void windowDeiconified(final WindowEvent e) { - view.repaintDuringNextViewUpdate(); + viewPanel.repaintDuringNextViewUpdate(); } @Override @@ -142,7 +139,7 @@ public class ViewFrame extends JFrame implements ViewListener, WindowListener { @Override public void windowOpened(final WindowEvent e) { - view.repaintDuringNextViewUpdate(); + viewPanel.repaintDuringNextViewUpdate(); } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewListener.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewListener.java deleted file mode 100644 index af68b15..0000000 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewListener.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 3 of the GNU Lesser General Public License - * or later as published by the Free Software Foundation. - * - */ - -package eu.svjatoslav.sixth.e3d.gui; - -public interface ViewListener { - - void exit(); - -} diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/View.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java similarity index 94% rename from src/main/java/eu/svjatoslav/sixth/e3d/gui/View.java rename to src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java index 615c69b..87f0dd3 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/View.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java @@ -19,16 +19,15 @@ import java.util.ArrayList; import java.util.List; import java.util.Timer; -public class View extends JPanel implements ComponentListener { +public class ViewPanel extends JPanel implements ComponentListener { private static final long serialVersionUID = 1683277888885045387L; - private final List viewListeners = new ArrayList<>(); private final List viewRenderListeners = new ArrayList<>(); private final ViewContext context = new ViewContext(this); /** - * Last time this view was updated + * Last time this view was updated. */ - long lastUpdateMillis = 0; + private long lastUpdateMillis = 0; private Timer canvasUpdateTimer; private ViewUpdateTimerTask canvasUpdateTimerTask; private RenderingContext renderingContext = null; @@ -39,7 +38,7 @@ public class View extends JPanel implements ComponentListener { private int targetFramerate = 30; private boolean repaintDuringNextViewUpdate = true; - public View() { + public ViewPanel() { viewRenderListeners.add(context.getAvatar()); // initialize input tracker @@ -53,10 +52,6 @@ public class View extends JPanel implements ComponentListener { addComponentListener(this); } - public void addViewListener(final ViewListener listener) { - getViewListeners().add(listener); - } - public void addViewUpdateListener(final ViewRenderListener listener) { viewRenderListeners.add(listener); } @@ -108,10 +103,6 @@ public class View extends JPanel implements ComponentListener { return renderingContext; } - public List getViewListeners() { - return viewListeners; - } - private void handleDetectedComponentMouseEvents() { if (renderingContext.clickedItem != null) { if (renderingContext.mouseClick.button == 0) { diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewUpdateTimerTask.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewUpdateTimerTask.java index 5946961..27e8e86 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewUpdateTimerTask.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewUpdateTimerTask.java @@ -11,17 +11,17 @@ package eu.svjatoslav.sixth.e3d.gui; public class ViewUpdateTimerTask extends java.util.TimerTask { - public View view; + public ViewPanel viewPanel; - public ViewUpdateTimerTask(final View view) { - this.view = view; + public ViewUpdateTimerTask(final ViewPanel viewPanel) { + this.viewPanel = viewPanel; } @Override public void run() { // update and possibly render view - view.updateView(); + viewPanel.updateView(); } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/UserInputTracker.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/UserInputTracker.java index 105a582..1dd6f7a 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/UserInputTracker.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/UserInputTracker.java @@ -11,7 +11,7 @@ package eu.svjatoslav.sixth.e3d.gui.humaninput; import eu.svjatoslav.sixth.e3d.geometry.Point2D; import eu.svjatoslav.sixth.e3d.gui.Avatar; -import eu.svjatoslav.sixth.e3d.gui.View; +import eu.svjatoslav.sixth.e3d.gui.ViewPanel; import eu.svjatoslav.sixth.e3d.gui.ViewContext; import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener; @@ -54,7 +54,7 @@ public class UserInputTracker @Override public boolean beforeRender(final ViewContext viewContext, final int millisecondsSinceLastFrame) { - boolean viewUpdateNeeded = handleDetectedMouseClicks(viewContext.getView()); + boolean viewUpdateNeeded = handleDetectedMouseClicks(viewContext.getViewPanel()); viewUpdateNeeded |= handleDetectedKeyEvents(); @@ -110,11 +110,11 @@ public class UserInputTracker /** * @return true if view needs to be repainted. */ - private synchronized boolean handleDetectedMouseClicks(final View view) { + private synchronized boolean handleDetectedMouseClicks(final ViewPanel viewPanel) { if (detectedMouseClicks.isEmpty()) { if (currentMouseLocation != null) - view.getRenderingContext().mouseClick = new MouseClick(currentMouseLocation, 0); + viewPanel.getRenderingContext().mouseClick = new MouseClick(currentMouseLocation, 0); if (mouseMoved) { mouseMoved = false; @@ -123,7 +123,7 @@ public class UserInputTracker return false; } - view.getRenderingContext().mouseClick = detectedMouseClicks.remove(0); + viewPanel.getRenderingContext().mouseClick = detectedMouseClicks.remove(0); return true; } @@ -137,7 +137,7 @@ public class UserInputTracker synchronized (detectedKeyEvents) { pressedKeysToPressedTimeMap.put(evt.getKeyCode(), System.currentTimeMillis()); detectedKeyEvents.add(evt); - viewContext.getView().repaintDuringNextViewUpdate(); + viewContext.getViewPanel().repaintDuringNextViewUpdate(); } } @@ -146,7 +146,7 @@ public class UserInputTracker synchronized (detectedKeyEvents) { pressedKeysToPressedTimeMap.remove(evt.getKeyCode()); detectedKeyEvents.add(evt); - viewContext.getView().repaintDuringNextViewUpdate(); + viewContext.getViewPanel().repaintDuringNextViewUpdate(); } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/RayTracer.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/RayTracer.java index 41d1c80..35ec06b 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/RayTracer.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/RayTracer.java @@ -9,7 +9,7 @@ package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer; -import eu.svjatoslav.sixth.e3d.gui.View; +import eu.svjatoslav.sixth.e3d.gui.ViewPanel; import eu.svjatoslav.sixth.e3d.renderer.octree.OctreeVolume; import eu.svjatoslav.sixth.e3d.renderer.raster.Color; import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture; @@ -21,20 +21,20 @@ public class RayTracer implements Runnable { private static final int PROGRESS_UPDATE_FREQUENCY_MILLIS = 1000; private final Camera camera; private final Texture texture; - private final View view; + private final ViewPanel viewPanel; private OctreeVolume octreeVolume; private Vector lights; private int computedLights; public RayTracer(final Texture texture, final OctreeVolume octreeVolume, final Vector lights, final Camera camera, - final View view) { + final ViewPanel viewPanel) { this.texture = texture; this.octreeVolume = octreeVolume; this.lights = lights; this.camera = camera; - this.view = view; + this.viewPanel = viewPanel; } @Override @@ -101,12 +101,12 @@ public class RayTracer implements Runnable { nextBitmapUpdate = System.currentTimeMillis() + PROGRESS_UPDATE_FREQUENCY_MILLIS; texture.resetResampledBitmapCache(); - view.repaintDuringNextViewUpdate(); + viewPanel.repaintDuringNextViewUpdate(); } } texture.resetResampledBitmapCache(); - view.repaintDuringNextViewUpdate(); + viewPanel.repaintDuringNextViewUpdate(); // System.out.println("Raytracing done."); // System.out.println("New lights computed:" + computedLights); } -- 2.20.1