From 3309f404f7f3ed50dbfa97356a2bfb4aac267ce3 Mon Sep 17 00:00:00 2001 From: thomaswoehlke Date: Sun, 11 Oct 2020 05:46:39 +0200 Subject: [PATCH] Issue #48 Split Mandelbrot-Tab into Mandelbrot-Julia and Mandelbrot-Zoom --- .../tabs/mandelbrot/MandelbrotModel.java | 29 +------- .../tabs/mandelbrot/MandelbrotTab.java | 9 +-- .../tabs/mandelbrot/canvas/PanelButtons.java | 68 ------------------- .../model/fractal/GaussianNumberPlane.java | 11 ++- .../model/state/ApplicationState.java | 4 +- .../model/state/ApplicationStateMachine.java | 31 +-------- 6 files changed, 15 insertions(+), 137 deletions(-) delete mode 100644 single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/canvas/PanelButtons.java diff --git a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/MandelbrotModel.java b/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/MandelbrotModel.java index ca1dcb6f..ad430214 100644 --- a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/MandelbrotModel.java +++ b/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/MandelbrotModel.java @@ -45,12 +45,6 @@ public synchronized boolean click(Point c) { case JULIA_SET: gaussianNumberPlane.computeTheJuliaSetFor(c); break; - case MANDELBROT_ZOOM: - gaussianNumberPlane.zoomIntoTheMandelbrotSet(c); - break; - case JULIA_SET_ZOOM: - gaussianNumberPlane.zoomIntoTheJuliaSetFor(c); - break; } return repaint; } @@ -62,8 +56,6 @@ public synchronized boolean step() { repaint = mandelbrotTuringMachine.step(); break; case JULIA_SET: - case MANDELBROT_ZOOM: - case JULIA_SET_ZOOM: break; } return repaint; @@ -80,16 +72,10 @@ public Point getWorldDimensions() { } public void setModeSwitch() { - this.applicationStateMachine.setModeSwitch(); + //this.applicationStateMachine.setModeSwitch(); this.frame.setModeSwitch(); } - public void setModeZoom() { - this.gaussianNumberPlane.setModeZoom(); - this.applicationStateMachine.setModeZoom(); - this.frame.setModeZoom(); - } - public GaussianNumberPlane getGaussianNumberPlane() { return gaussianNumberPlane; } @@ -98,17 +84,4 @@ public MandelbrotTab getFrame() { return frame; } - public void zoomOut() { - switch (applicationStateMachine.getApplicationState()) { - case MANDELBROT: - case JULIA_SET: - break; - case MANDELBROT_ZOOM: - gaussianNumberPlane.zoomOutOfTheMandelbrotSet(); - break; - case JULIA_SET_ZOOM: - gaussianNumberPlane.zoomOutOfTheJuliaSet(); - break; - } - } } diff --git a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/MandelbrotTab.java b/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/MandelbrotTab.java index 6f151622..59ee676a 100644 --- a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/MandelbrotTab.java +++ b/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/MandelbrotTab.java @@ -1,7 +1,6 @@ package org.woehlke.computer.kurzweil.tabs.mandelbrot; import org.woehlke.computer.kurzweil.application.ComputerKurzweilProperties; -import org.woehlke.computer.kurzweil.tabs.mandelbrot.canvas.PanelButtons; import org.woehlke.computer.kurzweil.tabs.mandelbrot.canvas.PanelCopyright; import org.woehlke.computer.kurzweil.tabs.mandelbrot.canvas.PanelSubtitle; import org.woehlke.computer.kurzweil.tabs.mandelbrot.model.turing.Point; @@ -39,7 +38,6 @@ public MandelbrotTab(ComputerKurzweilProperties properties) { BoxLayout layout = new BoxLayout(rootPane, BoxLayout.PAGE_AXIS); this.canvas = new MandelbrotCanvas(mandelbrotModel); this.mandelbrotController = new MandelbrotController(mandelbrotModel, this); - PanelButtons panelButtons = new PanelButtons(this.mandelbrotModel); PanelSubtitle panelSubtitle = new PanelSubtitle(properties.getMandelbrot().getView().getSubtitle()); PanelCopyright panelCopyright = new PanelCopyright(properties.getAllinone().getView().getCopyright()); JSeparator separator = new JSeparator(); @@ -47,8 +45,6 @@ public MandelbrotTab(ComputerKurzweilProperties properties) { rootPane.add(panelSubtitle); rootPane.add(canvas); rootPane.add(panelCopyright); - rootPane.add(separator); - rootPane.add(panelButtons); addWindowListener(this); this.canvas.addMouseListener( this); showMeInit(); @@ -104,7 +100,7 @@ public void showMeInit() { pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); double width = this.rootPane.getWidth(); - double height = this.canvas.getHeight() + 180; + double height = this.canvas.getHeight() + 90; double startX = (screenSize.getWidth() - width) / 2d; double startY = (screenSize.getHeight() - height) / 2d; int myheight = Double.valueOf(height).intValue(); @@ -137,10 +133,11 @@ public void setModeSwitch() { canvas.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); } + /* public void setModeZoom() { canvas.setCursor(new Cursor(Cursor.HAND_CURSOR)); } - +*/ public MandelbrotCanvas getCanvas() { return canvas; } diff --git a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/canvas/PanelButtons.java b/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/canvas/PanelButtons.java deleted file mode 100644 index 12c1c93f..00000000 --- a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/canvas/PanelButtons.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.woehlke.computer.kurzweil.tabs.mandelbrot.canvas; - -import org.woehlke.computer.kurzweil.tabs.mandelbrot.MandelbrotModel; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import static org.woehlke.computer.kurzweil.tabs.mandelbrot.canvas.RradioButtons.RADIO_BUTTONS_SWITCH; -import static org.woehlke.computer.kurzweil.tabs.mandelbrot.canvas.RradioButtons.RADIO_BUTTONS_ZOOM; - - -/** - * Mandelbrot Set drawn by a Turing Machine. - * - * (C) 2006 - 2015 Thomas Woehlke. - * https://thomas-woehlke.blogspot.com/2016/01/mandelbrot-set-drawn-by-turing-machine.html - * @author Thomas Woehlke - * - * Created by tw on 16.12.2019. - */ -public class PanelButtons extends JPanel implements ActionListener { - - private volatile JRadioButton radioButtonsSwitch; - private volatile JRadioButton radioButtonsZoom; - private volatile JButton zoomOut; - private volatile ButtonGroup radioButtonsGroup; - private volatile MandelbrotModel model; - - public PanelButtons(MandelbrotModel model) { - this.model = model; - JLabel buttonsLabel = new JLabel(model.getProperties().getMandelbrot().getView().getButtonsLabel()); - this.radioButtonsSwitch = new JRadioButton(model.getProperties().getMandelbrot().getView().getButtonsSwitch()); - this.radioButtonsSwitch.setMnemonic(RADIO_BUTTONS_SWITCH.ordinal()); - this.radioButtonsSwitch.setSelected(true); - this.radioButtonsSwitch.addActionListener(this); - this.radioButtonsZoom = new JRadioButton(model.getProperties().getMandelbrot().getView().getButtonsSwitch()); - this.radioButtonsZoom.setMnemonic(RADIO_BUTTONS_ZOOM.ordinal()); - this.radioButtonsZoom.addActionListener(this); - this.radioButtonsGroup = new ButtonGroup(); - this.radioButtonsGroup.add(radioButtonsSwitch); - this.radioButtonsGroup.add(radioButtonsZoom); - this.zoomOut = new JButton(model.getProperties().getMandelbrot().getView().getButtonsZoomOut()); - this.zoomOut.addActionListener(this); - FlowLayout layout = new FlowLayout(); - this.setLayout(layout); - this.add(buttonsLabel); - this.add(radioButtonsSwitch); - this.add(radioButtonsZoom); - this.add(zoomOut); - } - - /** - * TODO write doc. - */ - @Override - public void actionPerformed(ActionEvent ae) { - if (ae.getSource() == this.radioButtonsSwitch) { - this.model.setModeSwitch(); - } else if(ae.getSource() == this.radioButtonsZoom) { - this.model.setModeZoom(); - } else if(ae.getSource() == this.zoomOut){ - this.model.zoomOut(); - this.model.getFrame().getCanvas().repaint(); - } - } -} diff --git a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/fractal/GaussianNumberPlane.java b/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/fractal/GaussianNumberPlane.java index a480f4ed..82b7b689 100644 --- a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/fractal/GaussianNumberPlane.java +++ b/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/fractal/GaussianNumberPlane.java @@ -43,7 +43,6 @@ public class GaussianNumberPlane { private volatile ComplexNumber zoomCenter; - //public static Logger log = Logger.getLogger(GaussianNumberPlane.class.getName()); public GaussianNumberPlane(MandelbrotModel model) { @@ -64,10 +63,12 @@ public GaussianNumberPlane(MandelbrotModel model) { start(); } + /* public void setModeZoom() { this.setZoomLevel(1); this.setZoomCenter(complexCenterForMandelbrot); } +*/ public synchronized void start(){ zoomLevel = 1; @@ -120,11 +121,13 @@ private synchronized ComplexNumber getComplexNumberFromLatticeCoordsForZoomedMan return new ComplexNumber(realX,imgY); } + /* public synchronized boolean isInZooomedMandelbrotSet(Point turingPosition) { ComplexNumber position = this.getComplexNumberFromLatticeCoordsForZoomedMandelbrot(turingPosition); lattice[turingPosition.getX()][turingPosition.getY()] = position.computeMandelbrotSet(); return position.isInMandelbrotSet(); } +*/ public synchronized boolean isInMandelbrotSet(Point turingPosition) { ComplexNumber position = this.getComplexNumberFromLatticeCoordsForMandelbrot(turingPosition); @@ -158,6 +161,7 @@ public synchronized void computeTheJuliaSetFor(Point pointFromMandelbrotSet) { computeTheJuliaSetForC(c); } + /* public void zoomIntoTheMandelbrotSet(Point zoomPoint) { //log.info("zoomIntoTheMandelbrotSet: "+ zoomPoint +" - old: "+this.getZoomCenter()); this.inceaseZoomLevel(); @@ -201,11 +205,12 @@ public void zoomIntoTheJuliaSetFor(Point zoomPoint) { public void zoomOutOfTheJuliaSet() { } - +*/ public synchronized int getZoomLevel() { return zoomLevel; } + /* public synchronized int inceaseZoomLevel() { return zoomLevel *= 2; } @@ -213,7 +218,7 @@ public synchronized int inceaseZoomLevel() { public synchronized int deceaseZoomLevel() { return zoomLevel /= 2; } - +*/ public synchronized void setZoomLevel(int zoomLevel) { this.zoomLevel = zoomLevel; } diff --git a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/state/ApplicationState.java b/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/state/ApplicationState.java index 1eb0939c..ed856c63 100644 --- a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/state/ApplicationState.java +++ b/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/state/ApplicationState.java @@ -11,7 +11,5 @@ */ public enum ApplicationState { MANDELBROT, - JULIA_SET, - MANDELBROT_ZOOM, - JULIA_SET_ZOOM + JULIA_SET } diff --git a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/state/ApplicationStateMachine.java b/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/state/ApplicationStateMachine.java index 80d50e46..b0b9252a 100644 --- a/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/state/ApplicationStateMachine.java +++ b/single-apps/insourcing/insourcing-mandelbrot-switch/src/main/java/org/woehlke/computer/kurzweil/tabs/mandelbrot/model/state/ApplicationStateMachine.java @@ -1,7 +1,6 @@ package org.woehlke.computer.kurzweil.tabs.mandelbrot.model.state; import static org.woehlke.computer.kurzweil.tabs.mandelbrot.model.state.ApplicationState.*; -import static org.woehlke.computer.kurzweil.tabs.mandelbrot.model.state.ApplicationState.JULIA_SET_ZOOM; /** * Mandelbrot Set drawn by a Turing Machine. @@ -29,47 +28,21 @@ public void click(){ case JULIA_SET: nextApplicationState = MANDELBROT; break; - case MANDELBROT_ZOOM: - nextApplicationState = MANDELBROT_ZOOM; - break; - case JULIA_SET_ZOOM: - nextApplicationState = JULIA_SET_ZOOM; - break; } this.setApplicationState(nextApplicationState); } + /* public void setModeSwitch() { ApplicationState nextApplicationState = this.applicationState; switch (applicationState){ case MANDELBROT: case JULIA_SET: break; - case MANDELBROT_ZOOM: - nextApplicationState = MANDELBROT; - break; - case JULIA_SET_ZOOM: - nextApplicationState = JULIA_SET; - break; - } - this.setApplicationState(nextApplicationState); - } - - public void setModeZoom() { - ApplicationState nextApplicationState = this.applicationState; - switch (applicationState){ - case MANDELBROT: - nextApplicationState = MANDELBROT_ZOOM; - break; - case JULIA_SET: - nextApplicationState = JULIA_SET_ZOOM; - break; - case MANDELBROT_ZOOM: - case JULIA_SET_ZOOM: - break; } this.setApplicationState(nextApplicationState); } + */ public ApplicationState getApplicationState() { return applicationState;