ini.trakem2.display
Class Layer

java.lang.Object
  extended by ini.trakem2.persistence.DBObject
      extended by ini.trakem2.display.Layer
All Implemented Interfaces:
Bucketable, java.lang.Comparable<Layer>

public final class Layer
extends DBObject
implements Bucketable, java.lang.Comparable<Layer>


Field Summary
static java.util.Comparator<Layer> COMPARATOR
          Compare layers by Z.
static int IMAGE
           
static int IMAGEPLUS
           
static int IMAGEPROCESSOR
           
static int PIXELARRAY
           
 
Fields inherited from class ini.trakem2.persistence.DBObject
id, project
 
Constructor Summary
Layer(Project project, double z, double thickness, LayerSet parent)
           
Layer(Project project, long id, double z, double thickness)
          Reconstruct from database
Layer(Project project, long id, java.util.HashMap<java.lang.String,java.lang.String> ht_attributes)
          Reconstruct from XML file.
 
Method Summary
 void add(Displayable displ)
          Add a displayable and update all Display instances showing this Layer.
 void add(Displayable displ, boolean update_displays)
           
 void add(Displayable displ, boolean update_displays, boolean update_db)
           
 void addSilently(DBObject displ)
          Used for reconstruction purposes.
 void apply(java.lang.Class<?> c, java.awt.geom.AffineTransform at)
          Preconcatenate the given AffineTransform to all Displayable objects of class c, without respecting their links.
 void checkBuckets()
           
 Layer clone(Project pr, LayerSet ls, java.awt.Rectangle roi, boolean copy_id)
          Make a copy of this layer into the given LayerSet, enclosing only Displayable objects within the roi, and translating them for that roi x,y.
 int compareTo(Layer layer)
           
 boolean contains(java.lang.Class<?> c)
          Returns true if any of the Displayable objects are of the given class.
 boolean contains(java.lang.Class<?> c, boolean visible_only)
          Returns true if any of the Displayable objects are of the given class; if is true, will return true only if at least one of the matched objects is visible.
 boolean contains(Displayable displ)
           
 boolean contains(int x, int y, int inset)
           
 int count(java.lang.Class<?> c)
          Count instances of the given Class.
static Layer create(Project project, LayerSet parent)
          Creates a new Layer asking for z and thickness, and adds it to the parent and returns it.
static java.util.List<Layer> createMany(Project project, LayerSet parent)
          Pops up a dialog to choose the first Z coord, the thickness, the number of layers, and whether to skip the creation of any layers whose Z and thickness match that of existing layers.
 void destroy()
           
static void exportDTD(java.lang.StringBuilder sb_header, java.util.HashSet<java.lang.String> hs, java.lang.String indent)
          Includes all Displayable objects in the list of possible children.
 void exportXML(java.lang.StringBuilder sb_body, java.lang.String indent, java.lang.Object any)
          Subclasses can override this method to store the instance as XML.
 java.util.Collection<Displayable> find(java.lang.Class<?> c, int x, int y)
           
 java.util.Collection<Displayable> find(java.lang.Class<?> c, int x, int y, boolean visible_only)
          Find the Displayable objects of Class c that contain the point, with class equality.
 java.util.Collection<Displayable> find(java.lang.Class<?> c, int x, int y, boolean visible_only, boolean instance_of)
          Find the Displayable objects of Class c that contain the point, with instanceof if instance_of is true.
 java.util.Collection<Displayable> find(java.lang.Class<?> c, java.awt.Rectangle r, boolean visible_only)
           
 java.util.Collection<Displayable> find(java.lang.Class<?> c, java.awt.Rectangle r, boolean visible_only, boolean instance_of)
          Find the Displayable objects whose bounding box intersects with the given rectangle.
 java.util.Collection<Displayable> find(int x, int y)
           
 java.util.Collection<Displayable> find(int x, int y, boolean visible_only)
          Find the Displayable objects that contain the point.
 java.util.Collection<Displayable> find(java.awt.Rectangle r)
           
 java.util.Collection<Displayable> find(java.awt.Rectangle r, boolean visible_only)
          Find the Displayable objects whose bounding box intersects with the given rectangle.
 DBObject findById(long id)
           
 Displayable get(long id)
           
