01: import java.beans.PropertyEditorSupport; 02: 03: /** 04: A helper class for showing names of objects in a property 05: sheet that allows the user to pick one of a finite set of 06: named values. 07: */ 08: public class PropertySelector extends PropertyEditorSupport 09: { 10: /** 11: Constructs a selector that correlates names and objects. 12: @param n the strings to display in a combo box 13: @param v the corresponding object values 14: */ 15: PropertySelector(String[] n, Object[] v) 16: { 17: names = n; 18: values = v; 19: } 20: 21: public String[] getTags() 22: { 23: return names; 24: } 25: 26: public String getAsText() 27: { 28: for (int i = 0; i < values.length; i++) 29: if (getValue().equals(values[i])) return names[i]; 30: return null; 31: } 32: 33: public void setAsText(String s) 34: { 35: for (int i = 0; i < names.length; i++) 36: if (s.equals(names[i])) setValue(values[i]); 37: } 38: 39: private String[] names; 40: private Object[] values; 41: }