From 57cc1163708260f3e4f5b56cc1de2ad2ee625018 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 29 Apr 2015 22:37:13 +0200 Subject: cleanup --- Week11 Mandelbrot/src/fractals/MainWindow.java | 58 ++++++++++++++++++-------- 1 file changed, 40 insertions(+), 18 deletions(-) (limited to 'Week11 Mandelbrot/src/fractals/MainWindow.java') diff --git a/Week11 Mandelbrot/src/fractals/MainWindow.java b/Week11 Mandelbrot/src/fractals/MainWindow.java index 7a7a94f..b6276af 100644 --- a/Week11 Mandelbrot/src/fractals/MainWindow.java +++ b/Week11 Mandelbrot/src/fractals/MainWindow.java @@ -2,10 +2,10 @@ package fractals; -import com.camilstaps.mandelbrot.MandelbrotController; +import com.camilstaps.mandelbrot.MandelbrotView; import com.camilstaps.mandelbrot.ZoomFrame; import java.awt.BorderLayout; -import java.awt.FlowLayout; +import java.awt.GridLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -26,20 +26,25 @@ import javax.swing.JTextField; * creates a window to which a GridView panel is added * */ -public class MainWindow implements MandelbrotController.MandelbrotProvider, ZoomFrame.MandelbrotTextFields { +public class MainWindow implements MandelbrotView.MandelbrotProvider, ZoomFrame.MandelbrotTextFields { // the size of the window public static final int WIDTH = 650, HEIGHT = 650; + private final String INITIAL_CENTER_X = "0", + INITIAL_CENTER_Y = "0", + INITIAL_SCALE = "100", + INITIAL_REPETITIONS = "100"; + // The grip panel private final GridView grid; - private final JTextField field_centerX = new JTextField("0", 6); - private final JTextField field_centerY = new JTextField("0", 6); - private final JTextField field_scale = new JTextField("100", 6); - private final JTextField field_repetitions = new JTextField("100", 6); + private final JTextField field_centerX = new JTextField(INITIAL_CENTER_X, 6); + private final JTextField field_centerY = new JTextField(INITIAL_CENTER_Y, 6); + private final JTextField field_scale = new JTextField(INITIAL_SCALE, 6); + private final JTextField field_repetitions = new JTextField(INITIAL_REPETITIONS, 6); private final JButton button_redraw = new JButton("Redraw"); - private final MandelbrotController mandelbrotController; + private final MandelbrotView mandelbrotController; public MainWindow () { ZoomFrame mainFrame = new ZoomFrame ("Mandelbrot"); @@ -55,13 +60,15 @@ public class MainWindow implements MandelbrotController.MandelbrotProvider, Zoom grid = new GridView(WIDTH - insets.left - insets.right, HEIGHT - insets.top - insets.bottom); mainFrame.add(grid, BorderLayout.CENTER); - mandelbrotController = new MandelbrotController(this, grid); + mandelbrotController = new MandelbrotView(this, grid); mandelbrotController.redraw(); - mainFrame.setMandelbrotController(mandelbrotController); + mainFrame.setMandelbrotView(mandelbrotController); mainFrame.setMandelbrotTextFields(this); - JPanel panel = new JPanel(new FlowLayout()); + JPanel left = new JPanel(new BorderLayout()); + + JPanel panel = new JPanel(new GridLayout(10,1)); button_redraw.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { @@ -72,15 +79,30 @@ public class MainWindow implements MandelbrotController.MandelbrotProvider, Zoom }); panel.add(new JLabel("Center x:")); panel.add(field_centerX); - panel.add(new JLabel("y:")); + panel.add(new JLabel("Center y:")); panel.add(field_centerY); panel.add(new JLabel("Scale:")); panel.add(field_scale); panel.add(new JLabel("Repetitions:")); panel.add(field_repetitions); panel.add(button_redraw); + JButton button_reset = new JButton("Reset"); + button_reset.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + field_centerX.setText(INITIAL_CENTER_X); + field_centerY.setText(INITIAL_CENTER_Y); + field_scale.setText(INITIAL_SCALE); + field_repetitions.setText(INITIAL_REPETITIONS); + mandelbrotController.redraw(); + } + }); + panel.add(button_reset); + + left.add(panel, BorderLayout.NORTH); + left.add(new JPanel(), BorderLayout.CENTER); - mainFrame.add(panel, BorderLayout.PAGE_END); + mainFrame.add(left, BorderLayout.EAST); mainFrame.pack(); } @@ -115,22 +137,22 @@ public class MainWindow implements MandelbrotController.MandelbrotProvider, Zoom @Override public void setCenterX(double x) { - field_centerX.setText(Double.toString(x)); + field_centerX.setText(String.format("%.5f", x)); } @Override public void setCenterY(double y) { - field_centerY.setText(Double.toString(y)); + field_centerY.setText(String.format("%.5f", y)); } @Override public void setScale(double scale) { - field_scale.setText(Double.toString(scale)); + field_scale.setText(String.format("%.5f", scale)); } @Override - public void setRepetitions(double repetitions) { - field_repetitions.setText(Double.toString(repetitions)); + public void setRepetitions(int repetitions) { + field_repetitions.setText(Integer.toString(repetitions)); } } -- cgit v1.2.3