Permalink
Browse files

Show or hide shape with channel information (see #4858)

When the channel is set for a shape, show or hide the shape
when the user turns the channel on/off.
  • Loading branch information...
1 parent bd5fafc commit 386f9a53dcc60841757b63946de1017a51cb9d09 @jburel jburel committed Apr 2, 2012
@@ -312,8 +312,7 @@ public int getC()
if (shape == null)
throw new IllegalArgumentException("No shape specified.");
RInt value = shape.getTheC();
- if (value == null)
- throw new IllegalArgumentException("No C Specified.");
+ if (value == null) return -1;
return value.getValue();
}
@@ -34,6 +34,8 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import java.util.Map.Entry;
+
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileFilter;
@@ -599,18 +601,52 @@ public void setActiveChannels(Map activeChannels)
"state: "+state);
}
model.setActiveChannels(activeChannels);
+ //Show or hide some shapes if they are visible on a channel or not
+ TreeMap<Long, ROI> rois = model.getROI();
+ Collection<ROIFigure> figures = model.getAllFigures();
+ ROIFigure figure, f;
+ Iterator<ROIFigure> i = figures.iterator();
+ ROI roi;
+ TreeMap<Coord3D, ROIShape> shapeMap;
+
+ ROIShape shape;
+ Entry entry;
+ if (rois != null) {
+ Iterator j = rois.entrySet().iterator();
+ Iterator k;
+ Coord3D coord;
+ int c;
+ while (j.hasNext()) {
+ entry = (Entry) j.next();
+ roi = (ROI) entry.getValue();
+ shapeMap = roi.getShapes();
+ k = shapeMap.entrySet().iterator();
+ while (k.hasNext()) {
+ entry = (Entry) k.next();
+ coord = (Coord3D) entry.getKey();
+ shape = (ROIShape) entry.getValue();
+ f = shape.getFigure();
+ c = coord.getChannel();
+ if (c >= 0) {
+ f.setVisible(model.isChannelActive(c));
+ }
+ }
+ }
+ view.repaint();
+ }
if (!view.inDataView() || !view.isVisible()) return;
- Collection<ROIFigure> collection = getSelectedFigures();
- if (collection.size() != 1) return;
- ROIFigure figure = collection.iterator().next();
+ figures = getSelectedFigures();
+ if (figures.size() != 1) return;
+ figure = figures.iterator().next();
List<ROIShape> shapeList = new ArrayList<ROIShape>();
- ROI roi = figure.getROI();
- TreeMap<Coord3D, ROIShape> shapeMap = roi.getShapes();
- Iterator<Coord3D> shapeIterator = shapeMap.keySet().iterator();
- while (shapeIterator.hasNext())
- shapeList.add(shapeMap.get(shapeIterator.next()));
-
+ roi = figure.getROI();
+ shapeMap = roi.getShapes();
+ Iterator j = shapeMap.entrySet().iterator();
+ while (j.hasNext()) {
+ entry = (Entry) j.next();
+ shapeList.add( (ROIShape) entry.getValue());
+ }
if (shapeList.size() != 0) analyseShapeList(shapeList);
}
@@ -639,21 +639,28 @@ boolean setServerROI(Collection rois, boolean readOnly)
Iterator<ROI> i = roiList.iterator();
ROI roi;
TreeMap<Coord3D, ROIShape> shapeList;
- Iterator<ROIShape> shapeIterator;
+ Iterator j;
ROIShape shape;
- Coord3D c;
+ Coord3D coord;
int sizeZ = pixels.getSizeZ();
int sizeT = pixels.getSizeT();
-
+ Entry entry;
+ int c;
+ ROIFigure f;
while (i.hasNext()) {
roi = i.next();
shapeList = roi.getShapes();
- shapeIterator = shapeList.values().iterator();
- while (shapeIterator.hasNext()) {
- shape = shapeIterator.next();
- c = shape.getCoord3D();
- if (c.getTimePoint() > sizeT) return false;
- if (c.getZSection() > sizeZ) return false;
+ j = shapeList.entrySet().iterator();
+ while (j.hasNext()) {
+ entry = (Entry) j.next();
+ shape = (ROIShape) entry.getValue();
+ coord = shape.getCoord3D();
+ if (coord.getTimePoint() > sizeT) return false;
+ if (coord.getZSection() > sizeZ) return false;
+ c = coord.getChannel();
+ f = shape.getFigure();
+ if (c >= 0 && f.isVisible())
+ f.setVisible(isChannelActive(c));
}
}
component.attachListeners(roiList);
@@ -225,6 +225,11 @@ private ROIShape createROIShape(ShapeData data, ROI roi, boolean readOnly)
if (z < 0 || t < 0) return null;
Coord3D coord = new Coord3D(z, t);
ROIFigure fig = createROIFigure(data, readOnly);
+ try {
+ coord.setChannel(data.getC());
+ } catch (Exception e) {
+ }
+
// Check that the parent element is not a text element, as they have not
// got any other text associated with them.
addMissingAttributes(fig);
@@ -57,6 +57,9 @@
/** The z-section. */
private int z;
+ /** The channel. Default value is <code>-1</code> if not set.*/
+ private int c;
+
/** Creates a default point. */
public Coord3D()
{
@@ -75,9 +78,24 @@ public Coord3D(int zsec, int time)
throw new IllegalArgumentException("Coordinates not valid.");
t = time;
z = zsec;
+ c = -1;
}
/**
+ * Returns the channel or <code>-1</code> if not set.
+ *
+ * @return See above.
+ */
+ public int getChannel() { return c; }
+
+ /**
+ * Sets the channel.
+ *
+ * @param c The value to set.
+ */
+ public void setChannel(int c) { this.c = c; }
+
+ /**
* Returns the timepoint.
*
* @return See above.

0 comments on commit 386f9a5

Please sign in to comment.