if ((Settings.getInstance().getLegendVisibility()==1 && pageIndex==0) || Settings.getInstance().getLegendVisibility()==2) printLegend(graphics, pageWidth, pageHeight, pageIndex+1, maxNumPage);
if ((Settings.getInstance().getLegendVisibility()==1 && pageIndex==0) || Settings.getInstance().getLegendVisibility()==2) { if (Settings.getInstance().getLegendVisibility()==1) { view.setViewWidth((int)(viewWidth*converter)); view.setViewHeight((int)(viewHeight*converter)); } printLegend(graphics, pageWidth, pageHeight, pageIndex+1, maxNumPage); }
public int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex) throws java.awt.print.PrinterException {		graphics.translate((int)pageFormat.getImageableX(),					   (int)pageFormat.getImageableY());	int pageWidth = (int)pageFormat.getImageableWidth();	int pageHeight = (int)pageFormat.getImageableHeight();	//graphics.clipRect(0, 0, pageWidth, pageHeight);	//System.out.println(pageFormat.getOrientation()==PageFormat.LANDSCAPE);	//if (true) throw new java.awt.print.PrinterException();		/*------------------------------------------------------------*/		ViewState view = ViewState.getInstance();		double screen2printer = 0;	switch (Page.getPrintMode()) {		case Page.TRUE_SCALE:			// 1:1 ratio			screen2printer = 72.0/getWorkspacePanel().getToolkit().getScreenResolution();			break;					case Page.USER_SCALE:			screen2printer = 72.0/getWorkspacePanel().getToolkit().getScreenResolution();			screen2printer *= Page.getUserScale();			break;					case Page.FIT_SCALE:			// fit to paper			double xscale = pageWidth/(double)view.getViewWidth();			double yscale = pageHeight/(double)view.getViewHeight();			screen2printer = Math.min(xscale, yscale)*view.getScale();			break;	}		double converter = screen2printer/view.getScale();	int w = (int)(view.getViewWidth()*converter);	int h = (int)(view.getViewHeight()*converter);	if (w==0 || h==0)		return NO_SUCH_PAGE;	if (Page.getPrintMode()==Page.FIT_SCALE)	{		// center (surely one page)		graphics.translate((pageWidth-w)/2,						   (pageHeight-h)/2);	}			int nCol = Math.max((int)Math.ceil((double)w/pageWidth), 1);	int nRow = Math.max((int)Math.ceil((double)h/pageHeight), 1);	int maxNumPage = nCol * nRow;	if (pageIndex>=maxNumPage)		return NO_SUCH_PAGE;	int iCol = pageIndex % nCol;	int iRow = pageIndex / nCol;	int x = iCol * pageWidth;	int y = iRow * pageHeight;	int imageWidth = Math.min(pageWidth, w-x);	int imageHeight = Math.min(pageHeight, h-y);		graphics.clipRect(0, 0, imageWidth, imageHeight);		int rx = view.getRx(); int ry = view.getRy();	double scale = view.getScale();	try	{				view.setScale(screen2printer);			view.setRx((int)(rx*converter+x));		view.setRy((int)(ry*converter+y));			if (Settings.getInstance().getShowGrid())		{			graphics.setColor(Constants.GRID_COLOR);			int gridSize = view.getGridSize();			int sx = view.getGridSize() - view.getRx() % gridSize;			int y0 = view.getGridSize() - view.getRy() % gridSize;			int xsteps = view.getViewWidth() / gridSize + 1;			int ysteps = view.getViewHeight() / gridSize + 1;				if (gridSize >= 15)			// crosses			for (int gy=0; gy < ysteps; gy++) {				int x0 = sx;				for (int gx=0; gx < xsteps; gx++) {					graphics.drawLine(x0-1, y0-1, x0+1, y0+1);					graphics.drawLine(x0-1, y0+1, x0+1, y0-1);					x0+=gridSize;				}				y0+=gridSize;			}			else			// dots			for (int gy=0; gy < ysteps; gy++) {				int x0 = sx;				for (int gx=0; gx < xsteps; gx++) {					graphics.drawLine(x0, y0, x0, y0);					x0+=gridSize;				}				y0+=gridSize;			}		}		// change color sheme 		loadBlackOnWhiteColorScheme();		viewGroup.paintComponents(graphics, false, isFlat());		//resets clipping		if (Page.getPrintMode()==Page.FIT_SCALE) graphics.translate(-(pageWidth-w)/2, -(pageHeight-h)/2);		graphics.setClip(0,0,pageWidth, pageHeight);		if ((Settings.getInstance().getLegendVisibility()==1 && pageIndex==0) || Settings.getInstance().getLegendVisibility()==2)		printLegend(graphics, pageWidth, pageHeight, pageIndex+1, maxNumPage);		}	catch (Exception e)	{	}	finally	{		view.setScale(scale);		view.setRx(rx); view.setRy(ry);		//		restore color sheme 		 loadWhiteOnBlackColorScheme();		 createNavigatorImage();	}		/*------------------------------------------------------------*/		System.gc();		return PAGE_EXISTS;}