package view;

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

/****
 *
 * MonthlyAgenda display is a quick protyotype of a monthly view.  Since this
 * is intended to be displayed in a top-level screen window, it extends
 * JFrame.
 *                                                                          <p>
 * The display uses a JPanel with a Grid layout as the main structure of the
 * UI.  The outermost layout is a vertical box, with a row of day labels on the
 * top, and the month grid below.  The month grid is populated with small
 * day-sized JPanels, each with a number in the upper left corner.
 *                                                                          <p>
 * The particular month displayed has 30 days, 5 weeks, and the first day of
 * the month starting on Tuesday.  This is chosen as a representative sample.
 * 
 *
 */
public class MonthlyAgendaDisplay extends JFrame {

    /**
     * Construct this, per the design explained in the class comment.
     */
    public MonthlyAgendaDisplay() {
        JPanel grid = new JPanel(new GridLayout(5, 7));
        Box outerBox = Box.createVerticalBox();
        JLabel label = new JLabel(
            "Initial approximation of a month layout ...");
        Dimension defaultSize = new Dimension(
            7 * defaultCellWidth, 5 * defaultCellHeight);

        /*
         * Insert a couple grey days up front.
         */
        grid.add(greyDay());
        grid.add(greyDay());

        /*
         * Insert 30 small days in the grid.
         */
        for (int i = 1; i <= 30; i++) {
            grid.add(new SmallDayViewDisplay(" " + Integer.toString(i)));
        }

        /*
         * Finish the last row with three grey days.  Yes, these absolute
         * numbers are bad style, but this is a RAPID prototype we're building
         * here.
         */
        grid.add(greyDay());
        grid.add(greyDay());
        grid.add(greyDay());

        /*
         * Layout the overall window.  Don't forget to call JFrame.pack(), or
         * the window could be improperly sized.
         */
        grid.setBackground(Color.white);
        grid.setPreferredSize(defaultSize);
        outerBox.add(label);
        outerBox.add(grid);
        setContentPane(outerBox);
        setTitle("Monthy Agenda");
        pack();
    }

    /**
     * Build an empty grey-background, black-border day display.  A fresh one
     * of these needs to be allocated for each use since JFC doesn't play
     * reuses of a components in containers.
     */
    protected JPanel greyDay() {
        JPanel panel = new JPanel();
        panel.setBackground(Color.lightGray);
        panel.setBorder(BorderFactory.createLineBorder(Color.black));

        return panel;
    }

    /** Default constant for the height of one day display cell. */
    protected final int defaultCellHeight = 75;

    /** Default constant for the width of one day display cell. */
    protected final int defaultCellWidth = 75;

}