From f3abd2dbf8b73872c66a361f79b9d5bdad00c59f Mon Sep 17 00:00:00 2001 From: Albert Cardona Date: Mon, 13 Apr 2009 20:33:50 +0200 Subject: [PATCH] Now deleting a layer is more gentle on the display: just moves to the next or previous, if any. Otherwise closes the display. --- ini/trakem2/display/Display.java | 34 +++++++++++++++++++++++----------- ini/trakem2/display/Layer.java | 3 ++- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/ini/trakem2/display/Display.java b/ini/trakem2/display/Display.java index 4d38fb07..7cb5cabe 100644 --- a/ini/trakem2/display/Display.java +++ b/ini/trakem2/display/Display.java @@ -68,8 +68,6 @@ public final class Display extends DBObject implements ActionListener, ImageList /** All selected Displayable objects, including the active one. */ final private Selection selection = new Selection(this); - private ImagePlus last_temp = null; - private JFrame frame; private JTabbedPane tabs; private Hashtable ht_tabs; @@ -850,11 +848,11 @@ public final class Display extends DBObject implements ActionListener, ImageList // update active Displayable: // deselect all except ZDisplayables - final ArrayList sel = selection.getSelected(); + final ArrayList sel = selection.getSelected(); final Displayable last_active = Display.this.active; int sel_next = -1; - for (Iterator it = sel.iterator(); it.hasNext(); ) { - Displayable d = (Displayable)it.next(); + for (final Iterator it = sel.iterator(); it.hasNext(); ) { + final Displayable d = it.next(); if (!(d instanceof ZDisplayable)) { it.remove(); selection.remove(d); @@ -864,15 +862,11 @@ public final class Display extends DBObject implements ActionListener, ImageList } } } - if (-1 != sel_next && sel.size() > 0) select((Displayable)sel.get(sel_next), true); - else if (null != last_active && last_active.getClass() == Patch.class && null != last_temp && last_temp instanceof PatchStack) { - Displayable d = ((PatchStack)last_temp).getPatch(layer, (Patch)last_active); - if (null != d) selection.add(d); - } - // TODO last_temp doesn't remain the PatchStack // Utils.log2("last_temp is: " + last_temp.getClass().getName()); + if (-1 != sel_next && sel.size() > 0) select(sel.get(sel_next), true); // Keep Profile chain selected, for best ease of use: if (null != last_active && last_active.getClass() == Profile.class && last_active.isLinked(Profile.class)) { + Utils.log2("last active was a profile: " + last_active); Displayable other = null; for (final Displayable prof : last_active.getLinked(Profile.class)) { if (prof.getLayer() == layer) { @@ -934,6 +928,7 @@ public final class Display extends DBObject implements ActionListener, ImageList ht_panels.clear(); updateTab(panel_labels, "Labels", layer.getDisplayables(DLabel.class)); break; + // case 5: layer panels } } @@ -1167,6 +1162,23 @@ public final class Display extends DBObject implements ActionListener, ImageList } } + /** Find all Display instances that are showing the layer and either move to the next or previous layer, or close it if none. */ + static public void remove(final Layer layer) { + for (Iterator it = al_displays.iterator(); it.hasNext(); ) { + final Display d = it.next(); + if (d.isShowing(layer)) { + Layer la = layer.getParent().next(layer); + if (layer == la || null == la) la = layer.getParent().previous(layer); + if (null == la || layer == la) { + d.remove(false); + it.remove(); + } else { + d.slt.set(la); + } + } + } + } + public boolean remove(boolean check) { if (check) { if (!Utils.check("Delete the Display ?")) return false; diff --git a/ini/trakem2/display/Layer.java b/ini/trakem2/display/Layer.java index ae38a3b8..b82068f1 100644 --- a/ini/trakem2/display/Layer.java +++ b/ini/trakem2/display/Layer.java @@ -326,7 +326,7 @@ public final class Layer extends DBObject implements Bucketable { try { if (check && !Utils.check("Really delete " + this.toString() + " and all its children?")) return false; // destroy the Display objects that show this layer - Display.close(this); + Display.remove(this); // proceed to remove all the children Displayable[] displ = new Displayable[al_displayables.size()]; // to avoid concurrent modifications al_displayables.toArray(displ); @@ -340,6 +340,7 @@ public final class Layer extends DBObject implements Bucketable { // remove from the parent /*can't ever be null//if (null != parent) */ parent.remove(this); + Display.updateLayerScroller(parent); removeFromDatabase(); } catch (Exception e) { IJError.print(e); return false; } return true; -- 2.11.4.GIT