sclass ImageSurface_HighlightRegion > ImageSurfaceMouseHandler is G2Drawable { settable RegionPainter regionPainter = new RegionBoundingBoxPainter; FastRegions_BWImage regions; int iHighlightedRegion; Pt lastPt; *(ImageSurface is) { if (containsInstance(is.tools, getClass())) ret; register(is); is.overlays.add(this); } public void close :: after { is.overlays.remove(this); } public void mouseMoved aka mouseEntered(MouseEvent e) { lastPt = getPt(e); update(); } public void mouseExited(MouseEvent e) { lastPt = null; update(); } int newRegion() { if (lastPt == null || regions == null) ret 0; ret regions.regionAt(lastPt.x, lastPt.y); } void update { int r = newRegion(); if (iHighlightedRegion != r) { iHighlightedRegion = r; is.repaint(); } } void setRegions(FastRegions_BWImage regions) { this.regions = regions; iHighlightedRegion = -abs(iHighlightedRegion); update(); } public void drawOn(Graphics2D g) { if (iHighlightedRegion == 0 || regionPainter == null) ret; regionPainter.zoomX(is.getZoomX()); regionPainter.zoomY(is.getZoomY()); regionPainter.g(g); afterwards { regionPainter.g(null); } regionPainter.regions(regions).iRegion(iHighlightedRegion); regionPainter.drawRegion(); } }