/*
 * This file is part of the Turtle project
 *
 * (c) 2011 Julien Brochet <julien.brochet@etu.univ-lyon1.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

package turtle.gui;

import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;

import turtle.Kernel;
import turtle.entity.Game;
import turtle.entity.field.Field;
import turtle.gui.view.BallView;
import turtle.gui.view.FieldView;

/**
 * Fenêtre principale (ou se déroule le jeu de foot)
 *
 * @author Julien Brochet <julien.brochet@etu.univ-lyon1.fr>
 * @since 1.0
 */
public class GameWindow extends AbstractWindow
{
    protected BufferStrategy mBufferStrategy;

    protected Graphics mBuffer;

    public GameWindow(Kernel kernel, Game game, AbstractWindow parent)
    {
        super(kernel, game, parent);

        initialize();

        setVisible(true);

        setIgnoreRepaint(true);
        createBufferStrategy(2);

        mBufferStrategy = getBufferStrategy();
        mBuffer = mBufferStrategy.getDrawGraphics();
    }

    /**
     * Création de la fenêtre et de ses composants
     */
    private void initialize()
    {
        setTitle("Game");

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setSize(mGame.getField().getDimension());
        setLocationRelativeTo(null);
        setResizable(false);
    }

    public void render()
    {
        Field field = mGame.getField();

        FieldView.paint(field, mBuffer);

        if (mGame.isLaunched()) {
            BallView.paint(field.getBall(), mBuffer);
        }

        mBufferStrategy.show();
    }

    @Override
    public void updateView(Object arg)
    {
        render();
    }
}

@@ -286,16 +286,64 @@
 aphics;%0A
+import java.awt.Image;%0Aimport java.awt.Toolkit;%0A
 import j
@@ -743,55 +743,8 @@
 w%0A%7B%0A
-    protected BufferStrategy mBufferStrategy;%0A%0A
     
@@ -772,16 +772,45 @@
 uffer;%0A%0A
+    protected Image mImage;%0A%0A
     publ
@@ -968,175 +968,8 @@
 ue);
-%0A%0A        setIgnoreRepaint(true);%0A        createBufferStrategy(2);%0A%0A        mBufferStrategy = getBufferStrategy();%0A        mBuffer = mBufferStrategy.getDrawGraphics();
 %0A   
@@ -1290,27 +1290,50 @@
     
-public void render(
+@Override%0A    public void paint(Graphics g
 )%0A  
@@ -1373,24 +1373,260 @@
 etField();%0A%0A
+        // Double buffering software%0A        if (mBuffer == null) %7B%0A            mImage = createImage((int) field.getDimension().getWidth(), (int) field.getDimension().getHeight());%0A            mBuffer = mImage.getGraphics();%0A        %7D%0A%0A
         Fiel
@@ -1766,29 +1766,38 @@
     
-mBufferStrategy.show(
+g.drawImage(mImage, 0, 0, this
 );%0A 
@@ -1875,12 +1875,13 @@
   re
-nder
+paint
 ();%0A

use double buffering software instead of hardware