import java.awt.*;
import javax.swing.*;

/**
 * A GUI Component that can contain Fraction objects.
 * 
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class FractionLabel extends JPanel
{
  private static final long serialVersionUID = 1L;

  private Fraction fraction;
  private JLabel   denominatorLabel, numeratorLabel;
  
  /**
   * Default Constructor.
   */
  public FractionLabel()
  {
    super();
    JPanel west = new JPanel();
    west.setLayout(new GridLayout(2,1));
    numeratorLabel = new JLabel("");
    numeratorLabel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, numeratorLabel.getForeground()));
    west.add(numeratorLabel);
    
    denominatorLabel = new JLabel("");
    west.add(denominatorLabel);
    
    setLayout(new BorderLayout());
    add(west, BorderLayout.WEST);
  }

  /**
   * Get the Fraction that is on this Component.
   * 
   * @return  The Fraction
   */
  public Fraction getFraction()
  {
    return fraction;
  }

  /**
   * Set the Fraction that is on this Component.
   * 
   * @param f  The Fraction
   */
  public void setFraction(Fraction f)
  {
    this.fraction = f;
    numeratorLabel.setText(String.format("%d", f.getNumerator()));
    denominatorLabel.setText(String.format("%d", f.getDenominator()));
  }
}
