forked from ome/openmicroscopy
/
MeasurementViewerModel.java
1727 lines (1580 loc) · 45.7 KB
/
MeasurementViewerModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* org.openmicroscopy.shoola.agents.measurement.view.MeasurementViewerModel
*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2007 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*------------------------------------------------------------------------------
*/
package org.openmicroscopy.shoola.agents.measurement.view;
//Java imports
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry;
//Third-party libraries
import com.sun.opengl.util.texture.TextureData;
import org.jhotdraw.draw.AttributeKey;
import org.jhotdraw.draw.Drawing;
import org.jhotdraw.draw.DrawingEditor;
import org.jhotdraw.draw.Figure;
//Application-internal dependencies
import org.openmicroscopy.shoola.agents.events.SaveData;
import org.openmicroscopy.shoola.agents.events.iviewer.SaveRelatedData;
import org.openmicroscopy.shoola.agents.measurement.Analyser;
import org.openmicroscopy.shoola.agents.measurement.IconManager;
import org.openmicroscopy.shoola.agents.measurement.MeasurementAgent;
import org.openmicroscopy.shoola.agents.measurement.MeasurementViewerLoader;
import org.openmicroscopy.shoola.agents.measurement.ROILoader;
import org.openmicroscopy.shoola.agents.measurement.ROISaver;
import org.openmicroscopy.shoola.agents.measurement.ServerSideROILoader;
import org.openmicroscopy.shoola.agents.measurement.WorkflowLoader;
import org.openmicroscopy.shoola.agents.measurement.WorkflowSaver;
import org.openmicroscopy.shoola.agents.measurement.util.FileMap;
import pojos.WorkflowData;
import org.openmicroscopy.shoola.agents.util.EditorUtil;
import org.openmicroscopy.shoola.env.data.DSAccessException;
import org.openmicroscopy.shoola.env.data.DSOutOfServiceException;
import org.openmicroscopy.shoola.env.data.OmeroImageService;
import org.openmicroscopy.shoola.env.data.model.DeletableObject;
import org.openmicroscopy.shoola.env.data.model.DeleteActivityParam;
import org.openmicroscopy.shoola.env.data.model.ROIResult;
import org.openmicroscopy.shoola.env.event.EventBus;
import org.openmicroscopy.shoola.env.log.Logger;
import org.openmicroscopy.shoola.env.ui.UserNotifier;
import org.openmicroscopy.shoola.util.file.IOUtil;
import org.openmicroscopy.shoola.util.roi.model.annotation.AnnotationKeys;
import org.openmicroscopy.shoola.util.roi.model.annotation.MeasurementAttributes;
import org.openmicroscopy.shoola.util.roi.ROIComponent;
import org.openmicroscopy.shoola.util.roi.exception.NoSuchROIException;
import org.openmicroscopy.shoola.util.roi.exception.ParsingException;
import org.openmicroscopy.shoola.util.roi.exception.ROICreationException;
import org.openmicroscopy.shoola.util.roi.figures.ROIFigure;
import org.openmicroscopy.shoola.util.roi.model.ROI;
import org.openmicroscopy.shoola.util.roi.model.ROIShape;
import org.openmicroscopy.shoola.util.roi.model.ShapeList;
import org.openmicroscopy.shoola.util.roi.model.util.Coord3D;
import org.openmicroscopy.shoola.util.roi.model.util.MeasurementUnits;
import org.openmicroscopy.shoola.util.ui.MessageBox;
import org.openmicroscopy.shoola.util.ui.drawingtools.DrawingComponent;
import org.openmicroscopy.shoola.util.ui.drawingtools.canvas.DrawingCanvasView;
import pojos.ChannelData;
import pojos.ExperimenterData;
import pojos.FileAnnotationData;
import pojos.ImageData;
import pojos.PixelsData;
import pojos.ROIData;
/**
* The Model component in the <code>MeasurementViewer</code> MVC triad.
* This class tracks the <code>MeasurementViewer</code>'s state and knows how to
* initiate data retrievals. It also knows how to store and manipulate
* the results. This class provides a suitable data loader.
* The {@link MeasurementViewerComponent} intercepts the results of data
* loadings, feeds them back to this class and fires state transitions as
* appropriate.
*
* @author Jean-Marie Burel
* <a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a>
* @author Donald MacDonald
* <a href="mailto:donald@lifesci.dundee.ac.uk">donald@lifesci.dundee.ac.uk</a>
* @version 3.0
* <small>
* (<b>Internal version:</b> $Revision: $Date: $)
* </small>
* @since OME3.0
*/
class MeasurementViewerModel
{
/** The id of the image this {@link MeasurementViewer} is for. */
private long imageID;
/** The name of the image this {@link MeasurementViewer} is for. */
private String name;
/** The bounds of the component requesting the viewer. */
private Rectangle requesterBounds;
/** Holds one of the state flags defined by {@link MeasurementViewer}. */
private int state;
/**
* The drawing component to create drawing, view and editor and link them.
*/
private DrawingComponent drawingComponent;
/** The component managing the ROI. */
private ROIComponent roiComponent;
/** The currently selected plane. */
private Coord3D currentPlane;
/** The pixels set. */
private PixelsData pixels;
/** The image's magnification factor. */
private double magnification;
/** Collection of pairs (channel's index, channel's color). */
private Map activeChannels;
/** Collection of pairs (ROIShape, Map of ROIShapeStats). */
private Map analysisResults;
/** Metadata for the pixels set. */
private List<ChannelData> metadata;
/**
* Will either be a data loader or
* <code>null</code> depending on the current state.
*/
private MeasurementViewerLoader currentLoader;
/**
* The ROISaver.
*/
private MeasurementViewerLoader currentSaver;
/** Reference to the component that embeds this model. */
private MeasurementViewer component;
/**
* Reference to the event posted to save the data when closing the
* viewer.
*/
private SaveRelatedData event;
/** The rendered image either a buffered image or a texture data. */
private Object rndImage;
/** The roi file previously saved if any. */
private String fileSaved;
/** The measurements associated to the image. */
private List<FileAnnotationData> measurements;
/** The collection of ROIs and tables related to the measurements. */
private Collection measurementResults;
/** The current workflow namespace being used. */
private String workflowNamespace;
/** The map of workflow namespace, workflow. */
private Map<String, WorkflowData> workflows;
/** The keyword of the current workflow. */
private List<String> keyword;
/** Flag indicating if the tool is for HCS data. */
private boolean HCSData;
/** Collection of ROIs to delete. */
private List<ROI> roiToDelete;
/** Flag indicating that the current user can deleted the ROI. */
private boolean dataToDelete;
/** Flag indicating if it is a big image or not.*/
private boolean bigImage;
/**
* Sorts the passed nodes by row.
*
* @param nodes The nodes to sort.
* @return See above.
*/
private List sortROIShape(List nodes)
{
Comparator c = new Comparator() {
public int compare(Object o1, Object o2)
{
long i1 = ((ROIShape) o1).getID();
long i2 = ((ROIShape) o2).getID();
int v = 0;
if (i1 < i2) v = -1;
else if (i1 > i2) v = 1;
return v;
}
};
Collections.sort(nodes, c);
return nodes;
}
/**
* Map figure attributes to ROI and ROIShape annotations where necessary.
* @param attribute see above.
* @param figure see above.
*/
private void mapFigureAttributeToROIAnnotation(AttributeKey attribute,
ROIFigure figure)
{
if (MeasurementAttributes.TEXT.getKey().equals(attribute.getKey()))
{
ROIShape shape = figure.getROIShape();
AnnotationKeys.TEXT.set(shape,
MeasurementAttributes.TEXT.get(figure));
}
}
/** Checks the user currently logged in has ROI to delete. */
private void checkIfHasROIToDelete()
{
if (dataToDelete) return;
ExperimenterData exp =
(ExperimenterData) MeasurementAgent.getUserDetails();
long ownerID = exp.getId();
Collection<ROI> rois = roiComponent.getROIMap().values();
Iterator<ROI> i = rois.iterator();
List<ROI> ownedRois = new ArrayList<ROI>();
ROI roi;
List<ROIFigure> figures = new ArrayList<ROIFigure>();
while (i.hasNext()) {
roi = i.next();
if (roi.getOwnerID() == ownerID || roi.getOwnerID() == -1) {
figures.addAll(roi.getAllFigures());
ownedRois.add(roi);
}
}
dataToDelete = ownedRois.size() > 0;
}
/**
* Creates a new instance.
*
* @param imageID The image's id.
* @param pixels The pixels set the measurement tool is for.
* @param name The image's name.
* @param bounds The bounds of the component requesting the model.
* @param channelsData The channel metadata.
*/
MeasurementViewerModel(long imageID, PixelsData pixels, String name,
Rectangle bounds, List<ChannelData> channelsData)
{
metadata = channelsData;
this.imageID = imageID;
this.pixels = pixels;
this.name = name;
requesterBounds = bounds;
state = MeasurementViewer.NEW;
drawingComponent = new DrawingComponent();
roiComponent = new ROIComponent();
fileSaved = null;
roiComponent.setMicronsPixelX(getPixelSizeX());
roiComponent.setMicronsPixelY(getPixelSizeY());
roiComponent.setMicronsPixelZ(getPixelSizeZ());
workflows = new HashMap<String, WorkflowData>();
this.workflowNamespace = WorkflowData.DEFAULTWORKFLOW;
this.keyword = new ArrayList<String>();
}
/**
* Called by the <code>ROIViewer</code> after creation to allow this
* object to store a back reference to the embedding component.
*
* @param component The embedding component.
*/
void initialize(MeasurementViewer component)
{
this.component = component;
}
/**
* Get a link to the ROIComponent.
* @return see above.
*/
ROIComponent getROIComponent()
{
return roiComponent;
}
/**
* Returns the name used to log in.
*
* @return See above.
*/
String getUserName()
{
return MeasurementAgent.getRegistry().getAdminService().getLoggingName();
}
/**
* Returns the name of the server the user is connected to.
*
* @return See above.
*/
String getServerName()
{
return MeasurementAgent.getRegistry().getAdminService().getServerName();
}
/**
* Sets the selected z-section and timepoint.
*
* @param z The selected z-section.
* @param t The selected timepoint.
*/
void setPlane(int z, int t)
{
currentPlane = new Coord3D(z, t);
}
/**
* Compares another model to this one to tell if they would result in
* having the same display.
*
* @param other The other model to compare.
* @return <code>true</code> if <code>other</code> would lead to a viewer
* with the same display as the one in which this model belongs;
* <code>false</code> otherwise.
*/
boolean isSameDisplay(MeasurementViewerModel other)
{
if (other == null) return false;
return ((other.pixels.getId() == getPixelsID())
&& (other.imageID == imageID));
}
/**
* Returns the ID of the image.
*
* @return See above.
*/
long getImageID() { return imageID; }
/**
* Returns the ID of the pixels set this model is for.
*
* @return See above.
*/
long getPixelsID() { return pixels.getId(); }
/**
* Returns the name of the image.
*
* @return See above.
*/
String getImageName() { return name; }
/**
* Returns the name of image and id.
*
* @return See above.
*/
String getImageTitle()
{
return "[ID: "+getImageID()+"] "+
EditorUtil.getPartialName(getImageName());
}
/**
* Returns the bounds of the component invoking the
* {@link MeasurementViewer} or <code>null</code> if not available.
*
* @return See above.
*/
Rectangle getRequesterBounds() { return requesterBounds; }
/**
* Returns the current state.
*
* @return One of the flags defined by the {@link MeasurementViewer}
* interface.
*/
int getState() { return state; }
/**
* Returns the drawing editor.
*
* @return See above.
*/
DrawingEditor getDrawingEditor() { return drawingComponent.getEditor(); }
/**
* Returns the drawing.
*
* @return See above.
*/
Drawing getDrawing() { return drawingComponent.getDrawing(); }
/**
* Sets the object in the {@link MeasurementViewer#DISCARDED} state.
* Any ongoing data loading will be cancelled.
*/
void discard()
{
cancel();
state = MeasurementViewer.DISCARDED;
}
/**
* Sets the object in the {@link MeasurementViewer#READY} state.
* Any ongoing data loading will be cancelled.
*/
void cancel()
{
if (currentLoader != null) currentLoader.cancel();
state = MeasurementViewer.READY;
}
/**
* Returns the currently selected z-section.
*
* @return See above.
*/
int getDefaultZ() { return currentPlane.getZSection(); }
/**
* Returns the currently selected timepoint.
*
* @return See above.
*/
int getDefaultT() { return currentPlane.getTimePoint(); }
/**
* Returns the image's magnification factor.
*
* @return See above.
*/
double getMagnification() { return magnification; }
/**
* Returns the image's magnification factor.
*
* @param magnification The value to set.
*/
void setMagnification(double magnification)
{
this.magnification = magnification;
if (state != MeasurementViewer.NEW)
getDrawingView().setScaleFactor(magnification,
new Dimension(getSizeX(), getSizeY()));
else
getDrawingView().setScaleFactor(magnification);
}
/**
* Sets the attribute of all the ROI in the current plane to the key with
* value.
*
* @param key see above.
* @param value see above.
*/
void setAttributes(AttributeKey key, Object value)
{
List<Figure> figures = getDrawing().getFigures();
for (Figure f : figures)
f.setAttribute(key, value);
getDrawingView().repaint();
}
/**
* Sets the state.
*
* @param state The value to set.
*/
void setState(int state)
{
this.state = state;
}
/**
* Sets the ROI for the pixels set. Returns <code>true</code>
* if the ROI are compatible with the image, <code>false</code> otherwise.
*
* @param input The value to set.
* @return See above.
* @throws ROICreationException If the ROI cannot be created.
* @throws NoSuchROIException If the ROI does not exist.
* @throws ParsingException Thrown when an error occurred
* while parsing the stream.
*/
boolean setROI(InputStream input)
throws ROICreationException, NoSuchROIException, ParsingException
{
state = MeasurementViewer.READY;
if (input == null) return false;
List<ROI> roiList = roiComponent.loadROI(input);
if (roiList == null) return false;
Iterator<ROI> i = roiList.iterator();
ROI roi;
TreeMap<Coord3D, ROIShape> shapeList;
Iterator<ROIShape> shapeIterator;
ROIShape shape;
Coord3D c;
int sizeZ = pixels.getSizeZ();
int sizeT = pixels.getSizeT();
boolean b = true;
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) {
b = false;
break;
}
if (c.getZSection() > sizeZ) {
b = false;
break;
}
}
}
if (!b) {
i = roiList.iterator();
while (i.hasNext()) {
roi = i.next();
roiComponent.deleteROI(roi.getID());
}
return false;
}
component.attachListeners(roiList);
notifyDataChanged(true);
return true;
}
/**
* Returns the file corresponding to the passed id.
*
* @param fileID The id of the file.
* @return See above.
*/
FileAnnotationData getMeasurement(long fileID)
{
if (measurements == null) return null;
Iterator<FileAnnotationData> i = measurements.iterator();
FileAnnotationData fa;
while (i.hasNext()) {
fa = i.next();
if (fa.getId() == fileID) return fa;
}
return null;
}
/**
* Returns the measurements.
*
* @return See above.
*/
List<FileAnnotationData> getMeasurements() { return measurements; }
/**
* Returns the collection of measurements results.
*
* @return See above.
*/
Collection getMeasurementResults() { return measurementResults; }
/**
* Sets the server ROIS.
*
* @param rois The collection of Rois.
* @param readOnly Are the ROI read only.
* @return See above.
* @throws ROICreationException
* @throws NoSuchROIException
*/
boolean setServerROI(Collection rois, boolean readOnly)
throws ROICreationException, NoSuchROIException
{
measurementResults = rois;
state = MeasurementViewer.READY;
List<ROI> roiList = new ArrayList<ROI>();
Iterator r = rois.iterator();
ROIResult result;
long userID = MeasurementAgent.getUserDetails().getId();
while (r.hasNext()) {
result = (ROIResult) r.next();
roiList.addAll(roiComponent.loadROI(result.getFileID(),
result.getROIs(), readOnly, userID));
}
if (roiList == null) return false;
Iterator<ROI> i = roiList.iterator();
ROI roi;
TreeMap<Coord3D, ROIShape> shapeList;
Iterator<ROIShape> shapeIterator;
ROIShape shape;
Coord3D c;
int sizeZ = pixels.getSizeZ();
int sizeT = pixels.getSizeT();
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;
}
}
component.attachListeners(roiList);
checkIfHasROIToDelete();
return true;
}
/**
* Returns the ROI.
*
* @return See above.
*/
TreeMap getROI() { return roiComponent.getROIMap(); }
/**
* Returns the currently selected plane.
*
* @return See above.
*/
Coord3D getCurrentView() { return currentPlane; }
/**
* Returns the size in microns of a pixel along the X-axis.
*
* @return See above.
*/
double getPixelSizeX() { return pixels.getPixelSizeX(); }
/**
* Returns the size in microns of a pixel along the Y-axis.
*
* @return See above.
*/
double getPixelSizeY() { return pixels.getPixelSizeY(); }
/**
* Returns the size in microns of a pixel along the Z-axis.
*
* @return See above.
*/
double getPixelSizeZ() { return pixels.getPixelSizeZ(); }
/**
* Returns the number of z sections in an image.
*
* @return See above.
*/
int getNumZSections() { return pixels.getSizeZ(); }
/**
* Returns the number of timepoints in an image.
*
* @return See above.
*/
int getNumTimePoints() { return pixels.getSizeT(); }
/**
* Returns the number of pixels along the X-axis.
*
* @return See above.
*/
int getSizeX() { return pixels.getSizeX(); }
/**
* Returns the number of pixels along the Y-axis.
*
* @return See above.
*/
int getSizeY() { return pixels.getSizeY(); }
/**
* Returns the {@link DrawingCanvasView}.
*
* @return See above.
*/
DrawingCanvasView getDrawingView()
{
return drawingComponent.getDrawingView();
}
/**
* Returns the ROI of the currently selected figure in the drawing view.
*
* @return see above.
*/
Collection<ROI> getSelectedROI()
{
Collection<Figure> selectedFigs = getDrawingView().getSelectedFigures();
List<ROI> roiList = new ArrayList<ROI>();
Iterator<Figure> figIterator = selectedFigs.iterator();
ROIFigure fig;
while (figIterator.hasNext())
{
fig = (ROIFigure) figIterator.next();
roiList.add(fig.getROI());
}
return roiList;
}
/**
* Removes the <code>ROIShape</code> on the current View corresponding
* to the passed id.
*
* @param id The id of the <code>ROI</code>.
* @throws NoSuchROIException If the ROI does not exist.
*/
void removeROIShape(long id)
throws NoSuchROIException
{
ROIShape shape = roiComponent.getShape(id, getCurrentView());
if (shape != null)
{
if (drawingComponent.contains(shape.getFigure()))
drawingComponent.removeFigure(shape.getFigure());
else roiComponent.deleteShape(id, getCurrentView());
}
}
/**
* Removes the <code>ROIShape</code> corresponding to the passed id on
* the plane coordinates.
*
* @param id The id of the <code>ROI</code>.
* @param coord the coordinates of the shape to delete.
* @throws NoSuchROIException If the ROI does not exist.
*/
void removeROIShape(long id, Coord3D coord)
throws NoSuchROIException
{
ROIShape shape = roiComponent.getShape(id, coord);
if (shape != null) {
if (drawingComponent.contains(shape.getFigure()))
drawingComponent.removeFigure(shape.getFigure());
else
roiComponent.deleteShape(id, coord);
}
}
/**
* Removes the <code>ROI</code> corresponding to the passed id.
*
* @param id The id of the <code>ROI</code>.
* @throws NoSuchROIException If the ROI does not exist.
*/
void removeROI(long id)
throws NoSuchROIException
{
ROIShape shape = roiComponent.getShape(id, getCurrentView());
if (shape != null) {
if (drawingComponent.contains(shape.getFigure()))
drawingComponent.removeFigure(shape.getFigure());
}
if (roiComponent.containsROI(id))
roiComponent.deleteROI(id);
}
/**
* Removes all the <code>ROI</code> in the system.
*
* @throws NoSuchROIException If the ROI does not exist.
*/
void removeAllROI()
throws NoSuchROIException
{
state = MeasurementViewer.READY;
drawingComponent.removeAllFigures();
int size = roiComponent.getROIMap().values().size();
ROI[] valueList = new ROI[size];
roiComponent.getROIMap().values().toArray(valueList);
if (valueList != null)
for (ROI roi: valueList)
roiComponent.deleteROI(roi.getID());
}
/**
* Removes all the <code>ROI</code> in the system.
* Returns the collection of figures.
*
* @return See above.
* @throws NoSuchROIException If the ROI does not exist.
*/
List<ROIFigure> removeAllROI(long ownerID)
throws NoSuchROIException
{
Collection<ROI> rois = roiComponent.getROIMap().values();
Iterator<ROI> i = rois.iterator();
List<ROI> ownedRois = new ArrayList<ROI>();
ROI roi;
List<ROIFigure> figures = new ArrayList<ROIFigure>();
while (i.hasNext()) {
roi = i.next();
if (roi.getOwnerID() == ownerID || roi.getOwnerID() == -1) {
figures.addAll(roi.getAllFigures());
ownedRois.add(roi);
}
}
i = ownedRois.iterator();
while (i.hasNext()) {
roi = i.next();
roiComponent.deleteROI(roi.getID());
}
Iterator<ROIFigure> j = figures.iterator();
while (j.hasNext()) {
drawingComponent.removeFigure(j.next());
}
event = null;
notifyDataChanged(false);
dataToDelete = false;
return figures;
}
/**
* Returns the <code>ROI</code> corresponding to the passed id.
*
* @param id The id of the <code>ROI</code>.
* @return See above.
* @throws NoSuchROIException If the ROI does not exist.
*/
ROI getROI(long id)
throws NoSuchROIException
{
return roiComponent.getROI(id);
}
/**
* Returns the ROIComponent to create a <code>ROI</code> from
* the passed figure.
*
* @param figure The figure to create the <code>ROI</code> from.
* @param addAttribs add attributes to figure
* @return Returns the created <code>ROI</code>.
* @throws ROICreationException If the ROI cannot be created.
* @throws NoSuchROIException If the ROI does not exist.
*/
ROI createROI(ROIFigure figure, boolean addAttribs)
throws ROICreationException, NoSuchROIException
{
ROI roi = roiComponent.addROI(figure, getCurrentView(), addAttribs);
roi.setAnnotation(AnnotationKeys.NAMESPACE, this.workflowNamespace);
StringBuffer buffer = new StringBuffer();
for (int i = 0 ; i < keyword.size() ; i++)
{
buffer.append(keyword.get(i));
if (i < keyword.size()-1)
buffer.append(",");
}
roi.setAnnotation(AnnotationKeys.KEYWORDS, buffer.toString());
return roi;
}
/**
* Returns the {@link ShapeList} for the current plane.
*
* @return See above.
* @throws NoSuchROIException Thrown if the ROI doesn't exist.
*/
ShapeList getShapeList()
throws NoSuchROIException
{
return roiComponent.getShapeList(currentPlane);
}
/**
* Figure attribute has changed, need to add any special processing to see
* if it should affect ROIShape, ROI or other object.
*
* @param attribute
* @param figure
*/
void figureAttributeChanged(AttributeKey attribute, ROIFigure figure)
{
mapFigureAttributeToROIAnnotation(attribute, figure);
}
/**
* Loads the ROI associated to the image.
*
* @param measurements The measurements if any.
*/
void fireLoadROIFromServer(List<FileAnnotationData> measurements)
{
this.measurements = measurements;
List<Long> files = null;
if (measurements != null) {
files = new ArrayList<Long>();
Iterator<FileAnnotationData> i = measurements.iterator();
while (i.hasNext())
files.add(i.next().getId());
}
state = MeasurementViewer.LOADING_ROI;
ExperimenterData exp =
(ExperimenterData) MeasurementAgent.getUserDetails();
currentLoader = new ROILoader(component, getImageID(), files,
exp.getId());
currentLoader.load();
}
/**
* Fires an asynchronous retrieval of the ROI related to the pixels set.
*
* @param dataChanged Pass <code>true</code> if the ROI has been changed.
* <code>false</code> otherwise.
*/
void fireLoadROIServerOrClient(boolean dataChanged)
{
state = MeasurementViewer.LOADING_ROI;
ExperimenterData exp =
(ExperimenterData) MeasurementAgent.getUserDetails();
currentLoader = new ServerSideROILoader(component, getImageID(),
exp.getId());
currentLoader.load();
notifyDataChanged(dataChanged);
}
/**
* Fires an asynchronous retrieval of the Workflow related user.
*/
void fireLoadWorkflow()
{
ExperimenterData exp =
(ExperimenterData) MeasurementAgent.getUserDetails();
currentLoader = new WorkflowLoader(component, exp.getId());
currentLoader.load();
}
/**
* Retrieves the workflows saved.
*/
void retrieveWorkflowsFromServer()
{
ExperimenterData exp =
(ExperimenterData) MeasurementAgent.getUserDetails();
OmeroImageService svc =
MeasurementAgent.getRegistry().getImageService();
try
{
List<WorkflowData> result = svc.retrieveWorkflows(exp.getId());
workflows.clear();
component.setWorkflowList(result);
} catch (DSAccessException e)
{
Logger log = MeasurementAgent.getRegistry().getLogger();
log.error(this, "Cannot load workflows");
} catch (DSOutOfServiceException e)
{
Logger log = MeasurementAgent.getRegistry().getLogger();
log.error(this, "Cannot load workflows");
}
}
/**
* Fires an asynchronous retrieval of the ROI related to the pixels set.
*