// $Id: ToInfinityAndBeyond.java,v 1.5 2004/06/14 20:51:52 m31 Exp $
//
// This file is part of the program suite "Principia Mathematica II"
// which is a working prototype for the main project:
// "Hilbert II" - http://www.qedeq.org
//
// Copyright 2001-2004  Michael Meyling <mime@qedeq.org>.
//
// "Principia Mathematica II" is free software; you can redistribute
// it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

package com.meyling.principia.gui.puzzle;


import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.MalformedURLException;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.swing.JFrame;

import com.meyling.principia.log.Trace;


/**
 * Info window.
 *
 * @version     $Revision: 1.5 $
 * @author      Michael Meyling
 */
public class ToInfinityAndBeyond extends JFrame {

    private final Stars field;
    
    private Sequencer sequencer;


    public ToInfinityAndBeyond() {
        final String METHOD = "Constructor";
        this.setSize(new Dimension(400, 400));

        this.getContentPane().setLayout(null);
        addNotify();

        field = new Stars();
        field.setSize(400,400);
        this.getContentPane().add(field);

        this.addWindowListener( new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                sequencer.close();
                dispose();
            }
        });

        setTitle("To Infinity And Beyond.");
        this.getContentPane().repaint();
        field.init();
        field.start();

        try {
            final Sequence sequence = MidiSystem.getSequence(
                this.getClass().getResource(
                "/com/meyling/principia/resources/slow_drag_joplin.mid"));

            // Create a sequencer for the sequence
            sequencer = MidiSystem.getSequencer();
            sequencer.open();
            sequencer.setSequence(sequence);

            // Start playing
            sequencer.start();
        } catch (MalformedURLException e) {
            Trace.trace(this, METHOD, e);
        } catch (IOException e) {
            Trace.trace(this, METHOD, e);
        } catch (MidiUnavailableException e) {
            Trace.trace(this, METHOD, e);
        } catch (InvalidMidiDataException e) {
            Trace.trace(this, METHOD, e);
        } catch (RuntimeException e) {
            Trace.trace(this, METHOD, e);
        }

    }


    public static final void main(final String args[]) {
        try {
            final ToInfinityAndBeyond infinity = new ToInfinityAndBeyond();
            infinity.show();
        } catch (Exception e){
            e.printStackTrace();
        }
    }



 }
