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

package counter.swing.views;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

import gvt.mvc.*;
import gvt.swing.*;

import counter.models.*;


/**
 * This class implements a label view of a Counter 
 * as a panel 
 *
 * @author   Giuseppe Vitillaro
 * @version  $Id$
 */

public class CounterPanel extends JPanel
    implements View {

    private JLabel label;
    private JFixedLabel counter;

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

	add ( label );
	add ( counter );

	label.setForeground ( Color.black );
	
	counter.setForeground ( Color.red );
	counter.setBackground ( Color.white );
	counter.setOpaque ( true );
	counter.setHorizontalAlignment ( SwingConstants.TRAILING );

	setBorder ( new LineBorder(Color.black) );
    }

    /**
     * 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 );
    }
}
