You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2011/02/07 03:36:18 UTC
svn commit: r1067847 [23/27] - in /pivot/site/trunk/deploy: ./ assets/
demos/ images/ lib/ styles/ tutorials/ tutorials/component_and_container/
tutorials/platform_overview/ tutorials/windows/
Added: pivot/site/trunk/deploy/tutorials/stock-tracker.localization.html
URL: http://svn.apache.org/viewvc/pivot/site/trunk/deploy/tutorials/stock-tracker.localization.html?rev=1067847&view=auto
==============================================================================
--- pivot/site/trunk/deploy/tutorials/stock-tracker.localization.html (added)
+++ pivot/site/trunk/deploy/tutorials/stock-tracker.localization.html Mon Feb 7 02:36:04 2011
@@ -0,0 +1,213 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!--
+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.
+--><html xmlns="http://www.w3.org/1999/xhtml"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /><title>Localization | Apache Pivot</title><link xmlns="" type="text/css" rel="stylesheet" href="/styles/pivot.css"><script xmlns="http://www.w3.org/1999/xhtml" type="text/javascript">
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+ </script><script type="text/javascript">
+ try {
+ var pageTracker = _gat._getTracker("UA-7977275-3");
+ pageTracker._trackPageview();
+ } catch(err) {}</script></head><body><div xmlns="" id="wrapper"><div id="main"><div id="header"><div class="logo"><a href="/index.html"><img title="Apache Pivot Homepage" alt="Apache Pivot" src="/images/logo.png"></a></div><div class="tagline"><img style="visibility:hidden" alt="Rich Internet Applications in Java" src="/images/tagline.png"></div><ul class="navi"><li><a href="/demos/">Demos</a></li><li><a href="/download.cgi#2.0">Download</a></li><li><a href="/tutorials/">Tutorial</a></li><li><a href="/get-involved.html">Get Involved</a></li><li><a href="/about.html">About</a></li></ul></div><div class="group" id="contentBase"><h1>Localization</h1><ul class="naviLeft"><li><a href="/tutorials/sample-application.html">Sample Application</a></li><li><a href="/tutorials/platform-overview.html">Platform Overview</a></li><li><a href="/tutorials/hello-world.html">Hello, World!</a></li><li><a href="/tutorials/hello-bxml.html">Hello, BXML!</a></li><li><a href="/tutoria
ls/component-and-container.html">Component & Container</a></li><li><a href="/tutorials/labels-and-image-views.html">Labels & Image Views</a></li><li><a href="/tutorials/svg-images.html">SVG Images</a></li><li><a href="/tutorials/buttons.html">Buttons</a></li><li><a href="/tutorials/push-buttons.html">Push Buttons</a></li><li><a href="/tutorials/toggle-buttons.html">Toggle Buttons</a></li><li><a href="/tutorials/radio-buttons.html">Radio Buttons</a></li><li><a href="/tutorials/checkboxes.html">Checkboxes</a></li><li><a href="/tutorials/link-buttons.html">Link Buttons</a></li><li><a href="/tutorials/lists.html">Lists</a></li><li><a href="/tutorials/list-buttons.html">List Buttons</a></li><li><a href="/tutorials/repeatable-list-buttons.html">Repeatable List Buttons</a></li><li><a href="/tutorials/text.html">Text</a></li><li><a href="/tutorials/suggestion-popups.html">Suggestion Popups</a></li><li><a href="/tutorials/text-areas.html">Text Areas</a></li><li><a href="/tuto
rials/separators.html">Separators</a></li><li><a href="/tutorials/layout-containers.html">Layout Containers</a></li><li><a href="/tutorials/flow-panes.html">Flow Panes</a></li><li><a href="/tutorials/box-panes.html">Box Panes</a></li><li><a href="/tutorials/grid-panes.html">Grid Panes</a></li><li><a href="/tutorials/table-panes.html">Table Panes</a></li><li><a href="/tutorials/borders.html">Borders</a></li><li><a href="/tutorials/stack-panes.html">Stack Panes</a></li><li><a href="/tutorials/split-panes.html">Split Panes</a></li><li><a href="/tutorials/forms.html">Forms</a></li><li><a href="/tutorials/panels.html">Panels</a></li><li><a href="/tutorials/navigation-containers.html">Navigation Containers</a></li><li><a href="/tutorials/card-panes.html">Card Panes</a></li><li><a href="/tutorials/tab-panes.html">Tab Panes</a></li><li><a href="/tutorials/accordions.html">Accordions</a></li><li><a href="/tutorials/expanders.html">Expanders</a></li><li><a href="/tutorials/rollups.htm
l">Rollups</a></li><li><a href="/tutorials/viewports.html">Viewports</a></li><li><a href="/tutorials/scroll-panes.html">Scroll Panes</a></li><li><a href="/tutorials/panoramas.html">Panoramas</a></li><li><a href="/tutorials/progress-indicators.html">Progress Indicators</a></li><li><a href="/tutorials/meters.html">Meters</a></li><li><a href="/tutorials/activity-indicators.html">Activity Indicators</a></li><li><a href="/tutorials/bounded-range-components.html">Bounded Range Components</a></li><li><a href="/tutorials/sliders.html">Sliders</a></li><li><a href="/tutorials/scroll-bars.html">Scroll Bars</a></li><li><a href="/tutorials/spinners.html">Spinners</a></li><li><a href="/tutorials/calendars.html">Calendars</a></li><li><a href="/tutorials/menus.html">Menus</a></li><li><a href="/tutorials/context-menus.html">Context Menus</a></li><li><a href="/tutorials/menu-bars.html">Menu Bars</a></li><li><a href="/tutorials/menu-buttons.html">Menu Buttons</a></li><li><a href="/tutorials/co
lor-choosers.html">Color Choosers</a></li><li><a href="/tutorials/table-views.html">Table Views</a></li><li><a href="/tutorials/table-views.json.html">JSON-based TableView</a></li><li><a href="/tutorials/table-views.custom.html">Custom TableView</a></li><li><a href="/tutorials/tree-views.html">Tree Views</a></li><li><a href="/tutorials/file-browsing.html">File Browsing</a></li><li><a href="/tutorials/windows.html">Windows</a></li><li><a href="/tutorials/clipboard.html">Clipboard</a></li><li><a href="/tutorials/drag-and-drop.html">Drag and Drop</a></li><li><a href="/tutorials/effects.html">Effects</a></li><li><a href="/tutorials/effects.transitions.html">Transitions</a></li><li><a href="/tutorials/data-binding.html">Data Binding</a></li><li><a href="/tutorials/property-binding.html">Property Binding</a></li><li><a href="/tutorials/localization.html">Localization</a></li><li><a href="/tutorials/background-tasks.html">Background Tasks</a></li><li><a href="/tutorials/web-queries
.html">Web Queries</a></li><li><a href="/tutorials/query-servlet.html">QueryServlet</a></li><li><a href="/tutorials/scripting.html">Scripting</a></li><li><a href="/tutorials/summary.html">Summary</a></li><li><a href="/tutorials/stock-tracker.html">The "Stock Tracker" Application</a></li><li><a href="/tutorials/stock-tracker.ui.html">UI Markup Using BXML</a></li><li><a href="/tutorials/stock-tracker.events.html">Event Handling</a></li><li><a href="/tutorials/stock-tracker.web-queries.html">Web Queries</a></li><li><a href="/tutorials/stock-tracker.data-binding.html">Data Binding</a></li><li><a href="/tutorials/stock-tracker.localization.html">Localization</a></li><li><a href="/tutorials/bxml-primer.html">BXML Primer</a></li></ul><div class="content"><style type="text/css">
+ applet {
+ border: 1px solid #999999;
+ }
+ </style><!--NOTE: Syntax highlighting script is LGPL--><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js" type="text/javascript"></script><link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css"><link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css"><script type="text/javascript">
+ SyntaxHighlighter.all();
+ </script><div class="section">
+ <p>
+ In Java, any translatable text is generally stored in a set of localized property files
+ called "resource bundles". The appropriate file is loaded at runtime for either the
+ default locale or an explicitly selected non-default locale. While it is possible to
+ use standard Java resource bundles in a Pivot application, Pivot adds support for
+ JSON-based resource bundles that are slightly more flexible the built-in
+ properties-based bundles. JSON resource bundles allow developers to more easily work
+ with UTF-8 encoded resource strings, and also natively support hierarchical data, which
+ can only be simulated when using properties files.
+ </p>
+
+ <p>
+ Stock Tracker provides two resource files, one for English users and one for
+ French-speaking users:
+ </p>
+
+ <pre class="brush:jscript">
+
+ { stockTracker: "Pivot Stock Tracker",
+ symbol: "Symbol",
+ companyName: "Company",
+ value: "Value",
+ openingValue: "Open",
+ highValue: "High",
+ lowValue: "Low",
+ change: "Change",
+ volume: "Volume",
+ addSymbol: "Add symbol",
+ removeSymbol: "Remove selected symbols",
+ lastUpdate: "Last Update",
+ dataProvidedBy: "Data provided by",
+ yahooFinance: "Yahoo! Finance"
+ }
+
+ </pre>
+ <p class="caption">StockTracker.json</p>
+
+ <pre class="brush:jscript">
+
+ { stockTracker: "La Bourse Pivot",
+ symbol: "Code",
+ companyName: "Société",
+ value: "Cours",
+ openingValue: "Ouverture",
+ highValue: "+ Haut",
+ lowValue: "+ Bas",
+ change: "Variation",
+ volume: "Volume",
+ addSymbol: "Ajouter un code",
+ removeSymbol: "Enlever codes sélectionnés",
+ lastUpdate: "Dernier échange",
+ dataProvidedBy: "Données fournies par",
+ yahooFinance: "Yahoo! Finance"
+ }
+
+ </pre>
+ <p class="caption">StockTracker_fr.json</p>
+
+ <p>
+ As noted in earlier sections, references to these string resources can be embedded
+ directly within a BXML file:
+ </p>
+
+ <pre class="brush:xml">
+
+ <Form styles="{padding:0, fill:true, showFlagIcons:false, showFlagHighlight:false,
+ leftAlignLabels:true}">
+ <Form.Section>
+ <bxml:define>
+ <stocktracker:ValueMapping bxml:id="valueMapping"/>
+ <stocktracker:ChangeMapping bxml:id="changeMapping"/>
+ <stocktracker:VolumeMapping bxml:id="volumeMapping"/>
+ </bxml:define>
+
+ <Label bxml:id="valueLabel" Form.label="%value"
+ textKey="value" textBindMapping="$valueMapping"
+ styles="{horizontalAlignment:'right'}"/>
+ <Label bxml:id="changeLabel" Form.label="%change"
+ textKey="change" textBindMapping="$changeMapping"
+ styles="{horizontalAlignment:'right'}"/>
+ <Label bxml:id="openingValueLabel" Form.label="%openingValue"
+ textKey="openingValue" textBindMapping="$valueMapping"
+ styles="{horizontalAlignment:'right'}"/>
+ <Label bxml:id="highValueLabel" Form.label="%highValue"
+ textKey="highValue" textBindMapping="$valueMapping"
+ styles="{horizontalAlignment:'right'}"/>
+ <Label bxml:id="lowValueLabel" Form.label="%lowValue"
+ textKey="lowValue" textBindMapping="$valueMapping"
+ styles="{horizontalAlignment:'right'}"/>
+ <Label bxml:id="volumeLabel" Form.label="%volume"
+ textKey="volume" textBindMapping="$volumeMapping"
+ styles="{horizontalAlignment:'right'}"/>
+ </Form.Section>
+ </Form>
+
+ </pre>
+
+ <p>
+ The application loads the resources for the appropriate locale at startup, and the BXML
+ serializer handles the details of resource substitution so the developer doesn't have
+ to worry about it. The following applet demonstrates the Stock Tracker application run
+ using the "fr" locale. No code changes are required; the same JAR files are used to
+ execute both the English and French versions:
+ </p>
+
+ <script src="http://java.com/js/deployJava.js" type="text/javascript"></script><script type="text/javascript">
+
+ var attributes = {
+ code:"org.apache.pivot.wtk.BrowserApplicationContext$HostApplet",
+ width:"480",
+ height:"360"
+ };
+
+
+
+
+
+ var libraries = [];
+ libraries.push("/lib/pivot-core-2.0.signed.jar");
+ libraries.push("/lib/pivot-web-2.0.signed.jar");
+ libraries.push("/lib/pivot-wtk-2.0.signed.jar");
+ libraries.push("/lib/pivot-wtk-terra-2.0.signed.jar");
+ libraries.push("/lib/pivot-tutorials-2.0.signed.jar");
+
+ libraries.push("/lib/svgSalamander-tiny.signed.jar");
+
+
+ attributes.archive = libraries.join(",");
+
+
+ var parameters = {
+ codebase_lookup:false,
+ application_class_name:'org.apache.pivot.tutorials.stocktracker.StockTracker'
+ };
+
+
+ var javaArguments = ["-Dsun.awt.noerasebackground=true",
+ "-Dsun.awt.erasebackgroundonresize=true"];
+
+
+
+ parameters.java_arguments = javaArguments.join(" ");
+
+
+
+ var systemProperties = [];
+
+ systemProperties.push("user.language=fr");
+
+ parameters.system_properties = systemProperties.join("&");
+
+
+ deployJava.runApplet(attributes, parameters, "1.6");
+ </script>
+
+ <p>
+ Not all localization requirements can be handled by BXML alone, however. For example,
+ Stock Tracker needs to manually handle the localization of the "last updated" message:
+ </p>
+
+ <pre class="brush:java">
+
+ DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,
+ DateFormat.MEDIUM, Locale.getDefault());
+ lastUpdateLabel.setText(dateFormat.format(new Date()));
+
+ </pre>
+
+ <p>
+ However, most static localization can be addressed in the BXML source itself, making it
+ very easy to build internationalized applications in Pivot.
+ </p>
+
+ <h2>Summary</h2>
+
+ <p>
+ The examples in this section demonstrate the implementation of a simple but complete
+ application implemented in Pivot. They discuss features common to many "real-world"
+ applications, including UI markup, event handling, server communication, data binding,
+ and internationalization, and should provide a good starting point for any developer
+ interested in working with Pivot.
+ </p>
+ </div><p>Next: <a href="bxml-primer.html">BXML Primer</a></p></div></div></div><div class="group" id="footer"><div class="footerLogo">Copyright (c) 1999-2011<br>The Apache Software Foundation.</div><div class="footerLinks"><ul class="footerMenuGr"><li><strong>Demos</strong><ul><li><a href="/demos/kitchen-sink.html" target="_new">"Kitchen Sink"</a></li><li><a href="/demos/component-explorer.html" target="_new">Component Explorer</a></li><li><a href="http://ixnay.biz/pivot-jfree-demos/charts_demo.html" target="_new">Charting</a></li><li><a href="/demos/">More Demos</a></li></ul></li><li><strong>Documentation</strong><ul><li><a href="/getting-started.html">Getting Started</a></li><li><a href="/tutorials/">Tutorial</a></li><li><a href="/faq.html">FAQ</a></li><li><a href="/2.0/docs/api/">Javadoc (2.0)</a></li></ul></li><li><strong>Get Involved</strong><ul><li><a href="/svn.html">SVN Repositories</a></li><li><a href="/lists.html">Mailing Lists</a></li><li><a href="http://issue
s.apache.org/jira/browse/PIVOT">Bug Database</a></li><li><a href="http://cwiki.apache.org/PIVOT/">Wiki</a></li></ul></li><li><strong>Related</strong><ul><li><a href="http://code.google.com/p/pivot-jfree/">JFreeChart Provider</a></li></ul></li><li><strong>About</strong><ul><li><a href="/who-we-are.html">Who We Are</a></li><li><a href="/contact.html">Contact</a></li><li><a href="/news.html">News</a></li><li><a href="/legal.html">Legal/License</a></li></ul></li></ul></div></div></div></body></html>
\ No newline at end of file
Added: pivot/site/trunk/deploy/tutorials/stock-tracker.ui.html
URL: http://svn.apache.org/viewvc/pivot/site/trunk/deploy/tutorials/stock-tracker.ui.html?rev=1067847&view=auto
==============================================================================
--- pivot/site/trunk/deploy/tutorials/stock-tracker.ui.html (added)
+++ pivot/site/trunk/deploy/tutorials/stock-tracker.ui.html Mon Feb 7 02:36:04 2011
@@ -0,0 +1,197 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!--
+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.
+--><html xmlns="http://www.w3.org/1999/xhtml"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /><title>UI Markup Using BXML | Apache Pivot</title><link xmlns="" type="text/css" rel="stylesheet" href="/styles/pivot.css"><script xmlns="http://www.w3.org/1999/xhtml" type="text/javascript">
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+ </script><script type="text/javascript">
+ try {
+ var pageTracker = _gat._getTracker("UA-7977275-3");
+ pageTracker._trackPageview();
+ } catch(err) {}</script></head><body><div xmlns="" id="wrapper"><div id="main"><div id="header"><div class="logo"><a href="/index.html"><img title="Apache Pivot Homepage" alt="Apache Pivot" src="/images/logo.png"></a></div><div class="tagline"><img style="visibility:hidden" alt="Rich Internet Applications in Java" src="/images/tagline.png"></div><ul class="navi"><li><a href="/demos/">Demos</a></li><li><a href="/download.cgi#2.0">Download</a></li><li><a href="/tutorials/">Tutorial</a></li><li><a href="/get-involved.html">Get Involved</a></li><li><a href="/about.html">About</a></li></ul></div><div class="group" id="contentBase"><h1>UI Markup Using BXML</h1><ul class="naviLeft"><li><a href="/tutorials/sample-application.html">Sample Application</a></li><li><a href="/tutorials/platform-overview.html">Platform Overview</a></li><li><a href="/tutorials/hello-world.html">Hello, World!</a></li><li><a href="/tutorials/hello-bxml.html">Hello, BXML!</a></li><li><a href="
/tutorials/component-and-container.html">Component & Container</a></li><li><a href="/tutorials/labels-and-image-views.html">Labels & Image Views</a></li><li><a href="/tutorials/svg-images.html">SVG Images</a></li><li><a href="/tutorials/buttons.html">Buttons</a></li><li><a href="/tutorials/push-buttons.html">Push Buttons</a></li><li><a href="/tutorials/toggle-buttons.html">Toggle Buttons</a></li><li><a href="/tutorials/radio-buttons.html">Radio Buttons</a></li><li><a href="/tutorials/checkboxes.html">Checkboxes</a></li><li><a href="/tutorials/link-buttons.html">Link Buttons</a></li><li><a href="/tutorials/lists.html">Lists</a></li><li><a href="/tutorials/list-buttons.html">List Buttons</a></li><li><a href="/tutorials/repeatable-list-buttons.html">Repeatable List Buttons</a></li><li><a href="/tutorials/text.html">Text</a></li><li><a href="/tutorials/suggestion-popups.html">Suggestion Popups</a></li><li><a href="/tutorials/text-areas.html">Text Areas</a></li><li><a hre
f="/tutorials/separators.html">Separators</a></li><li><a href="/tutorials/layout-containers.html">Layout Containers</a></li><li><a href="/tutorials/flow-panes.html">Flow Panes</a></li><li><a href="/tutorials/box-panes.html">Box Panes</a></li><li><a href="/tutorials/grid-panes.html">Grid Panes</a></li><li><a href="/tutorials/table-panes.html">Table Panes</a></li><li><a href="/tutorials/borders.html">Borders</a></li><li><a href="/tutorials/stack-panes.html">Stack Panes</a></li><li><a href="/tutorials/split-panes.html">Split Panes</a></li><li><a href="/tutorials/forms.html">Forms</a></li><li><a href="/tutorials/panels.html">Panels</a></li><li><a href="/tutorials/navigation-containers.html">Navigation Containers</a></li><li><a href="/tutorials/card-panes.html">Card Panes</a></li><li><a href="/tutorials/tab-panes.html">Tab Panes</a></li><li><a href="/tutorials/accordions.html">Accordions</a></li><li><a href="/tutorials/expanders.html">Expanders</a></li><li><a href="/tutorials/rol
lups.html">Rollups</a></li><li><a href="/tutorials/viewports.html">Viewports</a></li><li><a href="/tutorials/scroll-panes.html">Scroll Panes</a></li><li><a href="/tutorials/panoramas.html">Panoramas</a></li><li><a href="/tutorials/progress-indicators.html">Progress Indicators</a></li><li><a href="/tutorials/meters.html">Meters</a></li><li><a href="/tutorials/activity-indicators.html">Activity Indicators</a></li><li><a href="/tutorials/bounded-range-components.html">Bounded Range Components</a></li><li><a href="/tutorials/sliders.html">Sliders</a></li><li><a href="/tutorials/scroll-bars.html">Scroll Bars</a></li><li><a href="/tutorials/spinners.html">Spinners</a></li><li><a href="/tutorials/calendars.html">Calendars</a></li><li><a href="/tutorials/menus.html">Menus</a></li><li><a href="/tutorials/context-menus.html">Context Menus</a></li><li><a href="/tutorials/menu-bars.html">Menu Bars</a></li><li><a href="/tutorials/menu-buttons.html">Menu Buttons</a></li><li><a href="/tuto
rials/color-choosers.html">Color Choosers</a></li><li><a href="/tutorials/table-views.html">Table Views</a></li><li><a href="/tutorials/table-views.json.html">JSON-based TableView</a></li><li><a href="/tutorials/table-views.custom.html">Custom TableView</a></li><li><a href="/tutorials/tree-views.html">Tree Views</a></li><li><a href="/tutorials/file-browsing.html">File Browsing</a></li><li><a href="/tutorials/windows.html">Windows</a></li><li><a href="/tutorials/clipboard.html">Clipboard</a></li><li><a href="/tutorials/drag-and-drop.html">Drag and Drop</a></li><li><a href="/tutorials/effects.html">Effects</a></li><li><a href="/tutorials/effects.transitions.html">Transitions</a></li><li><a href="/tutorials/data-binding.html">Data Binding</a></li><li><a href="/tutorials/property-binding.html">Property Binding</a></li><li><a href="/tutorials/localization.html">Localization</a></li><li><a href="/tutorials/background-tasks.html">Background Tasks</a></li><li><a href="/tutorials/web
-queries.html">Web Queries</a></li><li><a href="/tutorials/query-servlet.html">QueryServlet</a></li><li><a href="/tutorials/scripting.html">Scripting</a></li><li><a href="/tutorials/summary.html">Summary</a></li><li><a href="/tutorials/stock-tracker.html">The "Stock Tracker" Application</a></li><li><a href="/tutorials/stock-tracker.ui.html">UI Markup Using BXML</a></li><li><a href="/tutorials/stock-tracker.events.html">Event Handling</a></li><li><a href="/tutorials/stock-tracker.web-queries.html">Web Queries</a></li><li><a href="/tutorials/stock-tracker.data-binding.html">Data Binding</a></li><li><a href="/tutorials/stock-tracker.localization.html">Localization</a></li><li><a href="/tutorials/bxml-primer.html">BXML Primer</a></li></ul><div class="content"><style type="text/css">
+ applet {
+ border: 1px solid #999999;
+ }
+ </style><!--NOTE: Syntax highlighting script is LGPL--><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js" type="text/javascript"></script><link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css"><link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css"><script type="text/javascript">
+ SyntaxHighlighter.all();
+ </script><div class="section">
+ <p>
+ The user interface of a Pivot application is often defined using an XML markup language
+ called BXML ("Bean XML"). BXML is effectively a shorthand for instantiating and
+ configuring Java class instances. Though it can be used to declaratively construct any
+ type of Java object hierarchy, it is most often used to define the structure of an
+ application's user interface - the hierarchical structure of an XML document closely
+ parallels the structure of the application's component hierarchy, which makes it easy
+ to visualize the resulting output.
+ </p>
+
+ <p>
+ In general, XML elements in BXML refer either to class instances or properties of class
+ instances. Any element that begins with a capital letter represents a class instance,
+ and elements beginning with lowercase letters represent properties. The exception is
+ elements that use the "bxml" namespace prefix, which represent processing directives to
+ the BXML serializer. Similarly, XML attributes generally represent properties, with the
+ exception of attributes that begin with a "bxml" prefix, which contain processing
+ information used by the serializer.
+ </p>
+
+ <h2>StockTrackerWindow</h2>
+
+ <p>
+ The following is a snippet of code taken from <tt>stock_tracker_window.bxml</tt>,
+ the BXML file that defines the main window of the Stock Tracker application:
+ </p>
+
+ <pre class="brush:xml">
+
+ <stocktracker:StockTrackerWindow title="%stockTracker" maximized="true"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns:content="org.apache.pivot.wtk.content"
+ xmlns:stocktracker="org.apache.pivot.tutorials.stocktracker"
+ xmlns="org.apache.pivot.wtk">
+ <TablePane styles="{padding:8, horizontalSpacing:6, verticalSpacing:6}">
+ <columns>
+ <TablePane.Column width="1*" />
+ </columns>
+
+ <TablePane.Row height="-1">
+ <Label text="%stockTracker"
+ styles="{font:{size:14, bold:true}, verticalAlignment:'center'}" />
+ </TablePane.Row>
+
+ <TablePane.Row height="1*">
+ <SplitPane splitRatio="0.4">
+ <left>
+ ...
+ </left>
+
+ <right>
+ <Border styles="{padding:6, color:10}">
+ <bxml:include bxml:id="detailPane" src="detail_pane.bxml"/>
+ </Border>
+ </right>
+ </SplitPane>
+ </TablePane.Row>
+
+ <TablePane.Row height="-1">
+ <BoxPane styles="{horizontalAlignment:'left', verticalAlignment:'center'}">
+ <Label text="%symbol" styles="{font:{bold:true}}" />
+ <TextInput bxml:id="symbolTextInput" textSize="10"
+ maximumLength="8" />
+ ...
+ </TablePane>
+ </stocktracker:StockTrackerWindow>
+
+ </pre>
+
+ <p>
+ The root node of <tt>stock_tracker_window.bxml</tt> is a
+ <tt>stocktracker:StockTrackerWindow</tt> element. This element corresponds to an
+ instance of <tt>org.apache.pivot.tutorials.stocktracker.StockTrackerWindow</tt>. In
+ BXML, XML namespaces are used to associate a class element with a Java package. In this
+ case, "stocktracker" is mapped to <tt>org.apache.pivot.tutorials.stocktracker</tt>, and
+ "content" is mapped to <tt>org.apache.pivot.wtk.content</tt>; the default namespace is
+ mapped to <tt>org.apache.pivot.wtk</tt>, the Java package that contains most of Pivot's
+ common components. The file also declares the "bxml", which is specific to the
+ serializer.
+ </p>
+
+ <p>
+ <tt>StockTrackerWindow</tt> is an application-specific class that extends the base
+ <tt>org.apache.pivot.wtk.Window</tt> class. Windows are the primary entry point into a
+ Pivot user interface. Windows are always direct descendants of the "display" (an
+ instance of <tt>org.apache.pivot.wtk.Display</tt> that is created by the platform). An
+ application can open any number of windows on the display, though many applications
+ will use a single primary window and a number of secondary windows (for example,
+ dialogs, sheets, menu popups, or tooltips).
+ </p>
+
+ <h3>The Bindable Interface</h3>
+ <p>
+ <tt>StockTrackerWindow</tt> implements the <tt>org.apache.pivot.beans.Bindable</tt>
+ interface. This interface allows developers to easily map elements declared with a
+ <tt>bxml:id</tt> attribute to Java member variables. For example,
+ <tt>StockTrackerWindow</tt> declares the following member variables:
+ </p>
+
+ <pre class="brush:xml">
+
+ @BXML private TableView stocksTableView = null;
+ @BXML private TextInput symbolTextInput = null;
+ @BXML private Button addSymbolButton = null;
+ @BXML private Button removeSymbolsButton = null;
+ @BXML private BoxPane detailPane = null;
+ @BXML private Label lastUpdateLabel = null;
+ @BXML private Button yahooFinanceButton = null;
+
+ </pre>
+
+ <p>
+ Because <tt>StockTrackerWindow</tt> implements <tt>Bindable</tt>, these member variables
+ are automatically populated with the corresponding values declared in the BXML file.
+ For example, the object with ID "stocksTableView" in the BXML file will be assigned to
+ the <tt>stocksTableView</tt> member variable, and so on.
+ </p>
+
+ <p>
+ <tt>Bindable</tt> defines a single method, <tt>initialize()</tt>, that is called when
+ the root element has been fully loaded and the bound values have been processed. This
+ allows the bound class to perform any required initialization (generally event
+ registration, discussed in more detail in the
+ <a href="stock-tracker.events.html">Event Handling</a> section).
+ </p>
+
+ <h3>Attribute Resolution and Includes</h3>
+
+ <p>
+ The BXML snippet above also illustrates a couple other important aspects of BXML markup:
+ resource resolution and includes. Resource resolution allows a developer to insert
+ "tags" in the markup that will be replaced at load time with a localized equivalent.
+ This makes it very easy to build internationalized applications in Pivot. Any attribute
+ value that begins with a "%" character is considered a resource key, and the value
+ for the attribute is obtained from a resource bundle associated with the BXML file.
+ This is discussed in more detail in the
+ <a href="stock-tracker.localization.html">Localization</a> section.
+ </p>
+
+ <p>
+ BXML also supports two other attribute resolution operators: "@" and "$". The "at" symbol
+ is used to resolve URLs; any attribute value preceded by an "at" symbol is converted to an
+ instance of <tt>java.net.URL</tt> relative to the current BXML file. This notation is
+ very useful for loading images from a location relative to the current file.
+ </p>
+
+ <p>
+ The dollar sign is a "variable dereference" operator. Though it isn't shown in this
+ example, it is possible to embed script code in a BXML file using the
+ <tt><bxml:script></tt> tag. Any JVM-capable scripting language is supported,
+ including JavaScript, Groovy, and Clojure, among others. Any attribute value preceded by
+ a dollar sign is resolved to an instance of a script variable declared within the page.
+ This allows developers to define variables in script and then easily use them as
+ initialization parameters for class instances declared as elements. Script code can
+ also refer to any page elements identified via a <tt>bxml:id</tt> attribute as globally
+ scoped page level variables.
+ </p>
+
+ <p>
+ Includes allow a developer to embed content defined in an external BXML file as if it
+ was defined in the source file itself. This is useful for partitioning content into
+ manageable pieces (for example, when working on large applications or with multiple
+ developers, or when defining reusable content templates). The detail pane in the
+ Stock Tracker application is defined in an include, <tt>detail_pane.bxml</tt>. This file
+ is included into the main window via the <tt><bxml:include></tt> tag.
+ </p>
+ </div><p>Next: <a href="stock-tracker.events.html">Event Handling</a></p></div></div></div><div class="group" id="footer"><div class="footerLogo">Copyright (c) 1999-2011<br>The Apache Software Foundation.</div><div class="footerLinks"><ul class="footerMenuGr"><li><strong>Demos</strong><ul><li><a href="/demos/kitchen-sink.html" target="_new">"Kitchen Sink"</a></li><li><a href="/demos/component-explorer.html" target="_new">Component Explorer</a></li><li><a href="http://ixnay.biz/pivot-jfree-demos/charts_demo.html" target="_new">Charting</a></li><li><a href="/demos/">More Demos</a></li></ul></li><li><strong>Documentation</strong><ul><li><a href="/getting-started.html">Getting Started</a></li><li><a href="/tutorials/">Tutorial</a></li><li><a href="/faq.html">FAQ</a></li><li><a href="/2.0/docs/api/">Javadoc (2.0)</a></li></ul></li><li><strong>Get Involved</strong><ul><li><a href="/svn.html">SVN Repositories</a></li><li><a href="/lists.html">Mailing Lists</a></li><li><a href="
http://issues.apache.org/jira/browse/PIVOT">Bug Database</a></li><li><a href="http://cwiki.apache.org/PIVOT/">Wiki</a></li></ul></li><li><strong>Related</strong><ul><li><a href="http://code.google.com/p/pivot-jfree/">JFreeChart Provider</a></li></ul></li><li><strong>About</strong><ul><li><a href="/who-we-are.html">Who We Are</a></li><li><a href="/contact.html">Contact</a></li><li><a href="/news.html">News</a></li><li><a href="/legal.html">Legal/License</a></li></ul></li></ul></div></div></div></body></html>
\ No newline at end of file
Added: pivot/site/trunk/deploy/tutorials/stock-tracker.web-queries.html
URL: http://svn.apache.org/viewvc/pivot/site/trunk/deploy/tutorials/stock-tracker.web-queries.html?rev=1067847&view=auto
==============================================================================
--- pivot/site/trunk/deploy/tutorials/stock-tracker.web-queries.html (added)
+++ pivot/site/trunk/deploy/tutorials/stock-tracker.web-queries.html Mon Feb 7 02:36:04 2011
@@ -0,0 +1,479 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!--
+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.
+--><html xmlns="http://www.w3.org/1999/xhtml"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /><title>Web Queries | Apache Pivot</title><link xmlns="" type="text/css" rel="stylesheet" href="/styles/pivot.css"><script xmlns="http://www.w3.org/1999/xhtml" type="text/javascript">
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+ </script><script type="text/javascript">
+ try {
+ var pageTracker = _gat._getTracker("UA-7977275-3");
+ pageTracker._trackPageview();
+ } catch(err) {}</script></head><body><div xmlns="" id="wrapper"><div id="main"><div id="header"><div class="logo"><a href="/index.html"><img title="Apache Pivot Homepage" alt="Apache Pivot" src="/images/logo.png"></a></div><div class="tagline"><img style="visibility:hidden" alt="Rich Internet Applications in Java" src="/images/tagline.png"></div><ul class="navi"><li><a href="/demos/">Demos</a></li><li><a href="/download.cgi#2.0">Download</a></li><li><a href="/tutorials/">Tutorial</a></li><li><a href="/get-involved.html">Get Involved</a></li><li><a href="/about.html">About</a></li></ul></div><div class="group" id="contentBase"><h1>Web Queries</h1><ul class="naviLeft"><li><a href="/tutorials/sample-application.html">Sample Application</a></li><li><a href="/tutorials/platform-overview.html">Platform Overview</a></li><li><a href="/tutorials/hello-world.html">Hello, World!</a></li><li><a href="/tutorials/hello-bxml.html">Hello, BXML!</a></li><li><a href="/tutorial
s/component-and-container.html">Component & Container</a></li><li><a href="/tutorials/labels-and-image-views.html">Labels & Image Views</a></li><li><a href="/tutorials/svg-images.html">SVG Images</a></li><li><a href="/tutorials/buttons.html">Buttons</a></li><li><a href="/tutorials/push-buttons.html">Push Buttons</a></li><li><a href="/tutorials/toggle-buttons.html">Toggle Buttons</a></li><li><a href="/tutorials/radio-buttons.html">Radio Buttons</a></li><li><a href="/tutorials/checkboxes.html">Checkboxes</a></li><li><a href="/tutorials/link-buttons.html">Link Buttons</a></li><li><a href="/tutorials/lists.html">Lists</a></li><li><a href="/tutorials/list-buttons.html">List Buttons</a></li><li><a href="/tutorials/repeatable-list-buttons.html">Repeatable List Buttons</a></li><li><a href="/tutorials/text.html">Text</a></li><li><a href="/tutorials/suggestion-popups.html">Suggestion Popups</a></li><li><a href="/tutorials/text-areas.html">Text Areas</a></li><li><a href="/tutor
ials/separators.html">Separators</a></li><li><a href="/tutorials/layout-containers.html">Layout Containers</a></li><li><a href="/tutorials/flow-panes.html">Flow Panes</a></li><li><a href="/tutorials/box-panes.html">Box Panes</a></li><li><a href="/tutorials/grid-panes.html">Grid Panes</a></li><li><a href="/tutorials/table-panes.html">Table Panes</a></li><li><a href="/tutorials/borders.html">Borders</a></li><li><a href="/tutorials/stack-panes.html">Stack Panes</a></li><li><a href="/tutorials/split-panes.html">Split Panes</a></li><li><a href="/tutorials/forms.html">Forms</a></li><li><a href="/tutorials/panels.html">Panels</a></li><li><a href="/tutorials/navigation-containers.html">Navigation Containers</a></li><li><a href="/tutorials/card-panes.html">Card Panes</a></li><li><a href="/tutorials/tab-panes.html">Tab Panes</a></li><li><a href="/tutorials/accordions.html">Accordions</a></li><li><a href="/tutorials/expanders.html">Expanders</a></li><li><a href="/tutorials/rollups.html
">Rollups</a></li><li><a href="/tutorials/viewports.html">Viewports</a></li><li><a href="/tutorials/scroll-panes.html">Scroll Panes</a></li><li><a href="/tutorials/panoramas.html">Panoramas</a></li><li><a href="/tutorials/progress-indicators.html">Progress Indicators</a></li><li><a href="/tutorials/meters.html">Meters</a></li><li><a href="/tutorials/activity-indicators.html">Activity Indicators</a></li><li><a href="/tutorials/bounded-range-components.html">Bounded Range Components</a></li><li><a href="/tutorials/sliders.html">Sliders</a></li><li><a href="/tutorials/scroll-bars.html">Scroll Bars</a></li><li><a href="/tutorials/spinners.html">Spinners</a></li><li><a href="/tutorials/calendars.html">Calendars</a></li><li><a href="/tutorials/menus.html">Menus</a></li><li><a href="/tutorials/context-menus.html">Context Menus</a></li><li><a href="/tutorials/menu-bars.html">Menu Bars</a></li><li><a href="/tutorials/menu-buttons.html">Menu Buttons</a></li><li><a href="/tutorials/col
or-choosers.html">Color Choosers</a></li><li><a href="/tutorials/table-views.html">Table Views</a></li><li><a href="/tutorials/table-views.json.html">JSON-based TableView</a></li><li><a href="/tutorials/table-views.custom.html">Custom TableView</a></li><li><a href="/tutorials/tree-views.html">Tree Views</a></li><li><a href="/tutorials/file-browsing.html">File Browsing</a></li><li><a href="/tutorials/windows.html">Windows</a></li><li><a href="/tutorials/clipboard.html">Clipboard</a></li><li><a href="/tutorials/drag-and-drop.html">Drag and Drop</a></li><li><a href="/tutorials/effects.html">Effects</a></li><li><a href="/tutorials/effects.transitions.html">Transitions</a></li><li><a href="/tutorials/data-binding.html">Data Binding</a></li><li><a href="/tutorials/property-binding.html">Property Binding</a></li><li><a href="/tutorials/localization.html">Localization</a></li><li><a href="/tutorials/background-tasks.html">Background Tasks</a></li><li><a href="/tutorials/web-queries.
html">Web Queries</a></li><li><a href="/tutorials/query-servlet.html">QueryServlet</a></li><li><a href="/tutorials/scripting.html">Scripting</a></li><li><a href="/tutorials/summary.html">Summary</a></li><li><a href="/tutorials/stock-tracker.html">The "Stock Tracker" Application</a></li><li><a href="/tutorials/stock-tracker.ui.html">UI Markup Using BXML</a></li><li><a href="/tutorials/stock-tracker.events.html">Event Handling</a></li><li><a href="/tutorials/stock-tracker.web-queries.html">Web Queries</a></li><li><a href="/tutorials/stock-tracker.data-binding.html">Data Binding</a></li><li><a href="/tutorials/stock-tracker.localization.html">Localization</a></li><li><a href="/tutorials/bxml-primer.html">BXML Primer</a></li></ul><div class="content"><style type="text/css">
+ applet {
+ border: 1px solid #999999;
+ }
+ </style><!--NOTE: Syntax highlighting script is LGPL--><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js" type="text/javascript"></script><link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css"><link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css"><script type="text/javascript">
+ SyntaxHighlighter.all();
+ </script><div class="section">
+ <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.
+ However, they are sufficiently generic to support communication with any type of
+ HTTP-based service, using any data format.
+ </p>
+
+ <p>
+ For example, the data presented by the Stock Tracker application is retrieved from
+ Yahoo! Finance as a comma-separated value (CSV) file:
+ </p>
+
+ <p>
+ <tt>"AAPL","APPLE INC",171.06,169.59,172.17,166.00,+2.88,12995693</tt><br>
+ <tt>"AMZN","AMAZON.COM INC",72.54,72.35,73.83,70.52,+1.10,2748930</tt><br>
+ <tt>"EBAY","EBAY INC",27.09,27.35,27.44,27.04,-0.02,3426369</tt><br>
+ </p>
+
+ <p>
+ This data is returned by submitting an HTTP GET request to
+ <a href="http://download.finance.yahoo.com/d/quotes.csv/">http://download.finance.yahoo.com/d/quotes.csv/</a>
+ with an appropriate set of query string arguments. For example, the Stock Tracker
+ application passes the following arguments to the service URL:
+ </p>
+
+ <ul>
+ <li>
+ <b>s</b> - A comma-separated list of stock symbols representing the quotes to
+ retrieve.
+ </li>
+ <li>
+ <b>f</b> - the requested format for the resulting CSV file; this is a string of
+ characters representing the various data fields returned by the query. The format
+ used by the Stock Tracker application is "snl1ohgc1v":
+ <ul>
+ <li><i>s</i> - symbol</li>
+ <li><i>n</i> - company name</li>
+ <li><i>l1</i> - most recent value</li>
+ <li><i>o</i> - opening value</li>
+ <li><i>h</i> - high value</li>
+ <li><i>g</i> - low value</li>
+ <li><i>c1</i> - change percentage</li>
+ <li><i>v</i> - volume</li>
+ </ul>
+ </li>
+ </ul>
+
+ <p>
+ Note that this query actually returns more data than can be displayed in the table
+ view. The other data fields are used by the quote detail view, which is discussed in
+ more detail in the <a href="stock-tracker.data-binding.html">data binding</a> section.
+ </p>
+
+ <h2>Constructing the Web Query</h2>
+
+ <p>
+ In order to display the stock quotes to the user, Stock Tracker must execute a web
+ query to retrieve the data from the Yahoo! Finance web service and then populate the
+ stock quote table view with the results of the query. The query is executed in the
+ <tt>refreshTable()</tt> method, and the table is populated by a callback handler
+ implemented as an anonymous inner class defined in this method. This code is defined in
+ the <tt>StockTracker</tt> class.
+ </p>
+
+ <p>
+ First, the web query is created:
+ </p>
+
+ <pre class="brush:java">
+
+ getQuery = new GetQuery(SERVICE_HOSTNAME, SERVICE_PATH);
+
+ </pre>
+
+ <p>
+ Then, the value of the "s" parameter is constructed by joining the values in the symbol
+ list with commas, and the query arguments are applied:
+ </p>
+
+ <pre class="brush:java">
+
+ StringBuilder symbolsParameterBuilder = new StringBuilder();
+ for (int i = 0, n = symbols.getLength(); i < n; i++) {
+ if (i > 0) {
+ symbolsParameterBuilder.append(",");
+ }
+
+ symbolsParameterBuilder.append(symbols.get(i));
+ }
+
+ // Format:
+ // s - symbol
+ // n - company name
+ // l1 - most recent value
+ // o - opening value
+ // h - high value
+ // g - low value
+ // c1 - change percentage
+ // v - volume
+ String symbolsParameter = symbolsParameterBuilder.toString();
+ getQuery.getParameters().put("s", symbolsParameter);
+ getQuery.getParameters().put("f", "snl1ohgc1v");
+
+ </pre>
+
+ <p>
+ The resulting query URL would be similar to:
+ </p>
+
+ <p style="padding-left:24px">
+ <a href="http://download.finance.yahoo.com/d/quotes.csv?s=aapl,amzn,ebay&f=snl1ohgc1v">http://download.finance.yahoo.com/d/quotes.csv?s=aapl,amzn,ebay&f=snl1ohgc1v</a>
+ </p>
+
+ <p>
+ Next, an instance of CSVSerializer is created and configured:
+ </p>
+
+ <pre class="brush:java">
+
+ CSVSerializer quoteSerializer = new CSVSerializer(StockQuote.class);
+ quoteSerializer.setKeys("symbol",
+ "companyName",
+ "value",
+ "openingValue",
+ "highValue",
+ "lowValue",
+ "change",
+ "volume");
+
+ </pre>
+
+ <p>
+ By default, the <tt>GetQuery</tt> class uses an instance of
+ <tt>org.apache.pivot.core.serialization.JSONSerializer</tt> to deserialize data
+ returned by a GET request. However, the quote data from Yahoo! Finance is returned as
+ a CSV file; <tt>CSVSerializer</tt> is an implementation of the
+ <tt>org.apache.pivot.core.serialization.Serializer</tt> interface that parses a CSV
+ data stream into a sequence of name/value pairs.
+ </p>
+
+ <p>
+ By default, <tt>CSVSerializer</tt> will create an instance of
+ <tt>org.apache.pivot.collections.HashMap<String, Object></tt> for each row it
+ encounters in the CSV stream. However, a caller can specify the name of a different
+ class as a constructor argument to <tt>CSVSerializer</tt>. This avoids the performance
+ penalty of traversing the data twice: once to read it from the CSV stream and again to
+ convert it to the appropriate type.
+ </p>
+
+ <p>
+ If the item class implements the <tt>org.apache.pivot.collections.Dictionary</tt>
+ interface, the parsed values are <tt>put()</tt> directly into the item instance;
+ otherwise, the item is wrapped in a <tt>org.apache.pivot.beans.BeanAdapter</tt> into
+ which the values are <tt>put()</tt> (<tt>BeanAdapter</tt> is a handy class that allows
+ a caller to treat a Java bean object as if it were a dictionary).
+ </p>
+
+ <p>
+ Stock Tracker uses the <tt>StockQuote</tt> class to represent the rows in the CSV file:
+ </p>
+
+ <pre class="brush:java">
+
+ public class StockQuote {
+ private String symbol = null;
+ private String companyName = null;
+ private float value = 0;
+ private float openingValue = 0;
+ private float highValue = 0;
+ private float lowValue = 0;
+ private float change = 0;
+ private float volume = 0;
+
+ public String getSymbol() {
+ return symbol;
+ }
+
+ public void setSymbol(String symbol) {
+ this.symbol = symbol;
+ }
+
+ public String getCompanyName() {
+ return companyName;
+ }
+
+ public void setCompanyName(String companyName) {
+ this.companyName = companyName;
+ }
+
+ public float getValue() {
+ return value;
+ }
+
+ public void setValue(float value) {
+ this.value = value;
+ }
+
+ public void setValue(String value) {
+ try {
+ setValue(Float.parseFloat(value));
+ } catch(NumberFormatException exception) {
+ setValue(Float.NaN);
+ }
+ }
+
+ public float getOpeningValue() {
+ return openingValue;
+ }
+
+ public void setOpeningValue(float openingValue) {
+ this.openingValue = openingValue;
+ }
+
+ public void setOpeningValue(String openingValue) {
+ try {
+ setOpeningValue(Float.parseFloat(openingValue));
+ } catch(NumberFormatException exception) {
+ setOpeningValue(Float.NaN);
+ }
+ }
+
+ public float getHighValue() {
+ return highValue;
+ }
+
+ public void setHighValue(float highValue) {
+ this.highValue = highValue;
+ }
+
+ public void setHighValue(String highValue) {
+ try {
+ setHighValue(Float.parseFloat(highValue));
+ } catch(NumberFormatException exception) {
+ setHighValue(Float.NaN);
+ }
+ }
+
+ public float getLowValue() {
+ return lowValue;
+ }
+
+ public void setLowValue(float lowValue) {
+ this.lowValue = lowValue;
+ }
+
+ public void setLowValue(String lowValue) {
+ try {
+ setLowValue(Float.parseFloat(lowValue));
+ } catch(NumberFormatException exception) {
+ setLowValue(Float.NaN);
+ }
+ }
+
+ public float getChange() {
+ return change;
+ }
+
+ public void setChange(float change) {
+ this.change = change;
+ }
+
+ public void setChange(String change) {
+ try {
+ setChange(Float.parseFloat(change));
+ } catch(NumberFormatException exception) {
+ setChange(Float.NaN);
+ }
+ }
+
+ public float getVolume() {
+ return volume;
+ }
+
+ public void setVolume(float volume) {
+ this.volume = volume;
+ }
+
+ public void setVolume(String volume) {
+ try {
+ setVolume(Float.parseFloat(volume));
+ } catch(NumberFormatException exception) {
+ setVolume(Float.NaN);
+ }
+ }
+ }
+
+ </pre>
+
+ <p>
+ The cell renderers assigned to the columns in the BXML file ensure that the data
+ represented by this class is formatted and presented correctly.
+ </p>
+
+ <p>
+ Finally, the query is executed:
+ </p>
+
+ <pre class="brush:java">
+
+ getQuery.setSerializer(quoteSerializer);
+
+ getQuery.execute(new TaskAdapter<Object>(new TaskListener<Object>() {
+ ...
+ }
+
+ </pre>
+
+ <p>
+ The argument passed to the <tt>execute()</tt> method is a <tt>TaskAdapter</tt> wrapped
+ around an anonymous inner class implementation of <tt>TaskListener<Object></tt>.
+ <tt>TaskListener</tt> is an interface defined in the <tt>org.apache.pivot.util.concurrent</tt>
+ package and serves as a callback handler for asynchronous operations implemented by the
+ <tt>org.apache.pivot.util.concurrent.Task</tt> class, of which <tt>GetQuery</tt> is a subclass.
+ <tt>TaskAdapter</tt> is defined in the <tt>pivot.wtk</tt> package and ensures that the
+ callback occurs on the UI thread (otherwise, the listener is called in the context of
+ the background thread, which can produce non-deterministic results).
+ </p>
+
+ <p>
+ <tt>TaskListener</tt> defines two methods:
+ </p>
+
+ <p>
+ <tt>public void taskExecuted(Task<V> task);</tt><br>
+ <tt>public void executeFailed(Task<V> task);</tt><br>
+ </p>
+
+ <p>
+ The template parameter <tt>V</tt> is defined by the <tt>Task</tt> class and represents
+ the (optional) return value of the operation. The first method is called if the task
+ completes successfully, and the second is called if the task failed for any reason.
+ </p>
+
+ <p>
+ StockTracker's success handler is defined as follows:
+ </p>
+
+ <pre class="brush:java">
+
+ @Override
+ public void taskExecuted(Task<Object> task) {
+ if (task == getQuery) {
+ List<Object> quotes = (List<Object>)task.getResult();
+
+ // Preserve any existing sort and selection
+ Sequence<?> selectedStocks = stocksTableView.getSelectedRows();
+
+ List<Object> tableData = (List<Object>)stocksTableView.getTableData();
+ Comparator<Object> comparator = tableData.getComparator();
+ quotes.setComparator(comparator);
+
+ stocksTableView.setTableData(quotes);
+
+ if (selectedStocks.getLength() > 0) {
+ // Select current indexes of selected stocks
+ for (int i = 0, n = selectedStocks.getLength(); i < n; i++) {
+ Object selectedStock = selectedStocks.get(i);
+
+ int index = 0;
+ for (Object stock : stocksTableView.getTableData()) {
+ String symbol = JSON.get(stock, "symbol");
+ String selectedSymbol = JSON.get(selectedStock, "symbol");
+
+ if (symbol.equals(selectedSymbol)) {
+ stocksTableView.addSelectedIndex(index);
+ break;
+ }
+
+ index++;
+ }
+ }
+ } else {
+ if (quotes.getLength() > 0) {
+ stocksTableView.setSelectedIndex(0);
+ }
+ }
+
+ refreshDetail();
+
+ DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,
+ DateFormat.MEDIUM, Locale.getDefault());
+ lastUpdateLabel.setText(dateFormat.format(new Date()));
+
+ getQuery = null;
+ }
+ }
+ }
+
+ </pre>
+
+ <p>
+ If the source of the event is the currently executing task, the handler does the
+ following:
+ </p>
+
+ <ul>
+ <li>
+ <p>
+ Caches the current sort and selection state of the quote table view
+ </p>
+ </li>
+ <li>
+ <p>
+ Gets the result of the query and casts it to the appropriate type
+ (<tt>List<Object></tt>)
+ </p>
+ </li>
+ <li>
+ <p>
+ Sets the list as the model data for the table view
+ </p>
+ </li>
+ <li>
+ <p>
+ Restores any selection state (which would have been lost when the model data
+ was reset)
+ </p>
+ </li>
+ <li>
+ <p>
+ Updates the value of the "last updated" label to reflect the current time, in
+ a manner appropriate for the current locale
+ </p>
+ </li>
+ </ul>
+
+ <p>
+ In the case of a failure, the handler simply logs the exception to the console:
+ </p>
+
+ <pre class="brush:java">
+
+ @Override
+ public void executeFailed(Task<Object> task) {
+ if (task == getQuery) {
+ System.err.println(task.getFault());
+ getQuery = null;
+ }
+ }
+
+ </pre>
+
+ <p>
+ This example demonstrates the use of <tt>GetQuery</tt> only, but Pivot also provides
+ support for HTTP POST, PUT, and DELETE operations using the <tt>PostQuery</tt>,
+ <tt>PutQuery</tt>, and <tt>DeleteQuery</tt> classes, respectively. This makes it very
+ easy to built a complete REST client using Pivot.
+ </p>
+ </div><p>Next: <a href="stock-tracker.data-binding.html">Data Binding</a></p></div></div></div><div class="group" id="footer"><div class="footerLogo">Copyright (c) 1999-2011<br>The Apache Software Foundation.</div><div class="footerLinks"><ul class="footerMenuGr"><li><strong>Demos</strong><ul><li><a href="/demos/kitchen-sink.html" target="_new">"Kitchen Sink"</a></li><li><a href="/demos/component-explorer.html" target="_new">Component Explorer</a></li><li><a href="http://ixnay.biz/pivot-jfree-demos/charts_demo.html" target="_new">Charting</a></li><li><a href="/demos/">More Demos</a></li></ul></li><li><strong>Documentation</strong><ul><li><a href="/getting-started.html">Getting Started</a></li><li><a href="/tutorials/">Tutorial</a></li><li><a href="/faq.html">FAQ</a></li><li><a href="/2.0/docs/api/">Javadoc (2.0)</a></li></ul></li><li><strong>Get Involved</strong><ul><li><a href="/svn.html">SVN Repositories</a></li><li><a href="/lists.html">Mailing Lists</a></li><li><a hr
ef="http://issues.apache.org/jira/browse/PIVOT">Bug Database</a></li><li><a href="http://cwiki.apache.org/PIVOT/">Wiki</a></li></ul></li><li><strong>Related</strong><ul><li><a href="http://code.google.com/p/pivot-jfree/">JFreeChart Provider</a></li></ul></li><li><strong>About</strong><ul><li><a href="/who-we-are.html">Who We Are</a></li><li><a href="/contact.html">Contact</a></li><li><a href="/news.html">News</a></li><li><a href="/legal.html">Legal/License</a></li></ul></li></ul></div></div></div></body></html>
\ No newline at end of file
Added: pivot/site/trunk/deploy/tutorials/suggestion-popups.html
URL: http://svn.apache.org/viewvc/pivot/site/trunk/deploy/tutorials/suggestion-popups.html?rev=1067847&view=auto
==============================================================================
--- pivot/site/trunk/deploy/tutorials/suggestion-popups.html (added)
+++ pivot/site/trunk/deploy/tutorials/suggestion-popups.html Mon Feb 7 02:36:04 2011
@@ -0,0 +1,240 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!--
+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.
+--><html xmlns="http://www.w3.org/1999/xhtml"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /><title>Suggestion Popups | Apache Pivot</title><link xmlns="" type="text/css" rel="stylesheet" href="/styles/pivot.css"><script xmlns="http://www.w3.org/1999/xhtml" type="text/javascript">
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+ </script><script type="text/javascript">
+ try {
+ var pageTracker = _gat._getTracker("UA-7977275-3");
+ pageTracker._trackPageview();
+ } catch(err) {}</script></head><body><div xmlns="" id="wrapper"><div id="main"><div id="header"><div class="logo"><a href="/index.html"><img title="Apache Pivot Homepage" alt="Apache Pivot" src="/images/logo.png"></a></div><div class="tagline"><img style="visibility:hidden" alt="Rich Internet Applications in Java" src="/images/tagline.png"></div><ul class="navi"><li><a href="/demos/">Demos</a></li><li><a href="/download.cgi#2.0">Download</a></li><li><a href="/tutorials/">Tutorial</a></li><li><a href="/get-involved.html">Get Involved</a></li><li><a href="/about.html">About</a></li></ul></div><div class="group" id="contentBase"><h1>Suggestion Popups</h1><ul class="naviLeft"><li><a href="/tutorials/sample-application.html">Sample Application</a></li><li><a href="/tutorials/platform-overview.html">Platform Overview</a></li><li><a href="/tutorials/hello-world.html">Hello, World!</a></li><li><a href="/tutorials/hello-bxml.html">Hello, BXML!</a></li><li><a href="/tu
torials/component-and-container.html">Component & Container</a></li><li><a href="/tutorials/labels-and-image-views.html">Labels & Image Views</a></li><li><a href="/tutorials/svg-images.html">SVG Images</a></li><li><a href="/tutorials/buttons.html">Buttons</a></li><li><a href="/tutorials/push-buttons.html">Push Buttons</a></li><li><a href="/tutorials/toggle-buttons.html">Toggle Buttons</a></li><li><a href="/tutorials/radio-buttons.html">Radio Buttons</a></li><li><a href="/tutorials/checkboxes.html">Checkboxes</a></li><li><a href="/tutorials/link-buttons.html">Link Buttons</a></li><li><a href="/tutorials/lists.html">Lists</a></li><li><a href="/tutorials/list-buttons.html">List Buttons</a></li><li><a href="/tutorials/repeatable-list-buttons.html">Repeatable List Buttons</a></li><li><a href="/tutorials/text.html">Text</a></li><li><a href="/tutorials/suggestion-popups.html">Suggestion Popups</a></li><li><a href="/tutorials/text-areas.html">Text Areas</a></li><li><a href="
/tutorials/separators.html">Separators</a></li><li><a href="/tutorials/layout-containers.html">Layout Containers</a></li><li><a href="/tutorials/flow-panes.html">Flow Panes</a></li><li><a href="/tutorials/box-panes.html">Box Panes</a></li><li><a href="/tutorials/grid-panes.html">Grid Panes</a></li><li><a href="/tutorials/table-panes.html">Table Panes</a></li><li><a href="/tutorials/borders.html">Borders</a></li><li><a href="/tutorials/stack-panes.html">Stack Panes</a></li><li><a href="/tutorials/split-panes.html">Split Panes</a></li><li><a href="/tutorials/forms.html">Forms</a></li><li><a href="/tutorials/panels.html">Panels</a></li><li><a href="/tutorials/navigation-containers.html">Navigation Containers</a></li><li><a href="/tutorials/card-panes.html">Card Panes</a></li><li><a href="/tutorials/tab-panes.html">Tab Panes</a></li><li><a href="/tutorials/accordions.html">Accordions</a></li><li><a href="/tutorials/expanders.html">Expanders</a></li><li><a href="/tutorials/rollup
s.html">Rollups</a></li><li><a href="/tutorials/viewports.html">Viewports</a></li><li><a href="/tutorials/scroll-panes.html">Scroll Panes</a></li><li><a href="/tutorials/panoramas.html">Panoramas</a></li><li><a href="/tutorials/progress-indicators.html">Progress Indicators</a></li><li><a href="/tutorials/meters.html">Meters</a></li><li><a href="/tutorials/activity-indicators.html">Activity Indicators</a></li><li><a href="/tutorials/bounded-range-components.html">Bounded Range Components</a></li><li><a href="/tutorials/sliders.html">Sliders</a></li><li><a href="/tutorials/scroll-bars.html">Scroll Bars</a></li><li><a href="/tutorials/spinners.html">Spinners</a></li><li><a href="/tutorials/calendars.html">Calendars</a></li><li><a href="/tutorials/menus.html">Menus</a></li><li><a href="/tutorials/context-menus.html">Context Menus</a></li><li><a href="/tutorials/menu-bars.html">Menu Bars</a></li><li><a href="/tutorials/menu-buttons.html">Menu Buttons</a></li><li><a href="/tutoria
ls/color-choosers.html">Color Choosers</a></li><li><a href="/tutorials/table-views.html">Table Views</a></li><li><a href="/tutorials/table-views.json.html">JSON-based TableView</a></li><li><a href="/tutorials/table-views.custom.html">Custom TableView</a></li><li><a href="/tutorials/tree-views.html">Tree Views</a></li><li><a href="/tutorials/file-browsing.html">File Browsing</a></li><li><a href="/tutorials/windows.html">Windows</a></li><li><a href="/tutorials/clipboard.html">Clipboard</a></li><li><a href="/tutorials/drag-and-drop.html">Drag and Drop</a></li><li><a href="/tutorials/effects.html">Effects</a></li><li><a href="/tutorials/effects.transitions.html">Transitions</a></li><li><a href="/tutorials/data-binding.html">Data Binding</a></li><li><a href="/tutorials/property-binding.html">Property Binding</a></li><li><a href="/tutorials/localization.html">Localization</a></li><li><a href="/tutorials/background-tasks.html">Background Tasks</a></li><li><a href="/tutorials/web-qu
eries.html">Web Queries</a></li><li><a href="/tutorials/query-servlet.html">QueryServlet</a></li><li><a href="/tutorials/scripting.html">Scripting</a></li><li><a href="/tutorials/summary.html">Summary</a></li><li><a href="/tutorials/stock-tracker.html">The "Stock Tracker" Application</a></li><li><a href="/tutorials/stock-tracker.ui.html">UI Markup Using BXML</a></li><li><a href="/tutorials/stock-tracker.events.html">Event Handling</a></li><li><a href="/tutorials/stock-tracker.web-queries.html">Web Queries</a></li><li><a href="/tutorials/stock-tracker.data-binding.html">Data Binding</a></li><li><a href="/tutorials/stock-tracker.localization.html">Localization</a></li><li><a href="/tutorials/bxml-primer.html">BXML Primer</a></li></ul><div class="content"><style type="text/css">
+ applet {
+ border: 1px solid #999999;
+ }
+ </style><!--NOTE: Syntax highlighting script is LGPL--><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js" type="text/javascript"></script><script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js" type="text/javascript"></script><link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css"><link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css"><script type="text/javascript">
+ SyntaxHighlighter.all();
+ </script><div class="section">
+ <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>
+
+ <script src="http://java.com/js/deployJava.js" type="text/javascript"></script><script type="text/javascript">
+
+ var attributes = {
+ code:"org.apache.pivot.wtk.BrowserApplicationContext$HostApplet",
+ width:"320",
+ height:"200"
+ };
+
+
+
+
+
+ var libraries = [];
+ libraries.push("/lib/pivot-core-2.0.jar");
+ libraries.push("/lib/pivot-wtk-2.0.jar");
+ libraries.push("/lib/pivot-wtk-terra-2.0.jar");
+ libraries.push("/lib/pivot-tutorials-2.0.jar");
+
+ libraries.push("/lib/svgSalamander-tiny.jar");
+
+
+ attributes.archive = libraries.join(",");
+
+
+ var parameters = {
+ codebase_lookup:false,
+ application_class_name:'org.apache.pivot.wtk.ScriptApplication'
+ };
+
+
+ var javaArguments = ["-Dsun.awt.noerasebackground=true",
+ "-Dsun.awt.erasebackgroundonresize=true"];
+
+
+
+ parameters.java_arguments = javaArguments.join(" ");
+
+
+
+ var startupProperties = [];
+
+ startupProperties.push("src=/org/apache/pivot/tutorials/text/suggestion_popups.bxml");
+
+ parameters.startup_properties = startupProperties.join("&");
+
+
+ deployJava.runApplet(attributes, parameters, "1.6");
+ </script>
+
+ <p>
+ The following is the BXML 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>
+
+ <pre class="brush:xml">
+
+ <text:SuggestionPopups title="Suggestion Popups" maximized="true"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns:text="org.apache.pivot.tutorials.text"
+ xmlns="org.apache.pivot.wtk">
+ <Border>
+ <BoxPane orientation="vertical" styles="{padding:4, verticalAlignment:'top'}">
+ <BoxPane styles="{verticalAlignment:'center'}">
+ <Label text="State:"/>
+ <TextInput bxml:id="stateTextInput"/>
+ </BoxPane>
+ </BoxPane>
+ </Border>
+ </text:SuggestionPopups>
+
+ </pre>
+
+ <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>
+
+ <pre class="brush:java">
+
+ package org.apache.pivot.tutorials.text;
+
+ import java.net.URL;
+
+ import org.apache.pivot.beans.Bindable;
+ import org.apache.pivot.collections.ArrayList;
+ import org.apache.pivot.collections.Map;
+ import org.apache.pivot.util.Resources;
+ import org.apache.pivot.wtk.Display;
+ import org.apache.pivot.wtk.SuggestionPopup;
+ import org.apache.pivot.wtk.TextInput;
+ import org.apache.pivot.wtk.TextInputContentListener;
+ import org.apache.pivot.wtk.Window;
+
+ public class SuggestionPopups extends Window implements Bindable {
+ private TextInput stateTextInput = null;
+
+ private ArrayList<String> states;
+ private SuggestionPopup suggestionPopup = new SuggestionPopup();
+
+ 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 initialize(Map<String, Object> namespace, URL location, Resources resources) {
+ stateTextInput = (TextInput)namespace.get("stateTextInput");
+ stateTextInput.getTextInputContentListeners().add(new TextInputContentListener.Adapter() {
+ @Override
+ public void textInserted(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.setSuggestionData(suggestions);
+ suggestionPopup.open(textInput);
+ }
+ }
+
+ @Override
+ public void textRemoved(TextInput textInput, int index, int count) {
+ suggestionPopup.close();
+ }
+ });
+
+ suggestionPopup.setListSize(4);
+ }
+
+ @Override
+ public void open(Display display, Window owner) {
+ super.open(display, owner);
+ stateTextInput.requestFocus();
+ }
+ }
+
+ </pre>
+ </div><p>Next: <a href="text-areas.html">Text Areas</a></p></div></div></div><div class="group" id="footer"><div class="footerLogo">Copyright (c) 1999-2011<br>The Apache Software Foundation.</div><div class="footerLinks"><ul class="footerMenuGr"><li><strong>Demos</strong><ul><li><a href="/demos/kitchen-sink.html" target="_new">"Kitchen Sink"</a></li><li><a href="/demos/component-explorer.html" target="_new">Component Explorer</a></li><li><a href="http://ixnay.biz/pivot-jfree-demos/charts_demo.html" target="_new">Charting</a></li><li><a href="/demos/">More Demos</a></li></ul></li><li><strong>Documentation</strong><ul><li><a href="/getting-started.html">Getting Started</a></li><li><a href="/tutorials/">Tutorial</a></li><li><a href="/faq.html">FAQ</a></li><li><a href="/2.0/docs/api/">Javadoc (2.0)</a></li></ul></li><li><strong>Get Involved</strong><ul><li><a href="/svn.html">SVN Repositories</a></li><li><a href="/lists.html">Mailing Lists</a></li><li><a href="http://issues.
apache.org/jira/browse/PIVOT">Bug Database</a></li><li><a href="http://cwiki.apache.org/PIVOT/">Wiki</a></li></ul></li><li><strong>Related</strong><ul><li><a href="http://code.google.com/p/pivot-jfree/">JFreeChart Provider</a></li></ul></li><li><strong>About</strong><ul><li><a href="/who-we-are.html">Who We Are</a></li><li><a href="/contact.html">Contact</a></li><li><a href="/news.html">News</a></li><li><a href="/legal.html">Legal/License</a></li></ul></li></ul></div></div></div></body></html>
\ No newline at end of file