click selection in BT display

Cleaned up code. Hopefully fixed issue with clicks not selecting correctly on large displays.
This commit is contained in:
Douglas Gillespie 2024-09-16 16:31:22 +01:00
parent 2540fd0d32
commit 2d207a15c3
2 changed files with 68 additions and 21 deletions

View File

@ -400,12 +400,25 @@ public class FileInputSystem extends DaqSystem implements ActionListener, PamSe
* @param newFile * @param newFile
*/ */
public void setNewFile (String newFile) { public void setNewFile (String newFile) {
fileInputParameters.recentFiles.remove(newFile); if (newFile == null) {
fileInputParameters.recentFiles.add(0, newFile); return;
fillFileList(); }
String currentFirst = getFirstFile();
if (newFile.equals(currentFirst) == false) {
fileInputParameters.recentFiles.remove(newFile);
fileInputParameters.recentFiles.add(0, newFile);
fillFileList();
}
interpretNewFile(newFile); interpretNewFile(newFile);
} }
public String getFirstFile() {
if (fileInputParameters.recentFiles.size() == 0) {
return null;
}
return fileInputParameters.recentFiles.get(0);
}
/** /**
* Called when a new file or folder is selected. * Called when a new file or folder is selected.
* @param newFile * @param newFile
@ -434,7 +447,7 @@ public class FileInputSystem extends DaqSystem implements ActionListener, PamSe
if (file.isFile() && !file.isHidden() && acquisitionDialog != null) { if (file.isFile() && !file.isHidden() && acquisitionDialog != null) {
try { try {
System.out.println("FileInputSystem - interpretNewFile"); // System.out.println("FileInputSystem - interpretNewFile");
AudioInputStream audioStream = PamAudioFileManager.getInstance().getAudioInputStream(file); AudioInputStream audioStream = PamAudioFileManager.getInstance().getAudioInputStream(file);
// // Get additional information from the header if it's a wav file. // // Get additional information from the header if it's a wav file.

View File

@ -3131,7 +3131,8 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett
zoomer.paintShape(g, this, true); zoomer.paintShape(g, this, true);
} }
ArrayList<ClickDetection> clickCopy = clickData.getDataCopy(displayStartMillis, displayStartMillis+displayLengthMillis, true, getDataSelector()); // ArrayList<ClickDetection> clickCopy = clickData.getDataCopy(displayStartMillis, displayStartMillis+displayLengthMillis, true, getDataSelector());
ArrayList<ClickDetection> clickCopy = getPlottableClicks();
if (clickCopy.size() == 0) { if (clickCopy.size() == 0) {
return; return;
} }
@ -3484,23 +3485,20 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett
*/ */
ClickDetection findClick(int x, int y, int maxdist) { ClickDetection findClick(int x, int y, int maxdist) {
ClickDetection closestClick = null; ClickDetection closestClick = null;
PamDataBlock<ClickDetection> clickData = clickControl.getClickDataBlock();
ClickDetection unit; ClickDetection unit;
Point pt; Point pt;
int dist; int dist;
int closest = maxdist * maxdist; int closest = maxdist * maxdist;
synchronized (clickData.getSynchLock()) { ListIterator<ClickDetection> clickIterator = getPlottableClicksIterator(0);
ListIterator<ClickDetection> clickIterator = clickData.getListIterator(PamDataBlock.ITERATOR_END); while (clickIterator.hasNext()) {
while (clickIterator.hasPrevious()) { unit = clickIterator.next();
unit = clickIterator.previous(); // if (unit.getTimeMilliseconds() < displayStartMillis - 1000)
// if (unit.getTimeMilliseconds() < displayStartMillis - 1000) // break;
// break; if (!shouldPlot(unit)) continue;
if (!shouldPlot(unit)) continue; pt = clickXYPos(unit);
pt = clickXYPos(unit); if ((dist = ((pt.x - x) * (pt.x - x) + (pt.y - y) * (pt.y - y))) <= closest) {
if ((dist = ((pt.x - x) * (pt.x - x) + (pt.y - y) * (pt.y - y))) <= closest) { closest = dist;
closest = dist; closestClick = unit;
closestClick = unit;
}
} }
} }
@ -3763,7 +3761,8 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett
} }
// first find the current click // first find the current click
ClickDetection click; ClickDetection click;
ListIterator<ClickDetection> clickIterator = cdb.getListIterator(PamDataBlock.ITERATOR_END); // ListIterator<ClickDetection> clickIterator = cdb.getListIterator(PamDataBlock.ITERATOR_END);
ListIterator<ClickDetection> clickIterator = getPlottableClicksIterator(PamDataBlock.ITERATOR_END);
while (clickIterator.hasPrevious()) { while (clickIterator.hasPrevious()) {
click = clickIterator.previous(); click = clickIterator.previous();
if (click == selectedClick) { if (click == selectedClick) {
@ -3798,15 +3797,46 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett
super.clickedOnClick(click); super.clickedOnClick(click);
} }
/**
* Get plottable clicks, i.e ones within time range and ones which
* pass data selection.
* @return Array list of clicks.
*/
private ArrayList<ClickDetection> getPlottableClicks() {
/**
* In viewer mode, it may be possible to not bother calling this by simply keeping
* this list if the parameters haven't changed.
*/
PamDataBlock<ClickDetection> clickData = clickControl.getClickDataBlock();
return clickData.getDataCopy(displayStartMillis, displayStartMillis+displayLengthMillis, true, getClickDataSelector());
}
/**
* Get an iterator to plottable clicks, based around a COPY of underlying
* data, so no need to synchronize, but not to modify.
* @return iterator from start of plottable clicks array list.
*/
private ListIterator<ClickDetection> getPlottableClicksIterator(int whereFrom) {
ArrayList<ClickDetection> clicks = getPlottableClicks();
if (whereFrom == PamDataBlock.ITERATOR_END) {
whereFrom = Math.max(0, clicks.size()-1);
}
return clicks.listIterator(whereFrom);
}
private ClickDetection getFirstSelectableClick() { private ClickDetection getFirstSelectableClick() {
PamDataBlock<ClickDetection> cdb = clickControl.getClickDataBlock(); PamDataBlock<ClickDetection> cdb = clickControl.getClickDataBlock();
ListIterator<ClickDetection> clickIterator = cdb.getListIterator(0); ListIterator<ClickDetection> clickIterator = cdb.getListIterator(0);
ClickDetection click; ClickDetection click;
ClickDataSelector dataSelector = getClickDataSelector();
while (clickIterator.hasNext()) { while (clickIterator.hasNext()) {
click = clickIterator.next(); click = clickIterator.next();
if (!shouldPlot(click) || !clickInMarkedArea(click)) { if (!shouldPlot(click) || !clickInMarkedArea(click)) {
continue; continue;
} }
if (dataSelector != null && dataSelector.scoreData(click) == 0) {
continue;
}
return click; return click;
} }
return null; return null;
@ -3816,11 +3846,15 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett
PamDataBlock<ClickDetection> cdb = clickControl.getClickDataBlock(); PamDataBlock<ClickDetection> cdb = clickControl.getClickDataBlock();
ListIterator<ClickDetection> clickIterator = cdb.getListIterator(PamDataBlock.ITERATOR_END); ListIterator<ClickDetection> clickIterator = cdb.getListIterator(PamDataBlock.ITERATOR_END);
ClickDetection click; ClickDetection click;
ClickDataSelector dataSelector = getClickDataSelector();
while (clickIterator.hasPrevious()) { while (clickIterator.hasPrevious()) {
click = clickIterator.previous(); click = clickIterator.previous();
if (!shouldPlot(click) || !clickInMarkedArea(click)) { if (!shouldPlot(click) || !clickInMarkedArea(click)) {
continue; continue;
} }
if (dataSelector != null && dataSelector.scoreData(click) == 0) {
continue;
}
return click; return click;
} }
return null; return null;
@ -3860,7 +3894,7 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett
return; return;
} }
PamDataBlock<ClickDetection> cdb = clickControl.getClickDataBlock(); PamDataBlock<ClickDetection> cdb = clickControl.getClickDataBlock();
ListIterator<ClickDetection> clickIterator = cdb.getListIterator(0); ListIterator<ClickDetection> clickIterator = getPlottableClicksIterator(0);
ClickDetection click; ClickDetection click;
while (clickIterator.hasNext()) { while (clickIterator.hasNext()) {
click = clickIterator.next(); click = clickIterator.next();
@ -4027,7 +4061,7 @@ public class ClickBTDisplay extends ClickDisplay implements PamObserver, PamSett
double[][] clickWave = null; double[][] clickWave = null;
int clickLen = 0; int clickLen = 0;
try { try {
clickIterator = clickData.getListIterator(0); clickIterator = getPlottableClicksIterator(0);
click = getFirstClick(startMillis); click = getFirstClick(startMillis);
if (click != null) { if (click != null) {