-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPresets.j
180 lines (155 loc) · 7.22 KB
/
Presets.j
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
This file is part of FrACT10, a vision test battery.
Copyright © 2022 Michael Bach, bach@uni-freiburg.de, <https://michaelbach.de>
Presets.j
*/
/**
Allow presets of settings
2024-09-11 begin moving presets to categories← no, singletons
2024-05-09 major rewrite to avoid repeated information
2022-05-20 begun
*/
@import "ControlDispatcher.j"
@import "Presets_AT_LeviLab.j";
@import "Presets_BCM_Scheie.j";
@import "Presets_CNS_Freiburg.j";
@import "Presets_ESU.j";
@import "Presets_Hyper_TUDo.j";
@import "Presets_Maculight.j";
@import "Presets_ULV_Gensight.j";
@import "Presets_ETCF.j";
@import "Presets_HYPERION.j";
// after applying the preset, respond via GUI or send back to caller?
@typedef feedbackTypeType
kFeedbackTypeGUI = 1; kFeedbackTypeHTMLMessage = 2;
@implementation Presets: CPObject {
CPString _presetName;
CPPopUpButton _popUpButton;
}
/**
Init and add all preset names to the Presets popup in the Settings pane
*/
- (id) initWithPopup: (CPPopUpButton) thePopUpButton { //console.info("Presets>initWithPopup");
self = [super init];
if (self) {
/* first entry: Header, all others need corresponding code in the “switch orgy” further down. */
const allPresets = ["PRESETS", "Standard Defaults", "Demo", "Testing", "ESU", "Color Equiluminance", "BCM@Scheie", "CNS@Freiburg", "Maculight", "Hyper@TUDo", "AT@LeviLab", "ULV@Gensight", "ETCF", "HYPERION"];
_popUpButton = thePopUpButton; // local copy for later
[_popUpButton removeAllItems];
for (const aPreset of allPresets) [_popUpButton addItemWithTitle: aPreset];
[_popUpButton setSelectedIndex: 0]; // always show "PRESETS"
[[CPNotificationCenter defaultCenter] addObserver: self selector: @selector(applyPresetNamed:) name: "applyPresetNamed" object: nil];
}
return self;
}
/**
Called by the action of the preset selection pop-up, "Are you sure" dialog before applying
*/
- (void) apply: (id) sender { //console.info("Presets>apply");
const _presetIndex = [sender indexOfSelectedItem];
if (_presetIndex == 0) {//console.info("_presetIndex == 0");
return;
}
_presetName = [sender itemTitleAtIndex: _presetIndex];
const messageText = "Really all Settings to “" + _presetName + "” ?";
const alert1 = [CPAlert alertWithMessageText: messageText
defaultButton: "NO ߵnߴ" alternateButton: "YES ߵyߴ" otherButton: nil
informativeTextWithFormat: "Many Settings will change. You should know what you are doing here. Luckily, you can always return to defaults."];
[[alert1 buttons][0] setKeyEquivalent: "y"]; // the "YES" button selected by "y"
[[alert1 buttons][1] setKeyEquivalent: "n"]; // the "NO" button selected by "n"
[alert1 runModalWithDidEndBlock: function(alert, returnCode) {
if (returnCode==1) { // alternateButton
[self apply2withFeedbackType: kFeedbackTypeGUI];
}
}];
}
/**
Called by by ControlDispatcher after receiving a pertinent HTMLMessage
*/
- (void) applyPresetNamed: (CPNotification) aNotification { //console.info("Presets>applyPresetNamed");
_presetName = [aNotification object];
[self apply2withFeedbackType: kFeedbackTypeHTMLMessage];
}
/**
Apply selected preset after successful "Are you sure" dialog
*/
- (void) apply2withFeedbackType: (feedbackTypeType) feedbackType { //console.info("Presets>apply2", _presetName);
switch (_presetName) {
case "Standard Defaults":
[Settings setDefaults];
[Settings setPresetName: "Standard Defaults"];// setting here to check it worked
break;
case "Demo":
[Settings setDefaults];
[self applyTestingPresets]; [Settings setAutoRunIndex: kAutoRunIndexMid];
[Settings setPresetName: "Demo"];
break;
case "Testing": // easier testing
[self applyTestingPresets];
[Settings setPresetName: "Testing"];
break;
case "Color Equiluminance": // near equiluminant color acuity
[self applyTestingPresets];
[Settings setIsAcuityColor: YES];
[Settings setAcuityForeColor: [CPColor redColor]];
[Settings setAcuityBackColor: [CPColor colorWithRed: 0 green: 0.70 blue: 0 alpha: 1]];// dark green, near equiluminant to red
[[CPNotificationCenter defaultCenter] postNotificationName: "copyColorsFromSettings" object: nil];
[Settings setPresetName: "Color Equiluminance"];
break;
case "ESU": case "BCM@Scheie": case "CNS@Freiburg": case "Maculight":
case "AT@LeviLab": case "Hyper@TUDo": case "ULV@Gensight": case "ETCF": case "HYPERION":
// calculated class name requires strict discipline with filename systematics
const newPresetName = [_presetName stringByReplacingOccurrencesOfString:"@" withString:"_"]; //in filenames the @ is not allowed
const classObj = CPClassFromString("Presets_" + newPresetName);
[classObj performSelector: @selector(apply)];
break;
case "Generic Template": // template for new entries
[Settings setDefaults];
// General pane
// Acuity pane
// Contrast pane
// Gratings pane
// Gamma pane
// Misc pane
[Settings setPresetName: "Generic Template"];
break;
default:
console.log("FrACT10>Presets>unknown preset: ", _presetName);
if (feedbackType == kFeedbackTypeHTMLMessage) {
[ControlDispatcher post2parentM1: "Settings" m2: "Preset" m3: _presetName success: NO];
}
return;
}
[[CPNotificationCenter defaultCenter] postNotificationName: "updateSoundFiles" object: nil];
[[CPNotificationCenter defaultCenter] postNotificationName: "copyColorsFromSettings" object: nil]; // this synchronises the color settings between userdefaults & AppController
[_popUpButton setSelectedIndex: 0]; // always show "PRESETS"
switch (feedbackType) {
case kFeedbackTypeGUI:
const messageText = "Preset »" + _presetName + "« was applied."
const alert2 = [CPAlert alertWithMessageText: messageText
defaultButton: "OK" alternateButton: nil otherButton: nil
informativeTextWithFormat: ""];
[alert2 runModal];
break;
case kFeedbackTypeHTMLMessage:
[ControlDispatcher post2parentM1: "Settings" m2: "Preset" m3: _presetName success: true];
break;
}
}
- (void) applyTestingPresets { // used several times, so it has its own function
[Presets setStandardDefaultsKeepingCalBarLength];
// general pane
[Settings setDistanceInCM: 400]; [Settings setCalBarLengthInMM: 150];
[Settings setResponseInfoAtStart: NO];
// acuity pane
[Settings setShowCI95: YES];
// Misc pane
[Settings setSoundTrialYesIndex: 0]; [Settings setSoundTrialNoIndex: 1];
[Settings setSoundRunEndIndex: 1];
}
+ (void) setStandardDefaultsKeepingCalBarLength {
const calBarLengthInMM_prior = [Settings calBarLengthInMM];
[Settings setDefaults];
[Settings setCalBarLengthInMM: calBarLengthInMM_prior];
}
@end