graphics.drawImage(img, logoX, logoY, null);
if (img!=null) try { graphics.drawImage(img, logoX, logoY, null); } catch (NullPointerException e) {  }
private void printLegend(Graphics graphics, int width, int height, int page, int pagenum) {	Settings s = Settings.getInstance();		//prepare	int navigatorWidth = navigator.width, navigatorHeight = navigator.height;		Image img = Toolkit.getDefaultToolkit().getImage(s.getLegendLogo());	MediaTracker mediaTracker = new MediaTracker(VisualDCT.getInstance());	mediaTracker.addImage(img, 0);	try	{		mediaTracker.waitForID(0);	}	catch (InterruptedException ie)	{	}	int logoWidth = img.getWidth(null), logoHeight = img.getHeight(null)+8;		String label = "";	if (VisualDCT.getInstance().getOpenedFile()!=null)		label = VisualDCT.getInstance().getOpenedFile().getName()+", ";	label+=DateFormat.getDateInstance(DateFormat.SHORT).format(new Date())+", "			+(int)(ViewState.getInstance().getScale()*1000+0.5)/10.0+"% scale";	if (s.getLegendVisibility()==1) label+=", "+pagenum+" pages";	if (s.getLegendVisibility()==2) label+=", Page "+page+" of "+pagenum;				Font font =FontMetricsBuffer.getInstance().getAppropriateFont(		Constants.DEFAULT_FONT, Font.PLAIN, 		label, 200, 16);				FontMetrics fm = FontMetricsBuffer.getInstance().getFontMetrics(font);	int labelWidth = fm.stringWidth(label)+8, labelHeight = fm.getHeight();		int legendWidth = navigatorWidth + Math.max(logoWidth, labelWidth),		legendHeight = Math.max(navigatorHeight, logoHeight+labelHeight);		int navX, navY, labX=0, labY, logoX, logoY;	switch (s.getLegendPosition()) {		case 1:	 			navX=0; navY=0;			labX=navigatorWidth+8; labY=labelHeight;			logoX=navigatorWidth; logoY=labelHeight+8;			break;		case 2: 			navX=width-navigatorWidth-1; navY=0;			labX=width-navigatorWidth-labelWidth-8-1; labY=labelHeight;			logoX=width-navigatorWidth-logoWidth-1; logoY=labelHeight+8;			break;		case 3: 			navX=0; navY=height-navigatorHeight-1; 			labX=navigatorWidth+8; labY=height-1;			logoX=navigatorWidth; logoY=height-labelHeight-logoHeight-1;			break;		default:		case 4: 			navX=width-navigatorWidth-1; navY=height-navigatorHeight-1;			labX=width-navigatorWidth-labelWidth-8-1; labY=height-1;			logoX=width-navigatorWidth-logoWidth-1;  logoY=height-labelHeight-logoHeight-1;	}		// paints		//navigator	ViewState view = ViewState.getInstance();		AffineTransform transf = ((Graphics2D)graphics).getTransform();		graphics.translate(navX, navY);	graphics.setClip(new Rectangle(0,0,navigatorWidth, navigatorHeight));		Dimension navigatorSize = new Dimension(navigatorWidth, navigatorHeight);	double xscale = navigatorWidth/(double)view.getWidth();	double yscale = navigatorHeight/(double)view.getHeight();	double nscale = Math.min(xscale, yscale);		((Graphics2D)graphics).scale(nscale, nscale);		graphics.setColor(Constants.BACKGROUND_COLOR);	graphics.fillRect(0, 0, view.getWidth(), view.getHeight());		double rx=(double)view.getRx()*nscale, ry=(double)view.getRy()*nscale;	int rwidth = (int)(view.getViewWidth()*nscale), rheight = (int)(view.getViewHeight()*nscale);		view.setRx(0); view.setRy(0);	viewGroup.paintComponents(graphics, false, isFlat());	((Graphics2D)graphics).setTransform(transf);	graphics.translate(navX, navY);	graphics.setColor(Color.black);	graphics.drawRect((int)rx, (int)ry, rwidth, rheight);//	add lock rectangle if necessary	 final int min = 8;	 if ((rwidth<min) || (rheight<min)) {		 graphics.setColor(Color.lightGray);		 graphics.drawRect((int)(rx-min), (int)(ry-min), 		 		(int)(rwidth+2*min), (int)(rheight+2*min));	 }	 	graphics.setColor(Color.gray);	graphics.drawRect(0, 0, navigatorWidth-1, navigatorHeight-1);		graphics.setClip(null);	((Graphics2D)graphics).setTransform(transf);		graphics.drawImage(img, logoX, logoY, null);		graphics.setColor(Constants.FRAME_COLOR);	graphics.setFont(font);	graphics.drawString(label, labX, labY);}