fixed thresholds

This commit is contained in:
anhefti 2019-09-12 19:09:28 +02:00
parent 56d11b8e64
commit 751220272e
3 changed files with 15 additions and 8 deletions

View file

@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.gui.service.session;
import java.util.Collection;
import java.util.EnumMap;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -147,13 +148,17 @@ public class ClientConnectionDetails {
.forEach(indValue -> {
final IndicatorData indData = this.indicatorMapping.get(indValue.getType());
final double value = indValue.getValue();
final int colorIndex = IndicatorData.getColorIndex(indData, value);
if (this.connectionData.clientConnection.status != ConnectionStatus.ESTABLISHED) {
form.setFieldValue(indData.indicator.name, Constants.EMPTY_NOTE);
form.setFieldColor(indData.indicator.name, indData.defaultColor);
} else {
final int colorIndex = IndicatorData.getColorIndex(indData, value);
final Color color = (colorIndex >= 0)
? indData.thresholdColor[colorIndex].color
: indData.defaultColor;
form.setFieldValue(indData.indicator.name, String.valueOf(value));
form.setFieldColor(indData.indicator.name, indData.thresholdColor[colorIndex].color);
form.setFieldColor(indData.indicator.name, color);
}
});
}

View file

@ -22,6 +22,7 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@ -321,11 +322,11 @@ public final class ClientConnectionTable {
indicatorData.index,
indicatorData.defaultColor);
} else {
tableItem.setText(indicatorData.index, getDisplayValue(indicatorValue));
tableItem.setBackground(
indicatorData.index,
indicatorData.thresholdColor[this.thresholdColorIndices[i]].color);
final Color color = (this.thresholdColorIndices[i] >= 0)
? indicatorData.thresholdColor[this.thresholdColorIndices[i]].color
: indicatorData.defaultColor;
tableItem.setBackground(indicatorData.index, color);
}
}
}

View file

@ -20,6 +20,7 @@ import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold;
import ch.ethz.seb.sebserver.gbl.util.Utils;
final class IndicatorData {
final int index;
final Indicator indicator;
final Color defaultColor;
@ -51,12 +52,12 @@ final class IndicatorData {
static final int getColorIndex(final IndicatorData indicatorData, final double value) {
for (int j = 0; j < indicatorData.thresholdColor.length; j++) {
if (value < indicatorData.thresholdColor[j].value) {
if (value > indicatorData.thresholdColor[j].value && value < indicatorData.thresholdColor[j].value) {
return j;
}
}
return indicatorData.thresholdColor.length - 1;
return -1;
}
static final class ThresholdColor {