You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/10/13 20:51:55 UTC
svn commit: r824879 - in
/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: ./ skin/
Author: gbrown
Date: Tue Oct 13 18:51:54 2009
New Revision: 824879
URL: http://svn.apache.org/viewvc?rev=824879&view=rev
Log:
Resolve issue PIVOT-326; clean up key setters for other bindable components.
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Button.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewListener.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Button.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Button.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Button.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Button.java Tue Oct 13 18:51:54 2009
@@ -448,8 +448,11 @@
public void setSelectedKey(String selectedKey) {
String previousSelectedKey = this.selectedKey;
- this.selectedKey = selectedKey;
- buttonListeners.selectedKeyChanged(this, previousSelectedKey);
+
+ if (previousSelectedKey != selectedKey) {
+ this.selectedKey = selectedKey;
+ buttonListeners.selectedKeyChanged(this, previousSelectedKey);
+ }
}
public String getStateKey() {
@@ -458,8 +461,11 @@
public void setStateKey(String stateKey) {
String previousStateKey = this.stateKey;
- this.stateKey = stateKey;
- buttonListeners.stateKeyChanged(this, previousStateKey);
+
+ if (previousStateKey != stateKey) {
+ this.stateKey = stateKey;
+ buttonListeners.stateKeyChanged(this, previousStateKey);
+ }
}
@Override
@@ -468,24 +474,24 @@
&& JSONSerializer.containsKey(context, selectedKey)) {
Object value = JSONSerializer.get(context, selectedKey);
- if (!(value instanceof Boolean)) {
- throw new IllegalArgumentException("value must be an instance of "
- + Boolean.class.getName());
+ if (value instanceof Boolean) {
+ setSelected((Boolean)value);
+ } else {
+ throw new IllegalArgumentException(getClass().getName() + " can't bind to "
+ + value + ".");
}
-
- setSelected((Boolean)value);
}
if (stateKey != null
&& JSONSerializer.containsKey(context, stateKey)) {
Object value = JSONSerializer.get(context, stateKey);
- if (!(value instanceof State)) {
- throw new IllegalArgumentException("value must be an instance of "
- + State.class.getName());
+ if (value instanceof State) {
+ setState((State)value);
+ } else {
+ throw new IllegalArgumentException(getClass().getName() + " can't bind to "
+ + value + ".");
}
-
- setState((State)value);
}
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Calendar.java Tue Oct 13 18:51:54 2009
@@ -301,8 +301,7 @@
public void setSelectedDateKey(String selectedDateKey) {
String previousSelectedDateKey = this.selectedDateKey;
- if ((selectedDateKey == null ^ previousSelectedDateKey == null)
- || (selectedDateKey != null && !selectedDateKey.equals(previousSelectedDateKey))) {
+ if (selectedDateKey != previousSelectedDateKey) {
this.selectedDateKey = selectedDateKey;
calendarListeners.selectedDateKeyChanged(this, previousSelectedDateKey);
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java Tue Oct 13 18:51:54 2009
@@ -264,8 +264,7 @@
if (previousSelectedDateKey != selectedDateKey) {
this.selectedDateKey = selectedDateKey;
- calendarButtonListeners.selectedDateKeyChanged(this,
- previousSelectedDateKey);
+ calendarButtonListeners.selectedDateKeyChanged(this, previousSelectedDateKey);
}
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java Tue Oct 13 18:51:54 2009
@@ -18,6 +18,8 @@
import java.net.URL;
+import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.serialization.JSONSerializer;
import org.apache.pivot.util.ListenerList;
import org.apache.pivot.util.ThreadUtilities;
import org.apache.pivot.util.concurrent.TaskExecutionException;
@@ -36,9 +38,17 @@
listener.imageChanged(imageView, previousImage);
}
}
+
+ @Override
+ public void imageKeyChanged(ImageView imageView, String previousImageKey) {
+ for (ImageViewListener listener : this) {
+ listener.imageKeyChanged(imageView, previousImageKey);
+ }
+ }
}
private Image image = null;
+ private String imageKey = null;
private ImageViewListenerList imageViewListeners = new ImageViewListenerList();
@@ -137,6 +147,57 @@
}
/**
+ * Returns the image view's image key.
+ *
+ * @return
+ * The image key, or <tt>null</tt> if no key is set.
+ */
+ public String getImageKey() {
+ return imageKey;
+ }
+
+ /**
+ * Sets the image view's image key.
+ *
+ * @param imageKey
+ * The image key, or <tt>null</tt> to clear the binding.
+ */
+ public void setImageKey(String imageKey) {
+ String previousImageKey = this.imageKey;
+
+ if (previousImageKey != imageKey) {
+ this.imageKey = imageKey;
+ imageViewListeners.imageKeyChanged(this, previousImageKey);
+ }
+ }
+
+ @Override
+ public void load(Dictionary<String, ?> context) {
+ if (imageKey != null
+ && JSONSerializer.containsKey(context, imageKey)) {
+ Object value = JSONSerializer.get(context, imageKey);
+ if (value instanceof Image) {
+ setImage((Image)value);
+ } else if (value instanceof URL) {
+ setImage((URL)value);
+ } else if (value instanceof String) {
+ setImage((String)value);
+ } else {
+ throw new IllegalArgumentException(getClass().getName() + " can't bind to "
+ + value + ".");
+ }
+ }
+ }
+
+ @Override
+ public void store(Dictionary<String, ?> context) {
+ if (isEnabled()
+ && imageKey != null) {
+ JSONSerializer.put(context, imageKey, getImage());
+ }
+ }
+
+ /**
* Returns the image view listener list.
*
* @return
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewListener.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewListener.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewListener.java Tue Oct 13 18:51:54 2009
@@ -23,10 +23,31 @@
*/
public interface ImageViewListener {
/**
+ * Image view listener adapter.
+ */
+ public static class Adapter implements ImageViewListener {
+ @Override
+ public void imageChanged(ImageView imageView, Image previousImage) {
+ }
+
+ @Override
+ public void imageKeyChanged(ImageView imageView, String previousImageKey) {
+ }
+ }
+
+ /**
* Called when an image view's image has changed.
*
* @param imageView
* @param previousImage
*/
public void imageChanged(ImageView imageView, Image previousImage);
+
+ /**
+ * Called when an image view's image key has changed.
+ *
+ * @param imageView
+ * @param previousImageKey
+ */
+ public void imageKeyChanged(ImageView imageView, String previousImageKey);
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java Tue Oct 13 18:51:54 2009
@@ -87,10 +87,7 @@
public void setTextKey(String textKey) {
String previousTextKey = this.textKey;
- if ((previousTextKey != null
- && textKey != null
- && !previousTextKey.equals(textKey))
- || previousTextKey != textKey) {
+ if (previousTextKey != textKey) {
this.textKey = textKey;
labelListeners.textKeyChanged(this, previousTextKey);
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java Tue Oct 13 18:51:54 2009
@@ -317,8 +317,11 @@
public void setSelectedItemKey(String selectedItemKey) {
String previousSelectedItemKey = this.selectedItemKey;
- this.selectedItemKey = selectedItemKey;
- listButtonListeners.selectedItemKeyChanged(this, previousSelectedItemKey);
+
+ if (previousSelectedItemKey != selectedItemKey) {
+ this.selectedItemKey = selectedItemKey;
+ listButtonListeners.selectedItemKeyChanged(this, previousSelectedItemKey);
+ }
}
@Override
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java Tue Oct 13 18:51:54 2009
@@ -1400,8 +1400,11 @@
public void setSelectedItemKey(String selectedItemKey) {
String previousSelectedItemKey = this.selectedItemKey;
- this.selectedItemKey = selectedItemKey;
- listViewListeners.selectedItemKeyChanged(this, previousSelectedItemKey);
+
+ if (previousSelectedItemKey != selectedItemKey) {
+ this.selectedItemKey = selectedItemKey;
+ listViewListeners.selectedItemKeyChanged(this, previousSelectedItemKey);
+ }
}
public String getSelectedItemsKey() {
@@ -1410,8 +1413,11 @@
public void setSelectedItemsKey(String selectedItemsKey) {
String previousSelectedItemsKey = this.selectedItemsKey;
- this.selectedItemsKey = selectedItemsKey;
- listViewListeners.selectedItemsKeyChanged(this, previousSelectedItemsKey);
+
+ if (previousSelectedItemsKey != selectedItemsKey) {
+ this.selectedItemsKey = selectedItemsKey;
+ listViewListeners.selectedItemsKeyChanged(this, previousSelectedItemsKey);
+ }
}
@Override
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java Tue Oct 13 18:51:54 2009
@@ -388,8 +388,11 @@
*/
public void setSelectedItemKey(String selectedItemKey) {
String previousSelectedItemKey = this.selectedItemKey;
- this.selectedItemKey = selectedItemKey;
- spinnerListeners.selectedItemKeyChanged(this, previousSelectedItemKey);
+
+ if (previousSelectedItemKey != selectedItemKey) {
+ this.selectedItemKey = selectedItemKey;
+ spinnerListeners.selectedItemKeyChanged(this, previousSelectedItemKey);
+ }
}
@Override
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Tue Oct 13 18:51:54 2009
@@ -306,10 +306,7 @@
public void setTextKey(String textKey) {
String previousTextKey = this.textKey;
- if ((previousTextKey != null
- && textKey != null
- && !previousTextKey.equals(textKey))
- || previousTextKey != textKey) {
+ if (previousTextKey != textKey) {
this.textKey = textKey;
textAreaListeners.textKeyChanged(this, previousTextKey);
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java Tue Oct 13 18:51:54 2009
@@ -623,10 +623,7 @@
public void setTextKey(String textKey) {
String previousTextKey = this.textKey;
- if ((previousTextKey != null
- && textKey != null
- && !previousTextKey.equals(textKey))
- || previousTextKey != textKey) {
+ if (previousTextKey != textKey) {
this.textKey = textKey;
textInputListeners.textKeyChanged(this, previousTextKey);
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java?rev=824879&r1=824878&r2=824879&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java Tue Oct 13 18:51:54 2009
@@ -334,4 +334,9 @@
invalidateComponent();
}
+
+ @Override
+ public void imageKeyChanged(ImageView imageView, String previousImageKey) {
+ // No-op
+ }
}