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 2010/08/31 14:54:24 UTC
svn commit: r991179 - in /pivot/trunk: core/src/org/apache/pivot/util/
wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/skin/
Author: gbrown
Date: Tue Aug 31 12:54:24 2010
New Revision: 991179
URL: http://svn.apache.org/viewvc?rev=991179&view=rev
Log:
Resolve PIVOT-621; fix raw type warning in TypeLiteral.
Added:
pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewBindingListener.java
Modified:
pivot/trunk/core/src/org/apache/pivot/util/TypeLiteral.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewListener.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java
Modified: pivot/trunk/core/src/org/apache/pivot/util/TypeLiteral.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/TypeLiteral.java?rev=991179&r1=991178&r2=991179&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/TypeLiteral.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/TypeLiteral.java Tue Aug 31 12:54:24 2010
@@ -46,7 +46,7 @@ public class TypeLiteral<T> {
*/
protected TypeLiteral() {
Type superclass = getClass().getGenericSuperclass();
- if (superclass instanceof Class) {
+ if (superclass instanceof Class<?>) {
throw new RuntimeException("Missing type parameter.");
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java?rev=991179&r1=991178&r2=991179&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java Tue Aug 31 12:54:24 2010
@@ -34,6 +34,27 @@ import org.apache.pivot.wtk.media.Image;
*/
@DefaultProperty("image")
public class ImageView extends Component {
+ /**
+ * Translates between image and context data during data binding.
+ */
+ public interface ImageBindMapping {
+ /**
+ * Converts a value from the bind context to an image representation
+ * during a {@link Component#load(Object)} operation.
+ *
+ * @param value
+ */
+ public Image toImage(Object value);
+
+ /**
+ * Converts a text string to a value to be stored in the bind context
+ * during a {@link Component#store(Object)} operation.
+ *
+ * @param text
+ */
+ public Object valueOf(Image image);
+ }
+
private static class ImageViewListenerList extends ListenerList<ImageViewListener>
implements ImageViewListener {
@Override
@@ -49,20 +70,42 @@ public class ImageView extends Component
listener.asynchronousChanged(imageView);
}
}
+ }
+ private static class ImageViewBindingListenerList extends ListenerList<ImageViewBindingListener>
+ implements ImageViewBindingListener {
@Override
public void imageKeyChanged(ImageView imageView, String previousImageKey) {
- for (ImageViewListener listener : this) {
+ for (ImageViewBindingListener listener : this) {
listener.imageKeyChanged(imageView, previousImageKey);
}
}
+
+ @Override
+ public void imageBindTypeChanged(ImageView imageView,
+ BindType previousImageBindType) {
+ for (ImageViewBindingListener listener : this) {
+ listener.imageBindTypeChanged(imageView, previousImageBindType);
+ }
+ }
+
+ @Override
+ public void imageBindMappingChanged(ImageView imageView,
+ ImageView.ImageBindMapping previousImageBindMapping) {
+ for (ImageViewBindingListener listener : this) {
+ listener.imageBindMappingChanged(imageView, previousImageBindMapping);
+ }
+ }
}
private Image image = null;
private boolean asynchronous = false;
private String imageKey = null;
+ private BindType imageBindType = BindType.BOTH;
+ private ImageBindMapping imageBindMapping = null;
private ImageViewListenerList imageViewListeners = new ImageViewListenerList();
+ private ImageViewBindingListenerList imageViewBindingListeners = new ImageViewBindingListenerList();
// Maintains a mapping of image URL to image views that should be notified when
// an asynchronously loaded image is available
@@ -250,43 +293,92 @@ public class ImageView extends Component
if (previousImageKey != imageKey) {
this.imageKey = imageKey;
- imageViewListeners.imageKeyChanged(this, previousImageKey);
+ imageViewBindingListeners.imageKeyChanged(this, previousImageKey);
+ }
+ }
+
+ public BindType getImageBindType() {
+ return imageBindType;
+ }
+
+ public void setImageBindType(BindType imageBindType) {
+ if (imageBindType == null) {
+ throw new IllegalArgumentException();
+ }
+
+ BindType previousImageBindType = this.imageBindType;
+
+ if (previousImageBindType != imageBindType) {
+ this.imageBindType = imageBindType;
+ imageViewBindingListeners.imageBindTypeChanged(this, previousImageBindType);
+ }
+ }
+
+ public final void setImageBindType(String textBindType) {
+ if (textBindType == null) {
+ throw new IllegalArgumentException();
+ }
+
+ setImageBindType(BindType.valueOf(textBindType.toUpperCase()));
+ }
+
+ public ImageBindMapping getImageBindMapping() {
+ return imageBindMapping;
+ }
+
+ public void setImageBindMapping(ImageBindMapping imageBindMapping) {
+ ImageBindMapping previousImageBindMapping = this.imageBindMapping;
+
+ if (previousImageBindMapping != imageBindMapping) {
+ this.imageBindMapping = imageBindMapping;
+ imageViewBindingListeners.imageBindMappingChanged(this, previousImageBindMapping);
}
}
@Override
public void load(Object context) {
if (imageKey != null
- && JSON.containsKey(context, imageKey)) {
+ && JSON.containsKey(context, imageKey)
+ && imageBindType != BindType.STORE) {
Object value = JSON.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);
+
+ if (imageBindMapping == null) {
+ 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 + ".");
+ }
} else {
- throw new IllegalArgumentException(getClass().getName() + " can't bind to "
- + value + ".");
+ setImage(imageBindMapping.toImage(value));
}
}
}
@Override
public void store(Object context) {
- if (isEnabled()
- && imageKey != null) {
- JSON.put(context, imageKey, getImage());
+ if (imageKey != null
+ && imageBindType != BindType.LOAD) {
+ JSON.put(context, imageKey, (imageBindMapping == null) ?
+ image : imageBindMapping.valueOf(image));
}
}
/**
* Returns the image view listener list.
- *
- * @return
- * The image view listener list.
*/
public ListenerList<ImageViewListener> getImageViewListeners() {
return imageViewListeners;
}
+
+ /**
+ * Returns the image view binding listener list.
+ */
+ public ListenerList<ImageViewBindingListener> getImageViewBindingListeners() {
+ return imageViewBindingListeners;
+ }
}
Added: pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewBindingListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewBindingListener.java?rev=991179&view=auto
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewBindingListener.java (added)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewBindingListener.java Tue Aug 31 12:54:24 2010
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.wtk;
+
+/**
+ * Image view binding listener.
+ */
+public interface ImageViewBindingListener {
+ /**
+ * Image view binding listener adapter.
+ */
+ public static class Adapter implements ImageViewBindingListener {
+ @Override
+ public void imageKeyChanged(ImageView imageView, String previousImageKey) {
+ }
+
+ @Override
+ public void imageBindTypeChanged(ImageView imageView,
+ BindType previousImageBindType) {
+ }
+
+ @Override
+ public void imageBindMappingChanged(ImageView imageView,
+ ImageView.ImageBindMapping previousImageBindMapping) {
+
+ }
+ }
+
+ /**
+ * Called when an image view's image key has changed.
+ *
+ * @param imageView
+ * @param previousImageKey
+ */
+ public void imageKeyChanged(ImageView imageView, String previousImageKey);
+
+ /**
+ * Called when a image views's image bind type has changed.
+ *
+ * @param label
+ * @param previousImageBindType
+ */
+ public void imageBindTypeChanged(ImageView imageView,
+ BindType previousImageBindType);
+
+ /**
+ * Called when an image view's text bind mapping has changed.
+ *
+ * @param image
+ * @param previousImageBindMapping
+ */
+ public void imageBindMappingChanged(ImageView imageView,
+ ImageView.ImageBindMapping previousImageBindMapping);
+}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewListener.java?rev=991179&r1=991178&r2=991179&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageViewListener.java Tue Aug 31 12:54:24 2010
@@ -33,10 +33,6 @@ public interface ImageViewListener {
@Override
public void asynchronousChanged(ImageView imageView) {
}
-
- @Override
- public void imageKeyChanged(ImageView imageView, String previousImageKey) {
- }
}
/**
@@ -53,12 +49,4 @@ public interface ImageViewListener {
* @param imageView
*/
public void asynchronousChanged(ImageView imageView);
-
- /**
- * Called when an image view's image key has changed.
- *
- * @param imageView
- * @param previousImageKey
- */
- public void imageKeyChanged(ImageView imageView, String previousImageKey);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java?rev=991179&r1=991178&r2=991179&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java Tue Aug 31 12:54:24 2010
@@ -28,16 +28,16 @@ public class Label extends Component {
*/
public interface TextBindMapping {
/**
- * Converts a value from the bind context to a text representation during a
- * {@link Component#load(Object)} operation.
+ * Converts a value from the bind context to a text representation
+ * during a {@link Component#load(Object)} operation.
*
* @param value
*/
public String toString(Object value);
/**
- * Converts a text string to a value to be stored in the bind context during a
- * {@link Component#store(Object)} operation.
+ * Converts a text string to a value to be stored in the bind context
+ * during a {@link Component#store(Object)} operation.
*
* @param text
*/
@@ -180,9 +180,7 @@ public class Label extends Component {
Object value = JSON.get(context, textKey);
if (textBindMapping == null) {
- if (value != null) {
- value = value.toString();
- }
+ value = (value == null) ? null : value.toString();
} else {
value = textBindMapping.toString(value);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java?rev=991179&r1=991178&r2=991179&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java Tue Aug 31 12:54:24 2010
@@ -389,9 +389,4 @@ public class ImageViewSkin extends Compo
public void asynchronousChanged(ImageView imageView) {
// No-op
}
-
- @Override
- public void imageKeyChanged(ImageView imageView, String previousImageKey) {
- // No-op
- }
}