This subclass of ImageCanvas has special provisions for plots: - Zooming: sets the plot range - Scrolling: moves data area This behavior is suppressed if the plot is frozen
| 21 | * This behavior is suppressed if the plot is frozen |
| 22 | * */ |
| 23 | public class PlotCanvas extends ImageCanvas { |
| 24 | /** The plot displayed */ |
| 25 | Plot plot; |
| 26 | int xScrolled, yScrolled; //distance scrolled so far |
| 27 | int oldWidth, oldHeight; |
| 28 | int rangeArrowIndexWhenPressed = -1; |
| 29 | @AstroImageJ(reason = "Support custom zoom indicator for MP") |
| 30 | private BooleanSupplier zoomed = () -> false; |
| 31 | @AstroImageJ(reason = "Support custom zoom indicator for MP") |
| 32 | private static final Image ZOOM_INDICATOR = UIHelper.createImage("Astronomy/images/icons/multiplot/zoom.png"); |
| 33 | |
| 34 | /** Creates a new PlotCanvas */ |
| 35 | public PlotCanvas(ImagePlus imp) { |
| 36 | super(imp); |
| 37 | oldWidth = imp.getWidth(); |
| 38 | oldHeight = imp.getHeight(); |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | @AstroImageJ(reason = """ |
| 43 | Support custom zoom indicator for MP |
| 44 | Support vectorized plot and plot scaling |
| 45 | """) |
| 46 | public void paint(Graphics g) { |
| 47 | if (plot == null) { |
| 48 | imp.setProperty(VectorPlotDrawing.PROPERTY_KEY, null); |
| 49 | super.paint(g); |
| 50 | if (zoomed.getAsBoolean()) { |
| 51 | g.drawImage(ZOOM_INDICATOR, 0, 0, null); |
| 52 | } |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | imp.setProperty(VectorPlotDrawing.PROPERTY_KEY, plot); |
| 57 | ScopedValue.where(VectorPlotDrawing.SCALED_PLOT, plot.isAijPlot()).run(() -> super.paint(g)); |
| 58 | if (zoomed.getAsBoolean()) { |
| 59 | g.drawImage(ZOOM_INDICATOR, 0, 0, null); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | @AstroImageJ(reason = "Support custom zoom indicator for MP") |
| 64 | public void setZoomed(BooleanSupplier zoomed) { |
| 65 | this.zoomed = zoomed; |
| 66 | } |
| 67 | |
| 68 | /** Tells the PlotCanvas which plot to use for zooming etc. |
| 69 | * Call this immediately after construction */ |
| 70 | public void setPlot(Plot plot) { |
| 71 | this.plot = plot; |
| 72 | } |
| 73 | |
| 74 | /** Returns the Plot displayed in this canvas */ |
| 75 | public Plot getPlot() { |
| 76 | return plot; |
| 77 | } |
| 78 | |
| 79 | /** Whether the plot is frozen, i.e. its ImageProcessor can not be changed */ |
| 80 | public boolean isFrozen() { |
nothing calls this directly
no test coverage detected