From 3b4d9eab5128a79bc7f464cbf105798d7af44962 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 30 Apr 2015 17:18:11 +0200 Subject: Cleaned up; javadoc --- Week11 Mandelbrot/src/fractals/MainWindow.java | 48 +++++++++++++++----------- 1 file changed, 27 insertions(+), 21 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 b6276af..8f89217 100644 --- a/Week11 Mandelbrot/src/fractals/MainWindow.java +++ b/Week11 Mandelbrot/src/fractals/MainWindow.java @@ -1,7 +1,5 @@ package fractals; - - import com.camilstaps.mandelbrot.MandelbrotView; import com.camilstaps.mandelbrot.ZoomFrame; import java.awt.BorderLayout; @@ -17,19 +15,17 @@ import javax.swing.JPanel; import javax.swing.JTextField; /** - * + * The window for week 11: a gridview for the fractal, and controls * @author Sjaak Smetsers - * @version 1.0, 14-03-2013 - */ - -/** - * creates a window to which a GridView panel is added - * + * @author Camil Staps */ public class MainWindow implements MandelbrotView.MandelbrotProvider, ZoomFrame.MandelbrotTextFields { // the size of the window public static final int WIDTH = 650, HEIGHT = 650; + /** + * Initial values + */ private final String INITIAL_CENTER_X = "0", INITIAL_CENTER_Y = "0", INITIAL_SCALE = "100", @@ -38,13 +34,19 @@ public class MainWindow implements MandelbrotView.MandelbrotProvider, ZoomFrame. // The grip panel private final GridView grid; + /** + * Controls + */ 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 MandelbrotView mandelbrotController; + /** + * To allow redrawing + */ + private final MandelbrotView mandelbrotView; public MainWindow () { ZoomFrame mainFrame = new ZoomFrame ("Mandelbrot"); @@ -60,20 +62,26 @@ public class MainWindow implements MandelbrotView.MandelbrotProvider, ZoomFrame. grid = new GridView(WIDTH - insets.left - insets.right, HEIGHT - insets.top - insets.bottom); mainFrame.add(grid, BorderLayout.CENTER); - mandelbrotController = new MandelbrotView(this, grid); - mandelbrotController.redraw(); + mandelbrotView = new MandelbrotView(this, grid); + mandelbrotView.redraw(); - mainFrame.setMandelbrotView(mandelbrotController); + mainFrame.setMandelbrotView(mandelbrotView); mainFrame.setMandelbrotTextFields(this); - JPanel left = new JPanel(new BorderLayout()); + mainFrame.add(getControlsPanel(), BorderLayout.EAST); + + mainFrame.pack(); + } + + private JPanel getControlsPanel() { + JPanel right = new JPanel(new BorderLayout()); JPanel panel = new JPanel(new GridLayout(10,1)); button_redraw.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equals("Redraw")) { - mandelbrotController.redraw(); + mandelbrotView.redraw(); } } }); @@ -94,17 +102,15 @@ public class MainWindow implements MandelbrotView.MandelbrotProvider, ZoomFrame. field_centerY.setText(INITIAL_CENTER_Y); field_scale.setText(INITIAL_SCALE); field_repetitions.setText(INITIAL_REPETITIONS); - mandelbrotController.redraw(); + mandelbrotView.redraw(); } }); panel.add(button_reset); - left.add(panel, BorderLayout.NORTH); - left.add(new JPanel(), BorderLayout.CENTER); + right.add(panel, BorderLayout.NORTH); + right.add(new JPanel(), BorderLayout.CENTER); - mainFrame.add(left, BorderLayout.EAST); - - mainFrame.pack(); + return right; } /** -- cgit v1.2.3