Author: tchemit Date: 2013-03-18 09:34:23 +0100 (Mon, 18 Mar 2013) New Revision: 2634 Url: http://nuiton.org/projects/jaxx/repository/revisions/2634 Log: fixes #2499: Mnemonic should be able to be i18nAble (+ use it on jaxx-demo) Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/I18nHelper.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.css trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.jaxx trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/I18nHelper.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/I18nHelper.java 2013-03-18 06:31:44 UTC (rev 2633) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/I18nHelper.java 2013-03-18 08:34:23 UTC (rev 2634) @@ -25,6 +25,7 @@ package jaxx.compiler; +import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.i18n.I18n; @@ -78,7 +79,8 @@ * @param attributeName the name of the attribute * @param attributeValueCode the value code of the attribute value * @param compiler the current used compile - * @return the surrender i18n call if attribute name is matchrf the attributeValueCode otherwise + * @return the surrender i18n call if attribute name is match the + * attributeValueCode otherwise */ public static String addI18nInvocation(String widgetId, String attributeName, String attributeValueCode, JAXXCompiler compiler) { @@ -94,4 +96,33 @@ return attributeValueCode; } + + /** + * Box a i18n key with code to be used as a i18n mnemonic. + * <p/> + * Note: <b>Be ware : </b> no test is done here to ensure we are on a + * i18neable attribute for an i18nable compiler. + * + * @param object the object to use + * @param attributeName the name of the attribute + * @param attributeValueCode the value code of the attribute value + * @param compiler the current used compile + * @return the surrender i18n call if attribute name is match the + * attributeValueCode otherwise + * @since 2.6.11 + */ + public static String addI18nMnemonicInvocation(CompiledObject object, + String attributeName, + String attributeValueCode, + JAXXCompiler compiler) { + String stringValue = I18nHelper.addI18nInvocation( + object.getId(), + attributeName, + attributeValueCode, + compiler); + compiler.addImport(SwingUtil.class.getName()); + String result = "{" + SwingUtil.class.getSimpleName() + + ".getFirstCharAt(" + stringValue + ",'Z')}"; + return result; + } } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java 2013-03-18 06:31:44 UTC (rev 2633) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java 2013-03-18 08:34:23 UTC (rev 2634) @@ -32,6 +32,7 @@ import jaxx.compiler.UnsupportedAttributeException; import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; +import jaxx.compiler.types.TypeManager; import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -59,6 +60,8 @@ public static final String ACTION_ICON_ATTRIBUTE = "actionIcon"; + public static final String I18N_MNEMONIC_ATTRIBUTE = "i18nMnemonic"; + public static final String CONTAINER_DELEGATE_ATTRIBUTE = "containerDelegate"; public static final String FONT_FACE_ATTRIBUTE = "font-face"; @@ -320,8 +323,7 @@ if (!(stringValue.startsWith("{") || stringValue.endsWith("}"))) { // this is a customized icon, add the icon creation code // compiler.setNeedSwingUtil(true); - String type = - compiler.getImportedType(SwingUtil.class); + String type = compiler.getImportedType(SwingUtil.class); if (compiler.getConfiguration().isUseUIManagerForIcon()) { stringValue = "{" + type + ".getUIManagerIcon(\"" + stringValue + "\")}"; @@ -357,6 +359,13 @@ } else { stringValue = "{" + type + ".createActionIcon(\"" + stringValue + "\")}"; } + } else if (I18N_MNEMONIC_ATTRIBUTE.equals(propertyName)) { + propertyName = MNEMONIC_ATTRIBUTE; + stringValue = I18nHelper.addI18nMnemonicInvocation( + object, + I18N_MNEMONIC_ATTRIBUTE, + TypeManager.getJavaCode(stringValue), + compiler); } super.setAttribute(object, propertyName, stringValue, inline, compiler); } Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.css =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.css 2013-03-18 06:31:44 UTC (rev 2633) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.css 2013-03-18 08:34:23 UTC (rev 2634) @@ -47,7 +47,7 @@ #menuFile { text:"jaxxdemo.menu.file"; - mnemonic:F; + i18nMnemonic: "jaxxdemo.menu.file.mnemonic"; _help:{"ui.main.menu.file"}; } @@ -55,7 +55,7 @@ text:"jaxxdemo.action.configuration"; toolTipText:"jaxxdemo.action.configuration.tip"; actionIcon:"config"; - mnemonic:C; + i18nMnemonic: "jaxxdemo.action.configuration.mnemonic"; _help:{"ui.main.menu.file.configuration"}; } @@ -63,7 +63,7 @@ text:"jaxxdemo.menu.file.locale"; toolTipText:"jaxxdemo.menu.file.locale"; actionIcon:"translate"; - mnemonic:C; + i18nMnemonic: "jaxxdemo.menu.file.locale.mnemonic"; _help:{"ui.main.menu.file.locale"}; } @@ -73,7 +73,7 @@ toolTipText:"jaxxdemo.action.locale.fr.tip"; actionIcon:"i18n-fr"; enabled:{!acceptLocale(getConfig().getLocale(), "fr_FR")}; - mnemonic:F; + i18nMnemonic: "jaxxdemo.action.locale.fr.mnemonic"; _help:{"ui.main.menu.file.locale.fr"}; } @@ -82,7 +82,7 @@ toolTipText:"jaxxdemo.action.locale.uk.tip"; actionIcon:"i18n-uk"; enabled:{!acceptLocale(getConfig().getLocale(), "en_GB")}; - mnemonic:U; + i18nMnemonic: "jaxxdemo.action.locale.uk.mnemonic"; _help:{"ui.main.menu.file.locale.uk"}; } @@ -90,7 +90,7 @@ text:"jaxxdemo.action.fullscreen"; toolTipText:"jaxxdemo.action.fullscreen.tip"; actionIcon:"fullscreen"; - mnemonic:P; + i18nMnemonic: "jaxxdemo.action.fullscreen.mnemonic"; visible:{!isUndecorated()}; _help:{"ui.main.menu.file.fullscreen"}; } @@ -99,35 +99,36 @@ text:"jaxxdemo.action.normalscreen"; toolTipText:"jaxxdemo.action.normalscreen.tip"; actionIcon:"leave-fullscreen"; - mnemonic:N; + i18nMnemonic: "jaxxdemo.action.normalscreen.mnemonic"; visible:{isUndecorated()}; -_help:{"ui.main.menu.file.leave-fullscreen"}; + _help:{"ui.main.menu.file.leave-fullscreen"}; } #menuFileExit { text:"jaxxdemo.action.exit"; toolTipText:"jaxxdemo.action.exit.tip"; actionIcon:"exit"; - mnemonic:X; + i18nMnemonic: "jaxxdemo.action.exit.mnemonic"; _help:{"ui.main.menu.file.exit"}; } -#menuLogs { - text:"jaxxdemo.menu.showLogs"; - _help:{"ui.main.menu.showLogs"}; -} - #menuHelp { text:"jaxxdemo.menu.help"; - mnemonic:e; + i18nMnemonic: "jaxxdemo.menu.help.mnemonic"; _help:{"ui.main.menu.help"}; } +#menuHelpLogs { + text:"jaxxdemo.action.showLogs"; + i18nMnemonic: "jaxxdemo.action.showLogs.mnemonic"; + _help:{"ui.main.action.showLogs"}; +} + #menuHelpHelp { text:"jaxxdemo.action.help"; toolTipText:"jaxxdemo.action.help.tip"; actionIcon:"help"; - mnemonic:e; + i18nMnemonic: "jaxxdemo.action.help.mnemonic"; _help:{"ui.main.menu.help.help"}; } @@ -135,7 +136,7 @@ text:"jaxxdemo.action.site"; toolTipText:"jaxxdemo.action.site.tip"; actionIcon:"site"; - mnemonic:s; + i18nMnemonic: "jaxxdemo.action.site.mnemonic"; _help:{"ui.main.menu.help.site"}; } @@ -143,7 +144,7 @@ text:"jaxxdemo.action.about"; toolTipText:"jaxxdemo.action.about.tip"; actionIcon:"about"; - mnemonic:A; + i18nMnemonic: "jaxxdemo.action.about.mnemonic"; _help:{"ui.main.menu.help.about"}; } Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.jaxx 2013-03-18 06:31:44 UTC (rev 2633) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.jaxx 2013-03-18 08:34:23 UTC (rev 2634) @@ -85,7 +85,7 @@ </JMenu> <JMenu id='menuHelp'> - <JMenuItem id='menuLogs' + <JMenuItem id='menuHelpLogs' onActionPerformed="getHandler().showLogs(this)"/> <JMenuItem id='menuHelpHelp' onActionPerformed="getHandler().showHelp(this, null)"/> Modified: trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties =================================================================== --- trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties 2013-03-18 06:31:44 UTC (rev 2633) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties 2013-03-18 08:34:23 UTC (rev 2634) @@ -93,6 +93,7 @@ Yellow= You\ entered\:\ = Your\ name\:= +\\= \\u00f7= adjust\ the\ spacing= between\ these\ lines= @@ -148,25 +149,36 @@ jaxx.demo.label.lastName.tip=Last name jaxxdemo.about.message=<h3>JAXX Demo</h3><hr/>For more informations, visit the <a href\="http\://maven-site.nuiton.org/jaxx/jaxx-demo">website of the project</a>. jaxxdemo.action.about=About... +jaxxdemo.action.about.mnemonic=A jaxxdemo.action.about.tip=About JAXXDemo... jaxxdemo.action.add=Add jaxxdemo.action.configuration=Preferences +jaxxdemo.action.configuration.mnemonic=P jaxxdemo.action.configuration.tip=Change the preferences of the application jaxxdemo.action.exit=Quit +jaxxdemo.action.exit.mnemonic=Q jaxxdemo.action.exit.tip=Quit JAXXDemo jaxxdemo.action.fullscreen=Full screen +jaxxdemo.action.fullscreen.mnemonic=u jaxxdemo.action.fullscreen.tip=Change to full screen mode -jaxxdemo.action.help= +jaxxdemo.action.help=Help +jaxxdemo.action.help.mnemonic=e jaxxdemo.action.help.tip=Display help jaxxdemo.action.locale.fr=French +jaxxdemo.action.locale.fr.mnemonic=F jaxxdemo.action.locale.fr.tip=Change to french language jaxxdemo.action.locale.uk=English +jaxxdemo.action.locale.uk.mnemonic=E jaxxdemo.action.locale.uk.tip=Change to english language jaxxdemo.action.normalscreen=Normal screen +jaxxdemo.action.normalscreen.mnemonic=N jaxxdemo.action.normalscreen.tip=Change to normal screen mode jaxxdemo.action.remove=Remove jaxxdemo.action.show=show +jaxxdemo.action.showLogs=Show logs +jaxxdemo.action.showLogs.mnemonic=S jaxxdemo.action.site=Web site +jaxxdemo.action.site.mnemonic=W jaxxdemo.action.site.tip=Go to the web site jaxxdemo.beancomboboxdemo.autoComplete=AutoComplete jaxxdemo.beancomboboxdemo.configuration=Configuration @@ -254,8 +266,10 @@ jaxxdemo.listSelector.removeToolTipLbl=Remove button toolTip jaxxdemo.menu.file=File jaxxdemo.menu.file.locale=Languages -jaxxdemo.menu.help= -jaxxdemo.menu.showLogs=Show logs +jaxxdemo.menu.file.locale.mnemonic=L +jaxxdemo.menu.file.mnemonic=F +jaxxdemo.menu.help=Help +jaxxdemo.menu.help.mnemonic=h jaxxdemo.message.config.loaded=Configuration of JAXXDemo v. %1$s loaded. jaxxdemo.message.goto.site=Go to JAXXDemo Web site jaxxdemo.navigation.actor.title=Actor Modified: trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties =================================================================== --- trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties 2013-03-18 06:31:44 UTC (rev 2633) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties 2013-03-18 08:34:23 UTC (rev 2634) @@ -93,6 +93,7 @@ Yellow=Jaune You\ entered\:\ = Your\ name\:=Votre nom \: +\\= \\u00f7= adjust\ the\ spacing= between\ these\ lines= @@ -148,25 +149,37 @@ jaxx.demo.label.lastName.tip= jaxxdemo.about.message=<h3>JAXX Demo</h3><hr/>Pour plus d'informations, vous pouvez visiter le <a href\="http\://maven-site.nuiton.org/jaxx/jaxx-demo">site du projet</a>. jaxxdemo.action.about=A propos +jaxxdemo.action.about.mnemonic= jaxxdemo.action.about.tip=A propos de JAXX Demo... jaxxdemo.action.add=Ajouter jaxxdemo.action.configuration=Configuration +jaxxdemo.action.configuration.mnemonic= jaxxdemo.action.configuration.tip=Modifier la configuration jaxxdemo.action.exit=Quitter +jaxxdemo.action.exit.mnemonic= jaxxdemo.action.exit.tip=Quitter JAXX Demo jaxxdemo.action.fullscreen=Plein écran +jaxxdemo.action.fullscreen.mnemonic= jaxxdemo.action.fullscreen.tip=Passer en mode pleine écran jaxxdemo.action.help=Aide +jaxxdemo.action.help.mnemonic= jaxxdemo.action.help.tip=Affichier l'aide jaxxdemo.action.locale.fr=Français +jaxxdemo.action.locale.fr.mnemonic= jaxxdemo.action.locale.fr.tip=Changer la langue en français +jaxxdemo.action.locale.mnemonic= jaxxdemo.action.locale.uk=Anglais +jaxxdemo.action.locale.uk.mnemonic= jaxxdemo.action.locale.uk.tip=Changer la langue en anglais jaxxdemo.action.normalscreen=Ecran normal +jaxxdemo.action.normalscreen.mnemonic= jaxxdemo.action.normalscreen.tip=Revenir en mode normal jaxxdemo.action.remove=Supprimer jaxxdemo.action.show=Voir +jaxxdemo.action.showLogs= +jaxxdemo.action.showLogs.mnemonic= jaxxdemo.action.site=Site internet +jaxxdemo.action.site.mnemonic= jaxxdemo.action.site.tip=Accéder au site de l'application sur internet jaxxdemo.beancomboboxdemo.autoComplete= jaxxdemo.beancomboboxdemo.configuration= @@ -254,8 +267,12 @@ jaxxdemo.listSelector.removeToolTipLbl=Remove button toolTip jaxxdemo.menu.file=Fichier jaxxdemo.menu.file.locale=Langues +jaxxdemo.menu.file.locale.mnemonic= +jaxxdemo.menu.file.mnemonic= jaxxdemo.menu.help=Aide +jaxxdemo.menu.help.mnemonic= jaxxdemo.menu.showLogs=Afficher les logs +jaxxdemo.menu.showLogs.mnemonic= jaxxdemo.message.config.loaded=Configuration de JAXX Demo v. %1$s chargée. jaxxdemo.message.goto.site=Accéder au site de JAXX Demo (%1$s) jaxxdemo.navigation.actor.title=Acteur @@ -302,5 +319,7 @@ t0.isSelected()\ &&\ t1.isSelected()= t0.isSelected()\ ||\ t1.isSelected()= t1.isSelected()= +tutti.menu.file.mnemonic= +tutti.menu.help.mnemonic= valid=valide x=x Modified: trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties =================================================================== --- trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties 2013-03-18 06:31:44 UTC (rev 2633) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties 2013-03-18 08:34:23 UTC (rev 2634) @@ -93,6 +93,7 @@ Yellow=Jaune You\ entered\:\ = Your\ name\:=Votre nom \: +\\= \\u00f7= adjust\ the\ spacing= between\ these\ lines= @@ -148,25 +149,36 @@ jaxx.demo.label.lastName.tip=Nom jaxxdemo.about.message=<h3>JAXX Demo</h3><hr/>Pour plus d'informations, vous pouvez visiter le <a href\="http\://maven-site.nuiton.org/jaxx/jaxx-demo">site du projet</a>. jaxxdemo.action.about=A propos +jaxxdemo.action.about.mnemonic=A jaxxdemo.action.about.tip=A propos de JAXX Demo... jaxxdemo.action.add=Ajouter jaxxdemo.action.configuration=Configuration +jaxxdemo.action.configuration.mnemonic=C jaxxdemo.action.configuration.tip=Modifier la configuration jaxxdemo.action.exit=Quitter +jaxxdemo.action.exit.mnemonic=Q jaxxdemo.action.exit.tip=Quitter JAXX Demo jaxxdemo.action.fullscreen=Plein écran +jaxxdemo.action.fullscreen.mnemonic=P jaxxdemo.action.fullscreen.tip=Passer en mode pleine écran jaxxdemo.action.help=Aide +jaxxdemo.action.help.mnemonic=e jaxxdemo.action.help.tip=Affichier l'aide jaxxdemo.action.locale.fr=Français +jaxxdemo.action.locale.fr.mnemonic=F jaxxdemo.action.locale.fr.tip=Changer la langue en français jaxxdemo.action.locale.uk=Anglais +jaxxdemo.action.locale.uk.mnemonic=A jaxxdemo.action.locale.uk.tip=Changer la langue en anglais jaxxdemo.action.normalscreen=Ecran normal +jaxxdemo.action.normalscreen.mnemonic=N jaxxdemo.action.normalscreen.tip=Revenir en mode normal jaxxdemo.action.remove=Supprimer jaxxdemo.action.show=Voir +jaxxdemo.action.showLogs=Afficher les logs +jaxxdemo.action.showLogs.mnemonic=l jaxxdemo.action.site=Site internet +jaxxdemo.action.site.mnemonic=s jaxxdemo.action.site.tip=Accéder au site de l'application sur internet jaxxdemo.beancomboboxdemo.autoComplete=Auto complétion jaxxdemo.beancomboboxdemo.configuration=Configuration @@ -254,8 +266,10 @@ jaxxdemo.listSelector.removeToolTipLbl=Tooltip du boutton enlever jaxxdemo.menu.file=Fichier jaxxdemo.menu.file.locale=Langues +jaxxdemo.menu.file.locale.mnemonic=L +jaxxdemo.menu.file.mnemonic=F jaxxdemo.menu.help=Aide -jaxxdemo.menu.showLogs=Afficher les logs +jaxxdemo.menu.help.mnemonic=A jaxxdemo.message.config.loaded=Configuration de JAXX Demo v. %1$s chargée. jaxxdemo.message.goto.site=Accéder au site de JAXX Demo (%1$s) jaxxdemo.navigation.actor.title=Acteur Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2013-03-18 06:31:44 UTC (rev 2633) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2013-03-18 08:34:23 UTC (rev 2634) @@ -1388,4 +1388,19 @@ } }); } + + /** + * Get the first char of a String, or return default value. + * <p/> + * Used for example by generated code (i18nMnemonic). + * + * @param text the text to cut + * @param defaultValue default char value if text is null, or empty + * @return the first char of the given text or the default value if text is null or empty. + * @since 2.6.14 + */ + public static char getFirstCharAt(String text, char defaultValue) { + return text == null || text.trim().length() == 0 ? + defaultValue : text.charAt(0); + } }