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/02/23 02:44:06 UTC

svn commit: r915130 - in /pivot/trunk: tutorials/src/org/apache/pivot/tutorials/text/ wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/content/

Author: gbrown
Date: Tue Feb 23 01:44:05 2010
New Revision: 915130

URL: http://svn.apache.org/viewvc?rev=915130&view=rev
Log:
Add suggestion popup tutorial example; other minor updates.

Added:
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/SuggestionPopups.java
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/suggestion_popups.wtkx
Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonDataRenderer.java

Added: 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=915130&view=auto
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/SuggestionPopups.java (added)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/SuggestionPopups.java Tue Feb 23 01:44:05 2010
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.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, "text_inputs.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);
+    }
+}

Added: 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=915130&view=auto
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/suggestion_popups.wtkx (added)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/suggestion_popups.wtkx Tue Feb 23 01:44:05 2010
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<Window title="Suggestion Popups" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns="org.apache.pivot.wtk">
+    <content>
+        <BoxPane styles="{padding:4, verticalAlignment:'center'}">
+            <Label text="State:"/>
+            <TextInput wtkx:id="stateTextInput"/>
+        </BoxPane>
+    </content>
+</Window>

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java?rev=915130&r1=915129&r2=915130&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java Tue Feb 23 01:44:05 2010
@@ -36,6 +36,15 @@
 public final class BrowserApplicationContext extends ApplicationContext {
     /**
      * Applet used to host applications in a web browser.
+     * <p>
+     * This applet supports the following parameters:
+     * <ul>
+     * <li><tt>application_class_name</tt> - the class name of the application to launch.</li>
+     * <li><tt>startup_properties</tt> - startup properties to be passed to the application.
+     * Properties use HTTP query string syntax; e.g. "a=1&b=2".</li>
+     * <li><tt>system_properties</tt> - system properties to set at startup. Properties use HTTP
+     * query string syntax; e.g. "a=1&b=2" (trusted applets only).</li>
+     * </ul>
      */
     public static final class HostApplet extends Applet {
         private static final long serialVersionUID = -7710026348576806673L;

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonDataRenderer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonDataRenderer.java?rev=915130&r1=915129&r2=915130&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonDataRenderer.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonDataRenderer.java Tue Feb 23 01:44:05 2010
@@ -18,7 +18,6 @@
 
 import org.apache.pivot.wtk.Button;
 import org.apache.pivot.wtk.HorizontalAlignment;
-import org.apache.pivot.wtk.ListButton;
 
 /**
  * Default list button data renderer.
@@ -43,10 +42,5 @@
         }
 
         super.render(data, button, highlight);
-
-        ListButton listButton = (ListButton)button;
-        if (listButton.getSelectedIndex() == -1) {
-            label.getStyles().put("color", button.getStyles().get("borderColor"));
-        }
     }
 }