-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComboBoxChLabels.java
More file actions
174 lines (119 loc) · 4.35 KB
/
Copy pathComboBoxChLabels.java
File metadata and controls
174 lines (119 loc) · 4.35 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
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
package wf.util;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
public class ComboBoxChLabels extends ComboBox<Label> {
private static final ComboBoxChLabels INSTANCE = new ComboBoxChLabels();
private final Label ch0_lb = new Label("1", null);
private final Label ch1_lb = new Label("2", null);
private final Label ch2_lb = new Label("3", null);
private final Label ch3_lb = new Label("4", null);
private static int indexChannel;
private static DataHistoHandler dataHistoHandler = DataHistoHandler.getInstance();
public ComboBoxChLabels() {
this.getItems().add(ch0_lb);
this.getItems().add(ch1_lb);
this.getItems().add(ch2_lb);
this.getItems().add(ch3_lb);
ch0_lb.setId("coboLabel");
ch1_lb.setId("coboLabel");
ch2_lb.setId("coboLabel");
ch3_lb.setId("coboLabel");
this.setMaxWidth(80);
}
//A Custom ListCell that displays an image and string
static class StringRectangleCellFileOption extends ListCell<Label> {
@Override
protected void updateItem(Label item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setItem(null);
setGraphic(null);
} else {
switch(item.getText()) {
case "1":
indexChannel = 0;
break;
case "2":
indexChannel = 1;
break;
case "3":
indexChannel = 2;
break;
case "4":
indexChannel = 3;
break;
}
Label label = new Label("" + item.getText(), new RectangleGenerator().getRectangle(indexChannel));
label.setId("comboLabel");
//label.setDisable(true);
label.setStyle("-fx-text-fill: black;");
label.setStyle("-fx-text-background-color: white;");
//label.setStyle("-fx-text-fill: red;");
setGraphic(label);
}
};
}
//A Custom ListCell that displays an image and string
static class StringRectangleCell extends ListCell<Label> {
@Override
protected void updateItem(Label item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setItem(null);
setGraphic(null);
} else {
//System.out.println(dataHistoHandler.getSeriesValues().get(0).size());
//System.out.println(dataHistoHandler.getSeriesValues().get(1).size());
//System.out.println(dataHistoHandler.getSeriesValues().get(2).size());
//System.out.println(dataHistoHandler.getSeriesValues().get(3).size());
//setText(item.getText());
switch(item.getText()) {
case "1":
indexChannel = 0;
disableChannels(Integer.parseInt(item.getText())-1);
break;
case "2":
indexChannel = 1;
disableChannels(Integer.parseInt(item.getText())-1);
break;
case "3":
indexChannel = 2;
disableChannels(Integer.parseInt(item.getText())-1);
break;
case "4":
indexChannel = 3;
disableChannels(Integer.parseInt(item.getText())-1);
break;
}
Label label = new Label("" + item.getText(), new RectangleGenerator().getRectangle(indexChannel));
label.setId("comboLabel");
//label.setDisable(true);
label.setStyle("-fx-text-fill: black;");
label.setStyle("-fx-text-background-color: white;");
//label.setStyle("-fx-text-fill: red;");
setGraphic(label);
}
};
private void disableChannels(int channel) {
if(dataHistoHandler.getSeriesValues().get(channel).size() == 0) {
this.setDisable(true);
}
}
}
public void setCellFactoryButtonCellFileOption() {
this.setCellFactory(listview -> new StringRectangleCellFileOption());
this.setButtonCell(new StringRectangleCellFileOption());
}
public void setCellFactoryButtonCell() {
this.setCellFactory(listview -> new StringRectangleCell());
this.setButtonCell(new StringRectangleCell());
}
public void removeCellFactoryButtonCell() {
this.setCellFactory(null);
this.setButtonCell(null);
}
public static ComboBoxChLabels getInstance() {
return INSTANCE;
}
}