You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2017/10/24 15:24:35 UTC

svn commit: r1813186 - in /pivot/trunk: core/src/org/apache/pivot/util/ wtk-terra/src/org/apache/pivot/wtk/skin/terra/ wtk/src/org/apache/pivot/wtk/

Author: rwhitcomb
Date: Tue Oct 24 15:24:35 2017
New Revision: 1813186

URL: http://svn.apache.org/viewvc?rev=1813186&view=rev
Log:
PIVOT-999: Update Calendar and CalendarButton to use "forEach" in their
listener list methods.  Use Utils methods for parameter validation in the
skin classes and a few other places.  Add MIN_CALENDAR_YEAR and
MAX_CALENDAR_YEAR to CalendarDate and use these values in the Calendar skin
for the year spinner.  Remove unnecessary duplicate checks for null values
when "decode" and other methods are being used that also do these checks.
Use new "currentTheme()" method to access theme colors (instead of referring
to TerraTheme unnecessarily).  Consolidate some common code around padding.
Use some of the new GraphicsUtilities methods to simplify the code.  And
some code reformatting for readability.

Modified:
    pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java

Modified: pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java?rev=1813186&r1=1813185&r2=1813186&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java Tue Oct 24 15:24:35 2017
@@ -220,9 +220,15 @@ public final class CalendarDate implemen
 
     private static final int[] MONTH_LENGTHS = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 
-    private static final int GREGORIAN_CUTOVER_YEAR = 1582;
     private static final Pattern PATTERN = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})$");
 
+    private static final int GREGORIAN_CUTOVER_YEAR = 1582;
+
+    /** Minimum supported year (must be greater or equal). */
+    public static final int MIN_CALENDAR_YEAR = GREGORIAN_CUTOVER_YEAR + 1;
+    /** Maximum supported year (must be less or equal). */
+    public static final int MAX_CALENDAR_YEAR = 9999;
+
     /**
      * Creates a new <tt>CalendarDate</tt> representing the current day in the
      * default timezone and the default locale.
@@ -264,9 +270,11 @@ public final class CalendarDate implemen
      * @param year The year field. (e.g. <tt>2008</tt>)
      * @param month The month field, 0-based. (e.g. <tt>2</tt> for March)
      * @param day The day of the month, 0-based. (e.g. <tt>14</tt> for the 15th)
+     * @see #MIN_CALENDAR_YEAR
+     * @see #MAX_CALENDAR_YEAR
      */
     public CalendarDate(int year, int month, int day) {
-        if (year <= GREGORIAN_CUTOVER_YEAR || year > 9999) {
+        if (year < MIN_CALENDAR_YEAR || year > MAX_CALENDAR_YEAR) {
             throw new IllegalArgumentException("Invalid year: " + year);
         }
 
@@ -501,6 +509,8 @@ public final class CalendarDate implemen
      * @return The {@code CalendarDate} corresponding to the input string.
      */
     public static CalendarDate decode(String value) {
+        Utils.checkNullOrEmpty(value, "calendarDate");
+
         Matcher matcher = PATTERN.matcher(value);
 
         if (!matcher.matches()) {

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java?rev=1813186&r1=1813185&r2=1813186&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java Tue Oct 24 15:24:35 2017
@@ -28,6 +28,7 @@ import java.awt.geom.RoundRectangle2D;
 import java.util.Locale;
 
 import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.util.Utils;
 import org.apache.pivot.util.Vote;
 import org.apache.pivot.wtk.Border;
 import org.apache.pivot.wtk.Bounds;
@@ -147,7 +148,7 @@ public class TerraCalendarButtonSkin ext
     private static final int DEFAULT_CLOSE_TRANSITION_RATE = 30;
 
     public TerraCalendarButtonSkin() {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        Theme theme = currentTheme();
 
         font = theme.getFont();
         color = theme.getColor(1);
@@ -156,7 +157,7 @@ public class TerraCalendarButtonSkin ext
         disabledBackgroundColor = theme.getColor(10);
         borderColor = theme.getColor(7);
         disabledBorderColor = theme.getColor(7);
-        padding = new Insets(2, 3, 2, 3);
+        padding = new Insets(4, 6);    // height, width
 
         // Set the derived colors
         bevelColor = TerraTheme.brighten(backgroundColor);
@@ -178,6 +179,14 @@ public class TerraCalendarButtonSkin ext
         calendarPopup.getDecorators().add(dropShadowDecorator);
     }
 
+    private int paddingWidth() {
+        return TRIGGER_WIDTH + padding.getWidth() + 2;
+    }
+
+    private int paddingHeight() {
+        return padding.getHeight() + 2;
+    }
+
     @Override
     public int getPreferredWidth(int height) {
         CalendarButton calendarButton = (CalendarButton) getComponent();
@@ -185,8 +194,7 @@ public class TerraCalendarButtonSkin ext
         Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
         dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
 
-        int preferredWidth = dataRenderer.getPreferredWidth(-1) + TRIGGER_WIDTH + padding.left
-            + padding.right + 2;
+        int preferredWidth = dataRenderer.getPreferredWidth(-1) + paddingWidth();
 
         return preferredWidth;
     }
@@ -198,8 +206,7 @@ public class TerraCalendarButtonSkin ext
         Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
         dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
 
-        int preferredHeight = dataRenderer.getPreferredHeight(-1) + padding.top + padding.bottom
-            + 2;
+        int preferredHeight = dataRenderer.getPreferredHeight(-1) + paddingHeight();
 
         return preferredHeight;
     }
@@ -212,8 +219,8 @@ public class TerraCalendarButtonSkin ext
         dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
 
         Dimensions contentSize = dataRenderer.getPreferredSize();
-        int preferredWidth = contentSize.width + TRIGGER_WIDTH + padding.left + padding.right + 2;
-        int preferredHeight = contentSize.height + padding.top + padding.bottom + 2;
+        int preferredWidth = contentSize.width + paddingWidth();
+        int preferredHeight = contentSize.height + paddingHeight();
 
         return new Dimensions(preferredWidth, preferredHeight);
     }
@@ -225,8 +232,8 @@ public class TerraCalendarButtonSkin ext
         Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
         dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
 
-        int clientWidth = Math.max(width - (TRIGGER_WIDTH + padding.left + padding.right + 2), 0);
-        int clientHeight = Math.max(height - (padding.top + padding.bottom + 2), 0);
+        int clientWidth = Math.max(width - paddingWidth(), 0);
+        int clientHeight = Math.max(height - paddingHeight(), 0);
 
         int baseline = dataRenderer.getBaseline(clientWidth, clientHeight);
 
@@ -265,8 +272,7 @@ public class TerraCalendarButtonSkin ext
         }
 
         // Paint the background
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-            RenderingHints.VALUE_ANTIALIAS_ON);
+        GraphicsUtilities.setAntialiasingOn(graphics);
 
         if (!themeIsFlat()) {
             graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColorLocal, width / 2f,
@@ -278,16 +284,15 @@ public class TerraCalendarButtonSkin ext
             CORNER_RADIUS));
 
         // Paint the content
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-            RenderingHints.VALUE_ANTIALIAS_OFF);
+        GraphicsUtilities.setAntialiasingOff(graphics);
 
