// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov  Date: 08/10/2012 8:48:10
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   VideoPlayer.java

package project;

import java.awt.*;
import java.awt.event.*;
import java.io.PrintStream;
import java.net.URL;
import java.util.Properties;
import javax.media.*;
import javax.swing.JDialog;

// Referenced classes of package project:
//            AccederADatos

public class VideoPlayer extends JDialog
    implements ControllerListener, WindowListener, MouseListener
{
    public class CPanel extends Panel
    {

        public CPanel()
        {
            setBackground(Color.black);
            setLayout(null);
        }
    }


    public VideoPlayer(String direccionDelVideo2)
    {
        super(AccederADatos.frameActivo, "IT Txartela", true);
        visualComponent = null;
        controlComponent = null;
        progressBar = null;
        CachingSize = 0L;
        panel = null;
        vPanel = null;
        controlPanelHeight = 0;
        showmeImage = null;
        zoomImageUp = null;
        zoomImageDn = null;
        cPanel = null;
        playingVideo = false;
        direccionDelVideo = "";
        direccionDelVideo = direccionDelVideo2;
        direccionDelVideo = "file:" + System.getProperties().getProperty("user.dir") + "/java/" + direccionDelVideo;
        Toolkit tkit = Toolkit.getDefaultToolkit();
        init();
        getContentPane().setLayout(null);
        addWindowListener(this);
        start();
        try
        {
            Thread.sleep(1000L);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    public void mostrar()
    {
        if(!playingVideo)
        {
            playingVideo = true;
            setSize(player.getVisualComponent().getPreferredSize().width + 5, player.getVisualComponent().getPreferredSize().height + 26);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setLocation((screenSize.width - player.getVisualComponent().getPreferredSize().width) / 2, (screenSize.height - player.getVisualComponent().getPreferredSize().height) / 2);
            setResizable(false);
            player.prefetch();
            player.setMediaTime(new Time(0L));
            player.start();
            setVisible(true);
        }
    }

    public static void main(String argv[])
    {
        VideoPlayer vp = new VideoPlayer("file:C:/versionesGuc/Gv/Working/project/java/Videos/changeorient.avi");
    }

    public void init()
    {
        getContentPane().setLayout(null);
        setBackground(Color.white);
        cPanel = new CPanel();
        getContentPane().add(cPanel);
        String mediaFile = null;
        URL codeBase = null;
        try
        {
            codeBase = new URL(direccionDelVideo);
            player = Manager.createPlayer(codeBase);
            player.addControllerListener(this);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    public synchronized void controllerUpdate(ControllerEvent event)
    {
        if(player == null)
            return;
        if(event instanceof RealizeCompleteEvent)
        {
            if((visualComponent = player.getVisualComponent()) != null)
            {
                visualComponent.addMouseListener(this);
                cPanel.add(visualComponent);
            }
            if((controlComponent = player.getControlPanelComponent()) != null)
            {
                player.setMediaTime(new Time(0L));
                player.prefetch();
                controlComponent.repaint();
                getContentPane().add(controlComponent);
            }
            reSize();
            player.prefetch();
        } else
        if(event instanceof EndOfMediaEvent)
        {
            player.setMediaTime(new Time(0L));
            player.prefetch();
            setVisible(false);
            playingVideo = false;
        } else
        if(event instanceof ControllerErrorEvent)
        {
            player = null;
            Fatal(((ControllerErrorEvent)event).getMessage());
        } else
        if(event instanceof PrefetchCompleteEvent)
        {
            if(visualComponent == null);
        } else
        if(event instanceof SizeChangeEvent)
            reSize();
        else
        if(!(event instanceof DurationUpdateEvent));
    }

    public void normalize()
    {
        reSize();
        fullscreen = false;
    }

    public void setFullscreen()
    {
        fullscreen = true;
        setSize(player.getVisualComponent().getPreferredSize().width + 5, player.getVisualComponent().getPreferredSize().height + 26);
        controlComponent.invalidate();
        repaint();
    }

    public void start()
    {
        if(player != null)
            player.realize();
    }

    public void stop()
    {
        if(player != null)
        {
            player.stop();
            player.deallocate();
            playingVideo = false;
        }
    }

    public void destroy()
    {
        player.close();
    }

    void Fatal(String s)
    {
        System.err.println("FATAL ERROR: " + s);
        throw new Error(s);
    }

    public synchronized void reSize()
    {
        setSize(player.getVisualComponent().getPreferredSize().width + 5, player.getVisualComponent().getPreferredSize().height + 26);
        cPanel.setBounds(0, 0, player.getVisualComponent().getPreferredSize().width, player.getVisualComponent().getPreferredSize().height);
        if(visualComponent != null)
            visualComponent.setBounds(0, 0, player.getVisualComponent().getPreferredSize().width, player.getVisualComponent().getPreferredSize().height);
        if(controlComponent != null)
        {
            controlComponent.setBounds(0, player.getVisualComponent().getPreferredSize().height, player.getVisualComponent().getPreferredSize().width, 24);
            controlComponent.invalidate();
        }
        repaint();
    }

    public void windowDeactivated(WindowEvent windowevent)
    {
    }

    public void windowClosed(WindowEvent windowevent)
    {
    }

    public void windowDeiconified(WindowEvent windowevent)
    {
    }

    public void windowOpened(WindowEvent windowevent)
    {
    }

    public void windowIconified(WindowEvent windowevent)
    {
    }

    public void windowClosing(WindowEvent p1)
    {
        stop();
        setVisible(false);
    }

    public void windowActivated(WindowEvent windowevent)
    {
    }

    public void mouseReleased(MouseEvent mouseevent)
    {
    }

    public void mouseEntered(MouseEvent mouseevent)
    {
    }

    public void mouseClicked(MouseEvent p1)
    {
        if(fullscreen)
            normalize();
        else
            setFullscreen();
    }

    public void mousePressed(MouseEvent mouseevent)
    {
    }

    public void mouseExited(MouseEvent mouseevent)
    {
    }

    private boolean fullscreen;
    private Player player;
    Component visualComponent;
    Component controlComponent;
    Component progressBar;
    long CachingSize;
    Panel panel;
    Panel vPanel;
    int controlPanelHeight;
    Image showmeImage[];
    Image zoomImageUp[];
    Image zoomImageDn[];
    CPanel cPanel;
    boolean playingVideo;
    String direccionDelVideo;
}