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/03/27 01:31:42 UTC
svn commit: r928112 - in /pivot/trunk/tutorials:
src/org/apache/pivot/tutorials/text/ www/
Author: gbrown
Date: Sat Mar 27 00:31:41 2010
New Revision: 928112
URL: http://svn.apache.org/viewvc?rev=928112&view=rev
Log:
Finish SuggestionPopup tutorial.
Modified:
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/SuggestionPopups.java
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/suggestion_popups.wtkx
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/text_inputs.wtkx
pivot/trunk/tutorials/www/index.xml
pivot/trunk/tutorials/www/suggestion-popups.xml
pivot/trunk/tutorials/www/text.xml
pivot/trunk/tutorials/www/wtkx-primer.xml
Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/SuggestionPopups.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/SuggestionPopups.java?rev=928112&r1=928111&r2=928112&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/SuggestionPopups.java (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/SuggestionPopups.java Sat Mar 27 00:31:41 2010
@@ -121,7 +121,7 @@ public class SuggestionPopups implements
public void startup(Display display, Map<String, String> properties)
throws Exception {
WTKXSerializer wtkxSerializer = new WTKXSerializer();
- window = (Window)wtkxSerializer.readObject(this, "text_inputs.wtkx");
+ window = (Window)wtkxSerializer.readObject(this, "suggestion_popups.wtkx");
stateTextInput = (TextInput)wtkxSerializer.get("stateTextInput");
stateTextInput.getTextInputCharacterListeners().add(textInputCharacterListener);
Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/suggestion_popups.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/suggestion_popups.wtkx?rev=928112&r1=928111&r2=928112&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/suggestion_popups.wtkx (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/suggestion_popups.wtkx Sat Mar 27 00:31:41 2010
@@ -20,9 +20,15 @@ limitations under the License.
xmlns:wtkx="http://pivot.apache.org/wtkx"
xmlns="org.apache.pivot.wtk">
<content>
- <BoxPane styles="{padding:4, verticalAlignment:'top'}">
- <Label text="State:"/>
- <TextInput wtkx:id="stateTextInput"/>
- </BoxPane>
+ <Border>
+ <content>
+ <BoxPane orientation="vertical" styles="{padding:4, verticalAlignment:'top'}">
+ <BoxPane styles="{verticalAlignment:'center'}">
+ <Label text="State:"/>
+ <TextInput wtkx:id="stateTextInput"/>
+ </BoxPane>
+ </BoxPane>
+ </content>
+ </Border>
</content>
</Window>
Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/text_inputs.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/text_inputs.wtkx?rev=928112&r1=928111&r2=928112&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/text_inputs.wtkx (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/text_inputs.wtkx Sat Mar 27 00:31:41 2010
@@ -20,7 +20,7 @@ limitations under the License.
xmlns:wtkx="http://pivot.apache.org/wtkx"
xmlns="org.apache.pivot.wtk">
<content>
- <BoxPane styles="{padding:4, verticalAlignment:'top'}">
+ <BoxPane styles="{padding:4, verticalAlignment:'center'}">
<Label text="State:"/>
<TextInput wtkx:id="stateTextInput"/>
</BoxPane>
Modified: pivot/trunk/tutorials/www/index.xml
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/www/index.xml?rev=928112&r1=928111&r2=928112&view=diff
==============================================================================
--- pivot/trunk/tutorials/www/index.xml (original)
+++ pivot/trunk/tutorials/www/index.xml Sat Mar 27 00:31:41 2010
@@ -66,6 +66,7 @@ limitations under the License.
<document-item id="list-buttons"/>
</document-item>
<document-item id="text">
+ <document-item id="suggestion-popups"/>
<document-item id="text-areas"/>
</document-item>
<document-item id="separators"/>
Modified: pivot/trunk/tutorials/www/suggestion-popups.xml
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/www/suggestion-popups.xml?rev=928112&r1=928111&r2=928112&view=diff
==============================================================================
--- pivot/trunk/tutorials/www/suggestion-popups.xml (original)
+++ pivot/trunk/tutorials/www/suggestion-popups.xml Sat Mar 27 00:31:41 2010
@@ -23,9 +23,13 @@ limitations under the License.
<body>
<p>
+ <tt>SuggestionPopup</tt> is a component that can be used to provide "auto-complete"
+ functionality for a text input. This example is essentially an extension of the
+ previous example that replaces the inline auto-complete with a popup list of suggested
+ matches:
</p>
- <application class="org.apache.pivot.tutorials.text.SuggestionPopups" width="240" height="200">
+ <application class="org.apache.pivot.tutorials.text.SuggestionPopups" width="320" height="200">
<libraries>
<library>core</library>
<library>wtk</library>
@@ -35,18 +39,182 @@ limitations under the License.
</application>
<p>
+ The following is the WTKX source for the application. It is not significantly different
+ from the previous example, though it is arranged to provide more room for the suggestion
+ popup:
</p>
<source type="xml" location="org/apache/pivot/tutorials/text/suggestion_popups.wtkx">
<![CDATA[
+ <Window title="Suggestion Popups" maximized="true"
+ xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns="org.apache.pivot.wtk">
+ <content>
+ <Border>
+ <content>
+ <BoxPane orientation="vertical" styles="{padding:4, verticalAlignment:'top'}">
+ <BoxPane styles="{verticalAlignment:'center'}">
+ <Label text="State:"/>
+ <TextInput wtkx:id="stateTextInput"/>
+ </BoxPane>
+ </BoxPane>
+ </content>
+ </Border>
+ </content>
+ </Window>
]]>
</source>
<p>
+ The Java source is as follows. The only difference between this code and the code
+ from the previous example is the definition of the text input character listener.
+ In the previous example, the listener performed a binary search to identify possible
+ matches. In this example, the listener generates a list of suggestions and displays
+ them in a suggestion popup. As the user enters text in the text input, the listener
+ builds the suggestion list and then opens a <tt>SuggestionPopup</tt> to present the
+ suggestions. If the user selects an entry from the popup, it is automatically copied
+ to the text input:
</p>
<source type="java" location="org/apache/pivot/tutorials/text/SuggestionPopups.java">
<![CDATA[
+ package org.apache.pivot.tutorials.text;
+
+ import org.apache.pivot.collections.ArrayList;
+ import org.apache.pivot.collections.Map;
+ import org.apache.pivot.wtk.Application;
+ import org.apache.pivot.wtk.DesktopApplicationContext;
+ import org.apache.pivot.wtk.Display;
+ import org.apache.pivot.wtk.SuggestionPopup;
+ import org.apache.pivot.wtk.TextInput;
+ import org.apache.pivot.wtk.TextInputCharacterListener;
+ import org.apache.pivot.wtk.Window;
+ import org.apache.pivot.wtkx.WTKXSerializer;
+
+ public class SuggestionPopups implements Application {
+ private Window window = null;
+ private TextInput stateTextInput = null;
+
+ private ArrayList<String> states;
+ private SuggestionPopup suggestionPopup = new SuggestionPopup();
+
+ private TextInputCharacterListener textInputCharacterListener =
+ new TextInputCharacterListener() {
+ @Override
+ public void charactersInserted(TextInput textInput, int index, int count) {
+ String text = textInput.getText();
+ ArrayList<String> suggestions = new ArrayList<String>();
+
+ for (String state : states) {
+ if (state.toUpperCase().startsWith(text.toUpperCase())) {
+ suggestions.add(state);
+ }
+ }
+
+ if (suggestions.getLength() > 0) {
+ suggestionPopup.setSuggestions(suggestions);
+ suggestionPopup.open(textInput);
+ }
+ }
+
+ @Override
+ public void charactersRemoved(TextInput textInput, int index, int count) {
+ suggestionPopup.close();
+ }
+ };
+
+ public SuggestionPopups() {
+ // Populate the lookup values, ensuring that they are sorted
+ states = new ArrayList<String>();
+ states.setComparator(String.CASE_INSENSITIVE_ORDER);
+
+ states.add("Alabama");
+ states.add("Alaska");
+ states.add("Arizona");
+ states.add("Arkansas");
+ states.add("California");
+ states.add("Colorado");
+ states.add("Connecticut");
+ states.add("Delaware");
+ states.add("District of Columbia");
+ states.add("Florida");
+ states.add("Georgia");
+ states.add("Hawaii");
+ states.add("Idaho");
+ states.add("Illinois");
+ states.add("Indiana");
+ states.add("Iowa");
+ states.add("Kansas");
+ states.add("Kentucky");
+ states.add("Louisiana");
+ states.add("Maine");
+ states.add("Maryland");
+ states.add("Massachusetts");
+ states.add("Michigan");
+ states.add("Minnesota");
+ states.add("Mississippi");
+ states.add("Missouri");
+ states.add("Montana");
+ states.add("Nebraska");
+ states.add("Nevada");
+ states.add("New Hampshire");
+ states.add("New Jersey");
+ states.add("New Mexico");
+ states.add("New York");
+ states.add("North Carolina");
+ states.add("North Dakota");
+ states.add("Ohio");
+ states.add("Oklahoma");
+ states.add("Oregon");
+ states.add("Pennsylvania");
+ states.add("Rhode Island");
+ states.add("South Carolina");
+ states.add("South Dakota");
+ states.add("Tennessee");
+ states.add("Texas");
+ states.add("Utah");
+ states.add("Vermont");
+ states.add("Virginia");
+ states.add("Washington");
+ states.add("West Virginia");
+ states.add("Wisconsin");
+ states.add("Wyoming");
+ }
+
+ @Override
+ public void startup(Display display, Map<String, String> properties)
+ throws Exception {
+ WTKXSerializer wtkxSerializer = new WTKXSerializer();
+ window = (Window)wtkxSerializer.readObject(this, "suggestion_popups.wtkx");
+ stateTextInput = (TextInput)wtkxSerializer.get("stateTextInput");
+
+ stateTextInput.getTextInputCharacterListeners().add(textInputCharacterListener);
+
+ window.open(display);
+ stateTextInput.requestFocus();
+ }
+
+ @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(SuggestionPopups.class, args);
+ }
+ }
]]>
</source>
</body>
Modified: pivot/trunk/tutorials/www/text.xml
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/www/text.xml?rev=928112&r1=928111&r2=928112&view=diff
==============================================================================
--- pivot/trunk/tutorials/www/text.xml (original)
+++ pivot/trunk/tutorials/www/text.xml Sat Mar 27 00:31:41 2010
@@ -26,8 +26,7 @@ limitations under the License.
Text input components in Pivot include <tt>TextInput</tt> and <tt>TextArea</tt>.
<tt>TextInput</tt> allows a user to enter a single line of unformatted text; the text
may be presented in the clear or may be masked for use as a "password" field.
- <tt>TextArea</tt> is a rich, multi-line text component and is discussed in the next
- section.
+ <tt>TextArea</tt> multi-line text component and is discussed in the next section.
</p>
<p>
Modified: pivot/trunk/tutorials/www/wtkx-primer.xml
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/www/wtkx-primer.xml?rev=928112&r1=928111&r2=928112&view=diff
==============================================================================
--- pivot/trunk/tutorials/www/wtkx-primer.xml (original)
+++ pivot/trunk/tutorials/www/wtkx-primer.xml Sat Mar 27 00:31:41 2010
@@ -857,23 +857,23 @@ limitations under the License.
The <tt>org.apache.pivot.wtkx</tt> package includes an annotation that can be used to
simplify the process of mapping named objects into a Java application. The
<tt>@WTKX</tt> annotation is used to tag a member variable so that it will be
- automatically mapped to a named object in a WTKX file.
+ automatically mapped to a named object in a WTKX file.
</p>
-
+
<p>
- The <tt>bind()</tt> method of <tt>WTKXSerializer</tt> is used to perform the actual
- mapping. However, it is often easier to use the <tt>Bindable</tt> interface.
- Implementing this interface ensures that <tt>bind()</tt> will be automatically called
+ The <tt>bind()</tt> method of <tt>WTKXSerializer</tt> is used to perform the actual
+ mapping. However, it is often easier to use the <tt>Bindable</tt> interface.
+ Implementing this interface ensures that <tt>bind()</tt> will be automatically called
on the implementing class by the WTKX serializer.
</p>
-
+
<p>
- <tt>Bindable</tt> defines a single method, <tt>initialize()</tt>, that is called when
- the root element of a WTKX file has been fully loaded and the bound values have been
- processed. This allows the bound class to perform any required initialization (often
+ <tt>Bindable</tt> defines a single method, <tt>initialize()</tt>, that is called when
+ the root element of a WTKX file has been fully loaded and the bound values have been
+ processed. This allows the bound class to perform any required initialization (often
event registration on the bound members).
</p>
-
+
<p>
For example, given the following WTKX:
</p>
@@ -902,8 +902,8 @@ limitations under the License.
<p>
As a result, the <tt>@WTKX</tt> annotation can significanly simplify the process of
- working with loaded WTKX data in Java code. However, it is important to note that,
- because WTKX binding relies on reflection to set the member variables, it can only be
+ working with loaded WTKX data in Java code. However, it is important to note that,
+ because WTKX binding relies on reflection to set the member variables, it can only be
used with trusted code or to set the values of public fields.
</p>