package fractals; import com.camilstaps.mandelbrot.MandelbrotController; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; /** * * @author Sjaak Smetsers * @version 1.0, 14-03-2013 */ /** * creates a window to which a GridView panel is added * */ public class MainWindow implements MandelbrotController.MandelbrotProvider { // the size of the window public static final int WIDTH = 500, HEIGHT = 500; // The grip panel private final GridView grid; private final JTextField field_centerX = new JTextField("0"); private final JTextField field_centerY = new JTextField("0"); private final JTextField field_scale = new JTextField("100"); private final JTextField field_repetitions = new JTextField("100"); private final JButton button_redraw = new JButton("Redraw"); private final MandelbrotController mandelbrotController; public MainWindow () { JFrame mainFrame = new JFrame ("Mandelbrot"); mainFrame.setLayout(new BorderLayout()); mainFrame.setSize (WIDTH, HEIGHT); mainFrame.setLocationRelativeTo(null); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setResizable(false); mainFrame.setVisible(true); Insets insets = mainFrame.getInsets(); grid = new GridView(WIDTH - insets.left - insets.right, HEIGHT - insets.top - insets.bottom); mainFrame.add(grid, BorderLayout.CENTER); mandelbrotController = new MandelbrotController(this, grid); JPanel panel = new JPanel(new FlowLayout()); button_redraw.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equals("Redraw")) { mandelbrotController.redraw(); } } }); panel.add(field_centerX); panel.add(field_centerY); panel.add(field_scale); panel.add(field_repetitions); panel.add(button_redraw); mainFrame.add(panel, BorderLayout.PAGE_END); mainFrame.pack(); } /** * A getter for the grid * @return the grid */ public Grid getGrid () { return grid; } @Override public double getCenterX() { return Double.parseDouble(field_centerX.getText()); } @Override public double getCenterY() { return Double.parseDouble(field_centerY.getText()); } @Override public double getScale() { return Double.parseDouble(field_scale.getText()); } @Override public int getRepetitions() { return Integer.parseInt(field_repetitions.getText()); } }