Author: tchemit Date: 2008-07-24 21:07:45 +0000 (Thu, 24 Jul 2008) New Revision: 905 Added: trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/ui/DemoMainUI.java Removed: trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/ui/MyMainUI.java Modified: trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/DemoContext.java Log: demo :) Modified: trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/DemoContext.java =================================================================== --- trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/DemoContext.java 2008-07-24 21:07:14 UTC (rev 904) +++ trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/DemoContext.java 2008-07-24 21:07:45 UTC (rev 905) @@ -15,7 +15,7 @@ package org.codelutin.commandline.demo; import org.codelutin.commandline.demo.ui.JMainUI; -import org.codelutin.commandline.demo.ui.MyMainUI; +import org.codelutin.commandline.demo.ui.DemoMainUI; import org.codelutin.commandline.demo.ui.actions.CommandLineAction; import org.codelutin.i18n.I18n; import org.codelutin.jaxx.action.factory.ActionFactory; @@ -47,7 +47,7 @@ public JMainUI getMainUI() { if (mainUI == null) { - mainUI = new MyMainUI(); + mainUI = new DemoMainUI(); } return mainUI; } Copied: trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/ui/DemoMainUI.java (from rev 903, trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/ui/MyMainUI.java) =================================================================== --- trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/ui/DemoMainUI.java (rev 0) +++ trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/ui/DemoMainUI.java 2008-07-24 21:07:45 UTC (rev 905) @@ -0,0 +1,107 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.commandline.demo.ui; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.commandline.demo.DemoContext; +import org.codelutin.commandline.demo.DemoMain; +import org.codelutin.commandline.demo.ui.actions.ChangeLocaleAction; +import org.codelutin.commandline.demo.ui.actions.CommandLineAction; +import static org.codelutin.i18n.I18n._; + +import javax.swing.AbstractButton; +import javax.swing.JComponent; +import javax.swing.KeyStroke; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.util.Locale; +import java.util.regex.Matcher; + +/** @author chemit */ +public class DemoMainUI extends JMainUI { + + /** log */ + private static final Log log = LogFactory.getLog(DemoMainUI.class); + + public DemoMainUI() { + super(); + + DemoMain.checkInitContext(); + + finalizeInit(DemoMain.getContext()); + + } + + protected void finalizeInit(DemoContext context) { + + // chargement dans l'ui des actions + context.getActionFactory().loadActions(this); + + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK), "quit"); + getRootPane().getActionMap().put("quit", context.getActionFactory().newAction("quit", null)); + + // repaint i18n actions + refreshI18nActions(context); + + } + + /** + * Rafraichit les actions i18n dans le menu en fonction de la locale + * actuellement utilis�e. + * + * @param context application context + */ + public void refreshI18nActions(DemoContext context) { + + Locale locale = context.getMainConfig().getLocale(); + //CountryEnum country = context.getConfig().getUserCountry(); + String[] actions = context.getActionFactory().getActionNames(); + for (String actionName : actions) { + Matcher matcher = ChangeLocaleAction.PATTERN_NAME.matcher(actionName); + if (!matcher.matches()) { + continue; + } + AbstractButton button = (AbstractButton) getObjectById(actionName); + ChangeLocaleAction action = (ChangeLocaleAction) button.getAction(); + boolean enable = !action.equalsLocale(locale); + log.debug("incoming locale : " + locale); + log.debug("load i18n action " + action + " is enable ? " + enable); + UpdateButton(button, enable, enable ? action.getLocale() : null); + button.setEnabled(enable); + } + } + + public static void DisableButton(AbstractButton... buttons) { + for (AbstractButton button : buttons) { + UpdateButton(button, false); + } + } + + public static void EnableButton(AbstractButton button, Object... params) { + UpdateButton(button, true, params); + } + + public static void UpdateButton(AbstractButton button, boolean enabled, Object... params) { + button.setEnabled(enabled); + if (!enabled) { + button.setToolTipText(null); + } else { + CommandLineAction action = (CommandLineAction) button.getAction(); + String t = _(action.getI18nToolTipText(), params); + button.setToolTipText(t); + } + } +} Deleted: trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/ui/MyMainUI.java =================================================================== --- trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/ui/MyMainUI.java 2008-07-24 21:07:14 UTC (rev 904) +++ trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/ui/MyMainUI.java 2008-07-24 21:07:45 UTC (rev 905) @@ -1,107 +0,0 @@ -/** - * # #% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * # #% - */ -package org.codelutin.commandline.demo.ui; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.commandline.demo.DemoContext; -import org.codelutin.commandline.demo.DemoMain; -import org.codelutin.commandline.demo.ui.actions.ChangeLocaleAction; -import org.codelutin.commandline.demo.ui.actions.CommandLineAction; -import static org.codelutin.i18n.I18n._; - -import javax.swing.AbstractButton; -import javax.swing.JComponent; -import javax.swing.KeyStroke; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.util.Locale; -import java.util.regex.Matcher; - -/** @author chemit */ -public class MyMainUI extends JMainUI { - - /** log */ - private static final Log log = LogFactory.getLog(MyMainUI.class); - - public MyMainUI() { - super(); - - DemoMain.checkInitContext(); - - finalizeInit(DemoMain.getContext()); - - } - - protected void finalizeInit(DemoContext context) { - - // chargement dans l'ui des actions - context.getActionFactory().loadActions(this); - - getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK), "quit"); - getRootPane().getActionMap().put("quit", context.getActionFactory().newAction("quit", null)); - - // repaint i18n actions - refreshI18nActions(context); - - } - - /** - * Rafraichit les actions i18n dans le menu en fonction de la locale - * actuellement utilis�e. - * - * @param context application context - */ - public void refreshI18nActions(DemoContext context) { - - Locale locale = context.getMainConfig().getLocale(); - //CountryEnum country = context.getConfig().getUserCountry(); - String[] actions = context.getActionFactory().getActionNames(); - for (String actionName : actions) { - Matcher matcher = ChangeLocaleAction.PATTERN_NAME.matcher(actionName); - if (!matcher.matches()) { - continue; - } - AbstractButton button = (AbstractButton) getObjectById(actionName); - ChangeLocaleAction action = (ChangeLocaleAction) button.getAction(); - boolean enable = !action.equalsLocale(locale); - log.debug("incoming locale : " + locale); - log.debug("load i18n action " + action + " is enable ? " + enable); - UpdateButton(button, enable, enable ? action.getLocale() : null); - button.setEnabled(enable); - } - } - - public static void DisableButton(AbstractButton... buttons) { - for (AbstractButton button : buttons) { - UpdateButton(button, false); - } - } - - public static void EnableButton(AbstractButton button, Object... params) { - UpdateButton(button, true, params); - } - - public static void UpdateButton(AbstractButton button, boolean enabled, Object... params) { - button.setEnabled(enabled); - if (!enabled) { - button.setToolTipText(null); - } else { - CommandLineAction action = (CommandLineAction) button.getAction(); - String t = _(action.getI18nToolTipText(), params); - button.setToolTipText(t); - } - } -}