Draw the scale bar, based on the current configuration. If {previewOnly} is true, only the active slice will be labeled with a scalebar. If it is false, all slices of the stack will be labeled. This method chooses whether to use an overlay or the drawing tool to create the scalebar.
(boolean previewOnly)
| 576 | * drawing tool to create the scalebar. |
| 577 | */ |
| 578 | void updateScalebar(boolean previewOnly) { |
| 579 | removeScalebar(); |
| 580 | |
| 581 | Overlay scaleBarOverlay; |
| 582 | try { |
| 583 | scaleBarOverlay = createScaleBarOverlay(); |
| 584 | } catch (MissingRoiException e) { |
| 585 | return; // Simply don't draw the scalebar. |
| 586 | } |
| 587 | |
| 588 | Overlay impOverlay = imp.getOverlay(); |
| 589 | if (impOverlay==null) { |
| 590 | impOverlay = new Overlay(); |
| 591 | } |
| 592 | |
| 593 | if (config.useOverlay) { |
| 594 | for (Roi roi : scaleBarOverlay) |
| 595 | impOverlay.add(roi); |
| 596 | imp.setOverlay(impOverlay); |
| 597 | } else { |
| 598 | if (previewOnly) { |
| 599 | ImageProcessor ip = imp.getProcessor(); |
| 600 | drawOverlayOnProcessor(scaleBarOverlay, ip); |
| 601 | imp.updateAndDraw(); |
| 602 | } else { |
| 603 | ImageStack stack = imp.getStack(); |
| 604 | for (int i=1; i<=stack.size(); i++) { |
| 605 | ImageProcessor ip = stack.getProcessor(i); |
| 606 | drawOverlayOnProcessor(scaleBarOverlay, ip); |
| 607 | imp.updateAndDraw(); |
| 608 | } |
| 609 | imp.setStack(stack); |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | void drawOverlayOnProcessor(Overlay overlay, ImageProcessor processor) { |
| 615 | if (processor.getBitDepth() == 8 || processor.getBitDepth() == 24) { |
no test coverage detected