public void paint(Graphics g) {
	  	if (offsetPaint==null)  offsetPaint=createImage(257, 257);
	  	if (toRefresh) {
		    setPreferredSize(new Dimension(getMode()[0]*zoom, getMode()[1]*zoom));
	  		g.clearRect(0, 0, 100*8*zoom, 100*8*zoom);
	  		toRefresh=false;
	  		if (spanel!=null) {
	  			spanel.getGraphics().clearRect(0, 0, spanel.getWidth(), spanel.getHeight());
	  			spanel.getVerticalScrollBar().revalidate();
	  			spanel.getVerticalScrollBar().repaint();
	  			spanel.getHorizontalScrollBar().revalidate();
	  			spanel.getHorizontalScrollBar().repaint();
	  			spanel.revalidate();
	  			spanel.repaint();
	  		}
	  	}
		  if (image!=null && image.getImage()!=null && map != null && !refreshSelection) {
			  Graphics ofg = offsetPaint.getGraphics();
			  for (int i=0;i<map.size();i++) {
				  if (map.get(i) == -1) continue;
				  ofg.drawImage( image.getImage().getSubimage((map.get(i) % (image.getImage().getWidth()/(8*zoom)))*(8*zoom), (map.get(i) / (image.getImage().getWidth()/(8*zoom))) * (8*zoom), (8*zoom), (8*zoom)), (i%(width/8))*(8*zoom), (i/(width/8))*(8*zoom), null);
			  }
		}
		if (active) {
		g.drawImage(offsetPaint, 0, 0, null);
		if (gridV) g.drawImage(grid.getSubimage(0, 0, width*zoom+1, height*zoom+1), 0, 0, null);
		g.drawImage(selection, 0, 0, null);
		refreshSelection = false;
		}
  }