3 TrakEM2 plugin for ImageJ(C).
4 Copyright (C) 2005-2009 Albert Cardona and Rodney Douglas.
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.txt )
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 You may contact Albert Cardona at acardona at ini.phys.ethz.ch
20 Institute of Neuroinformatics, University of Zurich / ETH, Switzerland.
23 package ini
.trakem2
.display
;
25 import ini
.trakem2
.Project
;
26 import ini
.trakem2
.persistence
.XMLOptions
;
27 import ini
.trakem2
.utils
.Search
;
28 import ini
.trakem2
.utils
.Utils
;
30 import java
.awt
.Color
;
31 import java
.awt
.geom
.AffineTransform
;
32 import java
.awt
.geom
.Area
;
33 import java
.util
.ArrayList
;
34 import java
.util
.Collection
;
35 import java
.util
.HashMap
;
36 import java
.util
.HashSet
;
37 import java
.util
.List
;
39 /** For Pipes and other objects that must be shown in all Layers of a LayerSet. */
41 public abstract class ZDisplayable
extends Displayable
{
43 protected LayerSet layer_set
;
45 public ZDisplayable(Project project
, String title
, double x
, double y
) {
46 super(project
, title
, x
, y
);
49 /** For reconstruction from the database. */
50 public ZDisplayable(Project project
, long id
, String title
, boolean locked
, AffineTransform at
, float width
, float height
) {
51 super(project
, id
, title
, locked
, at
, width
, height
);
54 /** For reconstruction from an XML file. */
55 public ZDisplayable(Project project
, long id
, HashMap
<String
,String
> ht
, HashMap
<Displayable
,String
> ht_links
) {
56 super(project
, id
, ht
, ht_links
);
57 Object data
= ht
.get("layer_set_id");
59 // construct a dummy layerset
60 this.layer_set
= new LayerSet(project
, Long
.parseLong((String
)data
));
62 // -- one year later: seems like it will stay.
66 public void setLayerSet(LayerSet layer_set
) {
67 setLayerSet(layer_set
, true); // should check that the new LayerSet belongs to the same project
70 public void setLayerSet(LayerSet layer_set
, boolean update_db
) {
71 if (layer_set
== this.layer_set
) return;
72 this.layer_set
= layer_set
;
73 if (update_db
) updateInDatabase("layer_set_id");
76 public LayerSet
getLayerSet() { return layer_set
; }
78 // Overriding, for repainting the proper part, without updating the database
79 public void setLayer(Layer layer
) { this.layer
= layer
; }
81 /** Link the Patch objects that lay underneath the part of the bounding box of this profile that shows in the current layer, so that they cannot be dragged independently. */
82 abstract public boolean linkPatches();
84 /** Returns the layer of lowest Z coordinate where this ZDisplayable has a point in. */
85 abstract public Layer
getFirstLayer();
87 public void exportXML(StringBuilder sb_body
, String indent
, XMLOptions options
) {
88 super.exportXML(sb_body
, indent
, options
);
89 sb_body
.append(indent
).append("layer_set_id=\"").append(layer_set
.getId()).append("\"\n");
91 static public void exportDTD(final String type
, final StringBuilder sb_header
, final HashSet
<String
> hs
, final String indent
) {
92 if (hs
.contains(type
)) return;
93 Displayable
.exportDTD(type
, sb_header
, hs
, indent
);
94 sb_header
.append(indent
).append(TAG_ATTR1
).append(type
).append(" layer_set_id").append(TAG_ATTR2
)
98 /** Transform points falling within the given layer; translate by dx,dy and rotate by rot relative to origin xo,yo*/
100 public void transformPoints(Layer layer
, double dx
, double dy
, double rot
, double xo
, double yo
) {}
103 protected boolean remove2(boolean check
) {
104 return project
.getProjectTree().remove(check
, project
.findProjectThing(this), null); // will call remove(check) here
108 public boolean remove(boolean check
) {
109 if (check
&& !Utils
.check("Really remove " + this.toString() + " ?")) return false;
110 if (layer_set
.remove(this) && removeFromDatabase()) {
112 removeLinkedPropertiesFromOrigins();
113 Search
.remove(this); // duplication of code from Displayable.remove, because there isn't a proper hierarchy of classes
115 project
.decache(this);
121 /** Does not remove from the LayerSet. */
123 public boolean softRemove() {
124 if (removeFromDatabase()) {
126 removeLinkedPropertiesFromOrigins();
127 Search
.remove(this); // duplication of code from Displayable.remove, because there isn't a proper hierarchy of classes
134 /** Check if this instance will paint anything at the level of the given Layer. */
135 public boolean paintsAt(final Layer layer
) {
136 if (null == layer
|| layer_set
!= layer
.getParent()) return false;
140 /** Get the list of Layer ids on which this ZDisplayable has data on.*/
142 public Collection
<Long
> getLayerIds() {
143 // Unless overriden, return all
144 final ArrayList
<Long
> l
= new ArrayList
<Long
>();
145 for (final Layer la
: layer_set
.getLayers()) l
.add(la
.getId());
149 public void setColor(Color color
) {
150 if (null == color
|| color
.equals(this.color
)) return;
152 Displayable
.last_color
= color
;
153 updateInDatabase("color");
154 Display
.repaint(layer_set
, this, 5);
155 Display3D
.setColor(this, color
);
158 abstract public boolean intersects(Area area
, double z_first
, double z_last
);
160 public void setVisible(final boolean visible
, final boolean repaint
) {
161 if (visible
== this.visible
) {
162 // patching synch error
163 //Display.updateVisibilityCheckbox(layer, this, null);
166 this.visible
= visible
;
168 Display
.repaint(layer_set
, null, getBoundingBox(), 5, true);
170 updateInDatabase("visible");
173 public Bucketable
getBucketable() {
174 return this.layer_set
;
177 /** Retain the data within the layer range, and through out all the rest. */
178 public boolean crop(List
<Layer
> range
) {
182 /** Update internal datastructures to reflect the fact that @param layer has been removed from the containing LayerSet.*/
183 protected boolean layerRemoved(Layer la
) {
184 if (null != hs_linked
) {
185 for (final Displayable d
: hs_linked
) if (d
.layer
== la
) unlink(d
);
190 public void updateBucket(final Layer la
) {
191 if (null == la
) updateBucket(); // for all layers
192 else if (null != getBucketable()) getBucketable().updateBucket(this, la
);
195 /** Update buckets for all Layers. */
197 public void updateBucket() {
198 if (null == getBucketable()) return;
199 for (final Layer layer
: getLayersWithData()) {
200 getBucketable().updateBucket(this, layer
);
204 abstract protected boolean calculateBoundingBox(final Layer la
);