From 7b7b257bcd2a984a076d5045eeae8a93114e9124 Mon Sep 17 00:00:00 2001 From: Stephan Saalfeld Date: Sat, 5 Jan 2013 11:31:00 +0100 Subject: [PATCH] 877: it is legal for layerThing to be null --- .../src/main/java/ini/trakem2/display/Layer.java | 174 ++++++++++++--------- 1 file changed, 99 insertions(+), 75 deletions(-) diff --git a/TrakEM2_/src/main/java/ini/trakem2/display/Layer.java b/TrakEM2_/src/main/java/ini/trakem2/display/Layer.java index 805e85c2..fa50b4db 100644 --- a/TrakEM2_/src/main/java/ini/trakem2/display/Layer.java +++ b/TrakEM2_/src/main/java/ini/trakem2/display/Layer.java @@ -23,9 +23,8 @@ Institute of Neuroinformatics, University of Zurich / ETH, Switzerland. package ini.trakem2.display; -import ij.gui.GenericDialog; import ij.ImagePlus; - +import ij.gui.GenericDialog; import ini.trakem2.ControlWindow; import ini.trakem2.Project; import ini.trakem2.persistence.DBObject; @@ -35,21 +34,20 @@ import ini.trakem2.utils.IJError; import ini.trakem2.utils.M; import ini.trakem2.utils.Utils; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - import java.awt.Color; import java.awt.Polygon; import java.awt.Rectangle; import java.awt.geom.AffineTransform; import java.awt.geom.Area; import java.awt.geom.NoninvertibleTransformException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; import mpicbg.models.NoninvertibleModelException; @@ -67,15 +65,17 @@ public final class Layer extends DBObject implements Bucketable, Comparable COMPARATOR = new Comparator() { + @Override public final int compare(final Layer l1, final Layer l2) { if (l1 == l2) return 0; // the same layer if (l1.getZ() < l2.getZ()) return -1; return 1; // even if same Z, prefer the second } - public final boolean equals(Object ob) { return this == ob; } + @Override + public final boolean equals(final Object ob) { return this == ob; } }; - public Layer(Project project, double z, double thickness, LayerSet parent) { + public Layer(final Project project, final double z, final double thickness, final LayerSet parent) { super(project); this.z = z; this.thickness = thickness; @@ -84,7 +84,7 @@ public final class Layer extends DBObject implements Bucketable, Comparable ht_attributes) { + public Layer(final Project project, final long id, final HashMap ht_attributes) { super(project, id); this.parent = null; // parse data @@ -104,23 +104,23 @@ public final class Layer extends DBObject implements Bucketable, Comparable createMany(Project project, LayerSet parent) { + static public List createMany(final Project project, final LayerSet parent) { if (null == parent) return null; - GenericDialog gd = ControlWindow.makeGenericDialog("Many new layers"); + final GenericDialog gd = ControlWindow.makeGenericDialog("Many new layers"); gd.addNumericField("First Z coord: ", 0, 3); gd.addNumericField("thickness: ", 1.0, 3); gd.addNumericField("Number of layers: ", 1, 0); @@ -139,9 +139,9 @@ public final class Layer extends DBObject implements Bucketable, Comparable layers = new ArrayList(n_layers); + final List layers = new ArrayList(n_layers); for (int i=0; i c) { - for (Object ob : al_displayables) { + for (final Object ob : al_displayables) { if (ob.getClass() == c) return true; } return false; @@ -454,7 +457,7 @@ public final class Layer extends DBObject implements Bucketable, Comparable c) { int n = 0; - for (Object ob : al_displayables) { + for (final Object ob : al_displayables) { if (ob.getClass() == c) n++; } return n; @@ -471,6 +474,7 @@ public final class Layer extends DBObject implements Bucketable, Comparable getDisplayableList() { return al_displayables; } @@ -588,15 +592,17 @@ public final class Layer extends DBObject implements Bucketable, Comparable al = new ArrayList(); for (int i = al_displayables.size() -1; i>-1; i--) { - Displayable d = (Displayable)al_displayables.get(i); + final Displayable d = (Displayable)al_displayables.get(i); if (visible_only && !d.isVisible()) continue; if (d.contains(x, y)) { al.add(d); @@ -633,7 +639,7 @@ public final class Layer extends DBObject implements Bucketable, Comparable al = new ArrayList(); for (int i = al_displayables.size() -1; i>-1; i--) { - Displayable d = al_displayables.get(i); + final Displayable d = al_displayables.get(i); if (visible_only && !d.isVisible()) continue; if (d.getClass() == c && d.contains(x, y)) { al.add(d); @@ -686,9 +692,9 @@ public final class Layer extends DBObject implements Bucketable, Comparable al = new ArrayList(); for (int i = al_displayables.size() -1; i>-1; i--) { - Object ob = al_displayables.get(i); + final Object ob = al_displayables.get(i); if (ob.getClass() != target) continue; - Displayable da = (Displayable)ob; + final Displayable da = (Displayable)ob; if (d.intersects(da)) { al.add(da); } @@ -724,7 +730,7 @@ public final class Layer extends DBObject implements Bucketable, Comparable c = d.getClass(); + final Class c = d.getClass(); boolean done = false; int j = i - 1; for (; j > -1; j--) { @@ -806,10 +812,10 @@ public final class Layer extends DBObject implements Bucketable, Comparable c = d.getClass(); - int size = al_displayables.size(); + final Class c = d.getClass(); + final int size = al_displayables.size(); int i = k+1; for (; i setVisible(String type, boolean visible, boolean repaint) { + public HashSet setVisible(String type, final boolean visible, final boolean repaint) { type = type.toLowerCase(); if (type.equals("image")) type = "patch"; final HashSet hs = new HashSet(); - for (Displayable d : al_displayables) { + for (final Displayable d : al_displayables) { if (visible != d.isVisible() && d.getClass().getName().toLowerCase().endsWith(type)) { d.setVisible(visible, false); // don't repaint hs.add(d); @@ -842,9 +848,9 @@ public final class Layer extends DBObject implements Bucketable, Comparable setAllVisible(boolean repaint) { + public Collection setAllVisible(final boolean repaint) { final Collection col = new ArrayList(); - for (Displayable d : al_displayables) { + for (final Displayable d : al_displayables) { if (!d.isVisible()) { d.setVisible(true, repaint); col.add(d); @@ -854,9 +860,9 @@ public final class Layer extends DBObject implements Bucketable, Comparable hideExcept(ArrayList> type, boolean repaint) { + public HashSet hideExcept(final ArrayList> type, final boolean repaint) { final HashSet hs = new HashSet(); - for (Displayable d : al_displayables) { + for (final Displayable d : al_displayables) { if (!type.contains(d.getClass()) && d.isVisible()) { d.setVisible(false, repaint); hs.add(d); @@ -874,7 +880,10 @@ public final class Layer extends DBObject implements Bucketable, Comparable\n"); @@ -901,13 +910,14 @@ public final class Layer extends DBObject implements Bucketable, Comparable c, final AffineTransform at) { - boolean all = Displayable.class == c; + final boolean all = Displayable.class == c; for (final Displayable d : al_displayables) { if (all || d.getClass() == c) { d.at.preConcatenate(at); @@ -961,7 +971,7 @@ public final class Layer extends DBObject implements Bucketable, Comparable sub1 = new HashSet(la.al_displayables); @@ -1190,7 +1213,7 @@ public final class Layer extends DBObject implements Bucketable, Comparable(layer.al_displayables); } @Override - public boolean apply(int action) { + public boolean apply(final int action) { // Replace all ZDisplayable layer.al_displayables.clear(); layer.al_displayables.addAll(this.al_displayables); @@ -1206,7 +1229,7 @@ public final class Layer extends DBObject implements Bucketable, Comparable 0) return 1; return 0; @@ -1263,7 +1287,7 @@ public final class Layer extends DBObject implements Bucketable, Comparable