void drawAllROIs(Graphics g) {
   RoiManager rm = RoiManager.getInstance();
   if (rm == null) {
     rm = Interpreter.getBatchModeRoiManager();
     if (rm != null && rm.getList().getItemCount() == 0) rm = null;
   }
   if (rm == null) {
     // if (showAllList!=null)
     //	overlay = showAllList;
     showAllROIs = false;
     repaint();
     return;
   }
   initGraphics(g, null, showAllColor);
   Hashtable rois = rm.getROIs();
   java.awt.List list = rm.getList();
   boolean drawLabels = rm.getDrawLabels();
   currentRoi = null;
   int n = list.getItemCount();
   if (IJ.debugMode) IJ.log("paint: drawing " + n + " \"Show All\" ROIs");
   if (labelRects == null || labelRects.length != n) labelRects = new Rectangle[n];
   if (!drawLabels) showAllList = new Overlay();
   else showAllList = null;
   if (imp == null) return;
   int currentImage = imp.getCurrentSlice();
   int channel = 0, slice = 0, frame = 0;
   boolean hyperstack = imp.isHyperStack();
   if (hyperstack) {
     channel = imp.getChannel();
     slice = imp.getSlice();
     frame = imp.getFrame();
   }
   drawNames = Prefs.useNamesAsLabels;
   for (int i = 0; i < n; i++) {
     String label = list.getItem(i);
     Roi roi = (Roi) rois.get(label);
     if (roi == null) continue;
     if (showAllList != null) showAllList.add(roi);
     if (i < 200 && drawLabels && roi == imp.getRoi()) currentRoi = roi;
     if (Prefs.showAllSliceOnly && imp.getStackSize() > 1) {
       if (hyperstack && roi.getPosition() == 0) {
         int c = roi.getCPosition();
         int z = roi.getZPosition();
         int t = roi.getTPosition();
         if ((c == 0 || c == channel) && (z == 0 || z == slice) && (t == 0 || t == frame))
           drawRoi(g, roi, drawLabels ? i : -1);
       } else {
         int position = roi.getPosition();
         if (position == 0) position = getSliceNumber(roi.getName());
         if (position == 0 || position == currentImage) drawRoi(g, roi, drawLabels ? i : -1);
       }
     } else drawRoi(g, roi, drawLabels ? i : -1);
   }
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   drawNames = false;
 }
 void drawZoomIndicator(Graphics g) {
   int x1 = 10;
   int y1 = 10;
   double aspectRatio = (double) imageHeight / imageWidth;
   int w1 = 64;
   if (aspectRatio > 1.0) w1 = (int) (w1 / aspectRatio);
   int h1 = (int) (w1 * aspectRatio);
   if (w1 < 4) w1 = 4;
   if (h1 < 4) h1 = 4;
   int w2 = (int) (w1 * ((double) srcRect.width / imageWidth));
   int h2 = (int) (h1 * ((double) srcRect.height / imageHeight));
   if (w2 < 1) w2 = 1;
   if (h2 < 1) h2 = 1;
   int x2 = (int) (w1 * ((double) srcRect.x / imageWidth));
   int y2 = (int) (h1 * ((double) srcRect.y / imageHeight));
   if (zoomIndicatorColor == null) zoomIndicatorColor = new Color(128, 128, 255);
   g.setColor(zoomIndicatorColor);
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   g.drawRect(x1, y1, w1, h1);
   if (w2 * h2 <= 200 || w2 < 10 || h2 < 10) g.fillRect(x1 + x2, y1 + y2, w2, h2);
   else g.drawRect(x1 + x2, y1 + y2, w2, h2);
 }
 void drawOverlay(Graphics g) {
   if (imp != null && imp.getHideOverlay()) return;
   Color labelColor = overlay.getLabelColor();
   if (labelColor == null) labelColor = Color.white;
   initGraphics(g, labelColor, Roi.getColor());
   int n = overlay.size();
   if (IJ.debugMode) IJ.log("paint: drawing " + n + " ROI display list");
   int currentImage = imp != null ? imp.getCurrentSlice() : -1;
   if (imp.getStackSize() == 1) currentImage = -1;
   int channel = 0, slice = 0, frame = 0;
   boolean hyperstack = imp.isHyperStack();
   if (hyperstack) {
     channel = imp.getChannel();
     slice = imp.getSlice();
     frame = imp.getFrame();
   }
   drawNames = overlay.getDrawNames();
   boolean drawLabels = drawNames || overlay.getDrawLabels();
   for (int i = 0; i < n; i++) {
     if (overlay == null) break;
     Roi roi = overlay.get(i);
     if (hyperstack && roi.getPosition() == 0) {
       int c = roi.getCPosition();
       int z = roi.getZPosition();
       int t = roi.getTPosition();
       if ((c == 0 || c == channel) && (z == 0 || z == slice) && (t == 0 || t == frame))
         drawRoi(g, roi, drawLabels ? i + LIST_OFFSET : -1);
     } else {
       int position = roi.getPosition();
       if (position == 0 || position == currentImage)
         drawRoi(g, roi, drawLabels ? i + LIST_OFFSET : -1);
     }
   }
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   drawNames = false;
 }
