1 19 20 21 package org.netbeans.modules.i18n; 22 23 24 import java.awt.Color ; 25 import java.awt.Component ; 26 import java.awt.event.KeyEvent ; 27 import java.awt.SystemColor ; 28 import java.util.List ; 29 import javax.swing.DefaultComboBoxModel ; 30 import javax.swing.JPanel ; 31 import javax.swing.JTextField ; 32 import javax.swing.text.BadLocationException ; 33 import org.netbeans.beaninfo.editors.StringEditor; 34 import org.openide.awt.Mnemonics; 35 import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor; 36 import org.openide.util.HelpCtx; 37 import org.openide.ErrorManager; 38 39 40 45 public class HelpStringCustomEditor extends JPanel implements EnhancedCustomPropertyEditor { 46 47 53 public HelpStringCustomEditor(String value, List items, List helpItems, String comboText, String helpID) { 54 initComponents(); 55 56 combo.setModel(new DefaultComboBoxModel (items.toArray())); 57 combo.setSelectedItem(value); 58 59 list.setListData(helpItems.toArray()); 60 list.setBackground(javax.swing.UIManager.getDefaults().getColor("TextField..disabledBackground")); 63 Mnemonics.setLocalizedText(comboLabel, comboText); 64 Mnemonics.setLocalizedText(listLabel, I18nUtil.getBundle().getString("LBL_Arguments")); 65 66 initAccessibility (); 67 68 HelpCtx.setHelpIDString(this, helpID); 69 } 70 71 75 public Object getPropertyValue() throws IllegalStateException { 76 return (String )combo.getSelectedItem(); 77 } 78 79 80 private void initAccessibility() { 81 this.getAccessibleContext().setAccessibleDescription(I18nUtil.getBundle().getString("ACS_HelpStringCustomEditor")); 82 combo.getAccessibleContext().setAccessibleDescription(I18nUtil.getBundle().getString("ACS_HelpStringCombo")); 83 list.getAccessibleContext().setAccessibleDescription(I18nUtil.getBundle().getString("ACS_HelpStringList")); 84 } 85 86 91 private void initComponents() { 93 java.awt.GridBagConstraints gridBagConstraints; 94 95 combo = new javax.swing.JComboBox (); 96 scrollPane = new javax.swing.JScrollPane (); 97 list = new javax.swing.JList (); 98 comboLabel = new javax.swing.JLabel (); 99 listLabel = new javax.swing.JLabel (); 100 101 setLayout(new java.awt.GridBagLayout ()); 102 103 combo.setEditable(true); 104 gridBagConstraints = new java.awt.GridBagConstraints (); 105 gridBagConstraints.gridx = 0; 106 gridBagConstraints.gridy = 1; 107 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 108 gridBagConstraints.weightx = 1.0; 109 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 11); 110 add(combo, gridBagConstraints); 111 112 list.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 113 list.addKeyListener(new java.awt.event.KeyAdapter () { 114 public void keyPressed(java.awt.event.KeyEvent evt) { 115 listKeyPressed(evt); 116 } 117 }); 118 list.addMouseListener(new java.awt.event.MouseAdapter () { 119 public void mouseClicked(java.awt.event.MouseEvent evt) { 120 listMouseClicked(evt); 121 } 122 }); 123 124 scrollPane.setViewportView(list); 125 126 gridBagConstraints = new java.awt.GridBagConstraints (); 127 gridBagConstraints.gridx = 0; 128 gridBagConstraints.gridy = 3; 129 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 130 gridBagConstraints.weightx = 1.0; 131 gridBagConstraints.weighty = 1.0; 132 gridBagConstraints.insets = new java.awt.Insets (5, 12, 11, 11); 133 add(scrollPane, gridBagConstraints); 134 135 comboLabel.setLabelFor(combo); 136 comboLabel.setText("comboLabel"); 137 gridBagConstraints = new java.awt.GridBagConstraints (); 138 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 139 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 140 add(comboLabel, gridBagConstraints); 141 142 listLabel.setLabelFor(list); 143 listLabel.setText("listLabel"); 144 gridBagConstraints = new java.awt.GridBagConstraints (); 145 gridBagConstraints.gridx = 0; 146 gridBagConstraints.gridy = 2; 147 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 148 gridBagConstraints.insets = new java.awt.Insets (11, 12, 0, 11); 149 add(listLabel, gridBagConstraints); 150 151 } 153 private void listKeyPressed(java.awt.event.KeyEvent evt) { String selected = (String )list.getSelectedValue(); 155 if(evt.getKeyCode() == KeyEvent.VK_ENTER && selected != null) { 156 evt.consume(); 157 insertInFormat(selected); 158 } 159 } 161 private void listMouseClicked(java.awt.event.MouseEvent evt) { String selected = (String )list.getSelectedValue(); 163 if(evt.getClickCount() == 2 && selected != null) { 164 insertInFormat(selected); 165 } 166 } 168 169 private void insertInFormat(String selected) { 170 int index = selected.indexOf(' '); 171 172 if(index < 0 || index > selected.length()) 173 return; 174 175 String replace = selected.substring(0, index); 176 177 JTextField textField = (JTextField )combo.getEditor().getEditorComponent(); 178 try { 179 textField.getDocument().insertString(textField.getCaretPosition(), replace, null); } catch(BadLocationException ble) { 181 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ble); 182 } 183 } 184 185 private javax.swing.JComboBox combo; 187 private javax.swing.JLabel comboLabel; 188 private javax.swing.JList list; 189 private javax.swing.JLabel listLabel; 190 private javax.swing.JScrollPane scrollPane; 191 193 195 public static class InitCodeEditor extends StringEditor { 196 197 public Component getCustomEditor() { 198 return new HelpStringCustomEditor( 199 (String )getValue(), 200 I18nUtil.getInitFormatItems(), 201 I18nUtil.getInitHelpItems(), 202 I18nUtil.getBundle().getString("LBL_InitCodeFormat"), 203 I18nUtil.PE_BUNDLE_CODE_HELP_ID 204 ); 205 } 206 } 208 210 public static class ReplaceCodeEditor extends StringEditor { 211 212 public Component getCustomEditor() { 213 return new HelpStringCustomEditor( 214 (String )getValue(), 215 I18nUtil.getReplaceFormatItems(), 216 I18nUtil.getReplaceHelpItems(), 217 I18nUtil.getBundle().getString("LBL_ReplaceCodeFormat"), 218 I18nUtil.PE_REPLACE_CODE_HELP_ID 219 ); 220 } 221 } 223 225 public static class RegExpEditor extends StringEditor { 226 227 public Component getCustomEditor() { 228 return new HelpStringCustomEditor( 229 (String )getValue(), 230 I18nUtil.getRegExpItems(), 231 I18nUtil.getRegExpHelpItems(), 232 I18nUtil.getBundle().getString("LBL_NonI18nRegExpFormat"), 233 I18nUtil.PE_I18N_REGEXP_HELP_ID 234 ); 235 } 236 } 238 240 public static class I18nRegExpEditor extends StringEditor { 241 242 public Component getCustomEditor() { 243 return new HelpStringCustomEditor( 244 (String )getValue(), 245 I18nUtil.getI18nRegExpItems(), 246 I18nUtil.getRegExpHelpItems(), 247 I18nUtil.getBundle().getString("LBL_I18nRegExpFormat"), 248 I18nUtil.PE_TEST_REGEXP_HELP_ID 249 ); 250 } 251 } 253 } 254 | Popular Tags |