package caltool.model.view.view; import caltool.model.view.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; /**** * * Class DateLabelListener is an Implementation of MouseListener that listens * for a click on a date label. Putting this listener on a label is easier * than trying to figure out how to make button without its border graphic. *

* In the current preliminary implementation, the mousePressed handler toggles * the label from selected to unselected each time it is pressed. This will be * refined to correct behavior by implementing a listener for the entire day * grid that unselects whenever the mouse is clicked not on label. * */ public class DateLabelListener implements MouseListener { /** * Construct this with the companion View model, which is used to make the * clicked date current in the calendar. */ public DateLabelListener(DateNumberLabel label, MonthlyAgenda monthlyAgenda) { this.label = label; this.monthlyAgenda = monthlyAgenda; } /** * Highlight the pressed label and call the selectDate model method. */ public void mousePressed(MouseEvent e) { Color temp = label.getForeground(); label.setForeground(label.getBackground()); label.setBackground(temp); monthlyAgenda.selectDate(label.getNumber()); } /** Ignore mouseReleased events. */ public void mouseReleased(MouseEvent e) {} /** Ignore mouseEntered events. */ public void mouseEntered(MouseEvent e) {} /** Ignore mouseExited events. */ public void mouseExited(MouseEvent e) {} /** Ignore mouseClicked events. */ public void mouseClicked(MouseEvent e) {} /** Associated date label */ DateNumberLabel label; /** Companion model */ MonthlyAgenda monthlyAgenda; }