<T extends Displayable>
java.util.ArrayList<T>
getAll(java.lang.Class<T> c)
          Returns a list of Displayable of class c only.
 java.util.HashMap<Displayable,java.util.HashSet<Bucket>> getBucketMap(Layer layer)
           
 java.util.ArrayList<Displayable> getDisplayableList()
          Returns the real list of displayables, not a copy.
 java.util.ArrayList<Displayable> getDisplayables()
          Returns a copy of the list of Displayable objects.
 java.util.ArrayList<Displayable> getDisplayables(java.lang.Class<?> c)
          Returns a list of Displayable of class c only.
 java.util.Collection<Displayable> getDisplayables(java.lang.Class<?> c, java.awt.geom.Area aroi, boolean visible_only)
          Returns a list of all Displayable of class c that intersect the given area.
 java.util.Collection<Displayable> getDisplayables(java.lang.Class<?> c, java.awt.geom.Area aroi, boolean visible_only, boolean instance_of)
          Check class identity by instanceof instead of equality.
 java.util.ArrayList<Displayable> getDisplayables(java.lang.Class<?> c, boolean visible_only)
          Check class identity with equality, so no superclasses or interfaces are possible.
 java.util.Collection<Displayable> getDisplayables(java.lang.Class<?> c, java.awt.Rectangle roi)
          Returns a list of all Displayable of class c that intersect the given rectangle.
 java.util.Collection<Displayable> getIntersecting(Displayable d, java.lang.Class<?> target)
          Find the Displayable objects of class 'target' whose perimeter (not just the bounding box) intersect the given Displayable (which is itself included if present in this very Layer).
 float getLayerHeight()
           
protected  java.lang.String getLayerThingTitle()
           
 float getLayerWidth()
           
 java.awt.Rectangle getMinimalBoundingBox(java.lang.Class<?> c)
          Returns null if no Displayable objects of class c exist.
 java.awt.Rectangle getMinimalBoundingBox(java.lang.Class<?> c, boolean visible_only)
          Returns null if no Displayable objects of class c exist (or are visible if is true).
 int getNDisplayables()
           
 Overlay getOverlay()
          Return the current Overlay or a new one if none yet.
 LayerSet getParent()
           
 java.awt.geom.Area getPatchArea(boolean visible_only)
          Returns an Area in world coordinates that represents the inside of all Patches.
 int[] getPixel(int x, int y, double mag)
          Don't use this for fast pixel grabbing; this is intended for the dropper tool and status bar reporting by mouse motion.
 java.lang.String getPrintableTitle()
          Returns a title such as 018__4-K4_2__z1.67 , which is [layer_set index]__[title]__[z coord] .
 double getThickness()
           
 java.lang.String getTitle()
          Sublcasses can override this method to provide a proper String, otherwise calls toString()
 double getZ()
           
 java.lang.Object grab(java.awt.Rectangle r, double scale, java.lang.Class<?> c, int c_alphas, int format, int type)
          Returns the region defined by the rectangle as an image in the type and format specified.
 java.util.HashSet<Displayable> hideExcept(java.util.ArrayList<java.lang.Class<?>> type, boolean repaint)
          Hide all except those whose type is in 'type' list, whose visibility flag is left unchanged.
 int indexOf(Displayable d)
          Returns -1 if not found.
 boolean isBottom(Displayable d)
          Within its own class only.
 boolean isEmpty()
          Checks if there are any Displayable or if any ZDisplayable paints in this layer.
 boolean isTop(Displayable d)
          Within its own class only.
 void moveBottom(Displayable d)
          Within its own class only.
 void moveDown(Displayable d)
          Within its own class only.
 void moveTop(Displayable d)
          Within its own class only.
 void moveUp(Displayable d)
          Within its own class only.
 void recreateBuckets()
           
 int relativeIndexOf(Displayable d)
          Get the index of the given Displayable relative to the rest of its class.
 boolean remove(boolean check)
          Remove this layer and all its contents from the project.
 boolean remove(Displayable displ)
          Will recreate the buckets; if you intend to remove many, use "removeAll" instead, so that the expensive operation of recreating the buckets is done only once.
 boolean removeAll(java.util.Set<Displayable> ds)
          Remove a set of children.
 java.util.Collection<Displayable> setAllVisible(boolean repaint)
          Returns the collection of Displayable whose visibility state has changed.
 void setBucketsEnabled(boolean b)
           
 Overlay setOverlay(Overlay o)
          Set to null to remove the Overlay.
 void setParent(LayerSet layer_set)
           
 void setParentSilently(LayerSet layer_set)
          Used for reconstruction purposes.
 void setThickness(double thickness)
           
 java.util.HashSet<Displayable> setVisible(java.lang.String type, boolean visible, boolean repaint)
          Note: Not recursive into embedded LayerSet objects.
 void setZ(double z)
           
 java.lang.String toString()
           
 void updateBucket(Displayable d, Layer layer)
          Update buckets of a position change for the given Displayable.
 void updateLayerTree()
          Recursive into nested LayerSet objects.
 