-        Bounds contentBounds = new Bounds(0, 0, Math.max(width - TRIGGER_WIDTH - 1, 0), Math.max(
-            height - 1, 0));
+        Bounds contentBounds = new Bounds(0, 0,
+            Math.max(width - TRIGGER_WIDTH - 1, 0), Math.max(height - 1, 0));
         Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
         dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
         dataRenderer.setSize(
-            Math.max(contentBounds.width - (padding.left + padding.right + 2) + 1, 0),
-            Math.max(contentBounds.height - (padding.top + padding.bottom + 2) + 1, 0));
+            Math.max(contentBounds.width - paddingWidth() + 1, 0),
+            Math.max(contentBounds.height - paddingHeight() + 1, 0));
 
         Graphics2D contentGraphics = (Graphics2D) graphics.create();
         contentGraphics.translate(padding.left + 1, padding.top + 1);
@@ -295,8 +300,7 @@ public class TerraCalendarButtonSkin ext
         dataRenderer.paint(contentGraphics);
         contentGraphics.dispose();
 
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-            RenderingHints.VALUE_ANTIALIAS_ON);
+        GraphicsUtilities.setAntialiasingOn(graphics);
 
         if (!themeIsFlat()) {
             // Paint the border
@@ -318,8 +322,7 @@ public class TerraCalendarButtonSkin ext
                 height - 5, 0), CORNER_RADIUS / 2, CORNER_RADIUS / 2));
         }
 
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-            RenderingHints.VALUE_ANTIALIAS_OFF);
+        GraphicsUtilities.setAntialiasingOff(graphics);
 
         // Paint the trigger
         GeneralPath triggerIconShape = new GeneralPath(Path2D.WIND_EVEN_ODD);
@@ -349,27 +352,17 @@ public class TerraCalendarButtonSkin ext
     }
 
     public void setFont(Font font) {
-        if (font == null) {
-            throw new IllegalArgumentException("font is null.");
-        }
+        Utils.checkNull(font, "font");
 
         this.font = font;
         invalidateComponent();
     }
 
     public final void setFont(String font) {
-        if (font == null) {
-            throw new IllegalArgumentException("font is null.");
-        }
-
         setFont(decodeFont(font));
     }
 
     public final void setFont(Dictionary<String, ?> font) {
-        if (font == null) {
-            throw new IllegalArgumentException("font is null.");
-        }
-
         setFont(Theme.deriveFont(font));
     }
 
@@ -378,24 +371,18 @@ public class TerraCalendarButtonSkin ext
     }
 
     public void setColor(Color color) {
-        if (color == null) {
-            throw new IllegalArgumentException("color is null.");
-        }
+        Utils.checkNull(color, "color");
 
         this.color = color;
         repaintComponent();
     }
 
     public final void setColor(String color) {
-        if (color == null) {
-            throw new IllegalArgumentException("color is null.");
-        }
-
-        setColor(GraphicsUtilities.decodeColor(color));
+        setColor(GraphicsUtilities.decodeColor(color, "color"));
     }
 
     public final void setColor(int color) {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        Theme theme = currentTheme();
         setColor(theme.getColor(color));
     }
 
