// Copyright 1996, Marimba Inc. All Rights Reserved.


// @(#)AWTWidget.java, 1.10, 12/13/96





package marimba.gui;





import java.awt.*;





import marimba.persist.*;





/**


 * A wrapper widget for AWT widgets.


 *


 * @author	Arthur van Hoff


 * @version 	1.10, 12/13/96


 */


public abstract class AWTWidget extends Widget {


    /**


     * The component.


     * @see #newComponent


     * @see #getComponent


     */


    public Component  comp;





    /**


     * Cache the player panel.


     */


    PlayerPanel player;





    /**


     * Check if started.


     */


    boolean started;





    /**


     * Create the AWT component.


     * @see #comp


     */


    public abstract Component newComponent();





    /**


     * Get the AWT component.


     * @see #comp


     */


    public Component getComponent() {


	return comp;


    }


    


    /**


     * Initialize the widget. Create the corresponding


     * AWT component.


     */


    public void init() {


	if ((comp = newComponent()) != null) {


	    comp.hide();


	    comp.setBackground(background);


	    comp.setForeground(foreground);


	    comp.setFont(font);





	    PlayerPanel p = getPlayerPanel();


	    if (p != null) {


		p.add(comp);


	    }


	}


    }





    /**


     * Start the widget and show the AWT component.


     */


    public void start() {


	if ((comp != null) && !getPlayerPanel().editing()) {


	    //validate();


	    comp.setBackground(background);


	    comp.setForeground(foreground);


	    comp.setFont(font);


	    //comp.show();


	    started = true;


	    player = getPlayerPanel();


	}


    }





    /**


     * Hide the AWT component.


     */


    public void stop() {


	started = false;


	if (comp != null) {


	    comp.hide();


	}


    }





    /**


     * Destroy the AWT component.


     */


    public void destroy() {


	if (comp != null) {


	    comp.getParent().remove(comp);


	    comp = null;


	}


    }





    /**


     * Move the AWT component to the right position.


     */


    public void validate() {


	super.validate();


	if (started && (comp != null) && (player != null) && !player.editing()) {


	    int x = 0, y = 0;


	    for (Widget w = this ; w != null ; w = w.parent) {


		x += w.x + w.tx;


		y += w.y + w.ty;


	    }


	    comp.reshape(x, y, width, height);


	    comp.show();


	}


	/*


	if ((comp != null) && comp.isVisible()) {


	    int x = 0, y = 0;


	    for (Widget w = this ; w != null ; w = w.parent) {


		x += w.x + w.tx;


		y += w.y + w.ty;


	    }


	    comp.reshape(x, y, width, height);


	    comp.show();


	}


	*/


    }


}


