1 19 20 package org.netbeans.modules.form.editors2; 21 22 import javax.swing.*; 23 import org.netbeans.modules.form.editors.StringArrayEditor; 24 import org.openide.util.NbBundle; 25 26 30 31 public class ComboBoxModelEditor extends StringArrayEditor { 32 33 private ComboBoxModel comboModel = null; 34 35 public void setValue(Object val) { 36 if (val instanceof ComboBoxModel) { 37 comboModel = (ComboBoxModel) val; 38 super.setValue(getDataFromModel(comboModel)); 39 } 40 else if (val instanceof String []) { 41 comboModel = getModelForData((String [])val); 42 super.setValue(val); 43 } 44 else { 45 comboModel = getModelForData(new String [0]); 46 super.setValue(null); 47 } 48 } 49 50 public Object getValue() { 51 return comboModel; 52 } 53 54 public void setStringArray(String [] value) { 55 comboModel = getModelForData(value); 56 super.setValue(value); 57 } 58 59 public String [] getStringArray () { 60 return (String [])super.getValue (); 61 } 62 63 public String getJavaInitializationString() { 64 if (getStrings(true).equals("")) 65 return null; 66 StringBuffer buf = new StringBuffer ( 67 "new javax.swing.DefaultComboBoxModel(new String[] { "); buf.append(getStrings(true)); 69 buf.append(" })"); 71 return buf.toString(); 72 } 73 74 static String [] getDataFromModel(ComboBoxModel model) { 75 return ListModelEditor.getDataFromModel(model); 76 } 77 78 static ComboBoxModel getModelForData(String [] data) { 79 return new DefaultComboBoxModel(data); 80 } 81 82 public String getDisplayName() { 84 return NbBundle.getBundle(getClass()).getString("CTL_ComboBoxModelEditor_DisplayName"); } 86 87 } 88 | Popular Tags |