1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.prometheus.preference;
18
19 import io.github.tonywasher.joceanus.metis.preference.MetisPreferenceSet.MetisPreferenceItem;
20 import io.github.tonywasher.joceanus.metis.ui.MetisPreferenceSetView;
21 import io.github.tonywasher.joceanus.prometheus.preference.PrometheusPreferenceSet.PrometheusByteArrayPreference;
22 import io.github.tonywasher.joceanus.prometheus.preference.PrometheusPreferenceSet.PrometheusCharArrayPreference;
23 import io.github.tonywasher.joceanus.tethys.api.base.TethysUIAlignment;
24 import io.github.tonywasher.joceanus.tethys.api.control.TethysUILabel;
25 import io.github.tonywasher.joceanus.tethys.api.factory.TethysUIFactory;
26 import io.github.tonywasher.joceanus.tethys.api.field.TethysUIDataEditField.TethysUICharArrayEditField;
27 import io.github.tonywasher.joceanus.tethys.api.field.TethysUIFieldAttribute;
28 import io.github.tonywasher.joceanus.tethys.api.pane.TethysUIGridPaneManager;
29
30
31
32
33 public class PrometheusPreferenceSetView
34 extends MetisPreferenceSetView {
35
36
37
38
39
40
41 PrometheusPreferenceSetView(final TethysUIFactory<?> pFactory,
42 final PrometheusPreferenceSet pPreferenceSet) {
43 super(pFactory, pPreferenceSet);
44 }
45
46 @Override
47 protected PreferenceElement allocatePreferenceElement(final MetisPreferenceItem pItem) {
48 if (pItem instanceof PrometheusCharArrayPreference ca) {
49 return new CharArrayPreferenceElement(ca);
50 } else if (pItem instanceof PrometheusByteArrayPreference) {
51 return null;
52 } else {
53 return super.allocatePreferenceElement(pItem);
54 }
55 }
56
57
58
59
60 private final class CharArrayPreferenceElement
61 implements PreferenceElement {
62
63
64
65 private final PrometheusCharArrayPreference theItem;
66
67
68
69
70 private final TethysUICharArrayEditField theField;
71
72
73
74
75
76
77 CharArrayPreferenceElement(final PrometheusCharArrayPreference pItem) {
78
79 theItem = pItem;
80 theField = getFactory().fieldFactory().newCharArrayField();
81 theField.setEditable(true);
82
83
84 final TethysUILabel myLabel = getFactory().controlFactory().newLabel(pItem.getDisplay() + STR_COLON);
85 myLabel.setAlignment(TethysUIAlignment.EAST);
86
87
88 final TethysUIGridPaneManager myGrid = getGrid();
89 myGrid.addCell(myLabel);
90 myGrid.setCellAlignment(myLabel, TethysUIAlignment.EAST);
91 myGrid.addCell(theField);
92 myGrid.setCellColumnSpan(theField, 2);
93 myGrid.allowCellGrowth(theField);
94 myGrid.newRow();
95
96
97 theField.getEventRegistrar().addEventListener(e -> {
98 pItem.setValue(theField.getValue());
99 notifyChanges();
100 });
101 }
102
103 @Override
104 public void updateField() {
105
106 theField.setValue(theItem.getValue());
107
108
109 theField.setTheAttributeState(TethysUIFieldAttribute.CHANGED, theItem.isChanged());
110 theField.adjustField();
111
112
113 theField.setEnabled(!theItem.isHidden());
114 }
115 }
116 }