Author: rwhitcomb Date: Thu Feb 1 20:32:48 2018 New Revision: 1822902 URL: http://svn.apache.org/viewvc?rev=1822902&view=rev Log: PIVOT-1011: The last of the work moving the ListenerList implementations for listeners into the Listener interfaces themselves; implementing default methods in the interface, and deprecating the "xxx.Adapter" classes.
Modified: pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewCategoryListener.java pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewListener.java pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewSeriesListener.java pivot/trunk/tests/src/org/apache/pivot/tests/CalendarTest.java pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarBindingListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonBindingListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonSelectionListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarSelectionListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBar.java pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBarListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButton.java pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButtonListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuItemSelectionListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopup.java pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopupListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopupStateListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuButtonSkin.java Modified: pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java URL: http://svn.apache.org/viewvc/pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java (original) +++ pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java Thu Feb 1 20:32:48 2018 @@ -164,7 +164,7 @@ public abstract class ChartView extends if (category.getChartView() != null) { throw new IllegalArgumentException( - "category is already in use by another chart view."); + "Category is already in use by another chart view."); } categories.insert(category, index); @@ -280,130 +280,6 @@ public abstract class ChartView extends } } - /** - * Chart view listener list. - */ - private static class ChartViewListenerList extends ListenerList<ChartViewListener> implements - ChartViewListener { - @Override - public void chartDataChanged(ChartView chartView, List<?> previousChartData) { - for (ChartViewListener listener : this) { - listener.chartDataChanged(chartView, previousChartData); - } - } - - @Override - public void seriesNameKeyChanged(ChartView chartView, String previousSeriesNameKey) { - for (ChartViewListener listener : this) { - listener.seriesNameKeyChanged(chartView, previousSeriesNameKey); - } - } - - @Override - public void titleChanged(ChartView chartView, String previousTitle) { - for (ChartViewListener listener : this) { - listener.titleChanged(chartView, previousTitle); - } - } - - @Override - public void horizontalAxisLabelChanged(ChartView chartView, String previousXAxisLabel) { - for (ChartViewListener listener : this) { - listener.horizontalAxisLabelChanged(chartView, previousXAxisLabel); - } - } - - @Override - public void verticalAxisLabelChanged(ChartView chartView, String previousYAxisLabel) { - for (ChartViewListener listener : this) { - listener.verticalAxisLabelChanged(chartView, previousYAxisLabel); - } - } - - @Override - public void showLegendChanged(ChartView chartView) { - for (ChartViewListener listener : this) { - listener.showLegendChanged(chartView); - } - } - } - - /** - * Chart view category listener list. - */ - private static class ChartViewCategoryListenerList extends - ListenerList<ChartViewCategoryListener> implements ChartViewCategoryListener { - @Override - public void categoryInserted(ChartView chartView, int index) { - for (ChartViewCategoryListener listener : this) { - listener.categoryInserted(chartView, index); - } - } - - @Override - public void categoriesRemoved(ChartView chartView, int index, - Sequence<ChartView.Category> categories) { - for (ChartViewCategoryListener listener : this) { - listener.categoriesRemoved(chartView, index, categories); - } - } - - @Override - public void categoryKeyChanged(ChartView chartView, int index, String previousKey) { - for (ChartViewCategoryListener listener : this) { - listener.categoryKeyChanged(chartView, index, previousKey); - } - } - - @Override - public void categoryLabelChanged(ChartView chartView, int index, String previousLabel) { - for (ChartViewCategoryListener listener : this) { - listener.categoryLabelChanged(chartView, index, previousLabel); - } - } - } - - /** - * Chart view series listener list. - */ - private static class ChartViewSeriesListenerList extends ListenerList<ChartViewSeriesListener> - implements ChartViewSeriesListener { - @Override - public void seriesInserted(ChartView chartView, int index) { - for (ChartViewSeriesListener listener : this) { - listener.seriesInserted(chartView, index); - } - } - - @Override - public void seriesRemoved(ChartView chartView, int index, int count) { - for (ChartViewSeriesListener listener : this) { - listener.seriesRemoved(chartView, index, count); - } - } - - @Override - public void seriesUpdated(ChartView chartView, int index) { - for (ChartViewSeriesListener listener : this) { - listener.seriesUpdated(chartView, index); - } - } - - @Override - public void seriesCleared(ChartView chartView) { - for (ChartViewSeriesListener listener : this) { - listener.seriesCleared(chartView); - } - } - - @Override - public void seriesSorted(ChartView chartView) { - for (ChartViewSeriesListener listener : this) { - listener.seriesSorted(chartView); - } - } - } - protected List<?> chartData; private String seriesNameKey; @@ -418,9 +294,9 @@ public abstract class ChartView extends private ListHandler chartDataHandler = new ListHandler(); private ValueMarkersHandler valueMarkersHandler = new ValueMarkersHandler(); - private ChartViewListenerList chartViewListeners = new ChartViewListenerList(); - private ChartViewCategoryListenerList chartViewCategoryListeners = new ChartViewCategoryListenerList(); - private ChartViewSeriesListenerList chartViewSeriesListeners = new ChartViewSeriesListenerList(); + private ChartViewListener.Listeners chartViewListeners = new ChartViewListener.Listeners(); + private ChartViewCategoryListener.Listeners chartViewCategoryListeners = new ChartViewCategoryListener.Listeners(); + private ChartViewSeriesListener.Listeners chartViewSeriesListeners = new ChartViewSeriesListener.Listeners(); private List<ValueMarker> valueMarkers; Modified: pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewCategoryListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewCategoryListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewCategoryListener.java (original) +++ pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewCategoryListener.java Thu Feb 1 20:32:48 2018 @@ -17,12 +17,40 @@ package org.apache.pivot.charts; import org.apache.pivot.collections.Sequence; +import org.apache.pivot.util.ListenerList; /** * Chart view category listener interface. */ public interface ChartViewCategoryListener { /** + * Chart view category listener list. + */ + public static class Listeners extends ListenerList<ChartViewCategoryListener> + implements ChartViewCategoryListener { + @Override + public void categoryInserted(ChartView chartView, int index) { + forEach(listener -> listener.categoryInserted(chartView, index)); + } + + @Override + public void categoriesRemoved(ChartView chartView, int index, + Sequence<ChartView.Category> categories) { + forEach(listener -> listener.categoriesRemoved(chartView, index, categories)); + } + + @Override + public void categoryKeyChanged(ChartView chartView, int index, String previousKey) { + forEach(listener -> listener.categoryKeyChanged(chartView, index, previousKey)); + } + + @Override + public void categoryLabelChanged(ChartView chartView, int index, String previousLabel) { + forEach(listener -> listener.categoryLabelChanged(chartView, index, previousLabel)); + } + } + + /** * Fired when a category is inserted into a chart view. * * @param chartView The chart that is changing. Modified: pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewListener.java (original) +++ pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewListener.java Thu Feb 1 20:32:48 2018 @@ -17,12 +17,48 @@ package org.apache.pivot.charts; import org.apache.pivot.collections.List; +import org.apache.pivot.util.ListenerList; /** * Chart view listener interface. */ public interface ChartViewListener { /** + * Chart view listener list. + */ + public static class Listeners extends ListenerList<ChartViewListener> implements ChartViewListener { + @Override + public void chartDataChanged(ChartView chartView, List<?> previousChartData) { + forEach(listener -> listener.chartDataChanged(chartView, previousChartData)); + } + + @Override + public void seriesNameKeyChanged(ChartView chartView, String previousSeriesNameKey) { + forEach(listener -> listener.seriesNameKeyChanged(chartView, previousSeriesNameKey)); + } + + @Override + public void titleChanged(ChartView chartView, String previousTitle) { + forEach(listener -> listener.titleChanged(chartView, previousTitle)); + } + + @Override + public void horizontalAxisLabelChanged(ChartView chartView, String previousXAxisLabel) { + forEach(listener -> listener.horizontalAxisLabelChanged(chartView, previousXAxisLabel)); + } + + @Override + public void verticalAxisLabelChanged(ChartView chartView, String previousYAxisLabel) { + forEach(listener -> listener.verticalAxisLabelChanged(chartView, previousYAxisLabel)); + } + + @Override + public void showLegendChanged(ChartView chartView) { + forEach(listener -> listener.showLegendChanged(chartView)); + } + } + + /** * Fired when a chart view's data changes. * * @param chartView The chart that is changing. Modified: pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewSeriesListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewSeriesListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewSeriesListener.java (original) +++ pivot/trunk/charts/src/org/apache/pivot/charts/ChartViewSeriesListener.java Thu Feb 1 20:32:48 2018 @@ -16,11 +16,44 @@ */ package org.apache.pivot.charts; +import org.apache.pivot.util.ListenerList; + /** * Chart view series listener interface. */ public interface ChartViewSeriesListener { /** + * Chart view series listener list. + */ + public static class Listeners extends ListenerList<ChartViewSeriesListener> + implements ChartViewSeriesListener { + @Override + public void seriesInserted(ChartView chartView, int index) { + forEach(listener -> listener.seriesInserted(chartView, index)); + } + + @Override + public void seriesRemoved(ChartView chartView, int index, int count) { + forEach(listener -> listener.seriesRemoved(chartView, index, count)); + } + + @Override + public void seriesUpdated(ChartView chartView, int index) { + forEach(listener -> listener.seriesUpdated(chartView, index)); + } + + @Override + public void seriesCleared(ChartView chartView) { + forEach(listener -> listener.seriesCleared(chartView)); + } + + @Override + public void seriesSorted(ChartView chartView) { + forEach(listener -> listener.seriesSorted(chartView)); + } + } + + /** * Fired when a series is inserted into a chart view's data set. * * @param chartView The chart that has changed. Modified: pivot/trunk/tests/src/org/apache/pivot/tests/CalendarTest.java URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/CalendarTest.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/tests/src/org/apache/pivot/tests/CalendarTest.java (original) +++ pivot/trunk/tests/src/org/apache/pivot/tests/CalendarTest.java Thu Feb 1 20:32:48 2018 @@ -35,10 +35,8 @@ import org.apache.pivot.wtk.Window; public class CalendarTest implements Application { private Window window = null; - @BXML - private Calendar calendar = null; - @BXML - private CalendarButton calendarButton = null; + @BXML private Calendar calendar = null; + @BXML private CalendarButton calendarButton = null; @Override public void startup(Display display, Map<String, String> properties) throws Exception { @@ -57,7 +55,7 @@ public class CalendarTest implements App calendar.setDisabledDateFilter(todayFilter); - calendarButton.getCalendarButtonListeners().add(new CalendarButtonListener.Adapter() { + calendarButton.getCalendarButtonListeners().add(new CalendarButtonListener() { @Override public void yearChanged(CalendarButton calendarButtonArgument, int previousYear) { disable(); Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java Thu Feb 1 20:32:48 2018 @@ -52,59 +52,6 @@ public class Calendar extends Container public Object valueOf(CalendarDate calendarDate); } - private static class CalendarListenerList extends ListenerList<CalendarListener> implements - CalendarListener { - @Override - public void yearChanged(Calendar calendar, int previousYear) { - forEach(listener -> listener.yearChanged(calendar, previousYear)); - } - - @Override - public void monthChanged(Calendar calendar, int previousMonth) { - forEach(listener -> listener.monthChanged(calendar, previousMonth)); - } - - @Override - public void localeChanged(Calendar calendar, Locale previousLocale) { - forEach(listener -> listener.localeChanged(calendar, previousLocale)); - } - - @Override - public void disabledDateFilterChanged(Calendar calendar, - Filter<CalendarDate> previousDisabledDateFilter) { - forEach(listener -> listener.disabledDateFilterChanged(calendar, previousDisabledDateFilter)); - } - } - - private static class CalendarSelectionListenerList extends - ListenerList<CalendarSelectionListener> implements CalendarSelectionListener { - - @Override - public void selectedDateChanged(Calendar calendar, CalendarDate previousSelectedDate) { - forEach(listener -> listener.selectedDateChanged(calendar, previousSelectedDate)); - } - } - - private static class CalendarBindingListenerList extends - ListenerList<CalendarBindingListener> implements CalendarBindingListener { - @Override - public void selectedDateKeyChanged(Calendar calendar, String previousSelectedDateKey) { - forEach(listener -> listener.selectedDateKeyChanged(calendar, previousSelectedDateKey)); - } - - @Override - public void selectedDateBindTypeChanged(Calendar calendar, - BindType previousSelectedDateBindType) { - forEach(listener -> listener.selectedDateBindTypeChanged(calendar, previousSelectedDateBindType)); - } - - @Override - public void selectedDateBindMappingChanged(Calendar calendar, - SelectedDateBindMapping previousSelectedDateBindMapping) { - forEach(listener -> listener.selectedDateBindMappingChanged(calendar, previousSelectedDateBindMapping)); - } - } - private int year; private int month; @@ -116,9 +63,9 @@ public class Calendar extends Container private BindType selectedDateBindType = BindType.BOTH; private SelectedDateBindMapping selectedDateBindMapping = null; - private CalendarListenerList calendarListeners = new CalendarListenerList(); - private CalendarSelectionListenerList calendarSelectionListeners = new CalendarSelectionListenerList(); - private CalendarBindingListenerList calendarBindingListeners = new CalendarBindingListenerList(); + private CalendarListener.Listeners calendarListeners = new CalendarListener.Listeners(); + private CalendarSelectionListener.Listeners calendarSelectionListeners = new CalendarSelectionListener.Listeners(); + private CalendarBindingListener.Listeners calendarBindingListeners = new CalendarBindingListener.Listeners(); public static final String LANGUAGE_KEY = "language"; public static final String COUNTRY_KEY = "country"; Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarBindingListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarBindingListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarBindingListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarBindingListener.java Thu Feb 1 20:32:48 2018 @@ -16,13 +16,40 @@ */ package org.apache.pivot.wtk; +import org.apache.pivot.util.ListenerList; + /** * Calendar binding listener interface. */ public interface CalendarBindingListener { /** + * Calendar binding listeners. + */ + public static class Listeners extends ListenerList<CalendarBindingListener> + implements CalendarBindingListener { + @Override + public void selectedDateKeyChanged(Calendar calendar, String previousSelectedDateKey) { + forEach(listener -> listener.selectedDateKeyChanged(calendar, previousSelectedDateKey)); + } + + @Override + public void selectedDateBindTypeChanged(Calendar calendar, + BindType previousSelectedDateBindType) { + forEach(listener -> listener.selectedDateBindTypeChanged(calendar, previousSelectedDateBindType)); + } + + @Override + public void selectedDateBindMappingChanged(Calendar calendar, + Calendar.SelectedDateBindMapping previousSelectedDateBindMapping) { + forEach(listener -> listener.selectedDateBindMappingChanged(calendar, previousSelectedDateBindMapping)); + } + } + + /** * Calendar binding listener adapter. + * @deprecated Since 2.1 and Java 8 the interface itself has default implementations. */ + @Deprecated public static class Adapter implements CalendarBindingListener { @Override public void selectedDateKeyChanged(Calendar calendar, String previousSelectedDateKey) { @@ -48,7 +75,8 @@ public interface CalendarBindingListener * @param calendar The calendar that was updated. * @param previousSelectedDateKey The previous bind key for the calendar's selected date. */ - public void selectedDateKeyChanged(Calendar calendar, String previousSelectedDateKey); + default public void selectedDateKeyChanged(Calendar calendar, String previousSelectedDateKey) { + } /** * Called when a calendar's selected date bind type has changed. @@ -56,7 +84,8 @@ public interface CalendarBindingListener * @param calendar The calendar that has changed. * @param previousSelectedDateBindType The previous bind type for the selected date. */ - public void selectedDateBindTypeChanged(Calendar calendar, BindType previousSelectedDateBindType); + default public void selectedDateBindTypeChanged(Calendar calendar, BindType previousSelectedDateBindType) { + } /** * Called when a calendar's selected date bind mapping has changed. @@ -64,7 +93,8 @@ public interface CalendarBindingListener * @param calendar The calendar that changed. * @param previousSelectedDateBindMapping The previous bind mapping for the selected date. */ - public void selectedDateBindMappingChanged(Calendar calendar, - Calendar.SelectedDateBindMapping previousSelectedDateBindMapping); + default public void selectedDateBindMappingChanged(Calendar calendar, + Calendar.SelectedDateBindMapping previousSelectedDateBindMapping) { + } } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java Thu Feb 1 20:32:48 2018 @@ -33,62 +33,6 @@ import org.apache.pivot.wtk.content.Cale * hidden until the user pushes the button. */ public class CalendarButton extends Button { - private static class CalendarButtonListenerList extends ListenerList<CalendarButtonListener> - implements CalendarButtonListener { - @Override - public void yearChanged(CalendarButton calendarButton, int previousYear) { - forEach(listener -> listener.yearChanged(calendarButton, previousYear)); - } - - @Override - public void monthChanged(CalendarButton calendarButton, int previousMonth) { - forEach(listener -> listener.monthChanged(calendarButton, previousMonth)); - } - - @Override - public void localeChanged(CalendarButton calendarButton, Locale previousLocale) { - forEach(listener -> listener.localeChanged(calendarButton, previousLocale)); - } - - @Override - public void disabledDateFilterChanged(CalendarButton calendarButton, - Filter<CalendarDate> previousDisabledDateFilter) { - forEach(listener -> listener.disabledDateFilterChanged(calendarButton, previousDisabledDateFilter)); - } - } - - private static class CalendarButtonSelectionListenerList extends - ListenerList<CalendarButtonSelectionListener> implements CalendarButtonSelectionListener { - - @Override - public void selectedDateChanged(CalendarButton calendarButton, - CalendarDate previousSelectedDate) { - forEach(listener -> listener.selectedDateChanged(calendarButton, previousSelectedDate)); - } - } - - private static class CalendarButtonBindingListenerList extends - ListenerList<CalendarButtonBindingListener> implements CalendarButtonBindingListener { - @Override - public void selectedDateKeyChanged(CalendarButton calendarButton, - String previousSelectedDateKey) { - forEach(listener -> listener.selectedDateKeyChanged(calendarButton, previousSelectedDateKey)); - } - - @Override - public void selectedDateBindTypeChanged(CalendarButton calendarButton, - BindType previousSelectedDateBindType) { - forEach(listener -> listener.selectedDateBindTypeChanged(calendarButton, previousSelectedDateBindType)); - } - - @Override - public void selectedDateBindMappingChanged(CalendarButton calendarButton, - Calendar.SelectedDateBindMapping previousSelectedDateBindMapping) { - forEach(listener -> listener.selectedDateBindMappingChanged(calendarButton, - previousSelectedDateBindMapping)); - } - } - /** * CalendarButton skin interface. CalendarButton skins must implement this * interface to facilitate additional communication between the component @@ -109,9 +53,9 @@ public class CalendarButton extends Butt private BindType selectedDateBindType = BindType.BOTH; private Calendar.SelectedDateBindMapping selectedDateBindMapping = null; - private CalendarButtonListenerList calendarButtonListeners = new CalendarButtonListenerList(); - private CalendarButtonSelectionListenerList calendarButtonSelectionListeners = new CalendarButtonSelectionListenerList(); - private CalendarButtonBindingListenerList calendarButtonBindingListeners = new CalendarButtonBindingListenerList(); + private CalendarButtonListener.Listeners calendarButtonListeners = new CalendarButtonListener.Listeners(); + private CalendarButtonSelectionListener.Listeners calendarButtonSelectionListeners = new CalendarButtonSelectionListener.Listeners(); + private CalendarButtonBindingListener.Listeners calendarButtonBindingListeners = new CalendarButtonBindingListener.Listeners(); public static final String LANGUAGE_KEY = "language"; public static final String COUNTRY_KEY = "country"; @@ -432,4 +376,11 @@ public class CalendarButton extends Butt public ListenerList<CalendarButtonSelectionListener> getCalendarButtonSelectionListeners() { return calendarButtonSelectionListeners; } + + /** + * @return The calendar button binding listener list. + */ + public ListenerList<CalendarButtonBindingListener> getCalendarButtonBindingListeners() { + return calendarButtonBindingListeners; + } } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonBindingListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonBindingListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonBindingListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonBindingListener.java Thu Feb 1 20:32:48 2018 @@ -16,13 +16,42 @@ */ package org.apache.pivot.wtk; +import org.apache.pivot.util.ListenerList; + /** * Calender button binding listener interface. */ public interface CalendarButtonBindingListener { /** + * Calendar button binding listeners. + */ + public static class Listeners extends ListenerList<CalendarButtonBindingListener> + implements CalendarButtonBindingListener { + @Override + public void selectedDateKeyChanged(CalendarButton calendarButton, + String previousSelectedDateKey) { + forEach(listener -> listener.selectedDateKeyChanged(calendarButton, previousSelectedDateKey)); + } + + @Override + public void selectedDateBindTypeChanged(CalendarButton calendarButton, + BindType previousSelectedDateBindType) { + forEach(listener -> listener.selectedDateBindTypeChanged(calendarButton, previousSelectedDateBindType)); + } + + @Override + public void selectedDateBindMappingChanged(CalendarButton calendarButton, + Calendar.SelectedDateBindMapping previousSelectedDateBindMapping) { + forEach(listener -> listener.selectedDateBindMappingChanged(calendarButton, + previousSelectedDateBindMapping)); + } + } + + /** * Calendar button binding listener adapter. + * @deprecated Since 2.1 and Java 8 the interface itself has default implementations. */ + @Deprecated public static class Adapter implements CalendarButtonBindingListener { @Override public void selectedDateKeyChanged(CalendarButton calendarButton, @@ -49,7 +78,8 @@ public interface CalendarButtonBindingLi * @param calendarButton The calendar button that changed. * @param previousSelectedDateKey The previous value of the selected date binding key. */ - public void selectedDateKeyChanged(CalendarButton calendarButton, String previousSelectedDateKey); + default public void selectedDateKeyChanged(CalendarButton calendarButton, String previousSelectedDateKey) { + } /** * Called when a calendar button's selected date bind type has changed. @@ -57,8 +87,9 @@ public interface CalendarButtonBindingLi * @param calendarButton The calendar button that changed. * @param previousSelectedDateBindType The previous bind type for the selected date. */ - public void selectedDateBindTypeChanged(CalendarButton calendarButton, - BindType previousSelectedDateBindType); + default public void selectedDateBindTypeChanged(CalendarButton calendarButton, + BindType previousSelectedDateBindType) { + } /** * Called when a calendar button's selected date bind mapping has changed. @@ -66,7 +97,8 @@ public interface CalendarButtonBindingLi * @param calendarButton The calendar button that changed. * @param previousSelectedDateBindMapping The previous bind mapping for the selected date. */ - public void selectedDateBindMappingChanged(CalendarButton calendarButton, - Calendar.SelectedDateBindMapping previousSelectedDateBindMapping); + default public void selectedDateBindMappingChanged(CalendarButton calendarButton, + Calendar.SelectedDateBindMapping previousSelectedDateBindMapping) { + } } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonListener.java Thu Feb 1 20:32:48 2018 @@ -20,14 +20,44 @@ import java.util.Locale; import org.apache.pivot.util.CalendarDate; import org.apache.pivot.util.Filter; +import org.apache.pivot.util.ListenerList; /** * Calendar button listener interface. */ public interface CalendarButtonListener { /** + * Calendar button listeners. + */ + public static class Listeners extends ListenerList<CalendarButtonListener> + implements CalendarButtonListener { + @Override + public void yearChanged(CalendarButton calendarButton, int previousYear) { + forEach(listener -> listener.yearChanged(calendarButton, previousYear)); + } + + @Override + public void monthChanged(CalendarButton calendarButton, int previousMonth) { + forEach(listener -> listener.monthChanged(calendarButton, previousMonth)); + } + + @Override + public void localeChanged(CalendarButton calendarButton, Locale previousLocale) { + forEach(listener -> listener.localeChanged(calendarButton, previousLocale)); + } + + @Override + public void disabledDateFilterChanged(CalendarButton calendarButton, + Filter<CalendarDate> previousDisabledDateFilter) { + forEach(listener -> listener.disabledDateFilterChanged(calendarButton, previousDisabledDateFilter)); + } + } + + /** * Calendar button listener adapter. + * @deprecated Since 2.1 and Java 8 the interface itself has default implementations. */ + @Deprecated public static class Adapter implements CalendarButtonListener { @Override public void yearChanged(CalendarButton calendarButton, int previousYear) { @@ -57,7 +87,8 @@ public interface CalendarButtonListener * @param calendarButton The calendar button that changed. * @param previousYear The previously selected year. */ - public void yearChanged(CalendarButton calendarButton, int previousYear); + default public void yearChanged(CalendarButton calendarButton, int previousYear) { + } /** * Called when a calendar button's month value has changed. @@ -65,7 +96,8 @@ public interface CalendarButtonListener * @param calendarButton The calendar button that changed. * @param previousMonth The previously selected month. */ - public void monthChanged(CalendarButton calendarButton, int previousMonth); + default public void monthChanged(CalendarButton calendarButton, int previousMonth) { + } /** * Called when a calendar button's locale has changed. @@ -73,7 +105,8 @@ public interface CalendarButtonListener * @param calendarButton The calendar button that changed. * @param previousLocale The previously selected locale for the calendar. */ - public void localeChanged(CalendarButton calendarButton, Locale previousLocale); + default public void localeChanged(CalendarButton calendarButton, Locale previousLocale) { + } /** * Called when a calendar button's disabled date filter has changed. @@ -81,6 +114,7 @@ public interface CalendarButtonListener * @param calendarButton The calendar button that changed. * @param previousDisabledDateFilter The previous disabled date filter. */ - public void disabledDateFilterChanged(CalendarButton calendarButton, - Filter<CalendarDate> previousDisabledDateFilter); + default public void disabledDateFilterChanged(CalendarButton calendarButton, + Filter<CalendarDate> previousDisabledDateFilter) { + } } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonSelectionListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonSelectionListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonSelectionListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButtonSelectionListener.java Thu Feb 1 20:32:48 2018 @@ -17,12 +17,25 @@ package org.apache.pivot.wtk; import org.apache.pivot.util.CalendarDate; +import org.apache.pivot.util.ListenerList; /** * Calendar button selection listener interface. */ public interface CalendarButtonSelectionListener { /** + * Calendar button selection listeners. + */ + public static class Listeners extends ListenerList<CalendarButtonSelectionListener> + implements CalendarButtonSelectionListener { + @Override + public void selectedDateChanged(CalendarButton calendarButton, + CalendarDate previousSelectedDate) { + forEach(listener -> listener.selectedDateChanged(calendarButton, previousSelectedDate)); + } + } + + /** * Called when a calendar button's selected date has changed. * * @param calendarButton The calendar button that changed. Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarListener.java Thu Feb 1 20:32:48 2018 @@ -20,14 +20,43 @@ import java.util.Locale; import org.apache.pivot.util.CalendarDate; import org.apache.pivot.util.Filter; +import org.apache.pivot.util.ListenerList; /** * Calendar listener interface. */ public interface CalendarListener { /** + * Calendar listeners. + */ + public static class Listeners extends ListenerList<CalendarListener> implements CalendarListener { + @Override + public void yearChanged(Calendar calendar, int previousYear) { + forEach(listener -> listener.yearChanged(calendar, previousYear)); + } + + @Override + public void monthChanged(Calendar calendar, int previousMonth) { + forEach(listener -> listener.monthChanged(calendar, previousMonth)); + } + + @Override + public void localeChanged(Calendar calendar, Locale previousLocale) { + forEach(listener -> listener.localeChanged(calendar, previousLocale)); + } + + @Override + public void disabledDateFilterChanged(Calendar calendar, + Filter<CalendarDate> previousDisabledDateFilter) { + forEach(listener -> listener.disabledDateFilterChanged(calendar, previousDisabledDateFilter)); + } + } + + /** * Calendar listener adapter. + * @deprecated Since 2.1 and Java 8 the interface itself has default implementations. */ + @Deprecated public static class Adapter implements CalendarListener { @Override public void yearChanged(Calendar calendar, int previousYear) { @@ -57,7 +86,8 @@ public interface CalendarListener { * @param calendar The calendar that changed. * @param previousYear The previously selected year. */ - public void yearChanged(Calendar calendar, int previousYear); + default public void yearChanged(Calendar calendar, int previousYear) { + } /** * Called when a calendar's month value has changed. @@ -65,7 +95,8 @@ public interface CalendarListener { * @param calendar The calendar that changed. * @param previousMonth The previously selected month value. */ - public void monthChanged(Calendar calendar, int previousMonth); + default public void monthChanged(Calendar calendar, int previousMonth) { + } /** * Called when a calendar's locale has changed. @@ -73,7 +104,8 @@ public interface CalendarListener { * @param calendar The calendar that changed. * @param previousLocale The previously selected locale for the calendar. */ - public void localeChanged(Calendar calendar, Locale previousLocale); + default public void localeChanged(Calendar calendar, Locale previousLocale) { + } /** * Called when a calendar's disabled date filter has changed. @@ -81,6 +113,7 @@ public interface CalendarListener { * @param calendar The calendar that changed. * @param previousDisabledDateFilter The previous disabled date filter. */ - public void disabledDateFilterChanged(Calendar calendar, - Filter<CalendarDate> previousDisabledDateFilter); + default public void disabledDateFilterChanged(Calendar calendar, + Filter<CalendarDate> previousDisabledDateFilter) { + } } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarSelectionListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarSelectionListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarSelectionListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarSelectionListener.java Thu Feb 1 20:32:48 2018 @@ -17,12 +17,24 @@ package org.apache.pivot.wtk; import org.apache.pivot.util.CalendarDate; +import org.apache.pivot.util.ListenerList; /** * Calendar selection listener interface. */ public interface CalendarSelectionListener { /** + * Calendar selection listeners. + */ + public static class Listeners extends ListenerList<CalendarSelectionListener> + implements CalendarSelectionListener { + @Override + public void selectedDateChanged(Calendar calendar, CalendarDate previousSelectedDate) { + forEach(listener -> listener.selectedDateChanged(calendar, previousSelectedDate)); + } + } + + /** * Called when a calendar's selected date has changed. * * @param calendar The calendar that changed. Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java Thu Feb 1 20:32:48 2018 @@ -35,29 +35,12 @@ public class Menu extends Container { */ @DefaultProperty("menu") public static class Item extends Button { - private static class ItemListenerList extends ListenerList<ItemListener> implements - ItemListener { - @Override - public void menuChanged(Item item, Menu previousMenu) { - for (ItemListener listener : this) { - listener.menuChanged(item, previousMenu); - } - } - - @Override - public void activeChanged(Item item) { - for (ItemListener listener : this) { - listener.activeChanged(item); - } - } - } - private Section section = null; private Menu menu = null; private boolean active = false; - private ItemListenerList itemListeners = new ItemListenerList(); + private ItemListener.Listeners itemListeners = new ItemListener.Listeners(); private static final Button.DataRenderer DEFAULT_DATA_RENDERER = new MenuItemDataRenderer(); @@ -103,7 +86,7 @@ public class Menu extends Container { public void setMenu(Menu menu) { if (menu != null && menu.getItem() != null) { - throw new IllegalArgumentException("menu already belongs to an item."); + throw new IllegalArgumentException("Menu already belongs to an item."); } Menu previousMenu = this.menu; @@ -129,7 +112,7 @@ public class Menu extends Container { public void setActive(boolean active) { if (active && (getParent() == null || !isEnabled())) { - throw new IllegalStateException(); + throw new IllegalStateException("Cannot set menu active when it has no parent, or it is disabled."); } if (this.active != active) { @@ -150,8 +133,7 @@ public class Menu extends Container { activeItem.setActive(false); } } else { - // If this item is currently active, clear the - // selection + // If this item is currently active, clear the selection if (activeItem == this) { menuLocal.setActiveItem(null); } @@ -200,6 +182,21 @@ public class Menu extends Container { */ public interface ItemListener { /** + * Item listeners. + */ + public static class Listeners extends ListenerList<ItemListener> implements ItemListener { + @Override + public void menuChanged(Item item, Menu previousMenu) { + forEach(listener -> listener.menuChanged(item, previousMenu)); + } + + @Override + public void activeChanged(Item item) { + forEach(listener -> listener.activeChanged(item)); + } + } + + /** * Called when an item's menu has changed. * * @param item The item that has been moved. @@ -220,36 +217,12 @@ public class Menu extends Container { * within a menu. */ public static class Section implements Sequence<Item>, Iterable<Item> { - private static class SectionListenerList extends ListenerList<SectionListener> implements - SectionListener { - @Override - public void itemInserted(Menu.Section section, int index) { - for (SectionListener listener : this) { - listener.itemInserted(section, index); - } - } - - @Override - public void itemsRemoved(Menu.Section section, int index, Sequence<Item> removed) { - for (SectionListener listener : this) { - listener.itemsRemoved(section, index, removed); - } - } - - @Override - public void nameChanged(Menu.Section section, String previousName) { - for (SectionListener listener : this) { - listener.nameChanged(section, previousName); - } - } - } - private Menu menu = null; private String name = null; private ArrayList<Item> items = new ArrayList<>(); - private SectionListenerList sectionListeners = new SectionListenerList(); + private SectionListener.Listeners sectionListeners = new SectionListener.Listeners(); public Menu getMenu() { return menu; @@ -279,7 +252,7 @@ public class Menu extends Container { @Override public void insert(Item item, int index) { if (item.getSection() != null) { - throw new IllegalArgumentException("item already has a section."); + throw new IllegalArgumentException("Menu.Item already has a section."); } items.insert(item, index); @@ -355,6 +328,26 @@ public class Menu extends Container { */ public interface SectionListener { /** + * Section listeners. + */ + public static class Listeners extends ListenerList<SectionListener> implements SectionListener { + @Override + public void itemInserted(Menu.Section section, int index) { + forEach(listener -> listener.itemInserted(section, index)); + } + + @Override + public void itemsRemoved(Menu.Section section, int index, Sequence<Item> removed) { + forEach(listener -> listener.itemsRemoved(section, index, removed)); + } + + @Override + public void nameChanged(Menu.Section section, String previousName) { + forEach(listener -> listener.nameChanged(section, previousName)); + } + } + + /** * Called when a menu item has been inserted. * * @param section The section that is changing. @@ -398,7 +391,7 @@ public class Menu extends Container { @Override public void insert(Section section, int index) { if (section.menu != null) { - throw new IllegalArgumentException("section already has a menu."); + throw new IllegalArgumentException("Menu.Section already has a menu."); } sections.insert(section, index); @@ -469,40 +462,6 @@ public class Menu extends Container { } } - private static class MenuListenerList extends ListenerList<MenuListener> implements - MenuListener { - @Override - public void sectionInserted(Menu menu, int index) { - for (MenuListener listener : this) { - listener.sectionInserted(menu, index); - } - } - - @Override - public void sectionsRemoved(Menu menu, int index, Sequence<Section> removed) { - for (MenuListener listener : this) { - listener.sectionsRemoved(menu, index, removed); - } - } - - @Override - public void activeItemChanged(Menu menu, Menu.Item previousActiveItem) { - for (MenuListener listener : this) { - listener.activeItemChanged(menu, previousActiveItem); - } - } - } - - private static class MenuItemSelectionListenerList extends - ListenerList<MenuItemSelectionListener> implements MenuItemSelectionListener { - @Override - public void itemSelected(Menu.Item menuItem) { - for (MenuItemSelectionListener listener : this) { - listener.itemSelected(menuItem); - } - } - } - private Item item = null; private ArrayList<Section> sections = new ArrayList<>(); @@ -510,8 +469,8 @@ public class Menu extends Container { private Item activeItem = null; - private MenuListenerList menuListeners = new MenuListenerList(); - private MenuItemSelectionListenerList menuItemSelectionListeners = new MenuItemSelectionListenerList(); + private MenuListener.Listeners menuListeners = new MenuListener.Listeners(); + private MenuItemSelectionListener.Listeners menuItemSelectionListeners = new MenuItemSelectionListener.Listeners(); public Menu() { installSkin(Menu.class); Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBar.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBar.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBar.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBar.java Thu Feb 1 20:32:48 2018 @@ -35,27 +35,10 @@ public class MenuBar extends Container { */ @DefaultProperty("menu") public static class Item extends Button { - private static class ItemListenerList extends ListenerList<ItemListener> implements - ItemListener { - @Override - public void menuChanged(Item item, Menu previousMenu) { - for (ItemListener listener : this) { - listener.menuChanged(item, previousMenu); - } - } - - @Override - public void activeChanged(Item item) { - for (ItemListener listener : this) { - listener.activeChanged(item); - } - } - } - private Menu menu = null; private boolean active = false; - private ItemListenerList itemListeners = new ItemListenerList(); + private ItemListener.Listeners itemListeners = new ItemListener.Listeners(); private static final Button.DataRenderer DEFAULT_DATA_RENDERER = new MenuBarItemDataRenderer(); @@ -97,7 +80,7 @@ public class MenuBar extends Container { public void setMenu(Menu menu) { if (menu != null && menu.getItem() != null) { - throw new IllegalArgumentException("menu already belongs to an item."); + throw new IllegalArgumentException("Menu already belongs to an item."); } Menu previousMenu = this.menu; @@ -166,6 +149,21 @@ public class MenuBar extends Container { */ public interface ItemListener { /** + * Item listeners. + */ + public static class Listeners extends ListenerList<ItemListener> implements ItemListener { + @Override + public void menuChanged(Item item, Menu previousMenu) { + forEach(listener -> listener.menuChanged(item, previousMenu)); + } + + @Override + public void activeChanged(Item item) { + forEach(listener -> listener.activeChanged(item)); + } + } + + /** * Called when an item's menu has changed. * * @param item The item that has been moved. @@ -253,36 +251,12 @@ public class MenuBar extends Container { } } - private static class MenuBarListenerList extends ListenerList<MenuBarListener> implements - MenuBarListener { - @Override - public void itemInserted(MenuBar menuBar, int index) { - for (MenuBarListener listener : this) { - listener.itemInserted(menuBar, index); - } - } - - @Override - public void itemsRemoved(MenuBar menuBar, int index, Sequence<MenuBar.Item> removed) { - for (MenuBarListener listener : this) { - listener.itemsRemoved(menuBar, index, removed); - } - } - - @Override - public void activeItemChanged(MenuBar menuBar, MenuBar.Item previousActiveItem) { - for (MenuBarListener listener : this) { - listener.activeItemChanged(menuBar, previousActiveItem); - } - } - } - private ArrayList<Item> items = new ArrayList<>(); private ItemSequence itemSequence = new ItemSequence(); private Item activeItem = null; - private MenuBarListenerList menuBarListeners = new MenuBarListenerList(); + private MenuBarListener.Listeners menuBarListeners = new MenuBarListener.Listeners(); public MenuBar() { installSkin(MenuBar.class); Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBarListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBarListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBarListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBarListener.java Thu Feb 1 20:32:48 2018 @@ -17,14 +17,37 @@ package org.apache.pivot.wtk; import org.apache.pivot.collections.Sequence; +import org.apache.pivot.util.ListenerList; /** * Menu bar listener interface. */ public interface MenuBarListener { /** + * Menu bar listeners. + */ + public static class Listeners extends ListenerList<MenuBarListener> implements MenuBarListener { + @Override + public void itemInserted(MenuBar menuBar, int index) { + forEach(listener -> listener.itemInserted(menuBar, index)); + } + + @Override + public void itemsRemoved(MenuBar menuBar, int index, Sequence<MenuBar.Item> removed) { + forEach(listener -> listener.itemsRemoved(menuBar, index, removed)); + } + + @Override + public void activeItemChanged(MenuBar menuBar, MenuBar.Item previousActiveItem) { + forEach(listener -> listener.activeItemChanged(menuBar, previousActiveItem)); + } + } + + /** * Menu bar listener adapter. + * @deprecated Since 2.1 and Java 8 the interface itself has default implementations. */ + @Deprecated public static class Adapter implements MenuBarListener { @Override public void itemInserted(MenuBar menuBar, int index) { @@ -48,7 +71,8 @@ public interface MenuBarListener { * @param menuBar The menu bar that changed. * @param index The index where a new item was inserted. */ - public void itemInserted(MenuBar menuBar, int index); + default public void itemInserted(MenuBar menuBar, int index) { + } /** * Called when menu bar items have been removed. @@ -57,7 +81,8 @@ public interface MenuBarListener { * @param index The starting index where items were removed. * @param removed The sequence of removed items. */ - public void itemsRemoved(MenuBar menuBar, int index, Sequence<MenuBar.Item> removed); + default public void itemsRemoved(MenuBar menuBar, int index, Sequence<MenuBar.Item> removed) { + } /** * Called when a menu bar's active item has changed. @@ -65,5 +90,6 @@ public interface MenuBarListener { * @param menuBar The source of the event. * @param previousActiveItem Which item was active previously. */ - public void activeItemChanged(MenuBar menuBar, MenuBar.Item previousActiveItem); + default public void activeItemChanged(MenuBar menuBar, MenuBar.Item previousActiveItem) { + } } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButton.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButton.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButton.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButton.java Thu Feb 1 20:32:48 2018 @@ -31,14 +31,6 @@ import org.apache.pivot.wtk.content.Butt */ @DefaultProperty("menu") public class MenuButton extends Button { - private static class MenuButtonListenerList extends ListenerList<MenuButtonListener> - implements MenuButtonListener { - @Override - public void menuChanged(MenuButton menuButton, Menu previousMenu) { - forEach(listener -> listener.menuChanged(menuButton, previousMenu)); - } - } - /** * MenuButton skin interface. MenuButton skins must implement this interface * to facilitate additional communication between the component and the @@ -50,7 +42,7 @@ public class MenuButton extends Button { private Menu menu = null; - private MenuButtonListenerList menuButtonListeners = new MenuButtonListenerList(); + private MenuButtonListener.Listeners menuButtonListeners = new MenuButtonListener.Listeners(); private static final Button.DataRenderer DEFAULT_DATA_RENDERER = new ButtonDataRenderer(); @@ -86,7 +78,7 @@ public class MenuButton extends Button { public void setMenu(Menu menu) { if (menu != null && menu.getItem() != null) { - throw new IllegalArgumentException("menu already belongs to an item."); + throw new IllegalArgumentException("Menu already belongs to an item."); } Menu previousMenu = this.menu; Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButtonListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButtonListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButtonListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButtonListener.java Thu Feb 1 20:32:48 2018 @@ -16,11 +16,24 @@ */ package org.apache.pivot.wtk; +import org.apache.pivot.util.ListenerList; + /** * Menu button listener interface. */ public interface MenuButtonListener { /** + * Menu button listeners. + */ + public static class Listeners extends ListenerList<MenuButtonListener> + implements MenuButtonListener { + @Override + public void menuChanged(MenuButton menuButton, Menu previousMenu) { + forEach(listener -> listener.menuChanged(menuButton, previousMenu)); + } + } + + /** * Called when a menu button's menu has changed. * * @param menuButton The menu button that has changed. Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuItemSelectionListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuItemSelectionListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuItemSelectionListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuItemSelectionListener.java Thu Feb 1 20:32:48 2018 @@ -16,11 +16,24 @@ */ package org.apache.pivot.wtk; +import org.apache.pivot.util.ListenerList; + /** * Menu item selection listener interface. */ public interface MenuItemSelectionListener { /** + * Menu item selection listeners. + */ + public static class Listeners extends ListenerList<MenuItemSelectionListener> + implements MenuItemSelectionListener { + @Override + public void itemSelected(Menu.Item menuItem) { + forEach(listener -> listener.itemSelected(menuItem)); + } + } + + /** * Called when a descendant item of this menu has been selected. * * @param menuItem The newly selected menu item. Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuListener.java Thu Feb 1 20:32:48 2018 @@ -17,14 +17,37 @@ package org.apache.pivot.wtk; import org.apache.pivot.collections.Sequence; +import org.apache.pivot.util.ListenerList; /** * Menu listener interface. */ public interface MenuListener { /** + * Menu listeners. + */ + public static class Listeners extends ListenerList<MenuListener> implements MenuListener { + @Override + public void sectionInserted(Menu menu, int index) { + forEach(listener -> listener.sectionInserted(menu, index)); + } + + @Override + public void sectionsRemoved(Menu menu, int index, Sequence<Menu.Section> removed) { + forEach(listener -> listener.sectionsRemoved(menu, index, removed)); + } + + @Override + public void activeItemChanged(Menu menu, Menu.Item previousActiveItem) { + forEach(listener -> listener.activeItemChanged(menu, previousActiveItem)); + } + } + + /** * Menu listener adapter. + * @deprecated Since 2.1 and Java 8 the interface itself has default implementations. */ + @Deprecated public static class Adapter implements MenuListener { @Override public void sectionInserted(Menu menu, int index) { @@ -48,7 +71,8 @@ public interface MenuListener { * @param menu The source of the event. * @param index Where the menu section was inserted. */ - public void sectionInserted(Menu menu, int index); + default public void sectionInserted(Menu menu, int index) { + } /** * Called when menu sections have been removed. @@ -57,7 +81,8 @@ public interface MenuListener { * @param index The starting index of the removal. * @param removed The actual menu sections that were removed from the menu. */ - public void sectionsRemoved(Menu menu, int index, Sequence<Menu.Section> removed); + default public void sectionsRemoved(Menu menu, int index, Sequence<Menu.Section> removed) { + } /** * Called when a menu's active item has changed. @@ -65,5 +90,6 @@ public interface MenuListener { * @param menu The menu that changed. * @param previousActiveItem What the previously active menu item was. */ - public void activeItemChanged(Menu menu, Menu.Item previousActiveItem); + default public void activeItemChanged(Menu menu, Menu.Item previousActiveItem) { + } } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopup.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopup.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopup.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopup.java Thu Feb 1 20:32:48 2018 @@ -26,51 +26,13 @@ import org.apache.pivot.util.Vote; */ @DefaultProperty("menu") public class MenuPopup extends Window { - private static class MenuPopupListenerList extends ListenerList<MenuPopupListener> implements - MenuPopupListener { - @Override - public void menuChanged(MenuPopup menuPopup, Menu previousMenu) { - for (MenuPopupListener listener : this) { - listener.menuChanged(menuPopup, previousMenu); - } - } - } - - private static class MenuPopupStateListenerList extends ListenerList<MenuPopupStateListener> - implements MenuPopupStateListener { - @Override - public Vote previewMenuPopupClose(MenuPopup menuPopup, boolean immediate) { - Vote vote = Vote.APPROVE; - - for (MenuPopupStateListener listener : this) { - vote = vote.tally(listener.previewMenuPopupClose(menuPopup, immediate)); - } - - return vote; - } - - @Override - public void menuPopupCloseVetoed(MenuPopup menuPopup, Vote reason) { - for (MenuPopupStateListener listener : this) { - listener.menuPopupCloseVetoed(menuPopup, reason); - } - } - - @Override - public void menuPopupClosed(MenuPopup menuPopup) { - for (MenuPopupStateListener listener : this) { - listener.menuPopupClosed(menuPopup); - } - } - } - private Menu menu; private boolean contextMenu = false; private boolean closing = false; - private MenuPopupListenerList menuPopupListeners = new MenuPopupListenerList(); - private MenuPopupStateListenerList menuPopupStateListeners = new MenuPopupStateListenerList(); + private MenuPopupListener.Listeners menuPopupListeners = new MenuPopupListener.Listeners(); + private MenuPopupStateListener.Listeners menuPopupStateListeners = new MenuPopupStateListener.Listeners(); public MenuPopup() { this(null); Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopupListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopupListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopupListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopupListener.java Thu Feb 1 20:32:48 2018 @@ -16,11 +16,23 @@ */ package org.apache.pivot.wtk; +import org.apache.pivot.util.ListenerList; + /** * Menu popup listener interface. */ public interface MenuPopupListener { /** + * Menu popup listeners. + */ + public static class Listeners extends ListenerList<MenuPopupListener> implements MenuPopupListener { + @Override + public void menuChanged(MenuPopup menuPopup, Menu previousMenu) { + forEach(listener -> listener.menuChanged(menuPopup, previousMenu)); + } + } + + /** * Called when a menu popup's menu has changed. * * @param menuPopup The menu popup source of this event. Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopupStateListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopupStateListener.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopupStateListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopupStateListener.java Thu Feb 1 20:32:48 2018 @@ -16,15 +16,44 @@ */ package org.apache.pivot.wtk; +import org.apache.pivot.util.ListenerList; import org.apache.pivot.util.Vote; +import org.apache.pivot.util.VoteResult; /** * Menu popup state listener interface. */ public interface MenuPopupStateListener { /** + * Menu popup state listeners. + */ + public static class Listeners extends ListenerList<MenuPopupStateListener> + implements MenuPopupStateListener { + @Override + public Vote previewMenuPopupClose(MenuPopup menuPopup, boolean immediate) { + VoteResult result = new VoteResult(); + + forEach(listener -> result.tally(listener.previewMenuPopupClose(menuPopup, immediate))); + + return result.get(); + } + + @Override + public void menuPopupCloseVetoed(MenuPopup menuPopup, Vote reason) { + forEach(listener -> listener.menuPopupCloseVetoed(menuPopup, reason)); + } + + @Override + public void menuPopupClosed(MenuPopup menuPopup) { + forEach(listener -> listener.menuPopupClosed(menuPopup)); + } + } + + /** * Menu popup state listener adapter. + * @deprecated Since 2.1 and Java 8 the interface itself has default implementations. */ + @Deprecated public static class Adapter implements MenuPopupStateListener { @Override public Vote previewMenuPopupClose(MenuPopup menuPopup, boolean immediate) { @@ -49,7 +78,9 @@ public interface MenuPopupStateListener * @param immediate Whether the close is meant to be immediate. * @return The verdict as to whether to close from this listener. */ - public Vote previewMenuPopupClose(MenuPopup menuPopup, boolean immediate); + default public Vote previewMenuPopupClose(MenuPopup menuPopup, boolean immediate) { + return Vote.APPROVE; + } /** * Called when a menu popup close event has been vetoed. @@ -57,12 +88,14 @@ public interface MenuPopupStateListener * @param menuPopup The source of the event. * @param reason The accumulated vote that caused the veto. */ - public void menuPopupCloseVetoed(MenuPopup menuPopup, Vote reason); + default public void menuPopupCloseVetoed(MenuPopup menuPopup, Vote reason) { + } /** * Called when a menu popup has closed. * * @param menuPopup The menu popup that closed. */ - public void menuPopupClosed(MenuPopup menuPopup); + default public void menuPopupClosed(MenuPopup menuPopup) { + } } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java Thu Feb 1 20:32:48 2018 @@ -175,7 +175,7 @@ public abstract class CalendarButtonSkin public CalendarButtonSkin() { calendar = new Calendar(); - calendar.getCalendarListeners().add(new CalendarListener.Adapter() { + calendar.getCalendarListeners().add(new CalendarListener() { @Override public void yearChanged(Calendar calendarArgument, int previousYear) { CalendarButton calendarButton = (CalendarButton) getComponent(); Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuButtonSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuButtonSkin.java?rev=1822902&r1=1822901&r2=1822902&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuButtonSkin.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuButtonSkin.java Thu Feb 1 20:32:48 2018 @@ -63,7 +63,7 @@ public abstract class MenuButtonSkin ext } }; - private MenuPopupStateListener menuPopupStateListener = new MenuPopupStateListener.Adapter() { + private MenuPopupStateListener menuPopupStateListener = new MenuPopupStateListener() { @Override public Vote previewMenuPopupClose(MenuPopup menuPopupArgument, boolean immediate) { if (menuPopupArgument.containsFocus()) {