Guest User

Untitled

a guest
May 22nd, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. public static void main(final String... args) throws DSOutOfServiceException,
  2. ExecutionException, DSAccessException
  3. {
  4. final LoginCredentials cred = new LoginCredentials(username, password, host,
  5. port);
  6. final Logger simpleLogger = new SimpleLogger();
  7.  
  8. final Gateway gateway = new Gateway(simpleLogger);
  9. final ExperimenterData user = gateway.connect(cred);
  10. final SecurityContext ctx = new SecurityContext(user.getGroupId());
  11. final ROIFacility roiFac = gateway.getFacility(ROIFacility.class);
  12.  
  13. final Collection<ROIResult> rois = roiFac.loadROIs(ctx, 701);
  14.  
  15. for (final ROIResult result : rois) {
  16. final Collection<ROIData> roiDatas = result.getROIs();
  17. for (final ROIData roiData : roiDatas) {
  18. System.out.println("------------------------------");
  19. modifyAndSaveROI(roiData, roiFac, ctx);
  20. }
  21. }
  22.  
  23. gateway.disconnect();
  24. }
  25.  
  26. private static void modifyAndSaveROI(final ROIData roi,
  27. final ROIFacility roiFac, final SecurityContext ctx)
  28. throws DSOutOfServiceException, DSAccessException
  29. {
  30. final RectangleData rd = (RectangleData) roi.getIterator().next().get(0);
  31.  
  32. System.out.println("Downloaded state");
  33. System.out.println("ROIData ID: " + roi.getId());
  34. printRectangleInfo(rd);
  35.  
  36. rd.setX(18);
  37. rd.setY(105);
  38. System.out.println("Modified state");
  39. System.out.println("ROIData ID: " + roi.getId());
  40. printRectangleInfo(rd);
  41.  
  42. final Collection<ROIData> saved = roiFac.saveROIs(ctx, 701, Collections
  43. .singletonList(roi));
  44.  
  45. System.out.println("Returned state");
  46. for (final ROIData r : saved) {
  47. System.out.println("ROIData ID: " + r.getId());
  48. final Iterator<List<ShapeData>> itr = r.getIterator();
  49. while (itr.hasNext()) {
  50. final List<ShapeData> shapes = itr.next();
  51. for (final ShapeData shape : shapes) {
  52. if (shape instanceof RectangleData) printRectangleInfo(
  53. (RectangleData) shape);
  54. else System.out.println("Not a rectangle!?");
  55. }
  56. }
  57. }
  58. }
  59.  
  60. private static void printRectangleInfo(final RectangleData rd) {
  61. System.out.println("ID: " + rd.getId() + " Z: " + rd.getZ() + " T: " + rd
  62. .getT() + " C: " + rd.getC() + " X: " + rd.getX() + " Y: " + rd.getY() +
  63. " Width: " + rd.getWidth() + " Height: " + rd.getHeight());
  64. System.out.println();
  65. }
Add Comment
Please, Sign In to add comment