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/01/17 22:05:30 UTC
svn commit: r900218 - in /pivot/trunk: tests/src/org/apache/pivot/tests/
wtk-terra/src/org/apache/pivot/wtk/skin/terra/ wtk/src/org/apache/pivot/wtk/
Author: gbrown
Date: Sun Jan 17 21:05:30 2010
New Revision: 900218
URL: http://svn.apache.org/viewvc?rev=900218&view=rev
Log:
Complete baseline implementation of SuggestionPopup (object to string translation interface still TBD).
Added:
pivot/trunk/tests/src/org/apache/pivot/tests/SuggestionPopupTest.java
pivot/trunk/tests/src/org/apache/pivot/tests/suggestion_popup_test.wtkx
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopup.java
Added: pivot/trunk/tests/src/org/apache/pivot/tests/SuggestionPopupTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/SuggestionPopupTest.java?rev=900218&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/SuggestionPopupTest.java (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/SuggestionPopupTest.java Sun Jan 17 21:05:30 2010
@@ -0,0 +1,77 @@
+/*
+ * 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.tests;
+
+import org.apache.pivot.collections.ArrayList;
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonPressListener;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.SuggestionPopup;
+import org.apache.pivot.wtk.TextInput;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtkx.WTKX;
+import org.apache.pivot.wtkx.WTKXSerializer;
+
+public class SuggestionPopupTest implements Application {
+ private Window window = null;
+
+ @WTKX private TextInput textInput = null;
+ @WTKX private PushButton showSuggestionsButton = null;
+
+ @Override
+ public void startup(Display display, Map<String, String> properties) throws Exception {
+ WTKXSerializer wtkxSerializer = new WTKXSerializer();
+ window = (Window)wtkxSerializer.readObject(this, "suggestion_popup_test.wtkx");
+ wtkxSerializer.bind(this);
+
+ showSuggestionsButton.getButtonPressListeners().add(new ButtonPressListener() {
+ @Override
+ public void buttonPressed(Button button) {
+ ArrayList<String> suggestions = new ArrayList<String>("One", "Two", "Three", "Four", "Five");
+ SuggestionPopup suggestionPopup = new SuggestionPopup(suggestions);
+ suggestionPopup.open(textInput);
+ }
+ });
+
+ window.open(display);
+ }
+
+ @Override
+ public boolean shutdown(boolean optional) {
+ if (window != null) {
+ window.close();
+ }
+
+ return false;
+ }
+
+ @Override
+ public void suspend() {
+ }
+
+ @Override
+ public void resume() {
+ }
+
+ public static void main(String[] args) {
+ DesktopApplicationContext.main(SuggestionPopupTest.class, args);
+ }
+}
Added: pivot/trunk/tests/src/org/apache/pivot/tests/suggestion_popup_test.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/suggestion_popup_test.wtkx?rev=900218&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/suggestion_popup_test.wtkx (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/suggestion_popup_test.wtkx Sun Jan 17 21:05:30 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 Popup Test" maximized="true"
+ xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns="org.apache.pivot.wtk">
+ <content>
+ <BoxPane orientation="vertical">
+ <TextInput wtkx:id="textInput"/>
+ <PushButton wtkx:id="showSuggestionsButton" buttonData="Show Suggestions"/>
+ </BoxPane>
+ </content>
+</Window>
Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java?rev=900218&r1=900217&r2=900218&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java Sun Jan 17 21:05:30 2010
@@ -21,13 +21,23 @@
import org.apache.pivot.collections.Dictionary;
import org.apache.pivot.collections.List;
+import org.apache.pivot.collections.Sequence;
import org.apache.pivot.wtk.Border;
import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.ComponentKeyListener;
+import org.apache.pivot.wtk.Container;
+import org.apache.pivot.wtk.ContainerMouseListener;
+import org.apache.pivot.wtk.Direction;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.GraphicsUtilities;
+import org.apache.pivot.wtk.Keyboard;
import org.apache.pivot.wtk.ListView;
+import org.apache.pivot.wtk.ListViewSelectionListener;
+import org.apache.pivot.wtk.Mouse;
+import org.apache.pivot.wtk.Span;
import org.apache.pivot.wtk.SuggestionPopup;
import org.apache.pivot.wtk.SuggestionPopupListener;
+import org.apache.pivot.wtk.TextInput;
import org.apache.pivot.wtk.Theme;
import org.apache.pivot.wtk.Window;
import org.apache.pivot.wtk.skin.WindowSkin;
@@ -39,10 +49,74 @@
private Border suggestionListViewBorder = new Border();
private ListView suggestionListView = new ListView();
+ private ContainerMouseListener displayMouseListener = new ContainerMouseListener.Adapter() {
+ @Override
+ public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
+ SuggestionPopup suggestionPopup = (SuggestionPopup)getComponent();
+ TextInput textInput = suggestionPopup.getTextInput();
+
+ Display display = (Display)container;
+ Component descendant = display.getDescendantAt(x, y);
+
+ if (!suggestionPopup.isAncestor(descendant)
+ && descendant != textInput) {
+ suggestionPopup.close();
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean mouseWheel(Container container, Mouse.ScrollType scrollType,
+ int scrollAmount, int wheelRotation, int x, int y) {
+ return true;
+ }
+ };
+
+ private ComponentKeyListener textInputKeyListener = new ComponentKeyListener.Adapter() {
+ @Override
+ public boolean keyPressed(Component component, int keyCode,
+ Keyboard.KeyLocation keyLocation) {
+ boolean consumed = false;
+
+ SuggestionPopup suggestionPopup = (SuggestionPopup)getComponent();
+
+ if (keyCode == Keyboard.KeyCode.DOWN) {
+ if (suggestionListView.getListData().getLength() > 0) {
+ if (suggestionListView.getSelectedIndex() == -1) {
+ suggestionListView.setSelectedIndex(0);
+ }
+
+ suggestionPopup.requestFocus();
+ consumed = true;
+ }
+ } else if (keyCode == Keyboard.KeyCode.ESCAPE) {
+ suggestionPopup.close();
+ consumed = true;
+ }
+
+ return consumed;
+ }
+ };
+
+ private ListViewSelectionListener listViewSelectionListener = new ListViewSelectionListener.Adapter() {
+ @Override
+ public void selectedRangesChanged(ListView listView, Sequence<Span> previousSelectedRanges) {
+ SuggestionPopup suggestionPopup = (SuggestionPopup)getComponent();
+ TextInput textInput = suggestionPopup.getTextInput();
+
+ Object suggestion = suggestionListView.getSelectedItem();
+ if (suggestion != null) {
+ // TODO Add a translation interface so callers can provide custom toString()
+ // implementations
+ textInput.setText(suggestion.toString());
+ }
+ }
+ };
+
public TerraSuggestionPopupSkin () {
+ suggestionListView.getListViewSelectionListeners().add(listViewSelectionListener);
suggestionListViewBorder.setContent(suggestionListView);
-
- // TODO Attach listeners to suggestion list view
}
@Override
@@ -115,17 +189,67 @@
}
@Override
+ public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
+ SuggestionPopup suggestionPopup = (SuggestionPopup)getComponent();
+ suggestionPopup.close();
+
+ return true;
+ }
+
+ @Override
+ public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
+ SuggestionPopup suggestionPopup = (SuggestionPopup)getComponent();
+ TextInput textInput = suggestionPopup.getTextInput();
+
+ switch (keyCode) {
+ case Keyboard.KeyCode.TAB:
+ case Keyboard.KeyCode.ENTER:
+ case Keyboard.KeyCode.ESCAPE: {
+ suggestionPopup.close();
+
+ if (keyCode == Keyboard.KeyCode.TAB) {
+ Direction direction = (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) ?
+ Direction.BACKWARD : Direction.FORWARD;
+ textInput.transferFocus(direction);
+ }
+
+ break;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
public void windowOpened(Window window) {
super.windowOpened(window);
- // TODO Add listeners to text input
+ Display display = window.getDisplay();
+ display.getContainerMouseListeners().add(displayMouseListener);
+
+ SuggestionPopup suggestionPopup = (SuggestionPopup)getComponent();
+ TextInput textInput = suggestionPopup.getTextInput();
+ textInput.getComponentKeyListeners().add(textInputKeyListener);
+
+ // Reposition under text input
+ int x = textInput.getX();
+ int y = textInput.getY() + textInput.getHeight();
+ suggestionPopup.setLocation(x, y - 1);
+ suggestionPopup.setPreferredWidth(textInput.getWidth());
}
@Override
public void windowClosed(Window window, Display display, Window owner) {
- // TODO Remove listeners from text input
+ display.getContainerMouseListeners().remove(displayMouseListener);
+
+ SuggestionPopup suggestionPopup = (SuggestionPopup)getComponent();
+ TextInput textInput = suggestionPopup.getTextInput();
+ textInput.getComponentKeyListeners().remove(textInputKeyListener);
super.windowClosed(window, display, owner);
+
+ textInput.requestFocus();
+ textInput.setSelection(textInput.getTextLength(), 0);
}
@Override
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopup.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopup.java?rev=900218&r1=900217&r2=900218&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopup.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopup.java Sun Jan 17 21:05:30 2010
@@ -123,7 +123,7 @@
throw new IllegalStateException("textInput is null.");
}
- open(display, owner);
+ super.open(display, owner);
}
/**