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/05/18 20:29:50 UTC
svn commit: r776040 - in /incubator/pivot/trunk:
tutorials/src/pivot/tutorials/ wtk/src/pivot/wtk/ wtk/test/pivot/wtkx/test/
Author: gbrown
Date: Mon May 18 18:29:49 2009
New Revision: 776040
URL: http://svn.apache.org/viewvc?rev=776040&view=rev
Log:
Resolve issue PIVOT-67.
Modified:
incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java
incubator/pivot/trunk/tutorials/src/pivot/tutorials/alerts.wtkx
incubator/pivot/trunk/tutorials/src/pivot/tutorials/menu_popup.wtkx
incubator/pivot/trunk/wtk/src/pivot/wtk/Component.java
incubator/pivot/trunk/wtk/src/pivot/wtk/ComponentDataListener.java
incubator/pivot/trunk/wtk/test/pivot/wtkx/test/BindTestA.java
incubator/pivot/trunk/wtk/test/pivot/wtkx/test/BindTestB.java
Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java?rev=776040&r1=776039&r2=776040&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java Mon May 18 18:29:49 2009
@@ -243,7 +243,7 @@
Button.Group imageMenuGroup = Button.getGroup("imageMenuGroup");
Button selectedItem = imageMenuGroup.getSelection();
- String imageName = (String)selectedItem.getUserData();
+ String imageName = (String)selectedItem.getUserData().get("image");
ClassLoader classLoader = ThreadUtilities.getClassLoader();
URL imageURL = classLoader.getResource(imageName);
@@ -605,7 +605,8 @@
Button.Group messageTypeGroup = Button.getGroup("messageType");
Button selection = messageTypeGroup.getSelection();
- Map<String, ?> userData = JSONSerializer.parseMap((String)selection.getUserData());
+ Map<String, ?> userData =
+ JSONSerializer.parseMap((String)selection.getUserData().get("messageInfo"));
String messageType = (String)userData.get("type");
if (messageType.equals("custom")) {
@@ -640,7 +641,8 @@
Button.Group messageTypeGroup = Button.getGroup("messageType");
Button selection = messageTypeGroup.getSelection();
- Map<String, ?> userData = JSONSerializer.parseMap((String)selection.getUserData());
+ Map<String, ?> userData =
+ JSONSerializer.parseMap((String)selection.getUserData().get("messageInfo"));
String messageType = (String)userData.get("type");
if (messageType.equals("custom")) {
Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/alerts.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/alerts.wtkx?rev=776040&r1=776039&r2=776040&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/alerts.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/alerts.wtkx Mon May 18 18:29:49 2009
@@ -23,16 +23,21 @@
<content>
<FlowPane orientation="vertical" styles="{spacing: 12}">
<FlowPane orientation="vertical" styles="{padding: 6, spacing: 6}">
- <RadioButton buttonData="Error" group="messageType" selected="true"
- userData="{type:'error', message:'This is an error message.'}"/>
- <RadioButton buttonData="Warning" group="messageType"
- userData="{type:'warning', message:'This is a warning message.'}"/>
- <RadioButton buttonData="Question" group="messageType"
- userData="{type:'question', message:'This is a question message.'}"/>
- <RadioButton buttonData="Info" group="messageType"
- userData="{type:'info', message:'This is an info message.'}"/>
- <RadioButton buttonData="Custom" group="messageType"
- userData="{type:'custom', message:'This is a custom message.'}"/>
+ <RadioButton buttonData="Error" group="messageType" selected="true">
+ <userData messageInfo="{type:'error', message:'This is an error message.'}"/>
+ </RadioButton>
+ <RadioButton buttonData="Warning" group="messageType">
+ <userData messageInfo="{type:'warning', message:'This is a warning message.'}"/>
+ </RadioButton>
+ <RadioButton buttonData="Question" group="messageType">
+ <userData messageInfo="{type:'question', message:'This is a question message.'}"/>
+ </RadioButton>
+ <RadioButton buttonData="Info" group="messageType">
+ <userData messageInfo="{type:'info', message:'This is an info message.'}"/>
+ </RadioButton>
+ <RadioButton buttonData="Custom" group="messageType">
+ <userData messageInfo="{type:'custom', message:'This is a custom message.'}"/>
+ </RadioButton>
<FlowPane>
<PushButton wtkx:id="alertButton" buttonData="Show Alert"/>
Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/menu_popup.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/menu_popup.wtkx?rev=776040&r1=776039&r2=776040&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/menu_popup.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/menu_popup.wtkx Mon May 18 18:29:49 2009
@@ -22,14 +22,17 @@
<sections>
<Menu.Section>
<Menu.Item buttonData="IMG_0725_2.jpg" toggleButton="true"
- group="imageMenuGroup" userData="pivot/tutorials/IMG_0725_2.jpg"
- action="selectImageAction"/>
+ group="imageMenuGroup" action="selectImageAction">
+ <userData image="pivot/tutorials/IMG_0725_2.jpg"/>
+ </Menu.Item>
<Menu.Item buttonData="IMG_0735_2.jpg" toggleButton="true"
- group="imageMenuGroup" userData="pivot/tutorials/IMG_0735_2.jpg"
- action="selectImageAction"/>
+ group="imageMenuGroup" action="selectImageAction">
+ <userData image="pivot/tutorials/IMG_0735_2.jpg"/>
+ </Menu.Item>
<Menu.Item buttonData="IMG_0767_2.jpg" toggleButton="true"
- group="imageMenuGroup" userData="pivot/tutorials/IMG_0767_2.jpg"
- action="selectImageAction"/>
+ group="imageMenuGroup" action="selectImageAction">
+ <userData image="pivot/tutorials/IMG_0767_2.jpg"/>
+ </Menu.Item>
</Menu.Section>
</sections>
</Menu>
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/Component.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/Component.java?rev=776040&r1=776039&r2=776040&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/Component.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/Component.java Mon May 18 18:29:49 2009
@@ -55,7 +55,7 @@
* @author gbrown
*/
public final class StyleDictionary extends BeanDictionary {
- public StyleDictionary(pivot.wtk.Skin skin) {
+ private StyleDictionary(pivot.wtk.Skin skin) {
super(skin, true);
}
@@ -76,6 +76,58 @@
}
/**
+ * User data dictionary implementation.
+ *
+ * @author gbrown
+ */
+ public final class UserDataDictionary implements
+ Dictionary<String, Object>, Iterable<String> {
+ private UserDataDictionary() {
+ }
+
+ public Object get(String key) {
+ return userData.get(key);
+ }
+
+ public Object put(String key, Object value) {
+ boolean update = userData.containsKey(key);
+ Object previousValue = userData.put(key, value);
+
+ if (update) {
+ componentDataListeners.valueUpdated(Component.this, key, previousValue);
+ } else {
+ componentDataListeners.valueAdded(Component.this, key);
+ }
+
+ return previousValue;
+ }
+
+ public Object remove(String key) {
+ Object previousValue;
+ if (userData.containsKey(key)) {
+ previousValue = userData.remove(key);
+ componentDataListeners.valueRemoved(Component.this, key, previousValue);
+ } else {
+ previousValue = null;
+ }
+
+ return previousValue;
+ }
+
+ public boolean containsKey(String key) {
+ return userData.containsKey(key);
+ }
+
+ public boolean isEmpty() {
+ return userData.isEmpty();
+ }
+
+ public Iterator<String> iterator() {
+ return new ImmutableIterator<String>(userData.iterator());
+ }
+ }
+
+ /**
* Decorator sequence implementation.
*
* @author tvolkert
@@ -184,6 +236,9 @@
*/
public static class ComponentDictionary implements
Dictionary<Integer, Component>, Iterable<Integer> {
+ private ComponentDictionary() {
+ }
+
public Component get(Integer key) {
return components.get(key);
}
@@ -431,9 +486,21 @@
private static class ComponentDataListenerList extends ListenerList<ComponentDataListener>
implements ComponentDataListener {
- public void userDataChanged(Component component, Object previousValue) {
+ public void valueAdded(Component component, String key) {
+ for (ComponentDataListener listener : this) {
+ listener.valueAdded(component, key);
+ }
+ }
+
+ public void valueUpdated(Component component, String key, Object previousValue) {
for (ComponentDataListener listener : this) {
- listener.userDataChanged(component, previousValue);
+ listener.valueUpdated(component, key, previousValue);
+ }
+ }
+
+ public void valueRemoved(Component component, String key, Object value) {
+ for (ComponentDataListener listener : this) {
+ listener.valueRemoved(component, key, value);
}
}
}
@@ -497,7 +564,8 @@
private DropTarget dropTarget = null;
// User data
- private Object userData = null;
+ private HashMap<String, Object> userData = new HashMap<String, Object>();
+ private UserDataDictionary userDataDictionary = new UserDataDictionary();
// Proxy class for getting/setting style properties on the skin
private StyleDictionary styleDictionary = null;
@@ -2110,14 +2178,11 @@
}
}
- public Object getUserData() {
- return userData;
- }
-
- public void setUserData(Object userData) {
- Object previousUserData = this.userData;
- this.userData = userData;
- componentDataListeners.userDataChanged(this, previousUserData);
+ /**
+ * Returns the user data dictionary.
+ */
+ public UserDataDictionary getUserData() {
+ return userDataDictionary;
}
/**
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/ComponentDataListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/ComponentDataListener.java?rev=776040&r1=776039&r2=776040&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/ComponentDataListener.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/ComponentDataListener.java Mon May 18 18:29:49 2009
@@ -23,10 +23,31 @@
*/
public interface ComponentDataListener {
/**
- * Called when a component's user data has changed.
+ * Called when a value has been added to a component's user data
+ * dictionary.
*
* @param component
+ * @param key
+ */
+ public void valueAdded(Component component, String key);
+
+ /**
+ * Called when a value has been updated in a component's user data
+ * dictionary.
+ *
+ * @param component
+ * @param key
* @param previousValue
*/
- public void userDataChanged(Component component, Object previousValue);
+ public void valueUpdated(Component component, String key, Object previousValue);
+
+ /**
+ * Called when a value has been removed from a component's user data
+ * dictionary.
+ *
+ * @param component
+ * @param key
+ * @param value
+ */
+ public void valueRemoved(Component component, String key, Object value);
}
Modified: incubator/pivot/trunk/wtk/test/pivot/wtkx/test/BindTestA.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/pivot/wtkx/test/BindTestA.java?rev=776040&r1=776039&r2=776040&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/pivot/wtkx/test/BindTestA.java (original)
+++ incubator/pivot/trunk/wtk/test/pivot/wtkx/test/BindTestA.java Mon May 18 18:29:49 2009
@@ -1,3 +1,19 @@
+/*
+ * 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 pivot.wtkx.test;
import pivot.wtk.Window;
Modified: incubator/pivot/trunk/wtk/test/pivot/wtkx/test/BindTestB.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/pivot/wtkx/test/BindTestB.java?rev=776040&r1=776039&r2=776040&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/pivot/wtkx/test/BindTestB.java (original)
+++ incubator/pivot/trunk/wtk/test/pivot/wtkx/test/BindTestB.java Mon May 18 18:29:49 2009
@@ -1,3 +1,19 @@
+/*
+ * 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 pivot.wtkx.test;
import pivot.wtk.PushButton;