int sx = origX + (view.getGridSize() - view.getRx()) % gridSize; int y0 = origY + (view.getGridSize() - view.getRy()) % gridSize;
int sx = origX; if (view.getRx()>0) sx += (view.getGridSize() - view.getRx()) % gridSize;  int y0 = origY; if (view.getRy()>0) y0 += (view.getGridSize() - view.getRy()) % gridSize;
private void redraw(Graphics g) {	if (Settings.getInstance().getNavigator())		createNavigatorImage();	ViewState view = ViewState.getInstance();			if ((canvasImage==null) || 		(canvasSize.width!=width) || 		(canvasSize.height!=height)) {		    canvasImage = getWorkspacePanel().createImage(width, height);	    if (canvasImage==null) return;	    canvasSize = new Dimension(width, height);	    canvasGraphics = canvasImage.getGraphics();		// free old image memory	    	    System.gc();	}	int origX = 0;	int origY = 0;	int w = width;	int h = height;	canvasGraphics.setColor(Color.gray);	if (view.getRx()<0)	{		origX = -view.getRx();		canvasGraphics.fillRect(0, 0, origX, height);	}		if (view.getRy()<0)	{		origY = -view.getRy();		canvasGraphics.fillRect(origX, 0, width, origY);	}			if ((view.getRx()+view.getViewWidth())>(int)(view.getScale()*view.getWidth()))	{		w += (int)(view.getScale()*view.getWidth()) - view.getRx() - view.getViewWidth();		canvasGraphics.fillRect(w, origY, width, height);	}		if ((view.getRy()+view.getViewHeight())>(int)(view.getScale()*view.getHeight()))	{		h += (int)(view.getScale()*view.getHeight()) - view.getRy() - view.getViewHeight();		canvasGraphics.fillRect(origX, h, width, height);	}	canvasGraphics.setColor(Constants.BACKGROUND_COLOR);	canvasGraphics.fillRect(origX, origY, w, h);	if (Settings.getInstance().getShowGrid())	{		canvasGraphics.setColor(Constants.GRID_COLOR);		int gridSize = view.getGridSize();		int sx = origX + (view.getGridSize() - view.getRx()) % gridSize;		int y0 = origY + (view.getGridSize() - view.getRy()) % gridSize;//		int xsteps = view.getViewWidth() / gridSize + 1;//		int ysteps = view.getViewHeight() / gridSize + 1;		int xsteps = (w-origX+1) / gridSize + 1;		int ysteps = (h-origY+1) / gridSize + 1;		if (gridSize >= 15)		// crosses		for (int y=0; y < ysteps; y++) {			int x0 = sx;			for (int x=0; x < xsteps; x++) {				canvasGraphics.drawLine(x0-1, y0-1, x0+1, y0+1);				canvasGraphics.drawLine(x0-1, y0+1, x0+1, y0-1);				x0+=gridSize;			}			y0+=gridSize;		}		else		// dots		for (int y=0; y < ysteps; y++) {			int x0 = sx;			for (int x=0; x < xsteps; x++) {				canvasGraphics.drawLine(x0, y0, x0, y0);				x0+=gridSize;			}			y0+=gridSize;		}	}	viewGroup.paintComponents(canvasGraphics, false, isFlat());	if (canvasGraphics!=null) copyCanvasImage(g);	}