PIVOT-1014, PIVOT-1011, PIVOT-1012, PIVOT-999: Do all the recent changes in the
Separator and its skin classes. Add the default styles (which had/have some
conflicts) to the "terra_theme_defaults.json" file. Add a setter method for
"padding" using a Sequence.
Move the SeparatorListenerList into the interface (and rename to "Listeners"),
and change to use "forEach" for the iteration.
git-svn-id: https://svn.apache.org/repos/asf/pivot/trunk@1817553 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSeparatorSkin.java b/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSeparatorSkin.java
index 2f09bd3..cfbf2ce 100644
--- a/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSeparatorSkin.java
+++ b/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSeparatorSkin.java
@@ -24,8 +24,6 @@
*/
public class TerraSeparatorSkin extends SeparatorSkin {
public TerraSeparatorSkin() {
- setColor(7);
- setHeadingColor(12);
}
public void setColor(int color) {
diff --git a/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_theme_defaults.json b/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_theme_defaults.json
index c83b2a8..135b5bc 100644
--- a/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_theme_defaults.json
+++ b/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_theme_defaults.json
@@ -39,6 +39,21 @@
headingToggles : true
},
+ TerraSeparatorSkin : {
+ // TODO: conflicts between SeparatorSkin and TerraSeparatorSkin
+
+ // color = defaultForegroundColor();
+ // headingColor = defaultForegroundColor();
+
+ font : { bold : true },
+ thickness : 1,
+ padding : [ 4, 0, 4, 4 ],
+
+ // These are from TerraSeparatorSkin
+ color : 7,
+ headingColor : 12
+ },
+
TerraTextAreaSkin : {
// TODO: conflicts here b/w TextAreaSkin and TerraTextAreaSkin:
// This is what TextAreaSkin says right now:
diff --git a/wtk/src/org/apache/pivot/wtk/Separator.java b/wtk/src/org/apache/pivot/wtk/Separator.java
index 474d5db..d437fa8 100644
--- a/wtk/src/org/apache/pivot/wtk/Separator.java
+++ b/wtk/src/org/apache/pivot/wtk/Separator.java
@@ -22,19 +22,9 @@
* Component representing a horizontal divider.
*/
public class Separator extends Component {
- private static class SeparatorListenerList extends ListenerList<SeparatorListener> implements
- SeparatorListener {
- @Override
- public void headingChanged(Separator separator, String previousHeading) {
- for (SeparatorListener listener : this) {
- listener.headingChanged(separator, previousHeading);
- }
- }
- }
-
private String heading = null;
- private SeparatorListenerList separatorListeners = new SeparatorListenerList();
+ private SeparatorListener.Listeners separatorListeners = new SeparatorListener.Listeners();
public Separator() {
this(null);
@@ -48,7 +38,7 @@
/**
* Returns the separator's heading.
*
- * @return The separator's heading, or <tt>null</tt> if no heading is set.
+ * @return The separator's heading, or {@code null} if no heading is set.
*/
public String getHeading() {
return heading;
@@ -57,7 +47,7 @@
/**
* Sets the separator's heading.
*
- * @param heading The new heading, or <tt>null</tt> for no heading.
+ * @param heading The new heading, or {@code null} for no heading.
*/
public void setHeading(String heading) {
String previousHeading = this.heading;
diff --git a/wtk/src/org/apache/pivot/wtk/SeparatorListener.java b/wtk/src/org/apache/pivot/wtk/SeparatorListener.java
index f447b7f..20180fc 100644
--- a/wtk/src/org/apache/pivot/wtk/SeparatorListener.java
+++ b/wtk/src/org/apache/pivot/wtk/SeparatorListener.java
@@ -16,11 +16,24 @@
*/
package org.apache.pivot.wtk;
+import org.apache.pivot.util.ListenerList;
+
/**
* Separator listener interface.
*/
public interface SeparatorListener {
/**
+ * Separator listener listeners list.
+ */
+ public static class Listeners extends ListenerList<SeparatorListener> implements
+ SeparatorListener {
+ @Override
+ public void headingChanged(Separator separator, String previousHeading) {
+ forEach(listener -> listener.headingChanged(separator, previousHeading));
+ }
+ }
+
+ /**
* Called when a separator's heading has changed.
*
* @param separator The separator that changed.
diff --git a/wtk/src/org/apache/pivot/wtk/skin/SeparatorSkin.java b/wtk/src/org/apache/pivot/wtk/skin/SeparatorSkin.java
index bb63150..a74449d 100644
--- a/wtk/src/org/apache/pivot/wtk/skin/SeparatorSkin.java
+++ b/wtk/src/org/apache/pivot/wtk/skin/SeparatorSkin.java
@@ -27,6 +27,8 @@
import java.awt.geom.Rectangle2D;
import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.collections.Sequence;
+import org.apache.pivot.util.Utils;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.Dimensions;
import org.apache.pivot.wtk.GraphicsUtilities;
@@ -47,20 +49,15 @@
private Insets padding;
public SeparatorSkin() {
- Theme theme = Theme.getTheme();
- font = theme.getFont().deriveFont(Font.BOLD);
-
- color = defaultForegroundColor();
- headingColor = defaultForegroundColor();
-
- thickness = 1;
- padding = new Insets(4, 0, 4, 4);
}
@Override
public void install(Component component) {
super.install(component);
+ Theme theme = currentTheme();
+ theme.setDefaultStyles(this);
+
Separator separator = (Separator) component;
separator.getSeparatorListeners().add(this);
}
@@ -75,8 +72,7 @@
if (heading != null && heading.length() > 0) {
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
Rectangle2D headingBounds = font.getStringBounds(heading, fontRenderContext);
- preferredWidth = (int) Math.ceil(headingBounds.getWidth())
- + (padding.left + padding.right);
+ preferredWidth = (int) Math.ceil(headingBounds.getWidth()) + padding.getWidth();
}
return preferredWidth;
@@ -97,7 +93,7 @@
preferredHeight);
}
- preferredHeight += (padding.top + padding.bottom);
+ preferredHeight += padding.getHeight();
return preferredHeight;
}
@@ -120,8 +116,8 @@
preferredHeight);
}
- preferredHeight += (padding.top + padding.bottom);
- preferredWidth += (padding.left + padding.right);
+ preferredHeight += padding.getHeight();
+ preferredWidth += padding.getWidth();
return new Dimensions(preferredWidth, preferredHeight);
}
@@ -181,9 +177,7 @@
* @param font The new font for the heading.
*/
public void setFont(Font font) {
- if (font == null) {
- throw new IllegalArgumentException("font is null.");
- }
+ Utils.checkNull(font, "font");
this.font = font;
invalidateComponent();
@@ -195,10 +189,6 @@
* @param font A {@linkplain ComponentSkin#decodeFont(String) font specification}.
*/
public final void setFont(String font) {
- if (font == null) {
- throw new IllegalArgumentException("font is null.");
- }
-
setFont(decodeFont(font));
}
@@ -208,10 +198,6 @@
* @param font A dictionary {@link Theme#deriveFont describing a font}.
*/
public final void setFont(Dictionary<String, ?> font) {
- if (font == null) {
- throw new IllegalArgumentException("font is null.");
- }
-
setFont(Theme.deriveFont(font));
}
@@ -228,9 +214,7 @@
* @param color The new color for the horizontal rule.
*/
public void setColor(Color color) {
- if (color == null) {
- throw new IllegalArgumentException("color is null.");
- }
+ Utils.checkNull(color, "color");
this.color = color;
repaintComponent();
@@ -243,11 +227,7 @@
* values recognized by Pivot}.
*/
public final void setColor(String color) {
- if (color == null) {
- throw new IllegalArgumentException("color is null.");
- }
-
- setColor(GraphicsUtilities.decodeColor(color));
+ setColor(GraphicsUtilities.decodeColor(color, "color"));
}
/**
@@ -263,9 +243,7 @@
* @param headingColor The new color for the heading text.
*/
public void setHeadingColor(Color headingColor) {
- if (headingColor == null) {
- throw new IllegalArgumentException("headingColor is null.");
- }
+ Utils.checkNull(headingColor, "headingColor");
this.headingColor = headingColor;
repaintComponent();
@@ -278,11 +256,7 @@
* color values recognized by Pivot}.
*/
public final void setHeadingColor(String headingColor) {
- if (headingColor == null) {
- throw new IllegalArgumentException("headingColor is null.");
- }
-
- setHeadingColor(GraphicsUtilities.decodeColor(headingColor));
+ setHeadingColor(GraphicsUtilities.decodeColor(headingColor, "headingColor"));
}
/**
@@ -298,9 +272,8 @@
* @param thickness The new rule thickness (in pixels).
*/
public void setThickness(int thickness) {
- if (thickness < 0) {
- throw new IllegalArgumentException("thickness is negative.");
- }
+ Utils.checkNonNegative(thickness, "thickness");
+
this.thickness = thickness;
invalidateComponent();
}
@@ -311,9 +284,7 @@
* @param thickness The new integer value for the rule thickness (in pixels).
*/
public final void setThickness(Number thickness) {
- if (thickness == null) {
- throw new IllegalArgumentException("thickness is null.");
- }
+ Utils.checkNull(thickness, "thickness");
setThickness(thickness.intValue());
}
@@ -333,9 +304,7 @@
* @param padding The new padding values.
*/
public void setPadding(Insets padding) {
- if (padding == null) {
- throw new IllegalArgumentException("padding is null.");
- }
+ Utils.checkNull(padding, "padding");
this.padding = padding;
invalidateComponent();
@@ -349,10 +318,10 @@
* right}.
*/
public final void setPadding(Dictionary<String, ?> padding) {
- if (padding == null) {
- throw new IllegalArgumentException("padding is null.");
- }
+ setPadding(new Insets(padding));
+ }
+ public final void setPadding(Sequence<?> padding) {
setPadding(new Insets(padding));
}
@@ -373,11 +342,7 @@
* @param padding The new integer value to use for padding in all areas.
*/
public final void setPadding(Number padding) {
- if (padding == null) {
- throw new IllegalArgumentException("padding is null.");
- }
-
- setPadding(padding.intValue());
+ setPadding(new Insets(padding));
}
/**
@@ -388,10 +353,6 @@
* keys left, top, bottom, and/or right.
*/
public final void setPadding(String padding) {
- if (padding == null) {
- throw new IllegalArgumentException("padding is null.");
- }
-
setPadding(Insets.decode(padding));
}
@@ -400,4 +361,5 @@
public void headingChanged(Separator separator, String previousHeading) {
invalidateComponent();
}
+
}