-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDisplayRegistry.java
More file actions
53 lines (41 loc) · 1.67 KB
/
DisplayRegistry.java
File metadata and controls
53 lines (41 loc) · 1.67 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package stellarium.display;
import com.google.common.collect.ImmutableList;
import stellarium.client.ClientSettings;
import stellarium.display.ecgrid.EcGridType;
import stellarium.display.eqgrid.EqGridType;
import stellarium.display.horgrid.HorGridType;
public class DisplayRegistry {
private static final DisplayRegistry instance = new DisplayRegistry();
public static DisplayRegistry getInstance() {
return instance;
}
static {
// MAYBE Interaction with existing objects
instance.register(new HorGridType());
instance.register(new EqGridType());
instance.register(new EcGridType());
}
private ImmutableList.Builder<RegistryDelegate> builder = ImmutableList.builder();
public <Cfg extends PerDisplaySettings, Cache extends IDisplayCache<Cfg>>
void register(IDisplayElementType<Cfg, Cache> type) {
builder.add(new RegistryDelegate<Cfg, Cache>(type));
}
public void composeSettings(ClientSettings settings) {
DisplayOverallSettings displaySettings = new DisplayOverallSettings();
settings.putSubConfig("Display", displaySettings);
for(RegistryDelegate delegate : builder.build())
displaySettings.putSubConfig(delegate.type.getName(), delegate.perDisplay);
}
public void setupDisplay(IDisplayInjectable injectable) {
for(RegistryDelegate delegate : builder.build())
injectable.injectDisplay(delegate.type, delegate.perDisplay);
}
private static class RegistryDelegate<Cfg extends PerDisplaySettings, Cache extends IDisplayCache<Cfg>> {
private IDisplayElementType<Cfg, Cache> type;
private Cfg perDisplay;
private RegistryDelegate(IDisplayElementType<Cfg, Cache> type) {
this.type = type;
this.perDisplay = type.generateSettings();
}
}
}