Skip to content
Snippets Groups Projects
Commit bffc1f9d authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

CONTROLGUI-382: transmit history depth to sources

parent 81637351
Branches
Tags
No related merge requests found
......@@ -41,7 +41,7 @@ public class CometeTrendController {
}
private TrendFile trendFile;
private final HistoryDataSourceProducer historicProducer;
private final HistoryDataSourceProducer historyProducer;
private final TrendFile defaultTrendFile;
private final List<ITrendFileListener> trendFileListeners;
private final List<String> attributeList;
......@@ -54,10 +54,11 @@ public class CometeTrendController {
private final ColorUtils colorRotationTool;
private ChartProperties chartProperties;
private int refreshingPeriod;
private long historyDepth;
private boolean started;
public CometeTrendController() {
historicProducer = (HistoryDataSourceProducer) DataSourceProducerProvider
historyProducer = (HistoryDataSourceProducer) DataSourceProducerProvider
.getProducer(HistoryDataSourceProducer.ID);
plotPropertiesMap = new HashMap<>();
clickablePropertiesMap = new HashMap<>();
......@@ -71,6 +72,7 @@ public class CometeTrendController {
chartProperties.setDisplayDuration(AbstractHistoryDataSource.DEFAULT_HISTORY_DEPTH);
refreshingPeriod = TrendFile.DEFAULT_REFRESHING_PERIOD;
historyDepth = AbstractHistoryDataSource.DEFAULT_HISTORY_DEPTH;
attributeList = new ArrayList<>();
defaultTrendFile = new TrendFile(ObjectUtils.EMPTY_STRING, this);
trendFile = new TrendFile(ObjectUtils.EMPTY_STRING, this);
......@@ -148,17 +150,50 @@ public class CometeTrendController {
return trendFile;
}
protected void applyRefreshingPeriod() {
if (historicProducer != null) {
PolledRefreshingStrategy polledRefreshingStrategy = refreshingMap.get(refreshingPeriod);
protected void applyHistoryDepthNoCheck(IKey key) {
long depth = historyProducer.getHistoryDepth(key);
if (depth != historyDepth) {
historyProducer.setHistoryDepth(key, historyDepth);
}
}
public void applyHistoryDepth(IKey key) {
if (historyProducer != null) {
applyHistoryDepthNoCheck(key);
}
}
protected void applyHistoryDepth() {
if (historyProducer != null) {
Collection<IKey> keys = keyMap.values();
for (IKey key : keys) {
applyHistoryDepthNoCheck(key);
}
}
}
protected void applyRefreshingPeriodNoCheck(IKey key, PolledRefreshingStrategy polledRefreshingStrategy) {
historyProducer.setRefreshingStrategy(key, polledRefreshingStrategy);
}
protected PolledRefreshingStrategy getRefreshingStrategy() {
Integer period = Integer.valueOf(refreshingPeriod);
PolledRefreshingStrategy polledRefreshingStrategy = refreshingMap.get(period);
if (polledRefreshingStrategy == null) {
polledRefreshingStrategy = new PolledRefreshingStrategy(refreshingPeriod);
refreshingMap.put(refreshingPeriod, polledRefreshingStrategy);
polledRefreshingStrategy = new PolledRefreshingStrategy(period);
refreshingMap.put(period, polledRefreshingStrategy);
}
historicProducer.setDefaultRefreshingStrategy(polledRefreshingStrategy);
return polledRefreshingStrategy;
}
protected void applyRefreshingPeriod() {
if (historyProducer != null) {
PolledRefreshingStrategy polledRefreshingStrategy = getRefreshingStrategy();
historyProducer.setDefaultRefreshingStrategy(polledRefreshingStrategy);
Collection<IKey> keys = keyMap.values();
for (IKey key : keys) {
historicProducer.setRefreshingStrategy(key, polledRefreshingStrategy);
applyRefreshingPeriodNoCheck(key, polledRefreshingStrategy);
applyHistoryDepthNoCheck(key);
}
started = true;
}
......@@ -176,6 +211,14 @@ public class CometeTrendController {
setRefreshingPeriod(period, started);
}
public void setHistoryDepth(long historyDepth) {
long depth = historyDepth > 0 ? historyDepth : AbstractHistoryDataSource.DEFAULT_HISTORY_DEPTH;
if (this.historyDepth != depth) {
this.historyDepth = depth;
applyHistoryDepth();
}
}
public int getRefreshingPeriod() {
return refreshingPeriod;
}
......@@ -199,11 +242,11 @@ public class CometeTrendController {
public void stopRefreshing() {
started = false;
if (historicProducer != null) {
historicProducer.setDefaultRefreshingStrategy(null);
if (historyProducer != null) {
historyProducer.setDefaultRefreshingStrategy(null);
Collection<IKey> keySet = keyMap.values();
for (IKey key : keySet) {
historicProducer.setRefreshingStrategy(key, null);
historyProducer.setRefreshingStrategy(key, null);
}
}
fireTrendEvent(TrendEvent.EventType.STOP);
......@@ -215,10 +258,10 @@ public class CometeTrendController {
}
public void resetAction() {
if (historicProducer != null) {
if (historyProducer != null) {
Collection<IKey> keySet = keyMap.values();
for (IKey key : keySet) {
historicProducer.resetHistory(key);
historyProducer.resetHistory(key);
}
}
}
......@@ -364,8 +407,29 @@ public class CometeTrendController {
return chartProperties;
}
public long getHistoryDepth(double displayDuration) {
long depth;
if (displayDuration <= 0 || Double.isNaN(displayDuration) || Double.isInfinite(displayDuration)) {
depth = historyDepth;
} else {
depth = (long) displayDuration;
}
return depth;
}
public long getHistoryDepth(ChartProperties chartProperties) {
long depth;
if (chartProperties == null) {
depth = historyDepth;
} else {
depth = getHistoryDepth(chartProperties.getDisplayDuration());
}
return depth;
}
public void setChartProperties(ChartProperties chartProperties) {
this.chartProperties = chartProperties;
setHistoryDepth(chartProperties == null ? historyDepth : getHistoryDepth(chartProperties));
fireTrendEvent(EventType.CHART_PROPERTIES);
}
......
......@@ -11,10 +11,6 @@ public class TrendEvent extends EventObject {
private final EventType type;
private String messageToTrace;
public enum EventType {
LOAD, SAVE, ADD_ATTRIBUTE, REMOVE_ATTRIBUTE, STOP, PLAY, REFRESH_FREQUENCY, CONECT_ATTRIBUTE, ATTRIBUTE_AXIS, MODIFY, TREE_VISIBLE, TOOLBAR_VISIBLE, CHART_PROPERTIES, PLOT_PROPERTIES, TRACE
};
public TrendEvent(TrendFile source, EventType eventType) {
super(source);
this.type = eventType;
......@@ -39,4 +35,12 @@ public class TrendEvent extends EventObject {
return messageToTrace;
}
// ///////////// //
// Inner classes //
// ///////////// //
public enum EventType {
LOAD, SAVE, ADD_ATTRIBUTE, REMOVE_ATTRIBUTE, STOP, PLAY, REFRESH_FREQUENCY, CONECT_ATTRIBUTE, ATTRIBUTE_AXIS, MODIFY, TREE_VISIBLE, TOOLBAR_VISIBLE, CHART_PROPERTIES, PLOT_PROPERTIES, TRACE
};
}
......@@ -17,11 +17,14 @@ import fr.soleil.comete.definition.event.ChartViewerEvent;
import fr.soleil.comete.definition.event.ChartViewerEvent.Reason;
import fr.soleil.comete.definition.listener.IChartViewerListener;
import fr.soleil.comete.definition.widget.IChartViewer;
import fr.soleil.comete.definition.widget.properties.ChartProperties;
import fr.soleil.comete.definition.widget.properties.PlotProperties;
import fr.soleil.comete.definition.widget.properties.SamplingProperties;
import fr.soleil.comete.swing.Chart;
import fr.soleil.comete.swing.chart.axis.model.AxisAttributes;
import fr.soleil.comete.swing.chart.data.DataView;
import fr.soleil.comete.swing.util.CfFileReader;
import fr.soleil.comete.swing.util.EDTManager;
import fr.soleil.data.service.HistoryKey;
import fr.soleil.data.service.IKey;
import fr.soleil.lib.project.ObjectUtils;
......@@ -162,6 +165,9 @@ public class ChartPanel extends JPanel implements ITrendFileListener, IChartView
private void connectWidget(IKey key) {
chartBox.connectWidget(chart, key);
if (controller != null) {
controller.applyHistoryDepth(key);
}
}
private void addAttributeAction(TrendFile trendFile) {
......@@ -220,7 +226,7 @@ public class ChartPanel extends JPanel implements ITrendFileListener, IChartView
protected class TrendChart extends Chart {
private static final long serialVersionUID = -1553118290632067043L;
private static final long serialVersionUID = 2288351164385662330L;
public TrendChart() {
super();
......@@ -289,6 +295,36 @@ public class ChartPanel extends JPanel implements ITrendFileListener, IChartView
super.finalActionOnceDataLoaded();
}
protected void transmitDisplayDuration(double displayDuration) {
boolean fitDuration = (displayDuration > 0) && (!Double.isNaN(displayDuration))
&& (!Double.isInfinite(displayDuration));
AxisAttributes attributes = chartView.getAxis(X).getAttributes();
if (attributes.isFitXAxisToDisplayDuration() != fitDuration) {
attributes.setFitXAxisToDisplayDuration(fitDuration);
EDTManager.INSTANCE.runInDrawingThread(() -> {
doRefresh(true, null);
});
}
if (controller != null) {
// CONTROLGUI-382
controller.setHistoryDepth(controller.getHistoryDepth(displayDuration));
}
}
@Override
public void setDisplayDuration(double duration) {
super.setDisplayDuration(duration);
transmitDisplayDuration(duration);
}
@Override
public void setChartProperties(ChartProperties properties) {
super.setChartProperties(properties);
if (properties != null) {
transmitDisplayDuration(properties.getDisplayDuration());
}
}
}
protected static class TrendDataView extends DataView {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment