1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
package fractals;
import com.camilstaps.mandelbrot.MandelbrotController;
import com.camilstaps.mandelbrot.ZoomFrame;
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.JLabel;
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, ZoomFrame.MandelbrotTextFields {
// the size of the window
public static final int WIDTH = 650, HEIGHT = 650;
// 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 JButton button_redraw = new JButton("Redraw");
private final MandelbrotController mandelbrotController;
public MainWindow () {
ZoomFrame mainFrame = new ZoomFrame ("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);
mandelbrotController.redraw();
mainFrame.setMandelbrotController(mandelbrotController);
mainFrame.setMandelbrotTextFields(this);
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(new JLabel("Center x:"));
panel.add(field_centerX);
panel.add(new JLabel("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);
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());
}
@Override
public void setCenterX(double x) {
field_centerX.setText(Double.toString(x));
}
@Override
public void setCenterY(double y) {
field_centerY.setText(Double.toString(y));
}
@Override
public void setScale(double scale) {
field_scale.setText(Double.toString(scale));
}
@Override
public void setRepetitions(double repetitions) {
field_repetitions.setText(Double.toString(repetitions));
}
}
|