diff --git a/CodenameOne/src/com/codename1/ui/Calendar.java b/CodenameOne/src/com/codename1/ui/Calendar.java index e5099a85ba..3710bd297d 100644 --- a/CodenameOne/src/com/codename1/ui/Calendar.java +++ b/CodenameOne/src/com/codename1/ui/Calendar.java @@ -85,6 +85,7 @@ public class Calendar extends Container { static final long WEEK = DAY * 7; private EventDispatcher dispatcher = new EventDispatcher(); private EventDispatcher dataChangedListeners = new EventDispatcher(); + private EventDispatcher monthChangedListeners = new EventDispatcher(); private long[] dates = new long[42]; private boolean changesSelectedDateEnabled = true; private TimeZone tmz; @@ -124,7 +125,8 @@ public Calendar(long time, TimeZone tmz) { } /** - * Constructs a calendar with the current date and time with left and right images set + * Constructs a calendar with the current date and time with left and right + * images set * * @param leftArrowImage an image for calendar left arrow * @param rightArrowImage an image for calendar right arrow @@ -437,6 +439,24 @@ public void removeActionListener(ActionListener l) { mv.removeActionListener(l); } + /** + * Fires when a new month is selected + * + * @param l listener to add + */ + public void addMonthChangedListener(ActionListener l) { + mv.addMonthChangedListener(l); + } + + /** + * Fires when a new month is selected + * + * @param l listener to remove + */ + public void removeMonthChangedListener(ActionListener l) { + mv.removeMonthChangedListener(l); + } + /** * Adds an ActionListener to the day buttons. This is different from * {@code Calendar.addActionListener} and will only fire when an active day @@ -1128,6 +1148,7 @@ public void setSelectedDay(long selectedDay) { } private void setMonth(int year, int month) { + fireMonthChangedEvent(); java.util.Calendar cal = java.util.Calendar.getInstance(tmz); cal.setTimeZone(TimeZone.getDefault()); cal.set(java.util.Calendar.MONTH, month); @@ -1171,6 +1192,14 @@ public void removeActionListener(ActionListener l) { dispatcher.removeListener(l); } + public void addMonthChangedListener(ActionListener l) { + monthChangedListeners.addListener(l); + } + + public void removeMonthChangedListener(ActionListener l) { + monthChangedListeners.removeListener(l); + } + public void addDayActionListener(ActionListener l) { dayListeners.add(l); for (Component cmp : components) { @@ -1209,6 +1238,10 @@ protected void fireActionEvent() { dispatcher.fireActionEvent(new ActionEvent(Calendar.this, ActionEvent.Type.Calendar)); } + protected void fireMonthChangedEvent() { + monthChangedListeners.fireActionEvent(new ActionEvent(Calendar.this, ActionEvent.Type.Calendar)); + } + public void actionPerformed(ActionEvent evt) { Object src = evt.getSource(); if (src instanceof ComboBox) {