Methods inherited from class ini.trakem2.persistence.DBObject
addToDatabase, getId, getInfo, getProject, getShortTitle, getUniqueIdentifier, removeFromDatabase, updateInDatabase, updateInDatabase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ini.trakem2.display.Bucketable
getProject
 

Field Detail

COMPARATOR

public static final java.util.Comparator<Layer> COMPARATOR
Compare layers by Z.


IMAGEPROCESSOR

public static final int IMAGEPROCESSOR
See Also:
Constant Field Values

PIXELARRAY

public static final int PIXELARRAY
See Also:
Constant Field Values

IMAGE

public static final int IMAGE
See Also:
Constant Field Values

IMAGEPLUS

public static final int IMAGEPLUS
See Also:
Constant Field Values
Constructor Detail

Layer

public Layer(Project project,
             double z,
             double thickness,
             LayerSet parent)

Layer

public Layer(Project project,
             long id,
             double z,
             double thickness)
Reconstruct from database


Layer

public Layer(Project project,
             long id,
             java.util.HashMap<java.lang.String,java.lang.String> ht_attributes)
Reconstruct from XML file.

Method Detail

create

public static Layer create(Project project,
                           LayerSet parent)
Creates a new Layer asking for z and thickness, and adds it to the parent and returns it. Returns null if the dialog was canceled.


createMany

public static java.util.List<Layer> createMany(Project project,
                                               LayerSet parent)
Pops up a dialog to choose the first Z coord, the thickness, the number of layers, and whether to skip the creation of any layers whose Z and thickness match that of existing layers.

Returns:
The newly created layers.

getPrintableTitle

public java.lang.String getPrintableTitle()
Returns a title such as 018__4-K4_2__z1.67 , which is [layer_set index]__[title]__[z coord] . The ordinal number starts at 1 and finishes at parent's length, inclusive.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

add

public void add(Displayable displ)
Add a displayable and update all Display instances showing this Layer.


add

public void add(Displayable displ,
                boolean update_displays)

add

public void add(Displayable displ,
                boolean update_displays,
                boolean update_db)

getBucketMap

public java.util.HashMap<Displayable,java.util.HashSet<Bucket>> getBucketMap(Layer layer)
Specified by:
getBucketMap in interface Bucketable

addSilently

public void addSilently(DBObject displ)
Used for reconstruction purposes. Assumes the displ are given in the proper order!


remove

public boolean remove(Displayable displ)
Will recreate the buckets; if you intend to remove many, use "removeAll" instead, so that the expensive operation of recreating the buckets is done only once.


removeAll

public boolean removeAll(java.util.Set<Displayable> ds)
Remove a set of children. Does not destroy the children nor remove them from the database, only from the Layer and the Display.


setParentSilently

public void setParentSilently(LayerSet layer_set)
Used for reconstruction purposes.


setParent

public void setParent(LayerSet layer_set)

getParent

public LayerSet getParent()

getZ

public double getZ()

getThickness

public double getThickness()

remove

public boolean remove(boolean check)
Remove this layer and all its contents from the project.

Overrides:
remove in class DBObject

setZ

public void setZ(double z)

setThickness

public void setThickness(double thickness)

contains

public boolean contains(int x,
                        int y,
                        int inset)

contains

public boolean contains(Displayable displ)

contains

public boolean contains(java.lang.Class<?> c)
Returns true if any of the Displayable objects are of the given class.


contains

public boolean contains(java.lang.Class<?> c,
                        boolean visible_only)
Returns true if any of the Displayable objects are of the given class; if is true, will return true only if at least one of the matched objects is visible.


