@Override public void paint(Graphics g){
  Graphics2D g2d=(Graphics2D)g;
  g2d.setFont(gui_font);
synchronized (main_img) {
    g2d.drawImage(main_img,0,0,null);
  }
  for (  MapMarker marker : markers) {
    int x=(int)((shift_x + marker.x * 4) * zoom_level) + 2;
    int y=(int)((shift_y + marker.z * 4) * zoom_level) + 2;
    g2d.setColor(marker.color);
    g2d.drawLine(x - 3,y - 3,x + 3,y + 3);
    g2d.drawLine(x + 3,y - 3,x - 3,y + 3);
  }
  int z_p=100 - (zoom_level_pos * 100 / (zoom_levels.length - 1));
  int mx=getWidth() / 2;
  int my=getHeight() / 2;
  int px=(int)((mx / zoom_level - shift_x) / 4);
  int py=(int)((my / zoom_level - shift_y) / 4);
  FontMetrics metrics=g2d.getFontMetrics(gui_font);
  int fw;
  int fh=metrics.getHeight();
  g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,gui_bg_alpha));
  if (selection_start_x != selection_end_x && selection_start_z != selection_end_z) {
    screen_sx=(int)((shift_x + selection_start_x * 4) * zoom_level);
    screen_sz=(int)((shift_y + selection_start_z * 4) * zoom_level);
    screen_ex=(int)((shift_x + selection_end_x * 4) * zoom_level);
    screen_ez=(int)((shift_y + selection_end_z * 4) * zoom_level);
    int t;
    if (screen_ex < screen_sx) {
      t=screen_sx;
      screen_sx=screen_ex;
      screen_ex=t;
    }
    if (screen_ez < screen_sz) {
      t=screen_sz;
      screen_sz=screen_ez;
      screen_ez=t;
    }
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,gui_bg_alpha));
    g2d.setColor(Color.red);
    g2d.fillRect(screen_sx,screen_sz,screen_ex - screen_sx,screen_ez - screen_sz);
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1));
    g2d.setColor(Color.black);
    g2d.drawRect(screen_sx,screen_sz,screen_ex - screen_sx,screen_ez - screen_sz);
    g2d.setColor(Color.white);
    g2d.fillRect(screen_sx - 2,screen_sz - 2,4,4);
    g2d.fillRect(screen_sx - 2,screen_ez - 2,4,4);
    g2d.fillRect(screen_ex - 2,screen_sz - 2,4,4);
    g2d.fillRect(screen_ex - 2,screen_ez - 2,4,4);
    g2d.setColor(Color.black);
    g2d.drawRect(screen_sx - 2,screen_sz - 2,4,4);
    g2d.drawRect(screen_sx - 2,screen_ez - 2,4,4);
    g2d.drawRect(screen_ex - 2,screen_sz - 2,4,4);
    g2d.drawRect(screen_ex - 2,screen_ez - 2,4,4);
  }
 else {
    screen_sx=-1;
    screen_ex=-1;
    screen_sz=-1;
    screen_ez=-1;
  }
  g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,gui_bg_alpha));
  gui_text.clear();
  gui_text.add(zoom_level + "x");
  gui_text.add("(" + px + ","+ py+ ")");
  gui_text.add(Messages.getString("PreviewPanel.SELECTION"));
  gui_text.add("(" + selection_start_x + ","+ selection_start_z+ ")");
  gui_text.add("(" + selection_end_x + ","+ selection_end_z+ ")");
  g2d.setColor(gui_bg_color);
  g2d.fillRect(0,0,100,130 + gui_text.size() * (fh + 5));
  g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1));
  g2d.setColor(gui_color);
  g2d.drawRect(40,20,20,100);
  g2d.drawRect(37,18 + z_p,26,5);
  int start=125 + fh;
  for (  String s : gui_text) {
    fw=metrics.stringWidth(s);
    g2d.drawString(s,50 - fw / 2,start);
    start+=5 + fh;
  }
}

