1 19 20 package org.netbeans.modules.form.editors; 21 22 import java.beans.*; 23 24 30 31 public class EnumEditor extends PropertyEditorSupport 32 implements org.netbeans.modules.form.NamedPropertyEditor 33 { 34 39 private Object [] enumerationValues; 40 41 public EnumEditor(Object [] enumerationValues) { 42 translateEnumLabels(enumerationValues); 43 this.enumerationValues = enumerationValues; 44 } 45 46 48 public String [] getTags() { 49 int n = enumerationValues.length / 3; 50 String [] tags = new String [n]; 51 for (int i=0; i < n; i++) 52 tags[i] = (String ) enumerationValues[i*3]; 53 54 return tags; 55 } 56 57 public void setAsText(String str) { 58 int n = enumerationValues.length / 3; 59 for (int i=0; i < n; i++) 60 if (enumerationValues[i*3].toString().equals(str)) { 61 setValue(enumerationValues[i*3 + 1]); 62 break; 63 } 64 } 65 66 public String getAsText() { 67 Object value = getValue(); 68 int n = enumerationValues.length / 3; 69 for (int i=0; i < n; i++) { 70 Object eVal = enumerationValues[i*3 + 1]; 71 if ((eVal == null && value == null) || (eVal != null && eVal.equals(value))) 72 return enumerationValues[i*3].toString(); 73 } 74 75 return enumerationValues.length > 0 ? 76 enumerationValues[0].toString() : null; 77 } 78 79 public String getJavaInitializationString() { 80 String initString = null; 81 82 Object value = getValue(); 83 int n = enumerationValues.length / 3; 84 for (int i=0; i < n; i++) { 85 Object eVal = enumerationValues[i*3 + 1]; 86 if ((eVal == null && value == null) || (eVal != null && eVal.equals(value))) { 87 initString = (String ) enumerationValues[i*3 + 2]; 88 break; 89 } 90 } 91 92 if (initString == null) 93 initString = enumerationValues.length > 2 ? 94 (String ) enumerationValues[2] : null; 95 if (initString == null) 96 return null; 97 98 for (int i=0; i < swingClassNames.length; i++) 99 if (initString.startsWith(swingClassNames[i])) { 100 initString = "javax.swing." + initString; break; 102 } 103 104 return initString; 105 } 106 107 110 public String getDisplayName() { 111 return org.openide.util.NbBundle.getBundle(EnumEditor.class) 112 .getString("CTL_EnumEditorName"); } 114 115 117 122 private static void translateEnumLabels(Object [] enumerationValues) { 123 int n1 = enumerationValues.length / 3; 124 int n2 = arrangedEnumLabels.length / 2; 125 126 for (int i=0; i < n1; i++) { 127 String code = (String ) enumerationValues[i*3 + 2]; 128 for (int j=0; j < n2; j++) 129 if (code.endsWith(arrangedEnumLabels[j*2])) { 130 enumerationValues[i*3] = arrangedEnumLabels[j*2 + 1]; 131 break; 132 } 133 } 134 } 135 136 private static String [] arrangedEnumLabels = { 137 "WindowConstants.DISPOSE_ON_CLOSE", "DISPOSE", "WindowConstants.DO_NOTHING_ON_CLOSE", "DO_NOTHING", "WindowConstants.HIDE_ON_CLOSE", "HIDE", "JFrame.EXIT_ON_CLOSE", "EXIT", "ListSelectionModel.MULTIPLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL", "ListSelectionModel.SINGLE_INTERVAL_SELECTION", "SINGLE_INTERVAL", "ListSelectionModel.SINGLE_SELECTION", "SINGLE", "JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED", "AS_NEEDED", "JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS", "ALWAYS", "JScrollPane.HORIZONTAL_SCROLLBAR_NEVER", "NEVER", "JScrollPane.VERTICAL_SCROLLBAR_ALWAYS", "ALWAYS", "JScrollPane.VERTICAL_SCROLLBAR_NEVER", "NEVER", "JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED", "AS_NEEDED", "ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED", "AS_NEEDED", "ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS", "ALWAYS", "ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER", "NEVER", "ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS", "ALWAYS", "ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER", "NEVER", "ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED", "AS_NEEDED", "JTable.AUTO_RESIZE_NEXT_COLUMN", "NEXT_COLUMN", "JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS", "SUBSEQUENT_COLUMNS", "JTable.AUTO_RESIZE_OFF", "OFF", "JTable.AUTO_RESIZE_ALL_COLUMNS", "ALL_COLUMNS", "JTable.AUTO_RESIZE_LAST_COLUMN", "LAST_COLUMN" }; 162 163 private static String [] swingClassNames = { 164 "SwingConstants.", "DebugGraphics.", "JDesktopPane.", "JFileChooser.", "WindowConstants.", "ListSelectionModel.", "JScrollBar.", "JScrollPane.", "ScrollPaneConstants.", "JSlider.", "JSplitPane.", "JTabbedPane.", "JTable.", "JTextField.", "JViewport.", "JFrame.", "JList.", "JFormattedTextField." }; 183 } 184 | Popular Tags |