/** * This is a wrapper that preserves the layer settings on the Zone object. It calls {@link * takeEntireMapScreenShot()} to to the real work. * * @return the image to be saved to a file */ private static BufferedImage entireMapScreenShotWithLayers() throws Exception, OutOfMemoryError { final Zone zone = TabletopTool.getFrame().getCurrentZoneRenderer().getZone(); // // Preserve settings // // psuedo-layers final Zone.VisionType savedVision = zone.getVisionType(); final boolean savedFog = zone.hasFog(); final boolean savedBoard = zone.drawBoard(); // real layers final boolean savedToken = Zone.Layer.TOKEN.isEnabled(); final boolean savedHidden = Zone.Layer.GM.isEnabled(); final boolean savedObject = Zone.Layer.OBJECT.isEnabled(); final boolean savedBackground = Zone.Layer.BACKGROUND.isEnabled(); // // set according to dialog options // zone.setHasFog(ExportLayers.LAYER_FOG.isChecked()); if (!ExportLayers.LAYER_VISIBILITY.isChecked()) zone.setVisionType(Zone.VisionType.OFF); zone.setDrawBoard(ExportLayers.LAYER_BOARD.isChecked()); Zone.Layer.TOKEN.setEnabled(ExportLayers.LAYER_TOKEN.isChecked()); Zone.Layer.GM.setEnabled(ExportLayers.LAYER_HIDDEN.isChecked()); Zone.Layer.OBJECT.setEnabled(ExportLayers.LAYER_OBJECT.isChecked()); Zone.Layer.BACKGROUND.setEnabled(ExportLayers.LAYER_BACKGROUND.isChecked()); // This 'cache invalidation' is handled by setZone inside takeEntireMapScreenShot() // but it should be more robust. // TabletopTool.getFrame().getCurrentZoneRenderer().invalidateCurrentViewCache(); // // screenshot! // MCL: NOTE: while turning off Fog, there is a possibility the players // may see the map flash for a second with fog turned off-- need to look into // whether this is true. BufferedImage image = null; try { image = takeEntireMapScreenShot(); } finally { // // Restore settings // zone.setHasFog(savedFog); zone.setVisionType(savedVision); zone.setDrawBoard(savedBoard); Zone.Layer.TOKEN.setEnabled(savedToken); Zone.Layer.GM.setEnabled(savedHidden); Zone.Layer.OBJECT.setEnabled(savedObject); Zone.Layer.BACKGROUND.setEnabled(savedBackground); // TabletopTool.getFrame().getCurrentZoneRenderer().invalidateCurrentViewCache(); } return image; }