private void runPropertiesPlugin() { final Map<String, Object> inputMap = new HashMap<>(); inputMap.put("overlays", overlayService.getOverlayInfo().selectedOverlays()); // FIXME: Migrate OverlayProperties functionality into OverlayService API. commandService.run( "net.imagej.plugins.commands.overlay.SelectedManagerOverlayProperties", true, inputMap); }
private void properties() { int[] selected = overlayService.getOverlayInfo().selectedIndices(); if (selected.length == 0) { JOptionPane.showMessageDialog(this, "This command requires one or more selections"); return; } // else one or more selections exist runPropertiesPlugin(); }
private void sort() { overlayService.getOverlayInfo().sort(); int[] newSelections = overlayService.getOverlayInfo().selectedIndices(); jlist.setSelectedIndices(newSelections); jlist.updateUI(); }
/** * Takes the currently selected CompositeOverlay and turns it into its * constituent overlays. The CompositeOverlay is deleted. It does one layer * of division (it is not a deep division). */ private void divide() { List<Overlay> overlays = overlayService.getOverlayInfo().selectedOverlays(); int i = 0; while (i < overlays.size()) { Overlay o = overlays.get(i); if (! (o instanceof CompositeOverlay)) overlays.remove(i); else i++; } if (overlays.size() == 0) { JOptionPane.showMessageDialog( this, "One or more composite overlays must be selected"); return; } for (Overlay o : overlays) { overlayService.divideCompositeOverlay((CompositeOverlay) o); } }
private void deselect() { overlayService.getOverlayInfo().deselectAll(); jlist.clearSelection(); }
private void delete() { if (overlayService.getOverlayInfo().getOverlayInfoCount() == 0) return; List<Overlay> overlaysToDelete = new LinkedList<>(); final int[] selectedIndices = overlayService.getOverlayInfo().selectedIndices(); if (selectedIndices.length == 0) { final int result = JOptionPane.showConfirmDialog( this, "Delete all overlays?", "Delete All", JOptionPane.YES_NO_OPTION); if (result != JOptionPane.YES_OPTION) return; for (int i = 0; i < overlayService.getOverlayInfo().getOverlayInfoCount(); i++) { overlaysToDelete.add(overlayService.getOverlayInfo().getOverlayInfo(i).getOverlay()); } } else { for (int i = 0; i < selectedIndices.length; i++) { int index = selectedIndices[i]; overlaysToDelete.add(overlayService.getOverlayInfo().getOverlayInfo(index).getOverlay()); } } for (Overlay overlay : overlaysToDelete) { // NB - removeOverlay() can indirectly change our infoList contents. // Thus we first collect overlays from the infoList and then delete // them all afterwards to avoid interactions. overlayService.removeOverlay(overlay); } }
private void rename() { final int[] selectedIndices = overlayService.getOverlayInfo().selectedIndices(); if (selectedIndices.length < 1) { JOptionPane.showMessageDialog(this, "Must select an overlay to rename"); return; } if (selectedIndices.length > 1) { JOptionPane.showMessageDialog(this, "Cannot rename multiple overlays simultaneously"); return; } final OverlayInfo info = overlayService.getOverlayInfo().getOverlayInfo(selectedIndices[0]); if (info == null) return; // TODO - UI agnostic way here final String name = JOptionPane.showInputDialog(this, "Enter new name for overlay"); if ((name == null) || (name.length() == 0)) info.getOverlay().setName(null); else info.getOverlay().setName(name); jlist.updateUI(); }
@EventHandler protected void onEvent(final OverlayDeletedEvent event) { //System.out.println("\tDELETED: " + event.toString()); Overlay overlay = event.getObject(); overlayService.getOverlayInfo().deleteOverlay(overlay); int[] newSelectedIndices = overlayService.getOverlayInfo().selectedIndices(); jlist.setSelectedIndices(newSelectedIndices); jlist.updateUI(); }
private void populateOverlayList() { // Populate the list with all overlays for (final Overlay overlay : overlayService.getOverlays()) { boolean found = false; int totOverlays = overlayService.getOverlayInfo().getOverlayInfoCount(); for (int i = 0; i < totOverlays; i++) { OverlayInfo info = overlayService.getOverlayInfo().getOverlayInfo(i); if (overlay == info.getOverlay()) { found = true; break; } } if (!found) { OverlayInfo info = new OverlayInfo(overlay); overlayService.getOverlayInfo().addOverlayInfo(info); } } jlist.updateUI(); }
context.inject(this); jlist = new JList<>(new OverlayListModel(overlayService.getOverlayInfo()));
@EventHandler protected void onEvent(final OverlayCreatedEvent event) { //System.out.println("\tCREATED: " + event.toString()); overlayService.getOverlayInfo().addOverlay(event.getObject()); jlist.updateUI(); }
private void fill() { ChannelCollection channels = getChannels(); List<Overlay> selected = overlayService.getOverlayInfo().selectedOverlays(); for (Overlay o : selected) { ImageDisplay disp = overlayService.getFirstDisplay(o); overlayService.fillOverlay(o, disp, channels); } }
private void draw() { ChannelCollection channels = getChannels(); List<Overlay> selected = overlayService.getOverlayInfo().selectedOverlays(); for (Overlay o : selected) { ImageDisplay disp = overlayService.getFirstDisplay(o); overlayService.drawOverlay(o, disp, channels); } }
private void makeCompositeOverlay(CompositeOverlay.Operation op) { ImageDisplay imageDisplay = imageDisplayService.getActiveImageDisplay(); if (imageDisplay == null) return; List<Overlay> overlays = overlayService.getOverlayInfo().selectedOverlays(); if (overlays.size() == 0) overlays = overlayService.getOverlays(imageDisplay); if (overlays.size() < 2) { JOptionPane.showMessageDialog(this, "This command only works with 2 or more overlays"); return; } // else overlays.size() >= 2 CompositeOverlay newOverlay = new CompositeOverlay(context); for (Overlay o : overlays) newOverlay.doOperation(op, o); imageDisplay.display(newOverlay); imageDisplay.update(); }
final int overlayIndex = overlayService.getOverlayInfo().findIndex(overlay); final OverlayInfo overlayInfo = overlayService.getOverlayInfo().getOverlayInfo(overlayIndex); overlayInfo.setSelected(event.isSelected()); int[] selections = overlayService.getOverlayInfo().selectedIndices(); jlist.setSelectedIndices(selections); selecting = false;
@Override public void valueChanged(final ListSelectionEvent listSelectionEvent) { if (selecting) return; selecting = true; final ImageDisplay display = imageDisplayService.getActiveImageDisplay(); if (display == null) return; final JList<?> list = (JList<?>) listSelectionEvent.getSource(); final List<?> selectionValues = list.getSelectedValuesList(); overlayService.getOverlayInfo().deselectAll(); for (final Object overlayInfoObj : selectionValues) { final OverlayInfo overlayInfo = (OverlayInfo) overlayInfoObj; overlayInfo.setSelected(true); } for (final DataView overlayView : display) { overlayView.setSelected(false); for (final Object overlayInfoObj : selectionValues) { final OverlayInfo overlayInfo = (OverlayInfo) overlayInfoObj; if (overlayInfo.getOverlay() == overlayView.getData()) { overlayInfo.setSelected(true); overlayView.setSelected(true); break; } } } selecting = false; } };