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/18 15:46:23 UTC
svn commit: r900412 - in /pivot/trunk:
wtk-terra/src/org/apache/pivot/wtk/skin/terra/
wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/content/
Author: gbrown
Date: Mon Jan 18 14:46:22 2010
New Revision: 900412
URL: http://svn.apache.org/viewvc?rev=900412&view=rev
Log:
Add SuggestionRenderer interface to allow callers to provide custom suggestion to string translations.
Added:
pivot/trunk/wtk/src/org/apache/pivot/wtk/content/SuggestionPopupItemRenderer.java
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopup.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopupListener.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemRenderer.java
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=900412&r1=900411&r2=900412&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 Mon Jan 18 14:46:22 2010
@@ -106,9 +106,9 @@
Object suggestion = suggestionListView.getSelectedItem();
if (suggestion != null) {
- // TODO Add a translation interface so callers can provide custom toString()
- // implementations
- textInput.setText(suggestion.toString());
+ SuggestionPopup.SuggestionRenderer suggestionRenderer =
+ suggestionPopup.getSuggestionRenderer();
+ textInput.setText(suggestionRenderer.toString(suggestion));
}
}
};
@@ -261,7 +261,7 @@
@Override
public void suggestionRendererChanged(SuggestionPopup suggestionPopup,
- ListView.ItemRenderer previousSuggestionRenderer) {
+ SuggestionPopup.SuggestionRenderer previousSuggestionRenderer) {
suggestionListView.setItemRenderer(suggestionPopup.getSuggestionRenderer());
}
}
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=900412&r1=900411&r2=900412&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopup.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopup.java Mon Jan 18 14:46:22 2010
@@ -19,12 +19,26 @@
import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.List;
import org.apache.pivot.util.ListenerList;
-import org.apache.pivot.wtk.content.ListViewItemRenderer;
+import org.apache.pivot.wtk.content.SuggestionPopupItemRenderer;
/**
* Popup that presents a list of text suggestions to the user.
*/
public class SuggestionPopup extends Window {
+ /**
+ * Extends list view item renderer interface to provide support for converting
+ * suggestions to text.
+ */
+ public interface SuggestionRenderer extends ListView.ItemRenderer {
+ /**
+ * Converts a suggestion to a string representation for display in a
+ * text input.
+ *
+ * @param suggestion
+ */
+ public String toString(Object suggestion);
+ }
+
private static class SuggestionPopupListenerList extends ListenerList<SuggestionPopupListener>
implements SuggestionPopupListener {
@Override
@@ -37,7 +51,7 @@
@Override
public void suggestionRendererChanged(SuggestionPopup suggestionPopup,
- ListView.ItemRenderer previousSuggestionRenderer) {
+ SuggestionRenderer previousSuggestionRenderer) {
for (SuggestionPopupListener listener : this) {
listener.suggestionRendererChanged(suggestionPopup, previousSuggestionRenderer);
}
@@ -46,12 +60,12 @@
private TextInput textInput = null;
private List<?> suggestions;
- private ListView.ItemRenderer suggestionRenderer;
+ private SuggestionRenderer suggestionRenderer;
private SuggestionPopupListenerList suggestionPopupListeners = new SuggestionPopupListenerList();
- private static final ListView.ItemRenderer DEFAULT_SUGGESTION_RENDERER =
- new ListViewItemRenderer();
+ private static final SuggestionRenderer DEFAULT_SUGGESTION_RENDERER =
+ new SuggestionPopupItemRenderer();
public SuggestionPopup() {
this(new ArrayList<Object>());
@@ -99,7 +113,7 @@
/**
* Returns the list view item renderer used to present suggestions.
*/
- public ListView.ItemRenderer getSuggestionRenderer() {
+ public SuggestionRenderer getSuggestionRenderer() {
return suggestionRenderer;
}
@@ -108,8 +122,8 @@
*
* @param suggestionRenderer
*/
- public void setSuggestionRenderer(ListView.ItemRenderer suggestionRenderer) {
- ListView.ItemRenderer previousSuggestionRenderer = this.suggestionRenderer;
+ public void setSuggestionRenderer(SuggestionRenderer suggestionRenderer) {
+ SuggestionRenderer previousSuggestionRenderer = this.suggestionRenderer;
if (previousSuggestionRenderer != suggestionRenderer) {
this.suggestionRenderer = suggestionRenderer;
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopupListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopupListener.java?rev=900412&r1=900411&r2=900412&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopupListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/SuggestionPopupListener.java Mon Jan 18 14:46:22 2010
@@ -33,7 +33,7 @@
@Override
public void suggestionRendererChanged(SuggestionPopup suggestionPopup,
- ListView.ItemRenderer previousSuggestionRenderer) {
+ SuggestionPopup.SuggestionRenderer previousSuggestionRenderer) {
}
}
@@ -52,5 +52,5 @@
* @param previousSuggestionRenderer
*/
public void suggestionRendererChanged(SuggestionPopup suggestionPopup,
- ListView.ItemRenderer previousSuggestionRenderer);
+ SuggestionPopup.SuggestionRenderer previousSuggestionRenderer);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemRenderer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemRenderer.java?rev=900412&r1=900411&r2=900412&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemRenderer.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemRenderer.java Mon Jan 18 14:46:22 2010
@@ -49,7 +49,7 @@
add(imageView);
add(label);
- //imageView.setPreferredSize(DEFAULT_ICON_WIDTH, DEFAULT_ICON_HEIGHT);
+ imageView.setPreferredSize(DEFAULT_ICON_WIDTH, DEFAULT_ICON_HEIGHT);
imageView.setVisible(DEFAULT_SHOW_ICON);
}
Added: pivot/trunk/wtk/src/org/apache/pivot/wtk/content/SuggestionPopupItemRenderer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/SuggestionPopupItemRenderer.java?rev=900412&view=auto
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/content/SuggestionPopupItemRenderer.java (added)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/content/SuggestionPopupItemRenderer.java Mon Jan 18 14:46:22 2010
@@ -0,0 +1,41 @@
+/*
+ * 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.wtk.content;
+
+import org.apache.pivot.wtk.SuggestionPopup;
+
+/**
+ * Default suggestion popup item renderer.
+ */
+public class SuggestionPopupItemRenderer extends ListViewItemRenderer
+ implements SuggestionPopup.SuggestionRenderer{
+ public String toString(Object suggestion) {
+ if (suggestion == null) {
+ throw new IllegalArgumentException();
+ }
+
+ String string;
+ if (suggestion instanceof ListItem) {
+ ListItem listItem = (ListItem)suggestion;
+ string = listItem.getText();
+ } else {
+ string = suggestion.toString();
+ }
+
+ return string;
+ }
+}