-
Notifications
You must be signed in to change notification settings - Fork 0
/
FractalGUI.java
87 lines (71 loc) · 2.34 KB
/
FractalGUI.java
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
import java.awt.BorderLayout;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
/**
* The GUI for this program. Highest level swing component.
*
* @author Samuel Lieberman
*
*/
public class FractalGUI extends JFrame{
private static final long serialVersionUID = 7296079999810708782L;
private AbstractFractalViewer fractalViewer;
/**
* This is a list of instances of each fractal. Any new fractal should be added
* to this list to automatically be included in the program.
*/
private static final RecursiveFractal[] FRACTALS = {
new MandelbrotSet(),
new TriangleFractal(),
new JuliaSet_phi(),
new JuliaSet_687_312i(),
new JuliaCauliflower(),
new JuliaSet_neg1(),
new TestFractal(),
};
private static final int START_FRACTAL = 0;
private FractalButton[] fractalButtons;
/**
* constructs and sets up the GUI
*/
public FractalGUI() {
super("Fractal Drawer");
setDefaultCloseOperation(EXIT_ON_CLOSE);
initGUI();
pack();
setVisible(true);
fractalButtons[START_FRACTAL].select();
}
/**
* Initializes the actual components that make up this GUI
*/
private void initGUI() {
fractalViewer = new FractalViewer();
add(fractalViewer, BorderLayout.CENTER);
JScrollPane choicePane = new JScrollPane();
add(choicePane, BorderLayout.WEST);
choicePane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
choicePane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
JPanel choiceButtonsPanel = new JPanel();
choicePane.setViewportView(choiceButtonsPanel);
choiceButtonsPanel.setLayout(new BoxLayout(choiceButtonsPanel, BoxLayout.Y_AXIS));
fractalButtons = new FractalButton[FRACTALS.length];
for (int i = 0; i < FRACTALS.length; i++) {
FractalButton fractalButton = new FractalButton(FRACTALS[i], fractalViewer, this);
choiceButtonsPanel.add(fractalButton);
fractalButtons[i] = fractalButton;
}
}
/**
* Updates each button's enabled visuals. This method is called by any button
* after being pressed.
*/
public void updateButtons() {
for (FractalButton button:fractalButtons) {
button.updateEnabled();
}
}
}