diff --git a/src/PamguardMVC/dataSelector/CompoundDataSelector.java b/src/PamguardMVC/dataSelector/CompoundDataSelector.java index 67c58d2d..2060e419 100644 --- a/src/PamguardMVC/dataSelector/CompoundDataSelector.java +++ b/src/PamguardMVC/dataSelector/CompoundDataSelector.java @@ -108,4 +108,25 @@ public class CompoundDataSelector extends DataSelector { return selectorList; } + @Override + public DataSelector findDataSelector(Class selectorClass) { + /** + * Check this, then all in the selector list. Should iterate happily back to + * a basic data selector as required even if there are multiple Compound ones. + */ + if (this.getClass() == selectorClass) { + return this; + } + if (selectorList == null) { + return null; + } + for (DataSelector aSelector : selectorList) { + DataSelector subSel = aSelector.findDataSelector(selectorClass); + if (subSel != null) { + return subSel; + } + } + return null; + } + } diff --git a/src/PamguardMVC/dataSelector/DataSelector.java b/src/PamguardMVC/dataSelector/DataSelector.java index b033976c..e1573752 100644 --- a/src/PamguardMVC/dataSelector/DataSelector.java +++ b/src/PamguardMVC/dataSelector/DataSelector.java @@ -97,6 +97,23 @@ public abstract class DataSelector { */ abstract public DynamicSettingsPane getDialogPaneFX(); + /** + * Find a data selector within a data selector. This is primarily for use with + * ComoundDataSelector objects which may encapsulate multiple other selectors, + * particularly when annotations are in use. but it's needed here so that it + * can be called on any DataSelector object. + * @param selectorClass class to data selector to find. + * @return DataSelector or null if that class of data selector doesn't exist. + */ + public DataSelector findDataSelector(Class selectorClass) { + if (this.getClass() == selectorClass) { + return this; + } + else { + return null; + } + } + /** * Get a menu item for the data selector that can be easily added * to any other menu. diff --git a/src/clickDetector/BTAmplitudeSelector.java b/src/clickDetector/BTAmplitudeSelector.java index fac92954..eb7c1b7e 100644 --- a/src/clickDetector/BTAmplitudeSelector.java +++ b/src/clickDetector/BTAmplitudeSelector.java @@ -68,7 +68,7 @@ public class BTAmplitudeSelector implements PamDialogPanel { super(); this.clickControl = clickControl; this.btDisplay = btDisplay; - dataSelector = btDisplay.getDataSelector(); + dataSelector = btDisplay.getClickDataSelector(); clickDataBlock = clickControl.getClickDataBlock(); histoPlot = new HistogramDisplay(); histoPlot.setGraphicsOverLayer(histoOverLayer = new HistoOverLayer()); diff --git a/src/clickDetector/ClickBTDisplay.java b/src/clickDetector/ClickBTDisplay.java index ebf0ca07..eaa05353 100644 --- a/src/clickDetector/ClickBTDisplay.java +++ b/src/clickDetector/ClickBTDisplay.java @@ -117,6 +117,7 @@ import PamguardMVC.PamDataUnit; import PamguardMVC.PamObservable; import PamguardMVC.PamObserver; import PamguardMVC.dataSelector.DataSelectDialog; +import PamguardMVC.dataSelector.DataSelector; import PamguardMVC.superdet.SuperDetection; import clickDetector.ClickClassifiers.ClickIdInformation; import clickDetector.ClickClassifiers.ClickIdentifier; @@ -2244,11 +2245,15 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett if (btDisplayParameters.amplitudeSelect == false) { return; } + ClickDataSelector clickDataSelector = getClickDataSelector(); + if (clickDataSelector == null) { + return; + } int n = countAmplitudeDeselected(); PamDataBlock clickData = clickControl.getClickDataBlock(); int nAll = clickData.getUnitsCount(); String txt = String.format("%d of %d loaded clicks will not be displayed because their amplitude is < %3.1fdB", - n, nAll, getDataSelector().getParams().minimumAmplitude); + n, nAll, clickDataSelector.getParams().minimumAmplitude); Insets insets = getInsets(); int x = insets.left; int y = getHeight()-5; @@ -2789,7 +2794,7 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett BTDisplayParameters newParameters = ClickDisplayDialog.showDialog(clickControl, - clickControl.getGuiFrame(), btDisplayParameters, getDataSelector().getClickAlarmParameters()); + clickControl.getGuiFrame(), btDisplayParameters, getClickDataSelector().getClickAlarmParameters()); if (newParameters != null){ btDisplayParameters = newParameters.clone(); if (getVScaleManager() != null) { @@ -2812,8 +2817,23 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett * Get a data selector specific to this display. * @return click data selector specific to this display. */ - public ClickDataSelector getDataSelector() { - return (ClickDataSelector) clickControl.getClickDataBlock().getDataSelector(getUnitName(), false); + public DataSelector getDataSelector() { + return clickControl.getClickDataBlock().getDataSelector(getUnitName(), false); + } + + /** + * get the click specific data selector which may now be burried in a + * CompoundDataSelector if annotations have been used. + * @return ClickDataSelector. + */ + public ClickDataSelector getClickDataSelector() { + DataSelector baseSel = getDataSelector(); + if (baseSel == null) { + return null; + } + else { + return (ClickDataSelector) baseSel.findDataSelector(ClickDataSelector.class); + } } class AmplitudeSelector implements ActionListener { @@ -3403,7 +3423,7 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett else if (btDisplayParameters.colourScheme == BTDisplayParameters.COLOUR_BY_HYDROPHONE) { keyPanel.add(new TextKeyItem("Colour by hydrophone")); } - ClickAlarmParameters selectParams = getDataSelector().getParams(); + ClickAlarmParameters selectParams = getClickDataSelector().getParams(); // if (btDisplayParameters.getShowSpecies(0)) { if (selectParams.onlineAutoEvents | selectParams.onlineManualEvents) { keyPanel.add(symbolChooser.getDefaultSymbol(true).makeKeyItem("Unidentified species")); @@ -3487,7 +3507,7 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett PamDataBlock clickData = clickControl.getClickDataBlock(); ClickDetection click; int n = 0; - double minAmpli = getDataSelector().getParams().minimumAmplitude; + double minAmpli = getClickDataSelector().getParams().minimumAmplitude; synchronized (clickData.getSynchLock()) { ListIterator clickIterator = clickData.getListIterator(0); while (clickIterator.hasNext()) { @@ -4151,7 +4171,7 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett amplitudeSelectorLabel.setText(""); } else { - String txt = String.format(" Amplitude Selector showing clicks > %3.1fdB", getDataSelector().getParams().minimumAmplitude); + String txt = String.format(" Amplitude Selector showing clicks > %3.1fdB", getClickDataSelector().getParams().minimumAmplitude); amplitudeSelectorLabel.setText(txt); } } diff --git a/src/clickDetector/offlineFuncs/OfflineToolbar.java b/src/clickDetector/offlineFuncs/OfflineToolbar.java index 414bae2b..f7e1e34c 100644 --- a/src/clickDetector/offlineFuncs/OfflineToolbar.java +++ b/src/clickDetector/offlineFuncs/OfflineToolbar.java @@ -255,7 +255,7 @@ public class OfflineToolbar { return; } try { - ClickDataSelector clickDataSelector = currentBTDisplay.getDataSelector(); + ClickDataSelector clickDataSelector = currentBTDisplay.getClickDataSelector(); ClickAlarmParameters selectParams = clickDataSelector.getParams(); BTDisplayParameters btDisplayParameters = currentBTDisplay.getBtDisplayParameters(); @@ -288,7 +288,7 @@ public class OfflineToolbar { } private void checkButtons(BTDisplayParameters btDisplayParameters) { - ClickDataSelector clickDataSelector = currentBTDisplay.getDataSelector(); + ClickDataSelector clickDataSelector = currentBTDisplay.getClickDataSelector(); ClickAlarmParameters selectParams = clickDataSelector.getParams(); showEchoes.setSelected(selectParams.useEchoes); showNonSpecies.setSelected(selectParams.getUseSpecies(0));