diff --git a/src/PamView/paneloverlay/OverlayDataManager.java b/src/PamView/paneloverlay/OverlayDataManager.java index c633ed3d..0bdf69db 100644 --- a/src/PamView/paneloverlay/OverlayDataManager.java +++ b/src/PamView/paneloverlay/OverlayDataManager.java @@ -157,7 +157,10 @@ public abstract class OverlayDataManager gdIterator = gdDataBlock.getListIterator(0); +// ListIterator gdIterator = gdDataBlock.getListIterator(0); + ListIterator gdIterator = getGroupsForMenu(gdDataBlock, currentTime, maxItems); while (gdIterator.hasNext()) { DetectionGroupDataUnit gdUnit = gdIterator.next(); // if (superDets.contains(gdUnit)) { // continue; // } - String tit = String.format("Add %d %s to group with UID %d", groupSummary.getNumDataUnits(), dataName, gdUnit.getUID()); + String tit = String.format("Add %d %s to group UID %d", groupSummary.getNumDataUnits(), dataName, + gdUnit.getUID()); + String tip = String.format("Group start %s, end %s", + PamCalendar.formatDBDateTime(gdUnit.getTimeMilliseconds()), + PamCalendar.formatTime(gdUnit.getEndTimeInMilliseconds())); Color detColor = PamColors.getInstance().getWhaleColor((int) gdUnit.getUID()); PamSymbol sym = new PamSymbol(detectionGroupControl.getSymbolforMenuItems(gdUnit)); menuItem = new JMenuItem(tit, sym); + menuItem.setToolTipText(tip); menuItem.addActionListener(new AddToExisting(groupSummary, gdUnit)); subMenu.add(menuItem); nAdded++; @@ -201,6 +213,40 @@ public class EventBuilderFunctions { return popMenu; } + + /** + * Get a shortened list of menu items for adding to the group. This is all a bit complicated + * since there are often too many and we want the ones closest to our time. Therefore have + * to mess about copying, sorting and relisting things. + * @param groupDataBlock + * @param targetTime + * @param maxEntries + * @return + */ + private ListIterator getGroupsForMenu(DetectionGroupDataBlock groupDataBlock, long targetTime, int maxEntries) { + if (groupDataBlock.getUnitsCount() < maxEntries) { + return groupDataBlock.getListIterator(0); + } + ArrayList dataCopy = groupDataBlock.getDataCopy(); + dataCopy.sort(new Comparator() { + + @Override + public int compare(DetectionGroupDataUnit o1, DetectionGroupDataUnit o2) { + long t1 = Math.abs(o1.getTimeMilliseconds()-targetTime); + long t2 = Math.abs(o2.getTimeMilliseconds()-targetTime); + return (int) Math.signum((t1-t2)); + } + }); + // now reduce the size of the list to the allowed number + List dataCopy2 = dataCopy.subList(0, maxEntries-1); + dataCopy2.sort(new Comparator() { + @Override + public int compare(DetectionGroupDataUnit o1, DetectionGroupDataUnit o2) { + return (int) Math.signum(o1.getTimeMilliseconds()-o2.getTimeMilliseconds()); + } + }); + return dataCopy2.listIterator(); + } private class AddToExisting implements ActionListener { diff --git a/src/generalDatabase/SuperDetLogging.java b/src/generalDatabase/SuperDetLogging.java index 924e3bde..bfdc7a3f 100644 --- a/src/generalDatabase/SuperDetLogging.java +++ b/src/generalDatabase/SuperDetLogging.java @@ -238,7 +238,7 @@ public abstract class SuperDetLogging extends SQLLogging { /** * Modified view clause for super detections, may change the basic clause to either get absolutely - * everything, or to get events that overlap with the load time, no tjust start within it (requires a + * everything, or to get events that overlap with the load time, not just start within it (requires a * reference to an endtime column) * @param con * @param pamViewParameters diff --git a/src/pamViewFX/fxNodes/utilsFX/PamUtilsFX.java b/src/pamViewFX/fxNodes/utilsFX/PamUtilsFX.java index 15c2a171..19536ab8 100644 --- a/src/pamViewFX/fxNodes/utilsFX/PamUtilsFX.java +++ b/src/pamViewFX/fxNodes/utilsFX/PamUtilsFX.java @@ -303,6 +303,10 @@ public class PamUtilsFX { if (fxItem == null) { return null; } + String tip = swingItem.getToolTipText(); + if (tip != null) { + fxItem.setUserData("Tip:" + tip); + } // move over any action listeners from swing to fx. fxItem.setOnAction(new EventHandler() { @Override @@ -384,6 +388,13 @@ public class PamUtilsFX { if (jItem == null) { return null; } + Object userData = fxItem.getUserData(); + if (userData instanceof String) { + String tip = (String) userData; + if (tip.startsWith("Tip:")) { + jItem.setToolTipText(tip.substring(4)); + } + } jItem.addActionListener(new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) {