@@ -404,24 +391,18 @@ public class TerraCalendarButtonSkin ext
     }
 
     public void setDisabledColor(Color disabledColor) {
-        if (disabledColor == null) {
-            throw new IllegalArgumentException("disabledColor is null.");
-        }
+        Utils.checkNull(disabledColor, "disabledColor");
 
         this.disabledColor = disabledColor;
         repaintComponent();
     }
 
     public final void setDisabledColor(String disabledColor) {
-        if (disabledColor == null) {
-            throw new IllegalArgumentException("disabledColor is null.");
-        }
-
-        setDisabledColor(GraphicsUtilities.decodeColor(disabledColor));
+        setDisabledColor(GraphicsUtilities.decodeColor(disabledColor, "disabledColor"));
     }
 
     public final void setDisabledColor(int disabledColor) {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        Theme theme = currentTheme();
         setDisabledColor(theme.getColor(disabledColor));
     }
 
@@ -430,9 +411,7 @@ public class TerraCalendarButtonSkin ext
     }
 
     public void setBackgroundColor(Color backgroundColor) {
-        if (backgroundColor == null) {
-            throw new IllegalArgumentException("backgroundColor is null.");
-        }
+        Utils.checkNull(backgroundColor, "backgroundColor");
 
         this.backgroundColor = backgroundColor;
         bevelColor = TerraTheme.brighten(backgroundColor);
@@ -441,15 +420,11 @@ public class TerraCalendarButtonSkin ext
     }
 
     public final void setBackgroundColor(String backgroundColor) {
-        if (backgroundColor == null) {
-            throw new IllegalArgumentException("backgroundColor is null.");
-        }
-
-        setBackgroundColor(GraphicsUtilities.decodeColor(backgroundColor));
+        setBackgroundColor(GraphicsUtilities.decodeColor(backgroundColor, "backgroundColor"));
     }
 
     public final void setBackgroundColor(int backgroundColor) {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        Theme theme = currentTheme();
         setBackgroundColor(theme.getColor(backgroundColor));
     }
 
@@ -458,9 +433,7 @@ public class TerraCalendarButtonSkin ext
     }
 
     public void setDisabledBackgroundColor(Color disabledBackgroundColor) {
-        if (disabledBackgroundColor == null) {
-            throw new IllegalArgumentException("disabledBackgroundColor is null.");
-        }
+        Utils.checkNull(disabledBackgroundColor, "disabledBackgroundColor");
 
         this.disabledBackgroundColor = disabledBackgroundColor;
         disabledBevelColor = disabledBackgroundColor;
@@ -468,15 +441,11 @@ public class TerraCalendarButtonSkin ext
     }
 
     public final void setDisabledBackgroundColor(String disabledBackgroundColor) {
-        if (disabledBackgroundColor == null) {
-            throw new IllegalArgumentException("disabledBackgroundColor is null.");
-        }
-
-        setDisabledBackgroundColor(GraphicsUtilities.decodeColor(disabledBackgroundColor));
+        setDisabledBackgroundColor(GraphicsUtilities.decodeColor(disabledBackgroundColor, "disabledBackgroundColor"));
     }
 
     public final void setDisabledBackgroundColor(int disabledBackgroundColor) {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        Theme theme = currentTheme();
         setDisabledBackgroundColor(theme.getColor(disabledBackgroundColor));
     }
 
@@ -485,9 +454,7 @@ public class TerraCalendarButtonSkin ext
     }
 
     public void setBorderColor(Color borderColor) {
-        if (borderColor == null) {
-            throw new IllegalArgumentException("borderColor is null.");
-        }
+        Utils.checkNull(borderColor, "borderColor");
 
         this.borderColor = borderColor;
         calendarBorder.getStyles().put("color", borderColor);
@@ -495,15 +462,11 @@ public class TerraCalendarButtonSkin ext
     }
 
     public final void setBorderColor(String borderColor) {
-        if (borderColor == null) {
-            throw new IllegalArgumentException("borderColor is null.");
-        }
-
-        setBorderColor(GraphicsUtilities.decodeColor(borderColor));
+        setBorderColor(GraphicsUtilities.decodeColor(borderColor, "borderColor"));
     }
 
     public final void setBorderColor(int borderColor) {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        Theme theme = currentTheme();
         setBorderColor(theme.getColor(borderColor));
     }
 
