/**************************************************************************
* Copyright (c) 1996 Jim Crossley
*
* Although it's unlikely that anyone would actually want it,
* permission is hereby granted, without written agreement and
* without license or royalty fees, to use, copy, modify, and
* distribute this software and its documentation for any purpose,
* provided that the above copyright notice and the following three
* paragraphs appear in all copies of this software, its documentation
* and any derivative work.
*
* In no event shall Jim Crossley or Automated Design Systems, Inc. be
* liable to any party for direct, indirect, special, incidental, or
* consequential damages arising out of the use of this software and
* its documentation.
*
* The software provided hereunder is on an "as is" basis, and neither
* Jim Crossley nor Automated Design Systems, Inc. has any obligation
* to provide maintenance, support, updates, enhancements, or modifications.
*
* Derived or altered versions must be plainly marked as such, and
* must not be misrepresented as being the original software.
***************************************************************************/
package utilities;

import java.awt.*;

public class VCRFrame extends Frame {

    final static String BTN_PLAY = ">>";
    final static String BTN_PAUSE = "||";
    final static String BTN_BACKWARD = "<|";
    final static String BTN_FORWARD = "|>";
    VCRControls client;

    public VCRFrame(VCRControls client) {
        this(client, "VCR");
    }
    public VCRFrame(VCRControls client, String name) {
        super(name);
        this.client = client;

        //{{INIT_CONTROLS
        setLayout(null);
        addNotify();
        resize(insets().left + insets().right + 150, insets().top + insets().bottom + 50);
        pause=new Button(BTN_PAUSE);
        add(pause);
        pause.reshape(insets().left + 30,insets().top + 10,30,30);
        backward=new Button(BTN_BACKWARD);
        backward.disable();
        add(backward);
        backward.reshape(insets().left + 60,insets().top + 10,30,30);
        forward=new Button(BTN_FORWARD);
        forward.disable();
        add(forward);
        forward.reshape(insets().left + 90,insets().top + 10,30,30);
        //}}
    }

    public synchronized void show() {
    	move(50, 50);
    	super.show();
    }

    public boolean handleEvent(Event event) {
    	if (event.id == Event.ACTION_EVENT && event.target == forward) {
    	    	clickedForward();
    	    	return true;
    	}
    	else
    	if (event.id == Event.ACTION_EVENT && event.target == backward) {
    	    	clickedBackward();
    	    	return true;
    	}
    	else
    	if (event.id == Event.ACTION_EVENT && event.target == pause) {
    	    	clickedPause();
    	    	return true;
    	}
    	else

    	if (event.id == Event.WINDOW_DESTROY) {
    	    hide();
    	    return true;
    	}
    	return super.handleEvent(event);
    }

    //{{DECLARE_CONTROLS
    Button pause;
    Button backward;
    Button forward;
    //}}
    public void clickedPause() {
        // to do: put event handler code here.
        if (pause.getLabel() == BTN_PAUSE)
        {
            client.pause();
            pause.setLabel(BTN_PLAY);
            forward.enable();
            backward.enable();
        }
        else
        {
            client.play();
            pause.setLabel(BTN_PAUSE);
            forward.disable();
            backward.disable();
        }
    }
    public void clickedBackward() {
        // to do: put event handler code here.
        client.frameAdvance(VCRControls.BACKWARD);
    }
    public void clickedForward() {
        // to do: put event handler code here.
        client.frameAdvance(VCRControls.FORWARD);
    }
}

