diff --git a/src/clickDetector/ClickControl.java b/src/clickDetector/ClickControl.java index e03b73a7..9787c59f 100644 --- a/src/clickDetector/ClickControl.java +++ b/src/clickDetector/ClickControl.java @@ -26,6 +26,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.Serializable; import java.util.ArrayList; +import java.util.List; import java.util.ListIterator; import javax.swing.JMenu; @@ -1071,7 +1072,7 @@ public class ClickControl extends PamControlledUnit implements PamSettings { subDet.removeSuperDetection(event); } } - clickDetector.getOfflineEventDataBlock().remove(event); + clickDetector.getOfflineEventDataBlock().remove(event, true); } @Override @@ -1168,6 +1169,31 @@ public class ClickControl extends PamControlledUnit implements PamSettings { return targetMotionLocaliser; } + /** + * Remove clicks from existing events, if they have any. They may not. + * This is called whenever clicks are assigned to a new event to make + * sure that they don't end up in two events. + * @param markedClicks + */ + public void removeFromEvents(List markedClicks) { + if (markedClicks == null) { + return; + } + for (PamDataUnit dataUnit : markedClicks) { + OfflineEventDataUnit anEvent = (OfflineEventDataUnit) dataUnit.getSuperDetection(OfflineEventDataUnit.class); + if (anEvent == null) { + continue; + } + anEvent.removeSubDetection(dataUnit); + if (anEvent.getSubDetectionsCount() == 0) { + deleteEvent(anEvent); + } + else { + anEvent.updateDataUnit(System.currentTimeMillis()); + } + } + + } /** * Reassign all the clicks on one event to a different event @@ -1199,7 +1225,7 @@ public class ClickControl extends PamControlledUnit implements PamSettings { } clickEvent.setComment(clickEvent.getComment() + " Clicks reassigned to event " + reassignEvent.getEventId()); offlineEventDataBlock.updatePamData(clickEvent, PamCalendar.getTimeInMillis()); - offlineEventDataBlock.remove(clickEvent); + offlineEventDataBlock.remove(clickEvent, true); reassignEvent.sortSubDetections(); offlineEventDataBlock.updatePamData(reassignEvent, now); if (ClickTrainDetection.class.isAssignableFrom(reassignEvent.getClass())) { diff --git a/src/clickDetector/offlineFuncs/LabelClicksDialog.java b/src/clickDetector/offlineFuncs/LabelClicksDialog.java index 0e25b495..113f7864 100644 --- a/src/clickDetector/offlineFuncs/LabelClicksDialog.java +++ b/src/clickDetector/offlineFuncs/LabelClicksDialog.java @@ -146,6 +146,7 @@ public class LabelClicksDialog extends PamDialog { * @param thenClose option to close dialog */ private void addClicksToEvent(OfflineEventDataUnit event, boolean thenClose) { + removeFromOldEvent(markedClicks); event.addSubDetections(markedClicks); offlineEventListPanel.tableDataChanged(); clickControl.setLatestOfflineEvent(event); @@ -154,6 +155,15 @@ public class LabelClicksDialog extends PamDialog { } } + /** + * clicks may have already been part of an event, so need to remove them from that + * event first, and if there is nothing left in that event, delete the event. + * @param markedClicks2 + */ + private void removeFromOldEvent(List markedClicks) { + clickControl.removeFromEvents(markedClicks); + } + @Override public void restoreDefaultSettings() { // TODO Auto-generated method stub diff --git a/src/clickDetector/offlineFuncs/OfflineClickLogging.java b/src/clickDetector/offlineFuncs/OfflineClickLogging.java index a75897f7..5e10f545 100644 --- a/src/clickDetector/offlineFuncs/OfflineClickLogging.java +++ b/src/clickDetector/offlineFuncs/OfflineClickLogging.java @@ -51,7 +51,7 @@ public class OfflineClickLogging extends SQLLogging { tableDef.addTableItem(clickNumber = new PamTableItem("ClickNo", Types.INTEGER)); tableDef.addTableItem(amplitude = new PamTableItem("Amplitude", Types.DOUBLE)); tableDef.addTableItem(channelNumbers = new PamTableItem("Channels", Types.INTEGER)); - tableDef.setUseCheatIndexing(true); + tableDef.setUseCheatIndexing(false); setTableDefinition(tableDef); } diff --git a/src/generalDatabase/PamSubtableDefinition.java b/src/generalDatabase/PamSubtableDefinition.java index 0aa20215..ec3780b0 100644 --- a/src/generalDatabase/PamSubtableDefinition.java +++ b/src/generalDatabase/PamSubtableDefinition.java @@ -51,6 +51,7 @@ public class PamSubtableDefinition extends PamTableDefinition { addTableItem(parentUID = new PamTableItem(PARENTUIDNAME, Types.BIGINT)); addTableItem(longName = new PamTableItem(LONGDATANAME, Types.CHAR, DATANAME_LENGTH)); addTableItem(binaryFilename = new PamTableItem(BINARYFILE, Types.CHAR, BINARY_FILE_NAME_LENGTH)); + setUseCheatIndexing(false); } public PamTableItem getParentID() {