@ Override public void paint ( Graphics g ) { Graphics2D g2d = ( Graphics2D ) g ; g2d . setFont ( gui_font ) ; synchronized ( main_img ) { g2d . drawImage ( main_img , 0 , 0 , null ) ; } for ( MapMarker marker : markers ) { int x = ( int ) ( ( shift_x + marker . x * 4 ) * zoom_level ) + 2 ; int y = ( int ) ( ( shift_y + marker . z * 4 ) * zoom_level ) + 2 ; g2d . setColor ( marker . color ) ; g2d . drawLine ( x - 3 , y - 3 , x + 3 , y + 3 ) ; g2d . drawLine ( x + 3 , y - 3 , x - 3 , y + 3 ) ; } int z_p = 100 - ( zoom_level_pos * 100 / ( zoom_levels . length - 1 ) ) ; int mx = getWidth ( ) / 2 ; int my = getHeight ( ) / 2 ; int px = ( int ) ( ( mx / zoom_level - shift_x ) / 4 ) ; int py = ( int ) ( ( my / zoom_level - shift_y ) / 4 ) ; FontMetrics metrics = g2d . getFontMetrics ( gui_font ) ; int fw ; int fh = metrics . getHeight ( ) ; g2d . setComposite ( AlphaComposite . getInstance ( AlphaComposite . SRC_OVER , gui_bg_alpha ) ) ; if ( selection_start_x != selection_end_x && selection_start_z != selection_end_z ) { screen_sx = ( int ) ( ( shift_x + selection_start_x * 4 ) * zoom_level ) ; screen_sz = ( int ) ( ( shift_y + selection_start_z * 4 ) * zoom_level ) ; screen_ex = ( int ) ( ( shift_x + selection_end_x * 4 ) * zoom_level ) ; screen_ez = ( int ) ( ( shift_y + selection_end_z * 4 ) * zoom_level ) ; int t ; if ( screen_ex < screen_sx ) { t = screen_sx ; screen_sx = screen_ex ; screen_ex = t ; } if ( screen_ez < screen_sz ) { t = screen_sz ; screen_sz = screen_ez ; screen_ez = t ; } g2d . setComposite ( AlphaComposite . getInstance ( AlphaComposite . SRC_OVER , gui_bg_alpha ) ) ; g2d . setColor ( Color . red ) ; g2d . fillRect ( screen_sx , screen_sz , screen_ex - screen_sx , screen_ez - screen_sz ) ; g2d . setComposite ( AlphaComposite . getInstance ( AlphaComposite . SRC_OVER , 1 ) ) ; g2d . setColor ( Color . black ) ; g2d . drawRect ( screen_sx , screen_sz , screen_ex - screen_sx , screen_ez - screen_sz ) ; g2d . setColor ( Color . white ) ; g2d . fillRect ( screen_sx - 2 , screen_sz - 2 , 4 , 4 ) ; g2d . fillRect ( screen_sx - 2 , screen_ez - 2 , 4 , 4 ) ; g2d . fillRect ( screen_ex - 2 , screen_sz - 2 , 4 , 4 ) ; g2d . fillRect ( screen_ex - 2 , screen_ez - 2 , 4 , 4 ) ; g2d . setColor ( Color . black ) ; g2d . drawRect ( screen_sx - 2 , screen_sz - 2 , 4 , 4 ) ; g2d . drawRect ( screen_sx - 2 , screen_ez - 2 , 4 , 4 ) ; g2d . drawRect ( screen_ex - 2 , screen_sz - 2 , 4 , 4 ) ; g2d . drawRect ( screen_ex - 2 , screen_ez - 2 , 4 , 4 ) ; } else { screen_sx = - 1 ; screen_ex = - 1 ; screen_sz = - 1 ; screen_ez = - 1 ; } g2d . setComposite ( AlphaComposite . getInstance ( AlphaComposite . SRC_OVER , gui_bg_alpha ) ) ; gui_text . clear ( ) ; gui_text . add ( zoom_level + "x" ) ; gui_text . add ( "(" + px + "," + py + ")" ) ; gui_text . add ( Messages . getString ( "PreviewPanel.SELECTION" ) ) ; gui_text . add ( "(" + selection_start_x + "," + selection_start_z + ")" ) ; gui_text . add ( "(" + selection_end_x + "," + selection_end_z + ")" ) ; g2d . setColor ( gui_bg_color ) ; g2d . fillRect ( 0 , 0 , 100 , 130 + gui_text . size ( ) * ( fh + 5 ) ) ; g2d . setComposite ( AlphaComposite . getInstance ( AlphaComposite . SRC_OVER , 1 ) ) ; g2d . setColor ( gui_color ) ; g2d . drawRect ( 40 , 20 , 20 , 100 ) ; g2d . drawRect ( 37 , 18 + z_p , 26 , 5 ) ; int start = 125 + fh ; for ( String s : gui_text ) { fw = metrics . stringWidth ( s ) ; g2d . drawString ( s , 50 - fw / 2 , start ) ; start += 5 + fh ; } }
main repaint procedure ( run as much as possible ) .
