|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jdesktop.swingx.autocomplete.ObjectToStringConverter
public abstract class ObjectToStringConverter
This class is used to provide string representations for objects when doing automatic completion.
A class inherited from this class could be used, when the object's toString method is not appropriate for automatic completion.
An example for i18n:
public class I18NStringConverter extends ObjectToStringConverter {
ResourceBundle bundle;
public I18NStringConverter(ResourceBundle bundle) {
this.bundle = bundle;
}
public String getPreferredStringForItem(Object item) {
return item==null ? null : bundle.getString(item.toString());
}
}
It's also possible to return more than one string representation. The following example shows a converter that will allow a user to choose an airport using either the airport's full description (toString()) or its ICAO/IATA code:
public class AirportConverter extends ObjectToStringConverter {
public String[] getPossibleStringsForItem(Object item) {
if (item==null) return new String[0];
if (!(item instanceof Airport)) throw new IllegalArgumentException();
Airport airport = (Airport) item;
return new String[]{airport.toString(), airport.icaoCode, airport.iataCode};
}
public String getPreferredStringForItem(Object item) {
return item==null?null:getPossibleStringsForItem(item)[0];
}
}
Field Summary | |
---|---|
static ObjectToStringConverter |
DEFAULT_IMPLEMENTATION
This field contains the default implementation, that returns item.toString() for any item !=null. |
Constructor Summary | |
---|---|
ObjectToStringConverter()
|
Method Summary | |
---|---|
String[] |
getPossibleStringsForItem(Object item)
Returns all possible String representations for a given item. |
abstract String |
getPreferredStringForItem(Object item)
Returns the preferred String representations for a given item. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final ObjectToStringConverter DEFAULT_IMPLEMENTATION
Constructor Detail |
---|
public ObjectToStringConverter()
Method Detail |
---|
public String[] getPossibleStringsForItem(Object item)
item
- the item to convert
public abstract String getPreferredStringForItem(Object item)
item
- the item to convert
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |