[Buix-commits] r799 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: factory initializer
Author: tchemit Date: 2008-07-25 21:23:01 +0000 (Fri, 25 Jul 2008) New Revision: 799 Added: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionConfigurationResolver.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigConfigurationResolver.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigurationResolver.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigConfigurationResolver.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigConfigurationResolver.java Removed: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionInitializer.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigInitializer.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigInitializer.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java Log: rename ActionInitializer to ActionConfigurationResolver Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java 2008-07-25 21:21:46 UTC (rev 798) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java 2008-07-25 21:23:01 UTC (rev 799) @@ -23,11 +23,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codelutin.jaxx.action.MyAbstractAction; -import org.codelutin.jaxx.action.initializer.AbstractActionInitializer; -import org.codelutin.jaxx.action.initializer.ActionConfigInitializer; -import org.codelutin.jaxx.action.initializer.ActionInitializer; -import org.codelutin.jaxx.action.initializer.SelectActionConfigInitializer; -import org.codelutin.jaxx.action.initializer.ToggleActionConfigInitializer; +import org.codelutin.jaxx.action.initializer.AbstractActionConfigurationResolver; +import org.codelutin.jaxx.action.initializer.ActionConfigConfigurationResolver; +import org.codelutin.jaxx.action.initializer.ActionConfigurationResolver; +import org.codelutin.jaxx.action.initializer.SelectActionConfigConfigurationResolver; +import org.codelutin.jaxx.action.initializer.ToggleActionConfigConfigurationResolver; import javax.swing.AbstractButton; import javax.swing.Action; @@ -68,22 +68,22 @@ /** dictionary of instanciated actions */ private Map<String, A> cache; - protected final ActionConfigInitializer actionConfigInitializer; - protected final ToggleActionConfigInitializer toggleActionConfigInitializer; - protected final SelectActionConfigInitializer selectActionConfigInitializer; + protected final ActionConfigConfigurationResolver actionConfigInitializer; + protected final ToggleActionConfigConfigurationResolver toggleActionConfigInitializer; + protected final SelectActionConfigConfigurationResolver selectActionConfigInitializer; - protected List<AbstractActionInitializer> configurationResolvers; + protected List<AbstractActionConfigurationResolver> configurationResolvers; protected AbstractActionFactory(Class<A> baseImpl) { this.baseImpl = baseImpl; this.impls = init(); this.cache = new TreeMap<String, A>(); - this.configurationResolvers = new java.util.ArrayList<AbstractActionInitializer>(); + this.configurationResolvers = new java.util.ArrayList<AbstractActionConfigurationResolver>(); - this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigInitializer.class); - this.actionConfigInitializer = registerInitializer(ActionConfigInitializer.class); - this.selectActionConfigInitializer = registerInitializer(SelectActionConfigInitializer.class); + this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigConfigurationResolver.class); + this.actionConfigInitializer = registerInitializer(ActionConfigConfigurationResolver.class); + this.selectActionConfigInitializer = registerInitializer(SelectActionConfigConfigurationResolver.class); } public Class<A> getBaseImpl() { @@ -178,33 +178,33 @@ } // recherche de l'annotation de configuration - ActionInitializer<?, ?> initializer = resolveActionConfiguration(result); + ActionConfigurationResolver<?, ?> configurationResolver = resolveActionConfiguration(result); - if (initializer != null) { - initializer.applyConfiguration(component, result); + if (configurationResolver != null) { + configurationResolver.applyConfiguration(component, result); } try { - if (initializer != null) { - if (AbstractButton.class.isAssignableFrom(initializer.getComponentImpl())) { - finalizeNewAction((AbstractButton) component, result, initializer); + if (configurationResolver != null) { + if (AbstractButton.class.isAssignableFrom(configurationResolver.getComponentImpl())) { + finalizeNewAction((AbstractButton) component, result, configurationResolver); } - if (JComboBox.class.isAssignableFrom(initializer.getComponentImpl())) { - finalizeNewAction((JComboBox) component, result, initializer); + if (JComboBox.class.isAssignableFrom(configurationResolver.getComponentImpl())) { + finalizeNewAction((JComboBox) component, result, configurationResolver); } return result; } if (component == null || component instanceof AbstractButton) { - finalizeNewAction((AbstractButton) component, result, initializer); + finalizeNewAction((AbstractButton) component, result, configurationResolver); return result; } if (component instanceof JComboBox) { - finalizeNewAction((JComboBox) component, result, initializer); + finalizeNewAction((JComboBox) component, result, configurationResolver); } } finally { // save result in cache @@ -280,14 +280,14 @@ } /** - * @param component le button o� rattacher l'action - * @param action action - * @param initializer initializer + * @param component le button o� rattacher l'action + * @param action action + * @param configurationResolver initializer */ - protected void finalizeNewAction(AbstractButton component, MyAbstractAction action, ActionInitializer<?, ?> initializer) { + protected void finalizeNewAction(AbstractButton component, MyAbstractAction action, ActionConfigurationResolver<?, ?> configurationResolver) { - if (initializer == null) { - // no initializer matching, + if (configurationResolver == null) { + // no configurationResolver matching, if (component != null) { action.putValue(Action.ACTION_COMMAND_KEY, component.getName()); action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText()); @@ -323,13 +323,13 @@ } /** - * @param component le select box o� rattacher l'action - * @param action action - * @param initializer initializer + * @param component le select box o� rattacher l'action + * @param action action + * @param configurationResolver initializer */ - protected void finalizeNewAction(JComboBox component, MyAbstractAction action, ActionInitializer<?, ?> initializer) { + protected void finalizeNewAction(JComboBox component, MyAbstractAction action, ActionConfigurationResolver<?, ?> configurationResolver) { - if (initializer == null) { + if (configurationResolver == null) { action.putValue(Action.ACTION_COMMAND_KEY, component.getName()); action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText()); //result.putValue("selectedIndex", component.getSelectedIndex()); @@ -337,8 +337,8 @@ } - protected ActionInitializer resolveActionConfiguration(MyAbstractAction action) { - for (ActionInitializer resolver : configurationResolvers) { + protected ActionConfigurationResolver resolveActionConfiguration(MyAbstractAction action) { + for (ActionConfigurationResolver resolver : configurationResolvers) { if (resolver.resolveConfiguration(action) != null) { return resolver; } @@ -346,7 +346,7 @@ return null; } - protected <I extends AbstractActionInitializer> I registerInitializer(Class<I> initizalizer) { + protected <I extends AbstractActionConfigurationResolver> I registerInitializer(Class<I> initizalizer) { try { I instance = initizalizer.newInstance(); configurationResolvers.add(instance); Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionConfigurationResolver.java (from rev 797, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionInitializer.java) =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionConfigurationResolver.java (rev 0) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionConfigurationResolver.java 2008-07-25 21:23:01 UTC (rev 799) @@ -0,0 +1,72 @@ +/** + * # #% 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.jaxx.action.initializer; + +import org.codelutin.jaxx.action.MyAbstractAction; + +import javax.swing.JComponent; + +/** + * Common abstract class of a resolver of action configuration. + * <p/> + * The class implements the logic of research of the configuration annotation. + * + * @author chemit + */ +public abstract class AbstractActionConfigurationResolver<A extends java.lang.annotation.Annotation, C extends JComponent> implements ActionConfigurationResolver<A, C> { + + /** the type of configuration's annotation */ + protected final Class<A> annotationImpl; + + /** the type of component that can fire an action */ + protected final Class<C> componentImpl; + + /** + * The typed method (on component) to apply configuration on the action and component. + * + * @param component the component which fires the action + * @param action the given action + * @return the configuration's annotation + */ + protected abstract A applyConfiguration0(C component, MyAbstractAction action); + + protected AbstractActionConfigurationResolver(Class<A> annotationImpl, Class<C> componentImpl) { + this.annotationImpl = annotationImpl; + this.componentImpl = componentImpl; + } + + public A resolveConfiguration(MyAbstractAction action) { + if (action.hasDelegate()) { + return resolveConfiguration(action.getDelegate()); + } + return action.getClass().getAnnotation(annotationImpl); + } + + @SuppressWarnings({"unchecked"}) + public A applyConfiguration(JComponent component, MyAbstractAction action) { + if (component != null && componentImpl.isAssignableFrom(component.getClass())) + return applyConfiguration0((C) component, action); + + return null; + } + + public Class<A> getAnnotationImpl() { + return annotationImpl; + } + + public Class<C> getComponentImpl() { + return componentImpl; + } +} Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionInitializer.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionInitializer.java 2008-07-25 21:21:46 UTC (rev 798) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionInitializer.java 2008-07-25 21:23:01 UTC (rev 799) @@ -1,72 +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.jaxx.action.initializer; - -import org.codelutin.jaxx.action.MyAbstractAction; - -import javax.swing.JComponent; - -/** - * Common abstract class of a resolver of action configuration. - * <p/> - * The class implements the logic of research of the configuration annotation. - * - * @author chemit - */ -public abstract class AbstractActionInitializer<A extends java.lang.annotation.Annotation, C extends JComponent> implements ActionInitializer<A, C> { - - /** the type of configuration's annotation */ - protected final Class<A> annotationImpl; - - /** the type of component that can fire an action */ - protected final Class<C> componentImpl; - - /** - * The typed method (on component) to apply configuration on the action and component. - * - * @param component the component which fires the action - * @param action the given action - * @return the configuration's annotation - */ - protected abstract A applyConfiguration0(C component, MyAbstractAction action); - - protected AbstractActionInitializer(Class<A> annotationImpl, Class<C> componentImpl) { - this.annotationImpl = annotationImpl; - this.componentImpl = componentImpl; - } - - public A resolveConfiguration(MyAbstractAction action) { - if (action.hasDelegate()) { - return resolveConfiguration(action.getDelegate()); - } - return action.getClass().getAnnotation(annotationImpl); - } - - @SuppressWarnings({"unchecked"}) - public A applyConfiguration(JComponent component, MyAbstractAction action) { - if (component != null && componentImpl.isAssignableFrom(component.getClass())) - return applyConfiguration0((C) component, action); - - return null; - } - - public Class<A> getAnnotationImpl() { - return annotationImpl; - } - - public Class<C> getComponentImpl() { - return componentImpl; - } -} Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigConfigurationResolver.java (from rev 797, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigInitializer.java) =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigConfigurationResolver.java (rev 0) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigConfigurationResolver.java 2008-07-25 21:23:01 UTC (rev 799) @@ -0,0 +1,69 @@ +/** + * # #% 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.jaxx.action.initializer; + +import static org.codelutin.i18n.I18n._; +import org.codelutin.jaxx.action.ActionConfig; +import org.codelutin.jaxx.action.MyAbstractAction; + +import javax.swing.AbstractButton; +import javax.swing.Action; + +/** + * Implementation of configuration's resolver for annotation {@link ActionConfig} + * + * @author chemit + */ +public class ActionConfigConfigurationResolver extends AbstractActionConfigurationResolver<ActionConfig, AbstractButton> { + + public ActionConfigConfigurationResolver() { + super(ActionConfig.class, AbstractButton.class); + } + + protected ActionConfig applyConfiguration0(AbstractButton component, MyAbstractAction action) { + ActionConfig anno = resolveConfiguration(action); + if (anno == null) { + return null; + } + // inject les donn�es + if (!anno.name().isEmpty()) { + //System.out.println("found action with name : " + anno.name()); + action.putValue(Action.NAME, _(anno.name())); + } + //if (!anno.shortDescription().isEmpty()) { + action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription())); + //} + if (!anno.smallIcon().isEmpty()) { + action.putValue(Action.SMALL_ICON, org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon())); + } + if (anno.mnemonic() != '\0') { + action.putValue(Action.MNEMONIC_KEY, anno.mnemonic()); + } else if (component != null) { + action.putValue(Action.MNEMONIC_KEY, component.getMnemonic()); + } + //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator()); + + if (component == null) { + action.putValue("hideActionText", anno.hideActionText()); + } else { + boolean actionText = component.getHideActionText(); + action.putValue("hideActionText", anno.hideActionText() || actionText); + } + action.putValue(Action.SELECTED_KEY, anno.selected()); + action.setEnabled(anno.enabled()); + + return anno; + } +} Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigInitializer.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigInitializer.java 2008-07-25 21:21:46 UTC (rev 798) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigInitializer.java 2008-07-25 21:23:01 UTC (rev 799) @@ -1,69 +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.jaxx.action.initializer; - -import static org.codelutin.i18n.I18n._; -import org.codelutin.jaxx.action.ActionConfig; -import org.codelutin.jaxx.action.MyAbstractAction; - -import javax.swing.AbstractButton; -import javax.swing.Action; - -/** - * Implementation of configuration's resolver for annotation {@link ActionConfig} - * - * @author chemit - */ -public class ActionConfigInitializer extends AbstractActionInitializer<ActionConfig, AbstractButton> { - - public ActionConfigInitializer() { - super(ActionConfig.class, AbstractButton.class); - } - - protected ActionConfig applyConfiguration0(AbstractButton component, MyAbstractAction action) { - ActionConfig anno = resolveConfiguration(action); - if (anno == null) { - return null; - } - // inject les donn�es - if (!anno.name().isEmpty()) { - //System.out.println("found action with name : " + anno.name()); - action.putValue(Action.NAME, _(anno.name())); - } - //if (!anno.shortDescription().isEmpty()) { - action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription())); - //} - if (!anno.smallIcon().isEmpty()) { - action.putValue(Action.SMALL_ICON, org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon())); - } - if (anno.mnemonic() != '\0') { - action.putValue(Action.MNEMONIC_KEY, anno.mnemonic()); - } else if (component != null) { - action.putValue(Action.MNEMONIC_KEY, component.getMnemonic()); - } - //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator()); - - if (component == null) { - action.putValue("hideActionText", anno.hideActionText()); - } else { - boolean actionText = component.getHideActionText(); - action.putValue("hideActionText", anno.hideActionText() || actionText); - } - action.putValue(Action.SELECTED_KEY, anno.selected()); - action.setEnabled(anno.enabled()); - - return anno; - } -} Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigurationResolver.java (from rev 797, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java) =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigurationResolver.java (rev 0) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigurationResolver.java 2008-07-25 21:23:01 UTC (rev 799) @@ -0,0 +1,54 @@ +/** + * # #% 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.jaxx.action.initializer; + +import org.codelutin.jaxx.action.MyAbstractAction; + +import javax.swing.JComponent; + +/** + * The contract to be realized to resolve an {@link MyAbstractAction} configuration. + * <p/> + * Configuration is done by a Annotation of type {@link A} placed on the action class. + * <p/> + * If the instanciated action box the real action, we should always search on the boxed action. + * <p/> + * Moreover, a action can only be fired by a certain type of component (for example a Button or a ComboBox), the class + * of the component type is given by the {@link C} class. + * + * @author chemit + */ +public interface ActionConfigurationResolver<A extends java.lang.annotation.Annotation, C extends JComponent> { + /** + * Search the annotation that configure the given action (or the boxed action). + * + * @param action current action + * @return the configuration of the action + */ + A resolveConfiguration(MyAbstractAction action); + + /** + * @param component widget that requires the action + * @param action given action + * @return the configuration of the action + */ + A applyConfiguration(JComponent component, MyAbstractAction action); + + /** @return the configuration annotation dealed by this resolver */ + Class<A> getAnnotationImpl(); + + /** @return the class of the component which can fired the action */ + Class<C> getComponentImpl(); +} Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java 2008-07-25 21:21:46 UTC (rev 798) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java 2008-07-25 21:23:01 UTC (rev 799) @@ -1,54 +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.jaxx.action.initializer; - -import org.codelutin.jaxx.action.MyAbstractAction; - -import javax.swing.JComponent; - -/** - * The contract to be realized to resolve an {@link MyAbstractAction} configuration. - * <p/> - * Configuration is done by a Annotation of type {@link A} placed on the action class. - * <p/> - * If the instanciated action box the real action, we should always search on the boxed action. - * <p/> - * Moreover, a action can only be fired by a certain type of component (for example a Button or a ComboBox), the class - * of the component type is given by the {@link C} class. - * - * @author chemit - */ -public interface ActionInitializer<A extends java.lang.annotation.Annotation, C extends JComponent> { - /** - * Search the annotation that configure the given action (or the boxed action). - * - * @param action current action - * @return the configuration of the action - */ - A resolveConfiguration(MyAbstractAction action); - - /** - * @param component widget that requires the action - * @param action given action - * @return the configuration of the action - */ - A applyConfiguration(JComponent component, MyAbstractAction action); - - /** @return the configuration annotation dealed by this resolver */ - Class<A> getAnnotationImpl(); - - /** @return the class of the component which can fired the action */ - Class<C> getComponentImpl(); -} Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigConfigurationResolver.java (from rev 797, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigInitializer.java) =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigConfigurationResolver.java (rev 0) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigConfigurationResolver.java 2008-07-25 21:23:01 UTC (rev 799) @@ -0,0 +1,55 @@ +/** + * # #% 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.jaxx.action.initializer; + +import static org.codelutin.i18n.I18n._; +import org.codelutin.jaxx.action.MyAbstractAction; +import org.codelutin.jaxx.action.SelectActionConfig; + +import javax.swing.Action; +import javax.swing.JComboBox; + +/** + * Implementation of configuration's resolver for annotation {@link SelectActionConfig} + * + * @author chemit + */ +public class SelectActionConfigConfigurationResolver extends AbstractActionConfigurationResolver<SelectActionConfig, JComboBox> { + + public SelectActionConfigConfigurationResolver() { + super(SelectActionConfig.class, JComboBox.class); + } + + protected SelectActionConfig applyConfiguration0(JComboBox component, MyAbstractAction action) { + SelectActionConfig anno = resolveConfiguration(action); + if (anno == null) { + return null; + } + // inject les donn�es + if (!anno.name().isEmpty()) { + action.putValue(Action.NAME, _(anno.name())); + } + if (!anno.shortDescription().isEmpty()) { + action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription())); + } else { + action.putValue(Action.SHORT_DESCRIPTION, _(component.getToolTipText())); + } + action.putValue("selectedIndex", anno.selectedIndex()); + //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator()); + action.setEnabled(anno.enabled()); + + return anno; + } +} \ No newline at end of file Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigInitializer.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigInitializer.java 2008-07-25 21:21:46 UTC (rev 798) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigInitializer.java 2008-07-25 21:23:01 UTC (rev 799) @@ -1,55 +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.jaxx.action.initializer; - -import static org.codelutin.i18n.I18n._; -import org.codelutin.jaxx.action.MyAbstractAction; -import org.codelutin.jaxx.action.SelectActionConfig; - -import javax.swing.Action; -import javax.swing.JComboBox; - -/** - * Implementation of configuration's resolver for annotation {@link SelectActionConfig} - * - * @author chemit - */ -public class SelectActionConfigInitializer extends AbstractActionInitializer<SelectActionConfig, JComboBox> { - - public SelectActionConfigInitializer() { - super(SelectActionConfig.class, JComboBox.class); - } - - protected SelectActionConfig applyConfiguration0(JComboBox component, MyAbstractAction action) { - SelectActionConfig anno = resolveConfiguration(action); - if (anno == null) { - return null; - } - // inject les donn�es - if (!anno.name().isEmpty()) { - action.putValue(Action.NAME, _(anno.name())); - } - if (!anno.shortDescription().isEmpty()) { - action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription())); - } else { - action.putValue(Action.SHORT_DESCRIPTION, _(component.getToolTipText())); - } - action.putValue("selectedIndex", anno.selectedIndex()); - //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator()); - action.setEnabled(anno.enabled()); - - return anno; - } -} \ No newline at end of file Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigConfigurationResolver.java (from rev 797, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java) =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigConfigurationResolver.java (rev 0) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigConfigurationResolver.java 2008-07-25 21:23:01 UTC (rev 799) @@ -0,0 +1,81 @@ +/** + * # #% 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.jaxx.action.initializer; + +import static org.codelutin.i18n.I18n._; +import org.codelutin.jaxx.action.MyAbstractAction; +import org.codelutin.jaxx.action.ToggleActionConfig; + +import javax.swing.AbstractButton; +import javax.swing.Action; + +/** + * Implementation of configuration's resolver for annotation {@link ToggleActionConfig} + * + * @author chemit + */ +public class ToggleActionConfigConfigurationResolver extends AbstractActionConfigurationResolver<ToggleActionConfig, AbstractButton> { + + public ToggleActionConfigConfigurationResolver() { + super(ToggleActionConfig.class, AbstractButton.class); + } + + protected ToggleActionConfig applyConfiguration0(AbstractButton component, MyAbstractAction action) { + ToggleActionConfig anno = resolveConfiguration(action); + if (anno == null) { + return null; + } + // inject les donn�es + if (!anno.name().isEmpty()) { + //System.out.println("found action with name : " + anno.name()); + action.putValue(Action.NAME, _(anno.name())); + } + if (!anno.name2().isEmpty()) { + //System.out.println("found action with name2 : " + anno.name2()); + action.putValue(Action.NAME + "2", _(anno.name2())); + } + + if (!anno.shortDescription().isEmpty()) { + action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription())); + } + if (!anno.shortDescription2().isEmpty()) { + action.putValue(Action.SHORT_DESCRIPTION + "2", _(anno.shortDescription2())); + } + + if (!anno.smallIcon().isEmpty()) { + action.putValue(Action.SMALL_ICON, org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon())); + } + if (!anno.smallIcon2().isEmpty()) { + action.putValue(Action.SMALL_ICON + "2", org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon2())); + } + + if (anno.mnemonic() != '\0') { + action.putValue(Action.MNEMONIC_KEY, anno.mnemonic()); + } else if (component != null) { + action.putValue(Action.MNEMONIC_KEY, component.getMnemonic()); + } + if (anno.mnemonic2() != '\0') { + action.putValue(Action.MNEMONIC_KEY + "2", anno.mnemonic2()); + } + //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator()); + + + action.putValue("hideActionText", anno.hideActionText()); + action.putValue(Action.SELECTED_KEY, anno.selected()); + action.setEnabled(anno.enabled()); + + return anno; + } +} \ No newline at end of file Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java 2008-07-25 21:21:46 UTC (rev 798) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java 2008-07-25 21:23:01 UTC (rev 799) @@ -1,81 +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.jaxx.action.initializer; - -import static org.codelutin.i18n.I18n._; -import org.codelutin.jaxx.action.MyAbstractAction; -import org.codelutin.jaxx.action.ToggleActionConfig; - -import javax.swing.AbstractButton; -import javax.swing.Action; - -/** - * Implementation of configuration's resolver for annotation {@link ToggleActionConfig} - * - * @author chemit - */ -public class ToggleActionConfigInitializer extends AbstractActionInitializer<ToggleActionConfig, AbstractButton> { - - public ToggleActionConfigInitializer() { - super(ToggleActionConfig.class, AbstractButton.class); - } - - protected ToggleActionConfig applyConfiguration0(AbstractButton component, MyAbstractAction action) { - ToggleActionConfig anno = resolveConfiguration(action); - if (anno == null) { - return null; - } - // inject les donn�es - if (!anno.name().isEmpty()) { - //System.out.println("found action with name : " + anno.name()); - action.putValue(Action.NAME, _(anno.name())); - } - if (!anno.name2().isEmpty()) { - //System.out.println("found action with name2 : " + anno.name2()); - action.putValue(Action.NAME + "2", _(anno.name2())); - } - - if (!anno.shortDescription().isEmpty()) { - action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription())); - } - if (!anno.shortDescription2().isEmpty()) { - action.putValue(Action.SHORT_DESCRIPTION + "2", _(anno.shortDescription2())); - } - - if (!anno.smallIcon().isEmpty()) { - action.putValue(Action.SMALL_ICON, org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon())); - } - if (!anno.smallIcon2().isEmpty()) { - action.putValue(Action.SMALL_ICON + "2", org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon2())); - } - - if (anno.mnemonic() != '\0') { - action.putValue(Action.MNEMONIC_KEY, anno.mnemonic()); - } else if (component != null) { - action.putValue(Action.MNEMONIC_KEY, component.getMnemonic()); - } - if (anno.mnemonic2() != '\0') { - action.putValue(Action.MNEMONIC_KEY + "2", anno.mnemonic2()); - } - //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator()); - - - action.putValue("hideActionText", anno.hideActionText()); - action.putValue(Action.SELECTED_KEY, anno.selected()); - action.setEnabled(anno.enabled()); - - return anno; - } -} \ No newline at end of file
participants (1)
-
tchemit@users.labs.libre-entreprise.org