@@ -512,24 +475,18 @@ public class TerraCalendarButtonSkin ext
     }
 
     public void setDisabledBorderColor(Color disabledBorderColor) {
-        if (disabledBorderColor == null) {
-            throw new IllegalArgumentException("disabledBorderColor is null.");
-        }
+        Utils.checkNull(disabledBorderColor, "disabledBorderColor");
 
         this.disabledBorderColor = disabledBorderColor;
         repaintComponent();
     }
 
     public final void setDisabledBorderColor(String disabledBorderColor) {
-        if (disabledBorderColor == null) {
-            throw new IllegalArgumentException("disabledBorderColor is null.");
-        }
-
-        setDisabledBorderColor(GraphicsUtilities.decodeColor(disabledBorderColor));
+        setDisabledBorderColor(GraphicsUtilities.decodeColor(disabledBorderColor, "disabledBorderColor"));
     }
 
     public final void setDisabledBorderColor(int disabledBorderColor) {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        Theme theme = currentTheme();
         setDisabledBorderColor(theme.getColor(disabledBorderColor));
     }
 
@@ -538,19 +495,13 @@ public class TerraCalendarButtonSkin ext
     }
 
     public void setPadding(Insets padding) {
-        if (padding == null) {
-            throw new IllegalArgumentException("padding is null.");
-        }
+        Utils.checkNull(padding, "padding");
 
         this.padding = padding;
         invalidateComponent();
     }
 
     public final void setPadding(Dictionary<String, ?> padding) {
-        if (padding == null) {
-            throw new IllegalArgumentException("padding is null.");
-        }
-
         setPadding(new Insets(padding));
     }
 
@@ -559,18 +510,10 @@ public class TerraCalendarButtonSkin ext
     }
 
     public final void setPadding(Number padding) {
-        if (padding == null) {
-            throw new IllegalArgumentException("padding is null.");
-        }
-
-        setPadding(padding.intValue());
+        setPadding(new Insets(padding));
     }
 
     public final void setPadding(String padding) {
-        if (padding == null) {
-            throw new IllegalArgumentException("padding is null.");
-        }
-
         setPadding(Insets.decode(padding));
     }
 

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarSkin.java?rev=1813186&r1=1813185&r2=1813186&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarSkin.java Tue Oct 24 15:24:35 2017
@@ -31,6 +31,7 @@ import org.apache.pivot.serialization.Se
 import org.apache.pivot.util.CalendarDate;
 import org.apache.pivot.util.Filter;
 import org.apache.pivot.util.Resources;
+import org.apache.pivot.util.Utils;
 import org.apache.pivot.wtk.Bounds;
 import org.apache.pivot.wtk.Button;
 import org.apache.pivot.wtk.ButtonGroup;
@@ -135,8 +136,8 @@ public class TerraCalendarSkin extends C
 
             Dimensions preferredSize = dataRenderer.getPreferredSize();
 
-            return new Dimensions(preferredSize.width + padding * 2, preferredSize.height + padding
-                * 2);
+            return new Dimensions(preferredSize.width + padding * 2,
+                                  preferredSize.height + padding * 2);
         }
 
         @Override
