/***************************************************************
 * Source: @(#)$Id$
 * Scope:  CounterPanel class
 *
 *  12/16/1999  GVT  First Implementation
 ***************************************************************/

package counter.awt.views;

import java.awt.*;

import gvt.mvc.*;
import gvt.awt.*;

import counter.models.*;


/**
 * This class implements a label view of a Counter
 * as a panel
 *
 * @author   Giuseppe Vitillaro
 * @version  $Id$
 */
public class CounterPanel extends Panel
    implements View {

    private Label label;
    private FixedLabel counter;

    
    /**
     * The Constructor: it add the labels to the panel
     */
    public CounterPanel ( String title  ) {
	label    =  new Label ( title );
	counter  =  new FixedLabel ( 8 );

	add ( label );
	add ( counter );

	label.setForeground ( Color.black );
	
	counter.setForeground ( Color.red );
	counter.setBackground ( Color.white );
	counter.setAlignment ( Label.RIGHT );
    }

    
    /**
     * it will called from the model to update the view
     */
    public void updateView ( Model model ) {
	Counter m = (Counter)model;
	
	String  s = String.valueOf ( m.get().intValue() );
	counter.setText ( s );
	doLayout();
    }
}

