-
Notifications
You must be signed in to change notification settings - Fork 0
/
FractalButton.java
66 lines (57 loc) · 1.65 KB
/
FractalButton.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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
/**
* Updates the GUI to display the new fractal represented by the private
* RecursiveFractal instance variable.
*
* @author Samuel Lieberman
*
*/
public class FractalButton extends JButton {
private static final long serialVersionUID = -2547387484104386401L;
private static RecursiveFractal currentFractal;
private RecursiveFractal fractal;
private AbstractFractalViewer viewer;
private FractalGUI parent;
public FractalButton(RecursiveFractal fractal, AbstractFractalViewer viewer, FractalGUI parent) {
this.fractal = fractal;
this.viewer = viewer;
this.parent = parent;
setText(fractal.getName());
setToolTipText(fractal.getFormula());
addActionListener(new ClickListener());
}
/**
* updates the GUI to display the fratal represented by the private RecursiveFractal instance variable
*/
public void select() {
currentFractal = fractal;
parent.updateButtons();
viewer.start(fractal);
}
/**
* This button is only enabled depending on if it's currentFractal is being used.
*/
public void updateEnabled() {
setEnabled(!fractal.getClass().equals(currentFractal.getClass()));
}
/**
* @return the fractal that this button displays
*/
public RecursiveFractal getFractal() {
return fractal;
}
/**
* @return the JPanel displaying the fractal
*/
public AbstractFractalViewer getViewer() {
return viewer;
}
public class ClickListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent arg0) {
select();
}
}
}