Index: form/src/org/netbeans/modules/form/Bundle.properties =================================================================== RCS file: /cvs/form/src/org/netbeans/modules/form/Bundle.properties,v retrieving revision 1.134 diff -c -r1.134 Bundle.properties *** form/src/org/netbeans/modules/form/Bundle.properties 9 Jul 2002 12:54:25 -0000 1.134 --- form/src/org/netbeans/modules/form/Bundle.properties 9 Sep 2002 21:18:34 -0000 *************** *** 784,786 **** --- 784,821 ---- CTL_CW_Parameters=Parameters FMT_MSG_InvalidJavaIdentifier={0} is not a Java identifier. FMT_MSG_HandlersFor=Handlers for {0} + + #org.netbeans.modules.form.RADProperty + CTL_ASK_AMPERSAND_TITLE=Did you know? + + #org.netbeans.modules.form.RADProperty + TEXT_AMPERSAND_ASK=Form Editor now has the support for setting two additional \ + properties: mnemonic and displayedMnemonicIndex given the '&' in text property. \ + It means if you want to underline the second 'A' in menu item "Save As...", you \ + should enter "Save &As..." into the text property of your menu item.\n\nThis \ + feature is off by default, because it makes your forms not compatible with \ + earlier versions of Netbeans IDE and other IDE's. Also you are required to \ + redistribute a mnemonic.jar (found in /lib/ext) along with all your \ + form using this feature.\n\nHowever, setting mnemonic using ampersand is \ + I18n-enabled. It means that you may go far beyond Swing capabilities: set \ + Cyrillic, Greek & German umlaut letters as mnemonics, see docs for HOWTO enable \ + your custom language.\n\nTo enable it, go to Tools|Options, Editing|Form Editor \ + Settings, Expert tab, and enable the Option "Specify mnemonic using Ampersand". + + #org.netbeans.modules.form.RADProperty + TEXT_SHOW_AGAIN=&Don't show this dialog again. + + #org.netbeans.modules.form.RADProperty + CTL_BUTTON_CLOSE=&Close + + #org.netbeans.modules.form.FormLoaderSettingsBeanInfo + PROP_SHOW_AMPERSAND_DIALOG=Show mnemonic-via-ampersand dialog + + #org.netbeans.modules.form.FormLoaderSettingsBeanInfo + HINT_SHOW_AMPERSAND_DIALOG=If True, shows dialog about the mnemonic-via-ampersand feature when you type '&' in text property + + #org.netbeans.modules.form.FormLoaderSettingsBeanInfo + PROP_MNEMONIC_VIA_AMPERSAND=Specify Mnemonic using Ampersand + + #org.netbeans.modules.form.FormLoaderSettingsBeanInfo + HINT_MNEMONIC_VIA_AMPERSAND=If True, Form Editor sets Mnemonic based on the position of '&' in Text. I18N-compatible solution. Index: form/src/org/netbeans/modules/form/FormLoaderSettings.java =================================================================== RCS file: /cvs/form/src/org/netbeans/modules/form/FormLoaderSettings.java,v retrieving revision 1.47 diff -c -r1.47 FormLoaderSettings.java *** form/src/org/netbeans/modules/form/FormLoaderSettings.java 10 Jun 2002 16:34:52 -0000 1.47 --- form/src/org/netbeans/modules/form/FormLoaderSettings.java 9 Sep 2002 21:19:10 -0000 *************** *** 88,93 **** --- 88,99 ---- /** Property name of the variablesLocal property */ public static final String PROP_VARIABLES_LOCAL = "variablesLocal"; // NOI18N + + /** Property name of the showAmpersandDialog property **/ + public static final String PROP_SHOW_AMPERSAND_DIALOG = "showAmpersandDialog"; + + /** Property name of the mnemonicViaAmpersand property **/ + public static final String PROP_MNEMONIC_VIA_AMPERSAND = "mnemonicViaAmpersand"; /** Minimum output detail level */ public static final int OUTPUT_MINIMUM = 0; *************** *** 176,181 **** --- 182,191 ---- private static final int MIN_GRID_Y = 2; private static Map containerBeans; + + private static boolean showAmpersandDialog = true; + /** #27009, by default off **/ + private static boolean mnemonicViaAmpersand = false; // static { // String[] defaultPath = java.beans.PropertyEditorManager.getEditorSearchPath(); *************** *** 588,593 **** --- 598,638 ---- firePropertyChange(PROP_CONTAINER_BEANS, null, null); } + + /** @return Whether we should ask a user about enabling + * Mnemonic-via-Ampersand feature. + */ + public boolean getShowAmpersandDialog() { + return showAmpersandDialog; + } + + /** @param value Whether we should ask a user about enabling + * Mnemonic-via-Ampersand feature. + */ + public void setShowAmpersandDialog(boolean value) { + if (value == showAmpersandDialog) + return; + showAmpersandDialog = value; + firePropertyChange(PROP_SHOW_AMPERSAND_DIALOG, + new Boolean(!value), new Boolean(value)); + } + + /** @return Whether Form editor uses Mnemonic-via-Ampersand feature. + */ + public boolean getMnemonicViaAmpersand() { + return mnemonicViaAmpersand; + } + + /** @return Whether Form editor should use Mnemonic-via-Ampersand feature. + */ + public void setMnemonicViaAmpersand(boolean value) { + if (value == mnemonicViaAmpersand) + return; + mnemonicViaAmpersand = value; + firePropertyChange(PROP_MNEMONIC_VIA_AMPERSAND, + new Boolean(!value), new Boolean(value)); + } + // XXX(-tdt) Hmm, backward compatibility with com.netbeans package name // again. The property editor search path is stored in user settings, we // must translate Index: form/src/org/netbeans/modules/form/FormLoaderSettingsBeanInfo.java =================================================================== RCS file: /cvs/form/src/org/netbeans/modules/form/FormLoaderSettingsBeanInfo.java,v retrieving revision 1.50 diff -c -r1.50 FormLoaderSettingsBeanInfo.java *** form/src/org/netbeans/modules/form/FormLoaderSettingsBeanInfo.java 10 Jun 2002 16:34:52 -0000 1.50 --- form/src/org/netbeans/modules/form/FormLoaderSettingsBeanInfo.java 9 Sep 2002 21:19:22 -0000 *************** *** 98,104 **** "getVariablesLocal", "setVariablesLocal"), // NOI18N new PropertyDescriptor(FormLoaderSettings.PROP_DISPLAY_WRITABLE_ONLY, FormLoaderSettings.class, ! "getDisplayWritableOnly", "setDisplayWritableOnly") // NOI18N }; ResourceBundle bundle = FormUtils.getBundle(); --- 98,110 ---- "getVariablesLocal", "setVariablesLocal"), // NOI18N new PropertyDescriptor(FormLoaderSettings.PROP_DISPLAY_WRITABLE_ONLY, FormLoaderSettings.class, ! "getDisplayWritableOnly", "setDisplayWritableOnly"), // NOI18N ! new PropertyDescriptor(FormLoaderSettings.PROP_SHOW_AMPERSAND_DIALOG, ! FormLoaderSettings.class, ! "getShowAmpersandDialog", "setShowAmpersandDialog"), // NOI18N ! new PropertyDescriptor(FormLoaderSettings.PROP_MNEMONIC_VIA_AMPERSAND, ! FormLoaderSettings.class, ! "getMnemonicViaAmpersand", "setMnemonicViaAmpersand") // NOI18N }; ResourceBundle bundle = FormUtils.getBundle(); *************** *** 202,207 **** --- 208,221 ---- desc[20].setExpert(true); desc[21].setHidden(true); + + desc[22].setDisplayName(bundle.getString("PROP_SHOW_AMPERSAND_DIALOG")); // NOI18N + desc[22].setShortDescription(bundle.getString("HINT_SHOW_AMPERSAND_DIALOG")); // NOI18N + desc[22].setExpert(true); + + desc[23].setDisplayName(bundle.getString("PROP_MNEMONIC_VIA_AMPERSAND")); // NOI18N + desc[23].setShortDescription(bundle.getString("HINT_MNEMONIC_VIA_AMPERSAND")); // NOI18N + desc[23].setExpert(true); return desc; Index: form/src/org/netbeans/modules/form/JavaCodeGenerator.java =================================================================== RCS file: /cvs/form/src/org/netbeans/modules/form/JavaCodeGenerator.java,v retrieving revision 1.122 diff -c -r1.122 JavaCodeGenerator.java *** form/src/org/netbeans/modules/form/JavaCodeGenerator.java 25 Jun 2002 09:05:59 -0000 1.122 --- form/src/org/netbeans/modules/form/JavaCodeGenerator.java 9 Sep 2002 21:19:43 -0000 *************** *** 1251,1257 **** } } ! initCodeWriter.write(getVariableGenString(comp)); initCodeWriter.write(javaStr); initCodeWriter.write(";\n"); // NOI18N --- 1251,1261 ---- } } ! // Maxym Mykhalchuk's hack ! // if partialcode contains "org.openide.awt.Actions.", ! // there's no need to append, e.g. "jButton1." ! if( javaStr.indexOf("org.openide.awt.Actions.") == -1 ) // NOI18N ! initCodeWriter.write(getVariableGenString(comp)); initCodeWriter.write(javaStr); initCodeWriter.write(";\n"); // NOI18N Index: form/src/org/netbeans/modules/form/RADProperty.java =================================================================== RCS file: /cvs/form/src/org/netbeans/modules/form/RADProperty.java,v retrieving revision 1.19 diff -c -r1.19 RADProperty.java *** form/src/org/netbeans/modules/form/RADProperty.java 10 Jul 2002 13:29:22 -0000 1.19 --- form/src/org/netbeans/modules/form/RADProperty.java 9 Sep 2002 21:19:47 -0000 *************** *** 23,28 **** --- 23,35 ---- import org.netbeans.modules.form.editors.*; import org.netbeans.modules.form.fakepeer.FakePeerSupport; + import javax.swing.*; + import java.awt.*; + import org.openide.util.NbBundle; + import org.openide.DialogDescriptor; + import org.openide.TopManager; + import org.openide.util.SharedClassObject; + /** * Implementation of properties for (meta)components (class RADComponent). * RADComponent is used to get the component instance and *************** *** 123,132 **** --- 130,204 ---- IllegalArgumentException, InvocationTargetException { super.setValue(value); + + // Maxym Mykhalchuk's hack + if(getRADComponent().getFormModel().isFormLoaded() + && getName().equals("text") + && value instanceof String + && ((String)value).indexOf('&')>=0) { + showAmpersandAsMnemonicDialog(); + } component.debugChangedValues(); // do we need this?? } + private void showAmpersandAsMnemonicDialog() { + FormLoaderSettings settings = (FormLoaderSettings)SharedClassObject.findObject(FormLoaderSettings.class, true); + + if(!settings.getShowAmpersandDialog() || settings.getMnemonicViaAmpersand()) + return; + + JPanel panel = new JPanel(); + JLabel label1 = new JLabel(); + JTextArea textArea = new JTextArea(); + textArea.setEditable(false); + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + final JCheckBox box = new JCheckBox(); + panel.setLayout(new java.awt.GridBagLayout()); + StringBuffer buff = new StringBuffer(); + buff.append(NbBundle.getBundle(RADProperty.class).getString("TEXT_AMPERSAND_ASK")); // NOI18N + textArea.setText(buff.toString()); + // hack to get the right bg color.. + textArea.setBackground(label1.getBackground()); + textArea.setPreferredSize(new Dimension(250, 250)); + textArea.setMinimumSize(new Dimension(250, 250)); + + GridBagConstraints gridBagConstraints1; + gridBagConstraints1 = new java.awt.GridBagConstraints(); + gridBagConstraints1.gridx = 0; + gridBagConstraints1.gridy = 0; + gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0, 11); + panel.add(textArea, gridBagConstraints1); + + org.openide.awt.Actions.setMenuText(box,NbBundle.getBundle(RADProperty.class).getString("TEXT_SHOW_AGAIN"),true); //NOI18N + box.setSelected(true); + gridBagConstraints1 = new java.awt.GridBagConstraints(); + gridBagConstraints1.gridx = 0; + gridBagConstraints1.gridy = 3; + gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0, 11); + gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints1.weightx = 1.0; + gridBagConstraints1.weighty = 1.0; + panel.add(box, gridBagConstraints1); + + String title = NbBundle.getBundle(RADProperty.class).getString("CTL_ASK_AMPERSAND_TITLE"); // NOI18N + DialogDescriptor dd = new DialogDescriptor(panel, title); + dd.setModal(true); + JButton btnClose = new JButton(); + org.openide.awt.Actions.setMenuText(btnClose,NbBundle.getBundle(RADProperty.class).getString("CTL_BUTTON_CLOSE"),true); // NOI18N + Object[] options = new Object[] {btnClose}; + dd.setOptions(options); + dd.setClosingOptions(options); + dd.setValue(btnClose); + final DialogDescriptor ddFin = dd; + Object retValue = TopManager.getDefault().notify(ddFin); + + settings.setShowAmpersandDialog(!box.isSelected()); + } + + protected Object getRealValue(Object value) { Object realValue = super.getRealValue(value); *************** *** 231,236 **** --- 303,321 ---- if (str == null) return null; + // Maxym Mykhalchuk's hack + // to use org.openide.awt.Actions.setMenuText + // if the property is text and the component + // is descendant from AbstractButton + FormLoaderSettings settings = (FormLoaderSettings)SharedClassObject.findObject(FormLoaderSettings.class, true); + if( settings.getMnemonicViaAmpersand() + && getPropertyDescriptor().getName().equals("text") ) { + if( AbstractButton.class.isAssignableFrom(getRADComponent().getBeanClass()) ) + return "org.openide.awt.Actions.setMenuText("+getRADComponent().getName()+","+str+",true)"; // NOI18N + else if( JLabel.class.isAssignableFrom(getRADComponent().getBeanClass()) ) + // pending + return writeMethod.getName() + "(" + str + ")"; // NOI18N + } return writeMethod.getName() + "(" + str + ")"; // NOI18N }