package com.bbn.openmap.image; import com.bbn.openmap.Layer; import com.bbn.openmap.MapBean; import com.bbn.openmap.MapHandler; import com.bbn.openmap.proj.Projection; import com.bbn.openmap.proj.ProjectionFactory; import java.awt.Component; import java.awt.Graphics; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import java.util.ArrayList; import javax.swing.ImageIcon; /** * AbstractMapBeanPrinter is a generic class for creating print jobs * with MapBeans in it. This class can be subclassed to add extra * printing code, for istance to add text labels, map thumbnails, or any * other "extra" printable in addition to the map itself. * * Any subclass must implement the print(...) method specified in interface * Printable. * * Subclasses may use the following functions in the implementation of the * print method: * * alignPaper(...) - aligns the paper so that (0,0) represents the upper left * corner of the printable area. * * drawMap(...) - draws the map to a specified area of the print with * the specified size. * * Protected variables layersToBePrinted and printProjection may also be * accessed, perhaps to manipulate an off-screen image. * * Modified from MapBeanPrinter.java distributed with openmap-4.6. * * @author Brian Sperlongano */ public abstract class AbstractMapBeanPrinter implements Printable { protected Layer[] layersToBePrinted; protected Projection printProjection; /** * Constructor * * @param layersToBePrinted Layers to print * @param printProj Projection to print * */ public AbstractMapBeanPrinter(Layer[] layersToBePrinted, Projection printProj) { this.layersToBePrinted = layersToBePrinted; this.printProjection = printProj; } /** * Constructor * * @param mapHandlerToBePrinted MapHandler which contains the MapBean and * Layers to be printed. * */ public AbstractMapBeanPrinter(MapHandler mapHandlerToBePrinted) { this.printProjection = ((MapBean)(mapHandlerToBePrinted.getAll("com.bbn.openmap.MapBean") .toArray()[0])) .getProjection().makeClone(); this.layersToBePrinted = convertToLayers (mapHandlerToBePrinted.getAll("com.bbn.openmap.Layer").toArray()); } /** * Constructor * * @param mapBean MapBean to be printed * */ public AbstractMapBeanPrinter(MapBean mapBean) { this.printProjection = mapBean.getProjection().makeClone(); Component[] mapChildren = mapBean.getComponents(); ArrayList mapLayerArrayList = new ArrayList(); for(int i=0; i