Exemple #4
0
 public void draw(Graphics g) {
   updatePolygon();
   Color color = strokeColor != null ? strokeColor : ROIColor;
   boolean hasHandles = xSpline != null || type == POLYGON || type == POLYLINE || type == ANGLE;
   boolean isActiveOverlayRoi = !overlay && isActiveOverlayRoi();
   if (isActiveOverlayRoi && !hasHandles) {
     if (color == Color.cyan) color = Color.magenta;
     else color = Color.cyan;
   }
   boolean fill = false;
   mag = getMagnification();
   if (fillColor != null && !isLine() && state != CONSTRUCTING) {
     color = fillColor;
     fill = true;
   }
   g.setColor(color);
   Graphics2D g2d = (Graphics2D) g;
   if (stroke != null && !isActiveOverlayRoi) g2d.setStroke(getScaledStroke());
   if (xSpline != null) {
     if (type == POLYLINE || type == FREELINE) {
       drawSpline(g, xSpline, ySpline, splinePoints, false, fill, isActiveOverlayRoi);
       if (wideLine && !overlay) {
         g2d.setStroke(onePixelWide);
         g.setColor(getColor());
         drawSpline(g, xSpline, ySpline, splinePoints, false, fill, isActiveOverlayRoi);
       }
     } else drawSpline(g, xSpline, ySpline, splinePoints, true, fill, isActiveOverlayRoi);
   } else {
     if (type == POLYLINE || type == FREELINE || type == ANGLE || state == CONSTRUCTING) {
       g.drawPolyline(xp2, yp2, nPoints);
       if (wideLine && !overlay) {
         g2d.setStroke(onePixelWide);
         g.setColor(getColor());
         g.drawPolyline(xp2, yp2, nPoints);
       }
     } else {
       if (fill) {
         if (isActiveOverlayRoi) {
           g.setColor(Color.cyan);
           g.drawPolygon(xp2, yp2, nPoints);
         } else g.fillPolygon(xp2, yp2, nPoints);
       } else g.drawPolygon(xp2, yp2, nPoints);
     }
     if (state == CONSTRUCTING && type != FREEROI && type != FREELINE) drawStartBox(g);
   }
   if (hasHandles && state != CONSTRUCTING && clipboard == null && !overlay) {
     int size2 = HANDLE_SIZE / 2;
     if (activeHandle > 0)
       drawHandle(g, xp2[activeHandle - 1] - size2, yp2[activeHandle - 1] - size2);
     if (activeHandle < nPoints - 1)
       drawHandle(g, xp2[activeHandle + 1] - size2, yp2[activeHandle + 1] - size2);
     handleColor = strokeColor != null ? strokeColor : ROIColor;
     drawHandle(g, xp2[0] - size2, yp2[0] - size2);
     handleColor = Color.white;
     for (int i = 1; i < nPoints; i++) drawHandle(g, xp2[i] - size2, yp2[i] - size2);
   }
   drawPreviousRoi(g);
   if (!(state == MOVING_HANDLE || state == CONSTRUCTING || state == NORMAL)) showStatus();
   if (updateFullWindow) {
     updateFullWindow = false;
     imp.draw();
   }
 }