-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFractalSetting.java
More file actions
39 lines (32 loc) · 1.19 KB
/
FractalSetting.java
File metadata and controls
39 lines (32 loc) · 1.19 KB
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
import javax.swing.*;
import java.awt.*;
/**
* Base class for FractalSettings. This class makes it easy to assign
* settings to Fractals.
*/
public abstract class FractalSetting {
protected final Fractal mFractal;
private JComponent mJComponent;
FractalSetting(Fractal fractal) {
mFractal = fractal;
}
// Function used for preventing duplicate JComponents
JComponent getJComponent() {
if (mJComponent == null) {
mJComponent = buildJComponent();
}
return mJComponent;
}
// Returns label for the setting
abstract String getLabel();
// Builds the UI component that controls the setting
abstract JComponent buildJComponent();
// Helper function that gets numeric values from a FractalSetting array
static int getNumberAt(FractalSetting[] fractalSettings, int index) {
return ((FractalSettingNumber) fractalSettings[index]).getValue();
}
// Helper function that gets Color objects from a FractalSetting array
static Color getColorAt(FractalSetting[] fractalSettings, int index) {
return ((FractalSettingColor) fractalSettings[index]).getValue();
}
}