@@ -351,8 +352,7 @@ public class TerraCalendarSkin extends C
         public void render(Object item, Spinner spinner) {
             Calendar calendar = (Calendar) getComponent();
 
-            // Since we're only rendering the month, the year and day do not
-            // matter here
+            // Since we're only rendering the month, the year and day do not matter here
             CalendarDate date = new CalendarDate(2000, ((Integer) item).intValue(), 0);
 
             SimpleDateFormat monthFormat = new SimpleDateFormat("MMMM", calendar.getLocale());
@@ -401,7 +401,7 @@ public class TerraCalendarSkin extends C
 
     @SuppressWarnings("unused")
     public TerraCalendarSkin() {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        Theme theme = currentTheme();
         font = theme.getFont();
         color = theme.getColor(1);
         disabledColor = theme.getColor(7);
@@ -436,7 +436,8 @@ public class TerraCalendarSkin extends C
 
         // Year spinner
         yearSpinner = new Spinner();
-        yearSpinner.setSpinnerData(new NumericSpinnerData(0, Short.MAX_VALUE));
+        yearSpinner.setSpinnerData(
+            new NumericSpinnerData(CalendarDate.MIN_CALENDAR_YEAR, CalendarDate.MAX_CALENDAR_YEAR));
 
         yearSpinner.getSpinnerSelectionListeners().add(new SpinnerSelectionListener.Adapter() {
             @Override
@@ -504,7 +505,8 @@ public class TerraCalendarSkin extends C
                     // result of the user toggling the date button (as opposed
                     // to changing the month or year), clear the selection
                     if (selectedDate == null
-                        || (selectedDate.year == yearSpinner.getSelectedIndex() && selectedDate.month == monthSpinner.getSelectedIndex())) {
+                        || (selectedDate.year == yearSpinner.getSelectedIndex()
+                        && selectedDate.month == monthSpinner.getSelectedIndex())) {
                         calendar.setSelectedDate((CalendarDate) null);
                     }
                 } else {
@@ -583,8 +585,8 @@ public class TerraCalendarSkin extends C
         int width = getWidth();
         Bounds monthYearRowBounds = calendarTablePane.getRowBounds(0);
         graphics.setColor(highlightBackgroundColor);
-        graphics.fillRect(monthYearRowBounds.x, monthYearRowBounds.y, monthYearRowBounds.width,
-            monthYearRowBounds.height);
+        graphics.fillRect(monthYearRowBounds.x, monthYearRowBounds.y,
+            monthYearRowBounds.width, monthYearRowBounds.height);
 
         Bounds labelRowBounds = calendarTablePane.getRowBounds(1);
 
@@ -626,7 +628,8 @@ public class TerraCalendarSkin extends C
         Locale locale = calendar.getLocale();
         GregorianCalendar gregorianCalendar = new GregorianCalendar(locale);
         gregorianCalendar.set(year, month, 1);
-        int firstIndex = (7 + gregorianCalendar.get(java.util.Calendar.DAY_OF_WEEK) - gregorianCalendar.getFirstDayOfWeek()) % 7;
+        int firstIndex = (7 + gregorianCalendar.get(java.util.Calendar.DAY_OF_WEEK)
+            - gregorianCalendar.getFirstDayOfWeek()) % 7;
         int lastIndex = firstIndex
             + gregorianCalendar.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
 
@@ -718,7 +721,8 @@ public class TerraCalendarSkin extends C
     private static int getCellIndex(int year, int month, int day, Locale locale) {
         GregorianCalendar gregorianCalendar = new GregorianCalendar(locale);
         gregorianCalendar.set(year, month, 1);
-        int firstDay = ((gregorianCalendar.get(java.util.Calendar.DAY_OF_WEEK) - gregorianCalendar.getFirstDayOfWeek()) + 7) % 7;
+        int firstDay = ((gregorianCalendar.get(java.util.Calendar.DAY_OF_WEEK)
+            - gregorianCalendar.getFirstDayOfWeek()) + 7) % 7;
         int cellIndex = firstDay + day;
 
         return cellIndex;
@@ -729,9 +733,7 @@ public class TerraCalendarSkin extends C
     }
 
     public void setFont(Font font) {
-        if (font == null) {
-            throw new IllegalArgumentException("font is null.");
-        }
+        Utils.checkNull(font, "font");
 
         this.font = font;
 
@@ -748,18 +750,10 @@ public class TerraCalendarSkin extends C
     }
 
     public final void setFont(String font) {
-        if (font == null) {
-            throw new IllegalArgumentException("font is null.");
-        }
-
         setFont(decodeFont(font));
     }
 
     public final void setFont(Dictionary<String, ?> font) {
-        if (font == null) {
-            throw new IllegalArgumentException("font is null.");
-        }
-
         setFont(Theme.deriveFont(font));
     }
 
@@ -768,20 +762,14 @@ public class TerraCalendarSkin extends C
     }
 
     public void setColor(Color color) {
-        if (color == null) {
-            throw new IllegalArgumentException("color is null.");
-        }
+        Utils.checkNull(color, "color");
 
         this.color = color;
         repaintComponent();
     }
 
     public final void setColor(String color) {
-        if (color == null) {
-            throw new IllegalArgumentException("color is null.");
-        }
-
-        setColor(GraphicsUtilities.decodeColor(color));
+        setColor(GraphicsUtilities.decodeColor(color, "color"));
     }
 
     public Color getDisabledColor() {
@@ -789,20 +777,14 @@ public class TerraCalendarSkin extends C
     }
 
     public void setDisabledColor(Color disabledColor) {
-        if (disabledColor == null) {
-            throw new IllegalArgumentException("disabledColor is null.");
-        }
+        Utils.checkNull(disabledColor, "disabledColor");
 
         this.disabledColor = disabledColor;
         repaintComponent();
     }
 
     public final void setDisabledColor(String disabledColor) {
-        if (disabledColor == null) {
-            throw new IllegalArgumentException("disabledColor is null.");
-        }
-
-        setDisabledColor(GraphicsUtilities.decodeColor(disabledColor));
+        setDisabledColor(GraphicsUtilities.decodeColor(disabledColor, "disabledColor"));
     }
 
     public Color getSelectionColor() {
@@ -810,20 +792,14 @@ public class TerraCalendarSkin extends C
     }
 
     public void setSelectionColor(Color selectionColor) {
-        if (selectionColor == null) {
-            throw new IllegalArgumentException("selectionColor is null.");
-        }
+        Utils.checkNull(selectionColor, "selectionColor");
 
         this.selectionColor = selectionColor;
         repaintComponent();
     }
 
     public final void setSelectionColor(String selectionColor) {
-        if (selectionColor == null) {
-            throw new IllegalArgumentException("selectionColor is null.");
-        }
-
-        setSelectionColor(GraphicsUtilities.decodeColor(selectionColor));
+        setSelectionColor(GraphicsUtilities.decodeColor(selectionColor, "selectionColor"));
     }
 
     public Color getSelectionBackgroundColor() {
@@ -831,9 +807,7 @@ public class TerraCalendarSkin extends C
     }
 
     public void setSelectionBackgroundColor(Color selectionBackgroundColor) {
-        if (selectionBackgroundColor == null) {
-            throw new IllegalArgumentException("selectionBackgroundColor is null.");
-        }
+        Utils.checkNull(selectionBackgroundColor, "selectionBackgroundColor");
 
         this.selectionBackgroundColor = selectionBackgroundColor;
         selectionBevelColor = TerraTheme.brighten(selectionBackgroundColor);
@@ -841,11 +815,7 @@ public class TerraCalendarSkin extends C
     }
 
     public final void setSelectionBackgroundColor(String selectionBackgroundColor) {
-        if (selectionBackgroundColor == null) {
-            throw new IllegalArgumentException("selectionBackgroundColor is null.");
-        }
-
-        setSelectionBackgroundColor(GraphicsUtilities.decodeColor(selectionBackgroundColor));
+        setSelectionBackgroundColor(GraphicsUtilities.decodeColor(selectionBackgroundColor, "selectionBackgroundColor"));
     }
 
     public Color getHighlightColor() {
@@ -853,20 +823,14 @@ public class TerraCalendarSkin extends C
     }
 
     public void setHighlightColor(Color highlightColor) {
-        if (highlightColor == null) {
-            throw new IllegalArgumentException("highlightColor is null.");
-        }
+        Utils.checkNull(highlightColor, "highlightColor");
 
         this.highlightColor = highlightColor;
         repaintComponent();
     }
 
     public final void setHighlightColor(String highlightColor) {
-        if (highlightColor == null) {
-            throw new IllegalArgumentException("highlightColor is null.");
-        }
-
-        setHighlightColor(GraphicsUtilities.decodeColor(highlightColor));
+        setHighlightColor(GraphicsUtilities.decodeColor(highlightColor, "highlightColor"));
     }
 
     public Color getHighlightBackgroundColor() {
@@ -874,20 +838,14 @@ public class TerraCalendarSkin extends C
     }
 
     public void setHighlightBackgroundColor(Color highlightBackgroundColor) {
-        if (highlightBackgroundColor == null) {
-            throw new IllegalArgumentException("highlightBackgroundColor is null.");
-        }
+        Utils.checkNull(highlightBackgroundColor, "highlightBackgroundColor");
 
         this.highlightBackgroundColor = highlightBackgroundColor;
         repaintComponent();
     }
 
     public final void setHighlightBackgroundColor(String highlightBackgroundColor) {
-        if (highlightBackgroundColor == null) {
-            throw new IllegalArgumentException("highlightBackgroundColor is null.");
-        }
-
-        setHighlightBackgroundColor(GraphicsUtilities.decodeColor(highlightBackgroundColor));
+        setHighlightBackgroundColor(GraphicsUtilities.decodeColor(highlightBackgroundColor, "highlightBackgroundColor"));
     }
 
     public Color getDividerColor() {
@@ -895,20 +853,14 @@ public class TerraCalendarSkin extends C
     }
 
     public void setDividerColor(Color dividerColor) {
-        if (dividerColor == null) {
-            throw new IllegalArgumentException("dividerColor is null.");
-        }
+        Utils.checkNull(dividerColor, "dividerColor");
 
         this.dividerColor = dividerColor;
         repaintComponent();
     }
 
     public final void setDividerColor(String dividerColor) {
-        if (dividerColor == null) {
-            throw new IllegalArgumentException("dividerColor is null.");
-        }
-
-        setDividerColor(GraphicsUtilities.decodeColor(dividerColor));
+        setDividerColor(GraphicsUtilities.decodeColor(dividerColor, "dividerColor"));
     }
 
     public int getPadding() {
@@ -916,18 +868,14 @@ public class TerraCalendarSkin extends C
     }
 
     public void setPadding(int padding) {
-        if (padding < 0) {
-            throw new IllegalArgumentException("padding is negative.");
-        }
+        Utils.checkNonNegative(padding, "padding");
 
         this.padding = padding;
         invalidateComponent();
     }
 
     public final void setPadding(Number padding) {
-        if (padding == null) {
-            throw new IllegalArgumentException("padding is null.");
-        }
+        Utils.checkNull(padding, "padding");
 
         setPadding(padding.intValue());
     }

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=1813186&r1=1813185&r2=1813186&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java Tue Oct 24 15:24:35 2017
@@ -25,6 +25,7 @@ import org.apache.pivot.serialization.Se
 import org.apache.pivot.util.CalendarDate;
 import org.apache.pivot.util.Filter;
 import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
 
 /**
  * Component that allows the user to select a date.
@@ -55,31 +56,23 @@ public class Calendar extends Container
         CalendarListener {
         @Override
         public void yearChanged(Calendar calendar, int previousYear) {
-            for (CalendarListener listener : this) {
-                listener.yearChanged(calendar, previousYear);
-            }
+            forEach(listener -> listener.yearChanged(calendar, previousYear));
         }
 
         @Override
         public void monthChanged(Calendar calendar, int previousMonth) {
-            for (CalendarListener listener : this) {
-                listener.monthChanged(calendar, previousMonth);
-            }
+            forEach(listener -> listener.monthChanged(calendar, previousMonth));
         }
 
         @Override
         public void localeChanged(Calendar calendar, Locale previousLocale) {
-            for (CalendarListener listener : this) {
-                listener.localeChanged(calendar, previousLocale);
-            }
+            forEach(listener -> listener.localeChanged(calendar, previousLocale));
         }
 
         @Override
         public void disabledDateFilterChanged(Calendar calendar,
             Filter<CalendarDate> previousDisabledDateFilter) {
-            for (CalendarListener listener : this) {
-                listener.disabledDateFilterChanged(calendar, previousDisabledDateFilter);
-            }
+            forEach(listener -> listener.disabledDateFilterChanged(calendar, previousDisabledDateFilter));
         }
     }
 
@@ -88,9 +81,7 @@ public class Calendar extends Container
 
         @Override
         public void selectedDateChanged(Calendar calendar, CalendarDate previousSelectedDate) {
-            for (CalendarSelectionListener listener : this) {
-                listener.selectedDateChanged(calendar, previousSelectedDate);
-            }
+            forEach(listener -> listener.selectedDateChanged(calendar, previousSelectedDate));
         }
     }
 
@@ -98,25 +89,19 @@ public class Calendar extends Container
         ListenerList<CalendarBindingListener> implements CalendarBindingListener {
         @Override
         public void selectedDateKeyChanged(Calendar calendar, String previousSelectedDateKey) {
-            for (CalendarBindingListener listener : this) {
-                listener.selectedDateKeyChanged(calendar, previousSelectedDateKey);
-            }
+            forEach(listener -> listener.selectedDateKeyChanged(calendar, previousSelectedDateKey));
         }
 
         @Override
         public void selectedDateBindTypeChanged(Calendar calendar,
             BindType previousSelectedDateBindType) {
-            for (CalendarBindingListener listener : this) {
-                listener.selectedDateBindTypeChanged(calendar, previousSelectedDateBindType);
-            }
+            forEach(listener -> listener.selectedDateBindTypeChanged(calendar, previousSelectedDateBindType));
         }
 
         @Override
         public void selectedDateBindMappingChanged(Calendar calendar,
             SelectedDateBindMapping previousSelectedDateBindMapping) {
-            for (CalendarBindingListener listener : this) {
-                listener.selectedDateBindMappingChanged(calendar, previousSelectedDateBindMapping);
-            }
+            forEach(listener -> listener.selectedDateBindMappingChanged(calendar, previousSelectedDateBindMapping));
         }
     }
 
@@ -233,10 +218,6 @@ public class Calendar extends Container
      * @throws IllegalArgumentException if the given date is {@code null}.
      */
     public final void setSelectedDate(String selectedDate) {
-        if (selectedDate == null) {
-            throw new IllegalArgumentException("selectedDate is null.");
-        }
-
         setSelectedDate(CalendarDate.decode(selectedDate));
     }
 
@@ -254,9 +235,7 @@ public class Calendar extends Container
      * @throws IllegalArgumentException if the locale argument is {@code null}.
      */
     public void setLocale(Locale locale) {
-        if (locale == null) {
-            throw new IllegalArgumentException("locale is null.");
-        }
+        Utils.checkNull(locale, "locale");
 
         Locale previousLocale = this.locale;
         if (previousLocale != locale) {
@@ -276,9 +255,7 @@ public class Calendar extends Container
      * @throws IllegalArgumentException if the given locale dictionary is {@code null}.
      */
     public void setLocale(Dictionary<String, ?> locale) {
-        if (locale == null) {
-            throw new IllegalArgumentException("locale is null.");
-        }
+        Utils.checkNull(locale, "locale");
 
         String language = (String) locale.get(LANGUAGE_KEY);
         String country = (String) locale.get(COUNTRY_KEY);
@@ -303,9 +280,7 @@ public class Calendar extends Container
      * @see #setLocale(Dictionary)
      */
     public void setLocale(String locale) {
-        if (locale == null) {
-            throw new IllegalArgumentException("locale is null.");
-        }
+        Utils.checkNullOrEmpty(locale, "locale");
 
         try {
             setLocale(JSONSerializer.parseMap(locale));
@@ -355,9 +330,7 @@ public class Calendar extends Container
     }
 
     public void setSelectedDateBindType(BindType selectedDateBindType) {
-        if (selectedDateBindType == null) {
-            throw new IllegalArgumentException();
-        }
+        Utils.checkNull(selectedDateBindType, "selectedDateBindType");
 
         BindType previousSelectedDateBindType = this.selectedDateBindType;
 

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=1813186&r1=1813185&r2=1813186&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java Tue Oct 24 15:24:35 2017
@@ -25,6 +25,7 @@ import org.apache.pivot.serialization.Se
 import org.apache.pivot.util.CalendarDate;
 import org.apache.pivot.util.Filter;
 import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
 import org.apache.pivot.wtk.content.CalendarButtonDataRenderer;
 
 /**
@@ -36,31 +37,23 @@ public class CalendarButton extends Butt
         implements CalendarButtonListener {
         @Override
         public void yearChanged(CalendarButton calendarButton, int previousYear) {
-            for (CalendarButtonListener listener : this) {
-                listener.yearChanged(calendarButton, previousYear);
-            }
+            forEach(listener -> listener.yearChanged(calendarButton, previousYear));
         }
 
         @Override
         public void monthChanged(CalendarButton calendarButton, int previousMonth) {
-            for (CalendarButtonListener listener : this) {
-                listener.monthChanged(calendarButton, previousMonth);
-            }
+            forEach(listener -> listener.monthChanged(calendarButton, previousMonth));
         }
 
         @Override
         public void localeChanged(CalendarButton calendarButton, Locale previousLocale) {
-            for (CalendarButtonListener listener : this) {
-                listener.localeChanged(calendarButton, previousLocale);
-            }
+            forEach(listener -> listener.localeChanged(calendarButton, previousLocale));
         }
 
         @Override
         public void disabledDateFilterChanged(CalendarButton calendarButton,
             Filter<CalendarDate> previousDisabledDateFilter) {
-            for (CalendarButtonListener listener : this) {
-                listener.disabledDateFilterChanged(calendarButton, previousDisabledDateFilter);
-            }
+            forEach(listener -> listener.disabledDateFilterChanged(calendarButton, previousDisabledDateFilter));
         }
     }
 
@@ -70,9 +63,7 @@ public class CalendarButton extends Butt
         @Override
         public void selectedDateChanged(CalendarButton calendarButton,
             CalendarDate previousSelectedDate) {
-            for (CalendarButtonSelectionListener listener : this) {
-                listener.selectedDateChanged(calendarButton, previousSelectedDate);
-            }
+            forEach(listener -> listener.selectedDateChanged(calendarButton, previousSelectedDate));
         }
     }
 
@@ -81,26 +72,20 @@ public class CalendarButton extends Butt
         @Override
         public void selectedDateKeyChanged(CalendarButton calendarButton,
             String previousSelectedDateKey) {
-            for (CalendarButtonBindingListener listener : this) {
-                listener.selectedDateKeyChanged(calendarButton, previousSelectedDateKey);
-            }
+            forEach(listener -> listener.selectedDateKeyChanged(calendarButton, previousSelectedDateKey));
         }
 
         @Override
         public void selectedDateBindTypeChanged(CalendarButton calendarButton,
             BindType previousSelectedDateBindType) {
-            for (CalendarButtonBindingListener listener : this) {
-                listener.selectedDateBindTypeChanged(calendarButton, previousSelectedDateBindType);
-            }
+            forEach(listener -> listener.selectedDateBindTypeChanged(calendarButton, previousSelectedDateBindType));
         }
 
         @Override
         public void selectedDateBindMappingChanged(CalendarButton calendarButton,
             Calendar.SelectedDateBindMapping previousSelectedDateBindMapping) {
-            for (CalendarButtonBindingListener listener : this) {
-                listener.selectedDateBindMappingChanged(calendarButton,
-                    previousSelectedDateBindMapping);
-            }
+            forEach(listener -> listener.selectedDateBindMappingChanged(calendarButton,
+                previousSelectedDateBindMapping));
         }
     }
 
@@ -255,10 +240,6 @@ public class CalendarButton extends Butt
      * @throws IllegalArgumentException if the selected data value is {@code null}.
      */
     public final void setSelectedDate(String selectedDate) {
-        if (selectedDate == null) {
-            throw new IllegalArgumentException("selectedDate is null.");
-        }
-
         setSelectedDate(CalendarDate.decode(selectedDate));
     }
 
@@ -276,9 +257,7 @@ public class CalendarButton extends Butt
      * @throws IllegalArgumentException if the given locale is {@code null}.
      */
     public void setLocale(Locale locale) {
-        if (locale == null) {
-            throw new IllegalArgumentException("locale is null.");
-        }
+        Utils.checkNull(locale, "locale");
 
         Locale previousLocale = this.locale;
         if (previousLocale != locale) {
@@ -298,9 +277,7 @@ public class CalendarButton extends Butt
      * @throws IllegalArgumentException if the given locale dictionary is {@code null}.
      */
     public void setLocale(Dictionary<String, ?> locale) {
-        if (locale == null) {
-            throw new IllegalArgumentException("locale is null.");
-        }
+        Utils.checkNull(locale, "locale");
 
         String language = (String) locale.get(LANGUAGE_KEY);
         String country = (String) locale.get(COUNTRY_KEY);
@@ -325,9 +302,7 @@ public class CalendarButton extends Butt
      * @see #setLocale(Dictionary)
      */
     public void setLocale(String locale) {
-        if (locale == null) {
-            throw new IllegalArgumentException("locale is null.");
-        }
+        Utils.checkNullOrEmpty(locale, "locale");
 
         try {
             setLocale(JSONSerializer.parseMap(locale));
@@ -375,9 +350,7 @@ public class CalendarButton extends Butt
     }
 
     public void setSelectedDateBindType(BindType selectedDateBindType) {
-        if (selectedDateBindType == null) {
-            throw new IllegalArgumentException();
-        }
+        Utils.checkNull(selectedDateBindType, "selectedDateBindType");
 
         BindType previousSelectedDateBindType = this.selectedDateBindType;