count

public int count(java.lang.Class<?> c)
Count instances of the given Class.


isEmpty

public boolean isEmpty()
Checks if there are any Displayable or if any ZDisplayable paints in this layer.


getDisplayables

public java.util.ArrayList<Displayable> getDisplayables()
Returns a copy of the list of Displayable objects.


getDisplayableList

public final java.util.ArrayList<Displayable> getDisplayableList()
Returns the real list of displayables, not a copy. If you modify this list, Thor may ground you with His lightning.

Specified by:
getDisplayableList in interface Bucketable

getNDisplayables

public int getNDisplayables()

getAll

public <T extends Displayable> java.util.ArrayList<T> getAll(java.lang.Class<T> c)
Returns a list of Displayable of class c only.


getDisplayables

public java.util.ArrayList<Displayable> getDisplayables(java.lang.Class<?> c)
Returns a list of Displayable of class c only.


getDisplayables

public java.util.Collection<Displayable> getDisplayables(java.lang.Class<?> c,
                                                         java.awt.Rectangle roi)
Returns a list of all Displayable of class c that intersect the given rectangle.


getDisplayables

public java.util.Collection<Displayable> getDisplayables(java.lang.Class<?> c,
                                                         java.awt.geom.Area aroi,
                                                         boolean visible_only)
Returns a list of all Displayable of class c that intersect the given area.


getDisplayables

public java.util.Collection<Displayable> getDisplayables(java.lang.Class<?> c,
                                                         java.awt.geom.Area aroi,
                                                         boolean visible_only,
                                                         boolean instance_of)
Check class identity by instanceof instead of equality.


getDisplayables

public java.util.ArrayList<Displayable> getDisplayables(java.lang.Class<?> c,
                                                        boolean visible_only)
Check class identity with equality, so no superclasses or interfaces are possible.


get

public Displayable get(long id)

getLayerWidth

public float getLayerWidth()
Specified by:
getLayerWidth in interface Bucketable

getLayerHeight

public float getLayerHeight()
Specified by:
getLayerHeight in interface Bucketable

find

public java.util.Collection<Displayable> find(int x,
                                              int y)

find

public java.util.Collection<Displayable> find(int x,
                                              int y,
                                              boolean visible_only)
Find the Displayable objects that contain the point.


find

public java.util.Collection<Displayable> find(java.lang.Class<?> c,
                                              int x,
                                              int y)

find

public java.util.Collection<Displayable> find(java.lang.Class<?> c,
                                              int x,
                                              int y,
                                              boolean visible_only)
Find the Displayable objects of Class c that contain the point, with class equality.


find

public java.util.Collection<Displayable> find(java.lang.Class<?> c,
                                              int x,
                                              int y,
                                              boolean visible_only,
                                              boolean instance_of)
Find the Displayable objects of Class c that contain the point, with instanceof if instance_of is true.


find

public java.util.Collection<Displayable> find(java.awt.Rectangle r)

find

public java.util.Collection<Displayable> find(java.awt.Rectangle r,
                                              boolean visible_only)
Find the Displayable objects whose bounding box intersects with the given rectangle.


find

public java.util.Collection<Displayable> find(java.lang.Class<?> c,
                                              java.awt.Rectangle r,
                                              boolean visible_only)

find

public java.util.Collection<Displayable> find(java.lang.Class<?> c,
                                              java.awt.Rectangle r,
                                              boolean visible_only,
                                              boolean instance_of)
Find the Displayable objects whose bounding box intersects with the given rectangle.


getIntersecting

public java.util.Collection<Displayable> getIntersecting(Displayable d,
                                                         java.lang.Class<?> target)
Find the Displayable objects of class 'target' whose perimeter (not just the bounding box) intersect the given Displayable (which is itself included if present in this very Layer).


indexOf

public final int indexOf(Displayable d)
Returns -1 if not found.


moveUp

public void moveUp(Displayable d)
Within its own class only. 'up' is at the last element of the ArrayList (since when painting, the first one gets painted first, and thus gets buried the most while the last paints last, on top).


moveDown

public void moveDown(Displayable d)
Within its own class only.


moveTop

public void moveTop(Displayable d)
Within its own class only.


moveBottom

public void moveBottom(Displayable d)
Within its own class only.


isTop

