public IntensityPaint(ROI2D roi, Sequence seq, IcyCanvas canv) { canvas = canv; sequence = seq; guideRoi = roi; displayRectangle = new ROI2DRectangle( lastPoint.getX(), lastPoint.getY(), lastPoint.getX() + Math.min(800, sequence.getWidth() / 4), lastPoint.getY() + Math.min(800, sequence.getHeight() / 4)); displayRectangle.setName("(" + guideRoi.getName() + ")"); displayRectangle.setColor(guideRoi.getColor()); displayRectangle.setOpacity((float) 0.2); cursor1 = new Line2D.Double(); cursor2 = new Line2D.Double(); if (guideRoi.getClass().equals(ROI2DLine.class)) paintMode = PaintMode.line; else if (guideRoi.getClass().equals(ROI2DPoint.class)) paintMode = PaintMode.point; else paintMode = PaintMode.area; (new Thread(new computeRunnable())).start(); sequence.addListener(this); guideRoi.addListener(this); if (paintMode == PaintMode.line) canvas.getViewer().addListener(this); }
@Override public void paint(Graphics2D g, Sequence sequence, IcyCanvas canv) { if (canv != canvas) { canvas = canv; canvas.getViewer().addListener(this); canvas.getViewer().addKeyListener(this); } if (lastPoint == null) lastPoint = new Point(0, 0); // create a graphics object so that we can then dispose it at the end of the paint to clean // all change performed in the paint, // like transform, color change, stroke (...). HashMap<ROI2D, IntensityPaint> roiPairTemp = new HashMap<ROI2D, IntensityPaint>(); Graphics2D g2 = (Graphics2D) g.create(); for (ROI2D roi : sequence.getROI2Ds()) { if (roi.getName().startsWith("(") && roi.getName().endsWith(")")) continue; { IntensityPaint ip; if (roiPairDict.containsKey(roi)) { ip = roiPairDict.get(roi); // rect.displayRectangle.setName("["+roi.getName()+"]"); // Rectangle2D box2 = rect.displayRectangle.getBounds2D(); // // if(!sequence.getROI2Ds().contains(ip.displayRectangle)){// // sequence.removeROI(rect.displayRectangle);// // rect.displayRectangle.remove();// rect.displayRectangle new // ROI2DRectangle(lastPoint.getX(),lastPoint.getY(),Math.min(800,sequence.getWidth()),0);;;// rect.displayRectangle.setColor(roi.getColor());// sequence.addROI(rect.displayRectangle);// } if (ip != null) { if (!sequence.getROI2Ds().contains(ip.displayRectangle)) { ip.dispose(); } else roiPairTemp.put(roi, ip); } } else { ip = null; if (enableAddRoi) { roi.setName("" + Integer.toString(nameIndex) + "#"); nameIndex += 1; roi.setColor(getRandomColor()); // roi.setSelectedColor(getRandomColor()); ip = new IntensityPaint(roi, sequence, canvas); lastPoint.setLocation(lastPoint.getX() + 10, lastPoint.getY() + 10); if (lastPoint.getX() > sequence.getHeight() || lastPoint.getY() > sequence.getWidth()) lastPoint.setLocation(0, 0); sequence.addROI(ip.displayRectangle); } roiPairTemp.put(roi, ip); } if (ip != null && !skipSelect && roi instanceof ROI2DShape) { if (roi.isSelected()) ip.displayRectangle.setSelected(roi.isSelected()); else if (ip.displayRectangle.isSelected()) roi.setSelected(ip.displayRectangle.isSelected()); } try { if (ip != null) drawHisto(roi, g2, sequence, canvas); } catch (Exception e2) { } } } for (ROI2D roi : roiPairDict.keySet()) { if (!roiPairTemp.containsKey(roi)) { if (roiPairDict.get(roi) != null) { roiPairDict.get(roi).dispose(); sequence.removeROI(roiPairDict.get(roi).displayRectangle); } } } roiPairDict.clear(); roiPairDict = roiPairTemp; g2.dispose(); }