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/12 17:27:36 UTC
svn commit: r824383 - in /incubator/pivot/trunk:
core/src/org/apache/pivot/serialization/
tutorials/src/org/apache/pivot/tutorials/databinding/
tutorials/src/org/apache/pivot/tutorials/stocktracker/ tutorials/www/
wtk/src/org/apache/pivot/wtk/ wtk/src/...
Author: gbrown
Date: Mon Oct 12 15:27:35 2009
New Revision: 824383
URL: http://svn.apache.org/viewvc?rev=824383&view=rev
Log:
Add a clear() method to allow callers to clear bound data values; allow callers to use JSON paths for bind keys.
Modified:
incubator/pivot/trunk/core/src/org/apache/pivot/serialization/JSONSerializer.java
incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/Contact.java
incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/DataBinding.java
incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/stocktracker.detail.wtkx
incubator/pivot/trunk/tutorials/www/data_binding.html
incubator/pivot/trunk/tutorials/www/web_queries.html
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/Component.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.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/terra/TerraFrameSkin.java
Modified: incubator/pivot/trunk/core/src/org/apache/pivot/serialization/JSONSerializer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/serialization/JSONSerializer.java?rev=824383&r1=824382&r2=824383&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/serialization/JSONSerializer.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/serialization/JSONSerializer.java Mon Oct 12 15:27:35 2009
@@ -717,11 +717,11 @@
String key = keys.get(i);
if (value instanceof Dictionary<?, ?>) {
- Map<String, Object> map = (Map<String, Object>)value;
- value = map.get(key);
+ Dictionary<String, Object> dictionary = (Dictionary<String, Object>)value;
+ value = dictionary.get(key);
} else if (value instanceof Sequence<?>) {
- List<Object> list = (List<Object>)value;
- value = list.get(Integer.parseInt(key));
+ Sequence<Object> sequence = (Sequence<Object>)value;
+ value = sequence.get(Integer.parseInt(key));
} else {
value = null;
break;
@@ -886,8 +886,8 @@
Dictionary<String, Object> dictionary = (Dictionary<String, Object>)parent;
previousValue = dictionary.put(key, value);
} else if (parent instanceof Sequence<?>) {
- List<Object> list = (List<Object>)parent;
- previousValue = list.update(Integer.parseInt(key), value);
+ Sequence<Object> sequence = (Sequence<Object>)parent;
+ previousValue = sequence.update(Integer.parseInt(key), value);
} else {
throw new IllegalArgumentException("Invalid path: " + path + ".");
}
@@ -928,8 +928,8 @@
Dictionary<String, Object> dictionary = (Dictionary<String, Object>)parent;
previousValue = dictionary.remove(key);
} else if (parent instanceof Sequence<?>) {
- List<Object> list = (List<Object>)parent;
- previousValue = list.remove(Integer.parseInt(key), 1).get(0);
+ Sequence<Object> sequence = (Sequence<Object>)parent;
+ previousValue = sequence.remove(Integer.parseInt(key), 1).get(0);
} else {
throw new IllegalArgumentException("Invalid path: " + path + ".");
}
@@ -970,8 +970,8 @@
Dictionary<String, Object> dictionary = (Dictionary<String, Object>)parent;
containsKey = dictionary.containsKey(key);
} else if (parent instanceof Sequence<?>) {
- List<Object> list = (List<Object>)parent;
- containsKey = (list.getLength() > Integer.parseInt(key));
+ Sequence<Object> sequence = (Sequence<Object>)parent;
+ containsKey = (sequence.getLength() > Integer.parseInt(key));
} else {
containsKey = false;
}
Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/Contact.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/Contact.java?rev=824383&r1=824382&r2=824383&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/Contact.java (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/Contact.java Mon Oct 12 15:27:35 2009
@@ -24,10 +24,6 @@
private String emailAddress;
private IMAccount imAccount;
- public Contact() {
- this(null, null, new Address(), null, null, new IMAccount());
- }
-
public Contact(String id, String name, Address address, String phoneNumber,
String emailAddress, IMAccount imAccount) {
this.id = id;
Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/DataBinding.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/DataBinding.java?rev=824383&r1=824382&r2=824383&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/DataBinding.java (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/DataBinding.java Mon Oct 12 15:27:35 2009
@@ -84,7 +84,7 @@
clearButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
- form.load(new Contact());
+ form.clear();
sourceLabel.setText(null);
}
});
Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/stocktracker.detail.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/stocktracker.detail.wtkx?rev=824383&r1=824382&r2=824383&view=diff
==============================================================================
Binary files - no diff available.
Modified: incubator/pivot/trunk/tutorials/www/data_binding.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/data_binding.html?rev=824383&r1=824382&r2=824383&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/data_binding.html (original)
+++ incubator/pivot/trunk/tutorials/www/data_binding.html Mon Oct 12 15:27:35 2009
@@ -25,6 +25,7 @@
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js"></script>
+<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js"></script>
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css"/>
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css"/>
<script type="text/javascript">
@@ -33,7 +34,88 @@
</head>
<body>
<h1>Data Binding</h1>
-<p>This section is not yet complete.</p>
+<p>Data binding refers to the process of automatically populating or extracting data from a set of user interface elements. In Pivot, data binding is driven entirely by two methods of the <tt>Component</tt> class: <tt>load()</tt> and <tt>store()</tt>. The primary version of each method takes an instance of <tt>Dictionary<String, ?></tt> called the "context". During a load operation, data is extracted from the context and "loaded" into the component; during a store, data is taken from the component and "stored" back into the context. Overloaded versions of both <tt>load()</tt> and <tt>store()</tt> allow a caller to pass a JavaBean value as a bind context, which will be wrapped in a <tt>BeanDictionary</tt> and passed to the version that takes a dictionary argument.</p>
+
+<p>The <tt>Container</tt> class overrides <tt>load()</tt> and <tt>store()</tt> to facilitate the use of nested contexts. When a container is assigned a context key, if a value with that key exists in the context passed to <tt>Container#load()</tt> or <tt>store()</tt>, that value becomes the context that is propagated to sub-components in further binds. This can significantly simplify the task of binding to complex data structures.</p>
+
+<p>The following application demonstrates data binding. It allows the user to load a form with address data either from a JSON file or from a JavaBean object:</p>
+
+<script src="version.js"></script>
+<script>
+var attributes = {code:"org.apache.pivot.wtk.BrowserApplicationContext$HostApplet",
+ archive:"lib/pivot-core-" + version + ".jar"
+ + ",lib/pivot-wtk-" + version + ".jar"
+ + ",lib/pivot-wtk-" + version + ".terra.jar"
+ + ",lib/pivot-tutorials-" + version + ".jar",
+ width:260,
+ height:260
+};
+var parameters = {application_class_name:"org.apache.pivot.tutorials.databinding.DataBinding",
+ codebase_lookup:false,
+ java_arguments:"-Dsun.awt.noerasebackground=true -Dsun.awt.erasebackgroundonresize=true"
+};
+deployJava.writeAppletTag(attributes, parameters);
+</script>
+
+<p>The WTKX simply sets up the form structure and the bind keys:</p>
+
+<pre class="brush:xml">
+<Window title="Data Binding" maximized="true"
+ xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns="org.apache.pivot.wtk">
+ <content>
+ <Border styles="{thickness:0, padding:8}">
+ <content>
+ <BoxPane orientation="vertical" styles="{spacing:10, fill:true}">
+ <Form wtkx:id="form">
+ <sections>
+ <Form.Section>
+ <Label Form.label="ID" textKey="id"/>
+ <Label Form.label="Name" textKey="name"/>
+
+ <BoxPane Form.label="Address" orientation="vertical" contextKey="address">
+ <Label textKey="street"/>
+ <BoxPane>
+ <Label textKey="city"/>
+ <Label textKey="state"/>
+ <Label textKey="zip"/>
+ </BoxPane>
+ </BoxPane>
+
+ <Label Form.label="Phone" textKey="phoneNumber"/>
+ <Label Form.label="Email" textKey="emailAddress"/>
+
+ <BoxPane Form.label="IM" contextKey="imAccount">
+ <Label textKey="id"/>
+ <Label textKey="type"/>
+ </BoxPane>
+
+ <Label wtkx:id="sourceLabel" Form.label="Source" styles="{font:{italic:true}}"/>
+ </Form.Section>
+ </sections>
+ </Form>
+
+ <Separator/>
+
+ <BoxPane styles="{horizontalAlignment:'right'}">
+ <PushButton wtkx:id="loadJavaButton" buttonData="Load Java"/>
+ <PushButton wtkx:id="loadJSONButton" buttonData="Load JSON"/>
+ <PushButton wtkx:id="clearButton" buttonData="Clear"/>
+ </BoxPane>
+ </BoxPane>
+ </content>
+ </Border>
+ </content>
+</Window>
+</pre>
+
+<p>The application's <tt>startup()</tt> method attaches button press listeners to each button that load the form from an instance of a <tt>Contact</tt> JavaBean, a JSON file, or an empty map (to clear the form):</p>
+
+TBD - empty map may not be supported?
+
+<pre class="brush:java">
+</pre>
+
<p>Next: <a href="localization.html">Localization</a></p>
</body>
</html>
Modified: incubator/pivot/trunk/tutorials/www/web_queries.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/web_queries.html?rev=824383&r1=824382&r2=824383&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/web_queries.html (original)
+++ incubator/pivot/trunk/tutorials/www/web_queries.html Mon Oct 12 15:27:35 2009
@@ -33,7 +33,238 @@
</head>
<body>
<h1>Web Queries</h1>
-<p>This section is not yet complete.</p>
+
+<p>"Web queries" are Pivot's native means of communicating with remote data services. They are designed primarily to facilitate interaction with JSON-based REST services, but they are sufficiently generic to support communication with any type of HTTP-based service, using any data format.</p>
+
+<p>A web query is represented by an instance of <tt>org.apache.pivot.web.Query</tt>, which extends the <tt>Task</tt> class discussed in the previous section. <tt>Query</tt> is an abstract class with four concrete subclasses, each of which corresponds to once of the four primary HTTP verbs:</p>
+
+<ul>
+ <li><p><b>GetQuery</b> - executes an HTTP GET request</p></li>
+ <li><p><b>PostQuery</b> - executes an HTTP POST request</p></li>
+ <li><p><b>PutQuery</b> - executes an HTTP PUT request</p></li>
+ <li><p><b>DeleteQuery</b> - executes an HTTP DELETE request</p></li>
+</ul>
+
+<p>Query string parameters are specified via the query's parameter dictionary, and request headers can be specified via the request header dictionary. After the query has been executed, response headers are also available via the response header dictionary.</p>
+
+<p>All query types have an associated serializer that is used to serialize or deserialize the request or response data. <tt>GetQuery</tt> returns an <tt>Object</tt> representing the data that was returned by the server, <tt>PostQuery</tt> and <tt>PutQuery</tt> define a <tt>value</tt> property that is sent to the server when the query is executed, and, by definition, <tt>DeleteQuery</tt> neither accepts nor returns a value.</p>
+
+<p>Because they are instances of <tt>Task</tt>, web queries can be (and usually are) executed asynchronously, such that the UI doesn't get bogged down waiting for the server to respond. The following application demonstrates the use of a <tt>GetQuery</tt> to read data from a Yahoo! Pipe. The pipe in this example searches for "pizza" within 5 miles of Cambridge, Massachusetts (note that the applet is signed to allow it to communicate with the Yahoo web service):</p>
+
+<script src="version.js"></script>
+<script>
+var attributes = {code:"org.apache.pivot.wtk.BrowserApplicationContext$HostApplet",
+ archive:"lib/pivot-core-" + version + ".signed.jar"
+ + ",lib/pivot-wtk-" + version + ".signed.jar"
+ + ",lib/pivot-web-" + version + ".signed.jar"
+ + ",lib/pivot-wtk-" + version + ".terra.signed.jar"
+ + ",lib/pivot-tutorials-" + version + ".signed.jar",
+ width:240,
+ height:320
+};
+var parameters = {application_class_name:"org.apache.pivot.tutorials.webqueries.WebQueries",
+ codebase_lookup:false,
+ java_arguments:"-Dsun.awt.noerasebackground=true -Dsun.awt.erasebackgroundonresize=true"
+};
+deployJava.writeAppletTag(attributes, parameters);
+</script>
+
+<p>The WTKX for the application's user interface is as follows:</p>
+
+<pre class="brush:xml">
+<Window title="Web Queries" maximized="true"
+ xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns:webqueries="org.apache.pivot.tutorials.webqueries"
+ xmlns="org.apache.pivot.wtk">
+ <content>
+ <Border styles="{color:10, padding:0}">
+ <content>
+ <StackPane>
+ <ScrollPane horizontalScrollBarPolicy="fill">
+ <view>
+ <ListView wtkx:id="listView">
+ <itemRenderer>
+ <webqueries:ResultItemRenderer/>
+ </itemRenderer>
+ </ListView>
+ </view>
+ </ScrollPane>
+ <Label wtkx:id="loadingLabel" text="Loading..."
+ styles="{horizontalAlignment:'center', verticalAlignment:'center'}"/>
+ </StackPane>
+ </content>
+ </Border>
+ </content>
+</Window>
+</pre>
+
+<p>Note that the <tt>ListView</tt> defines a custom item renderer; this renderer is used to present the name, address, and phone number of the matching items returned by the query.</p>
+
+<p>The Java source for the application is as follows:</p>
+
+<pre class="brush:java">
+package org.apache.pivot.tutorials.webqueries;
+
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.serialization.JSONSerializer;
+import org.apache.pivot.util.concurrent.Task;
+import org.apache.pivot.util.concurrent.TaskListener;
+import org.apache.pivot.web.GetQuery;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.Label;
+import org.apache.pivot.wtk.ListView;
+import org.apache.pivot.wtk.TaskAdapter;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtkx.WTKXSerializer;
+
+public class WebQueries implements Application {
+ private Window window = null;
+
+ private ListView listView = null;
+ private Label loadingLabel = null;
+
+ @Override
+ public void startup(Display display, Map<String, String> properties) throws Exception {
+ WTKXSerializer wtkxSerializer = new WTKXSerializer();
+ window = (Window)wtkxSerializer.readObject(this, "web_queries.wtkx");
+
+ listView = (ListView)wtkxSerializer.get("listView");
+ loadingLabel = (Label)wtkxSerializer.get("loadingLabel");
+
+ // Execute the query:
+ // http://pipes.yahoo.com/pipes/pipe.run?_id=43115761f2da5af5341ae2e56a93d646&_render=json
+ GetQuery getQuery = new GetQuery("pipes.yahoo.com", "/pipes/pipe.run");
+ getQuery.getParameters().put("_id", "43115761f2da5af5341ae2e56a93d646");
+ getQuery.getParameters().put("_render", "json");
+
+ getQuery.execute(new TaskAdapter<Object>(new TaskListener<Object>() {
+ @Override
+ public void taskExecuted(Task<Object> task) {
+ listView.setListData(JSONSerializer.getList(task.getResult(), "value.items"));
+ loadingLabel.setVisible(false);
+ }
+
+ @Override
+ public void executeFailed(Task<Object> task) {
+ loadingLabel.setText(task.getFault().getMessage());
+ }
+ }));
+
+ window.open(display);
+ }
+
+ @Override
+ public boolean shutdown(boolean optional) {
+ if (window != null) {
+ window.close();
+ }
+
+ return false;
+ }
+
+ @Override
+ public void suspend() {
+ }
+
+ @Override
+ public void resume() {
+ }
+
+ public static void main(String[] args) {
+ DesktopApplicationContext.main(WebQueries.class, args);
+ }
+}
+</pre>
+
+<p>In <tt>startup()</tt>, the application creates the query object and sets the appropriate query string parameters to identify the pipe and ensure that the pipe's output is returned as JSON data. It then executes the query, wrapping the task listener in a task adapter to ensure that the callback is executed on the UI thread. When the data is obtained, the "items" list is extracted from it and set as the data of the list view component.</p>
+
+<p>The application uses a custom list item renderer to present the result data. The renderer is defined as follows (it extends <tt>BoxPane</tt> and uses labels to present the name, address, and phone numbers of the result items):</p>
+
+<pre class="brush:java">
+package org.apache.pivot.tutorials.webqueries;
+
+import java.awt.Color;
+import java.awt.Font;
+
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.BoxPane;
+import org.apache.pivot.wtk.Insets;
+import org.apache.pivot.wtk.Label;
+import org.apache.pivot.wtk.ListView;
+import org.apache.pivot.wtk.Orientation;
+
+public class ResultItemRenderer extends BoxPane implements ListView.ItemRenderer {
+ private Label titleLabel = new Label();
+ private Label addressLabel = new Label();
+ private Label phoneLabel = new Label();
+
+ public ResultItemRenderer() {
+ super(Orientation.VERTICAL);
+
+ add(titleLabel);
+ add(addressLabel);
+ add(phoneLabel);
+
+ getStyles().put("padding", new Insets(3, 2, 3, 2));
+ getStyles().put("spacing", 2);
+ }
+
+ @Override
+ public void setSize(int width, int height) {
+ super.setSize(width, height);
+ validate();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void render(Object item, int index, ListView listView, boolean selected,
+ boolean checked, boolean highlighted, boolean disabled) {
+ if (item != null) {
+ Map<String, Object> map = (Map<String, Object>)item;
+
+ titleLabel.setText((String)map.get("title"));
+ phoneLabel.setText((String)map.get("Phone"));
+
+ Map<String, Object> location = (Map<String, Object>)map.get("y:location");
+ if (location == null) {
+ addressLabel.setText(null);
+ } else {
+ String street = (String)location.get("street");
+ String city = (String)location.get("city");
+ String state = (String)location.get("state");
+ addressLabel.setText(street + ", " + city + " " + state);
+ }
+ }
+
+ Font font = (Font)listView.getStyles().get("font");
+ titleLabel.getStyles().put("font", font.deriveFont(font.getStyle() | Font.BOLD));
+ phoneLabel.getStyles().put("font", font);
+ addressLabel.getStyles().put("font", font);
+
+ Color color;
+ if (listView.isEnabled() && !disabled) {
+ if (selected) {
+ if (listView.isFocused()) {
+ color = (Color)listView.getStyles().get("selectionColor");
+ } else {
+ color = (Color)listView.getStyles().get("inactiveSelectionColor");
+ }
+ } else {
+ color = (Color)listView.getStyles().get("color");
+ }
+ } else {
+ color = (Color)listView.getStyles().get("disabledColor");
+ }
+
+ titleLabel.getStyles().put("color", color);
+ phoneLabel.getStyles().put("color", color);
+ addressLabel.getStyles().put("color", color);
+ }
+}
+</pre>
+
<p>Next: <a href="data_binding.html">Data Binding</a></p>
</body>
</html>
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=824383&r1=824382&r2=824383&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 Mon Oct 12 15:27:35 2009
@@ -17,6 +17,7 @@
package org.apache.pivot.wtk;
import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.serialization.JSONSerializer;
import org.apache.pivot.util.ListenerList;
/**
@@ -465,7 +466,7 @@
public void load(Dictionary<String, ?> context) {
if (selectedKey != null
&& context.containsKey(selectedKey)) {
- Object value = context.get(selectedKey);
+ Object value = JSONSerializer.get(context, selectedKey);
if (!(value instanceof Boolean)) {
throw new IllegalArgumentException("value must be an instance of "
@@ -477,7 +478,7 @@
if (stateKey != null
&& context.containsKey(stateKey)) {
- Object value = context.get(stateKey);
+ Object value = JSONSerializer.get(context, stateKey);
if (!(value instanceof State)) {
throw new IllegalArgumentException("value must be an instance of "
@@ -489,19 +490,26 @@
}
@Override
- @SuppressWarnings("unchecked")
public void store(Dictionary<String, ?> context) {
if (isEnabled()) {
if (selectedKey != null) {
- ((Dictionary<String, Boolean>)context).put(selectedKey, isSelected());
+ JSONSerializer.put(context, selectedKey, isSelected());
}
if (stateKey != null) {
- ((Dictionary<String, State>)context).put(stateKey, state);
+ JSONSerializer.put(context, stateKey, state);
}
}
}
+ @Override
+ public void clear() {
+ if (selectedKey != null
+ || stateKey != null) {
+ setSelected(false);
+ }
+ }
+
public ListenerList<ButtonListener> getButtonListeners() {
return buttonListeners;
}
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=824383&r1=824382&r2=824383&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 Mon Oct 12 15:27:35 2009
@@ -316,7 +316,7 @@
public void load(Dictionary<String, ?> context) {
if (selectedDateKey != null
&& context.containsKey(selectedDateKey)) {
- Object value = context.get(selectedDateKey);
+ Object value = JSONSerializer.get(context, selectedDateKey);
if (value instanceof CalendarDate) {
setSelectedDate((CalendarDate)value);
@@ -334,11 +334,20 @@
* picker's bind key, if one is set.
*/
@Override
- @SuppressWarnings("unchecked")
public void store(Dictionary<String, ?> context) {
if (isEnabled()
&& selectedDateKey != null) {
- ((Dictionary<String, CalendarDate>)context).put(selectedDateKey, selectedDate);
+ JSONSerializer.put(context, selectedDateKey, selectedDate);
+ }
+ }
+
+ /**
+ * If a bind key is set, clears the selected date.
+ */
+ @Override
+ public void clear() {
+ if (selectedDateKey != null) {
+ setSelectedDate((CalendarDate)null);
}
}
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=824383&r1=824382&r2=824383&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 Mon Oct 12 15:27:35 2009
@@ -279,7 +279,7 @@
if (selectedDateKey != null
&& context.containsKey(selectedDateKey)) {
- Object value = context.get(selectedDateKey);
+ Object value = JSONSerializer.get(context, selectedDateKey);
if (value instanceof CalendarDate) {
setSelectedDate((CalendarDate)value);
@@ -297,14 +297,20 @@
* picker button's bind key, if one is set.
*/
@Override
- @SuppressWarnings("unchecked")
public void store(Dictionary<String, ?> context) {
- if (isEnabled()) {
- String selectedDateKey = getSelectedDateKey();
+ if (isEnabled()
+ && selectedDateKey != null) {
+ JSONSerializer.put(context, selectedDateKey, selectedDate);
+ }
+ }
- if (selectedDateKey != null) {
- ((Dictionary<String, CalendarDate>)context).put(selectedDateKey, getSelectedDate());
- }
+ /**
+ * If a bind key is set, clears the selected date.
+ */
+ @Override
+ public void clear() {
+ if (selectedDateKey != null) {
+ setSelectedDate((CalendarDate)null);
}
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java?rev=824383&r1=824382&r2=824383&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java Mon Oct 12 15:27:35 2009
@@ -2348,6 +2348,12 @@
store(new BeanDictionary(context));
}
+ /**
+ * Clears any bound values in the component.
+ */
+ public void clear() {
+ }
+
public DragSource getDragSource() {
return dragSource;
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java?rev=824383&r1=824382&r2=824383&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java Mon Oct 12 15:27:35 2009
@@ -673,6 +673,16 @@
}
}
+ /**
+ * Propagates clear operation to subcomponents.
+ */
+ @Override
+ public void clear() {
+ for (Component component : components) {
+ component.clear();
+ }
+ }
+
@Override
protected boolean mouseMove(int x, int y) {
boolean consumed = false;
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=824383&r1=824382&r2=824383&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 Mon Oct 12 15:27:35 2009
@@ -17,6 +17,7 @@
package org.apache.pivot.wtk;
import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.serialization.JSONSerializer;
import org.apache.pivot.util.ListenerList;
@@ -99,7 +100,7 @@
public void load(Dictionary<String, ?> context) {
if (textKey != null
&& context.containsKey(textKey)) {
- Object value = context.get(textKey);
+ Object value = JSONSerializer.get(context, textKey);
if (value != null) {
value = value.toString();
}
@@ -109,11 +110,17 @@
}
@Override
- @SuppressWarnings("unchecked")
public void store(Dictionary<String, ?> context) {
if (isEnabled()
&& textKey != null) {
- ((Dictionary<String, String>)context).put(textKey, getText());
+ JSONSerializer.put(context, textKey, getText());
+ }
+ }
+
+ @Override
+ public void clear() {
+ if (textKey != null) {
+ setText(null);
}
}
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=824383&r1=824382&r2=824383&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 Mon Oct 12 15:27:35 2009
@@ -325,18 +325,24 @@
public void load(Dictionary<String, ?> context) {
if (selectedItemKey != null
&& context.containsKey(selectedItemKey)) {
- Object item = context.get(selectedItemKey);
+ Object item = JSONSerializer.get(context, selectedItemKey);
setSelectedItem(item);
}
}
@Override
- @SuppressWarnings("unchecked")
public void store(Dictionary<String, ?> context) {
if (isEnabled()
&& selectedItemKey != null) {
Object item = getSelectedItem();
- ((Dictionary<String, Object>)context).put(selectedItemKey, item);
+ JSONSerializer.put(context, selectedItemKey, item);
+ }
+ }
+
+ @Override
+ public void clear() {
+ if (selectedItemKey != null) {
+ setSelectedItem(null);
}
}
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=824383&r1=824382&r2=824383&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 Mon Oct 12 15:27:35 2009
@@ -1419,13 +1419,14 @@
public void load(Dictionary<String, ?> context) {
if (selectedItemKey != null
&& context.containsKey(selectedItemKey)) {
- Object item = context.get(selectedItemKey);
+ Object item = JSONSerializer.get(context, selectedItemKey);
setSelectedItem(item);
}
if (selectedItemsKey != null
&& context.containsKey(selectedItemsKey)) {
- Sequence<Object> items = (Sequence<Object>)context.get(selectedItemsKey);
+ Sequence<Object> items = (Sequence<Object>)JSONSerializer.get(context,
+ selectedItemsKey);
setSelectedItems(items);
}
}
@@ -1436,16 +1437,24 @@
if (isEnabled()) {
if (selectedItemKey != null) {
Object item = getSelectedItem();
- ((Dictionary<String, Object>)context).put(selectedItemKey, item);
+ JSONSerializer.put(context, selectedItemKey, item);
}
if (selectedItemsKey != null) {
Sequence<Object> items = (Sequence<Object>)getSelectedItems();
- ((Dictionary<String, Sequence<Object>>)context).put(selectedItemsKey, items);
+ JSONSerializer.put(context, selectedItemsKey, items);
}
}
}
+ @Override
+ public void clear() {
+ if (selectedItemKey != null
+ || selectedItemsKey != null) {
+ setSelectedItem(null);
+ }
+ }
+
/**
* Returns the index of the item at a given location.
*
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=824383&r1=824382&r2=824383&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 Mon Oct 12 15:27:35 2009
@@ -396,18 +396,24 @@
public void load(Dictionary<String, ?> context) {
if (selectedItemKey != null
&& context.containsKey(selectedItemKey)) {
- Object item = context.get(selectedItemKey);
+ Object item = JSONSerializer.get(context, selectedItemKey);
setSelectedItem(item);
}
}
@Override
- @SuppressWarnings("unchecked")
public void store(Dictionary<String, ?> context) {
if (isEnabled()
&& selectedItemKey != null) {
Object item = getSelectedItem();
- ((Dictionary<String, Object>)context).put(selectedItemKey, item);
+ JSONSerializer.put(context, selectedItemKey, item);
+ }
+ }
+
+ @Override
+ public void clear() {
+ if (selectedItemKey != null) {
+ setSelectedItem(null);
}
}
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=824383&r1=824382&r2=824383&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 Mon Oct 12 15:27:35 2009
@@ -22,6 +22,7 @@
import org.apache.pivot.collections.Dictionary;
import org.apache.pivot.collections.Sequence;
+import org.apache.pivot.serialization.JSONSerializer;
import org.apache.pivot.serialization.SerializationException;
import org.apache.pivot.util.ListenerList;
import org.apache.pivot.wtk.media.Image;
@@ -318,7 +319,7 @@
public void load(Dictionary<String, ?> context) {
if (textKey != null
&& context.containsKey(textKey)) {
- Object value = context.get(textKey);
+ Object value = JSONSerializer.get(context, textKey);
if (value != null) {
value = value.toString();
}
@@ -328,11 +329,17 @@
}
@Override
- @SuppressWarnings("unchecked")
public void store(Dictionary<String, ?> context) {
if (isEnabled()
&& textKey != null) {
- ((Dictionary<String, String>)context).put(textKey, getText());
+ JSONSerializer.put(context, textKey, getText());
+ }
+ }
+
+ @Override
+ public void clear() {
+ if (textKey != null) {
+ setText(null);
}
}
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=824383&r1=824382&r2=824383&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 Mon Oct 12 15:27:35 2009
@@ -19,6 +19,7 @@
import java.io.IOException;
import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.serialization.JSONSerializer;
import org.apache.pivot.util.ListenerList;
import org.apache.pivot.wtk.text.Element;
import org.apache.pivot.wtk.text.Node;
@@ -635,24 +636,31 @@
public void load(Dictionary<String, ?> context) {
if (textKey != null
&& context.containsKey(textKey)) {
- Object value = context.get(textKey);
+ Object value = JSONSerializer.get(context, textKey);
if (value != null) {
value = value.toString();
}
- setText((String)value);
+ setText((String)value);
}
}
@Override
- @SuppressWarnings("unchecked")
public void store(Dictionary<String, ?> context) {
if (isEnabled()
&& textKey != null) {
- ((Dictionary<String, String>)context).put(textKey, getText());
+ JSONSerializer.put(context, textKey, getText());
}
}
+ @Override
+ public void clear() {
+ if (textKey != null) {
+ setText("");
+ }
+ }
+
+
/**
* Tells whether or not this text input's text is currently valid as
* defined by its validator. If there is no validator associated with this
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java?rev=824383&r1=824382&r2=824383&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java Mon Oct 12 15:27:35 2009
@@ -333,6 +333,8 @@
titleChanged(frame, null);
activeChanged(frame, null);
maximizedChanged(frame);
+
+ setShowMinimizeButton(false);
}
@Override
@@ -633,8 +635,8 @@
public boolean getShowWindowControls() {
return (getShowMinimizeButton()
- && getShowMaximizeButton()
- && getShowCloseButton());
+ || getShowMaximizeButton()
+ || getShowCloseButton());
}
public void setShowWindowControls(boolean showWindowControls) {