public boolean isTop(Displayable d)
Within its own class only.


isBottom

public boolean isBottom(Displayable d)
Within its own class only.


relativeIndexOf

public int relativeIndexOf(Displayable d)
Get the index of the given Displayable relative to the rest of its class. Beware that the order of the al_displayables is bottom at zero, top at last, but the relative index returned here is inverted: top at zero, bottom at last -to match the tabs' vertical orientation in a Display.


setVisible

public java.util.HashSet<Displayable> setVisible(java.lang.String type,
                                                 boolean visible,
                                                 boolean repaint)
Note: Not recursive into embedded LayerSet objects. Returns the hash set of objects whose visibility has changed.


setAllVisible

public java.util.Collection<Displayable> setAllVisible(boolean repaint)
Returns the collection of Displayable whose visibility state has changed.


hideExcept

public java.util.HashSet<Displayable> hideExcept(java.util.ArrayList<java.lang.Class<?>> type,
                                                 boolean repaint)
Hide all except those whose type is in 'type' list, whose visibility flag is left unchanged. Returns the list of displayables made hidden.


exportXML

public void exportXML(java.lang.StringBuilder sb_body,
                      java.lang.String indent,
                      java.lang.Object any)
Description copied from class: DBObject
Subclasses can override this method to store the instance as XML.

Overrides:
exportXML in class DBObject

exportDTD

public static void exportDTD(java.lang.StringBuilder sb_header,
                             java.util.HashSet<java.lang.String> hs,
                             java.lang.String indent)
Includes all Displayable objects in the list of possible children.


getLayerThingTitle

protected java.lang.String getLayerThingTitle()

getTitle

public java.lang.String getTitle()
Description copied from class: DBObject
Sublcasses can override this method to provide a proper String, otherwise calls toString()

Overrides:
getTitle in class DBObject

destroy

public void destroy()

getMinimalBoundingBox

public java.awt.Rectangle getMinimalBoundingBox(java.lang.Class<?> c)
Returns null if no Displayable objects of class c exist.


getMinimalBoundingBox

public java.awt.Rectangle getMinimalBoundingBox(java.lang.Class<?> c,
                                                boolean visible_only)
Returns null if no Displayable objects of class c exist (or are visible if is true).


getPatchArea

public java.awt.geom.Area getPatchArea(boolean visible_only)
Returns an Area in world coordinates that represents the inside of all Patches.


apply

public void apply(java.lang.Class<?> c,
                  java.awt.geom.AffineTransform at)
Preconcatenate the given AffineTransform to all Displayable objects of class c, without respecting their links.


clone

public Layer clone(Project pr,
                   LayerSet ls,
                   java.awt.Rectangle roi,
                   boolean copy_id)
Make a copy of this layer into the given LayerSet, enclosing only Displayable objects within the roi, and translating them for that roi x,y.


grab

public java.lang.Object grab(java.awt.Rectangle r,
                             double scale,
                             java.lang.Class<?> c,
                             int c_alphas,
                             int format,
                             int type)
Returns the region defined by the rectangle as an image in the type and format specified. The type is either ImagePlus.GRAY8 or ImagePlus.COLOR_RGB. The format is either Layer.IMAGEPROCESSOR, Layer.IMAGEPLUS, Layer.PIXELARRAY or Layer.IMAGE.


findById

public DBObject findById(long id)

updateLayerTree

public void updateLayerTree()
Recursive into nested LayerSet objects.


getPixel

public int[] getPixel(int x,
                      int y,
                      double mag)
Don't use this for fast pixel grabbing; this is intended for the dropper tool and status bar reporting by mouse motion.


recreateBuckets

public void recreateBuckets()

updateBucket

public void updateBucket(Displayable d,
                         Layer layer)
Update buckets of a position change for the given Displayable.

Specified by:
updateBucket in interface Bucketable

checkBuckets

public void checkBuckets()

setBucketsEnabled

public void setBucketsEnabled(boolean b)

getOverlay

public Overlay getOverlay()
Return the current Overlay or a new one if none yet.


setOverlay

public Overlay setOverlay(Overlay o)
Set to null to remove the Overlay.

Returns:
the previous Overlay, if any.

compareTo

public int compareTo(Layer layer)
Specified by:
compareTo in interface java.lang.Comparable<Layer>