Buix-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
July 2008
- 1 participants
- 124 discussions
r786 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 18:50:03 +0000 (Thu, 24 Jul 2008)
New Revision: 786
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/IActionFactory.java
Log:
introduction ActionFactory interface
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java (from rev 783, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/IActionFactory.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java 2008-07-24 18:50:03 UTC (rev 786)
@@ -0,0 +1,47 @@
+/**
+ * # #% 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.factory;
+
+import jaxx.runtime.JAXXObject;
+import org.codelutin.jaxx.action.MyAbstractAction;
+
+import javax.swing.JComponent;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/** @author chemit */
+public interface ActionFactory {
+ void resetCache();
+
+ MyAbstractAction get(String actionKey);
+
+ MyAbstractAction[] loadActions(JAXXObject ui);
+
+ MyAbstractAction newAction(String actionKey, JComponent component);
+
+ String[] getActionNames();
+
+ Set<Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet();
+
+ Set<Entry<String, MyAbstractAction>> cacheEntrySet();
+
+ void fireAction(String actionKey, Object source, JComponent component);
+
+ void fireAction(String actionKey, Object source);
+
+ MyAbstractAction getActionFromCache(String actionKey);
+
+ void dispose();
+}
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/IActionFactory.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/IActionFactory.java 2008-07-24 18:49:32 UTC (rev 785)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/IActionFactory.java 2008-07-24 18:50:03 UTC (rev 786)
@@ -1,47 +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.factory;
-
-import jaxx.runtime.JAXXObject;
-import org.codelutin.jaxx.action.MyAbstractAction;
-
-import javax.swing.JComponent;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/** @author chemit */
-public interface IActionFactory {
- void resetCache();
-
- MyAbstractAction get(String actionKey);
-
- MyAbstractAction[] loadActions(JAXXObject ui);
-
- MyAbstractAction newAction(String actionKey, JComponent component);
-
- String[] getActionNames();
-
- Set<Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet();
-
- Set<Entry<String, MyAbstractAction>> cacheEntrySet();
-
- void fireAction(String actionKey, Object source, JComponent component);
-
- void fireAction(String actionKey, Object source);
-
- MyAbstractAction getActionFromCache(String actionKey);
-
- void dispose();
-}
1
0
r785 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 18:49:32 +0000 (Thu, 24 Jul 2008)
New Revision: 785
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java
Log:
introduction ActionFactory interface
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java 2008-07-24 18:49:25 UTC (rev 784)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java 2008-07-24 18:49:32 UTC (rev 785)
@@ -25,7 +25,7 @@
import java.util.TreeMap;
/**
- * A simple implementation of {@link ActionFactory} using a properties file to
+ * A simple implementation of {@link AbstractActionFactory} using a properties file to
* load action mapping.
* <p/>
* An entry is in that form : <code>action.actionName=fqn</code> where
@@ -35,7 +35,7 @@
*
* @author chemit
*/
-public class ActionFactoryFromProvider<A extends MyAbstractAction> extends ActionFactory<A> {
+public class ActionFactoryFromProvider<A extends MyAbstractAction> extends AbstractActionFactory<A> {
public static <A extends MyAbstractAction> ActionFactoryFromProvider<A> newInstance(Class<A> klazz) {
return new ActionFactoryFromProvider<A>(klazz);
1
0
r784 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 18:49:25 +0000 (Thu, 24 Jul 2008)
New Revision: 784
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java
Log:
introduction ActionFactory interface
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java (from rev 783, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java 2008-07-24 18:49:25 UTC (rev 784)
@@ -0,0 +1,386 @@
+/*
+* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 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.factory;
+
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.swing.JAXXToggleButton;
+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 javax.swing.AbstractAction;
+import javax.swing.AbstractButton;
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import java.awt.event.ActionEvent;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+/**
+ * Action factory using the ActionConfig annotations to configure the action.
+ * <p/>
+ * The factory is abstract, implements method {@link #init()} to fill the
+ * dictonary of known action implementations.
+ * <p/>
+ * Use after the {@link #loadActions(jaxx.runtime.JAXXObject)} to instanciate
+ * actions in ui with id equals a known action...
+ * <p/>
+ * TODO Finish doc
+ *
+ * @author chemit
+ */
+public abstract class AbstractActionFactory<A extends MyAbstractAction> implements IActionFactory {
+
+ protected static Log log = LogFactory.getLog(AbstractActionFactory.class);
+
+ /** class of encapsuling action */
+ protected Class<A> baseImpl;
+
+ /** dictionary of known actions implementations */
+ private Map<String, Class<? extends MyAbstractAction>> impls;
+
+ /** dictionary of instanciated actions */
+ private Map<String, MyAbstractAction> cache;
+
+ protected final ActionConfigInitializer actionConfigInitializer;
+ protected final ToggleActionConfigInitializer toggleActionConfigInitializer;
+ protected final SelectActionConfigInitializer selectActionConfigInitializer;
+
+ /**
+ * Method to init the dictionary of knwon action implementations.
+ *
+ * @return the dictionary of known action implementations
+ */
+ protected abstract Map<String, Class<? extends MyAbstractAction>> init();
+
+ protected List<AbstractActionInitializer> registredInitializers;
+
+
+ protected AbstractActionFactory(Class<A> baseImpl) {
+ this.baseImpl = baseImpl;
+ this.impls = init();
+ this.cache = new TreeMap<String, MyAbstractAction>();
+ this.registredInitializers = new java.util.ArrayList<AbstractActionInitializer>();
+
+ this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigInitializer.class);
+ this.actionConfigInitializer = registerInitializer(ActionConfigInitializer.class);
+ this.selectActionConfigInitializer = registerInitializer(SelectActionConfigInitializer.class);
+ }
+
+ public void resetCache() {
+ cache.clear();
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ resetCache();
+ impls.clear();
+ }
+
+ public MyAbstractAction get(String actionKey) {
+ return cache.get(actionKey);
+ }
+
+ public MyAbstractAction[] loadActions(JAXXObject ui) {
+ if (log.isDebugEnabled()) {
+ log.debug("for ui " + ui.getClass());
+ }
+ List<MyAbstractAction> result = new ArrayList<MyAbstractAction>();
+ for (Map.Entry<String, Class<? extends MyAbstractAction>> entry : implsEntrySet()) {
+ String actionKey = entry.getKey();
+ Object comp = ui.getObjectById(actionKey);
+ if (comp == null || !(comp instanceof AbstractButton || comp instanceof JComboBox)) {
+ // nothing to do
+ continue;
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("detect action " + actionKey);
+ }
+ if (comp instanceof AbstractButton) {
+ AbstractButton component = (AbstractButton) comp;
+ MyAbstractAction action = newAction(actionKey, component);
+
+ component.setAction(action);
+
+ if (component instanceof JAXXToggleButton) {
+ JAXXToggleButton glueComponent = (JAXXToggleButton) component;
+ glueComponent.setIcon((Icon) action.getValue(Action.SMALL_ICON));
+ Integer integer = (Integer) action.getValue(Action.MNEMONIC_KEY);
+ if (integer != null) {
+ glueComponent.setNormalMnemonic(integer);
+ }
+ glueComponent.setSelectedIcon((Icon) action.getValue(Action.SMALL_ICON + 2));
+ integer = (Integer) action.getValue(Action.MNEMONIC_KEY + 2);
+ if (integer != null) {
+ glueComponent.setGlueMnemonic(integer);
+ }
+ glueComponent.setGlueText((String) action.getValue(Action.NAME + 2));
+ glueComponent.setGlueTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION + 2));
+
+ glueComponent.setNormalText((String) action.getValue(Action.NAME));
+ glueComponent.setNormalTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION));
+ }
+
+ Boolean value = (Boolean) action.getValue("hideActionText");
+ component.setHideActionText(value != null && value);
+ action.setEnabled(true);
+ result.add(action);
+ continue;
+ }
+ // is JComboBox
+ JComboBox component = (JComboBox) comp;
+ MyAbstractAction action = newAction(actionKey, component);
+
+ component.setAction(action);
+ Integer val = (Integer) action.getValue("selectedIndex");
+ if (val != null && val != -1 && val < component.getItemCount() && val != component.getSelectedIndex()) {
+ component.setSelectedIndex(val);
+ }
+ result.add(action);
+ }
+ return result.toArray(new MyAbstractAction[result.size()]);
+ }
+
+ /**
+ * @param actionKey le nom de l'action tel que d�finie dans le fichier
+ * de mapping (sans le prefix action.)
+ * @param component le button o� rattacher l'action
+ * @return une nouvelle instance de l'action associ�e � sa clef.
+ */
+ public MyAbstractAction newAction(String actionKey, JComponent component) {
+ // try first in cache
+ MyAbstractAction result = getActionFromCache(actionKey);
+ if (result != null) {
+ return result;
+ }
+
+ try {
+ result = newActionInstance(actionKey);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("create <" + actionKey + " : " + result + ">");
+ }
+
+ // recherche de l'annotation de configuration
+ ActionInitializer<?, ?> initializer = findInitializer(result.getClass());
+
+ if (initializer != null) {
+ initializer.initAction(component, result);
+ }
+
+ try {
+
+ if (initializer != null) {
+ if (AbstractButton.class.isAssignableFrom(initializer.getComponentImpl())) {
+ finalizeNewAction((AbstractButton) component, result, initializer);
+ }
+
+ if (JComboBox.class.isAssignableFrom(initializer.getComponentImpl())) {
+ finalizeNewAction((JComboBox) component, result, initializer);
+ }
+
+ return result;
+ }
+
+ if (component == null || component instanceof AbstractButton) {
+ finalizeNewAction((AbstractButton) component, result, initializer);
+ return result;
+ }
+
+ if (component instanceof JComboBox) {
+ finalizeNewAction((JComboBox) component, result, initializer);
+ }
+ } finally {
+ // save result in cache
+ cache.put(actionKey, result);
+ }
+
+ return result;
+ }
+
+ public String[] getActionNames() {
+ return impls.keySet().toArray(new String[impls.size()]);
+ }
+
+ public Set<Map.Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet() {
+ return impls.entrySet();
+ }
+
+ public Set<Map.Entry<String, MyAbstractAction>> cacheEntrySet() {
+ return cache.entrySet();
+ }
+
+ public void fireAction(String actionKey, Object source, JComponent component) {
+ AbstractAction action = newAction(actionKey, component);
+ fireAction0(actionKey, source, action);
+ }
+
+ public void fireAction(String actionKey, Object source) {
+ fireAction(actionKey, source, null);
+ }
+
+ /**
+ * @param actionKey la clef de l'action
+ * @return l'action deja stockee dans le cache d'action, ou <code>null</code> si non trouv�e.
+ */
+ public MyAbstractAction getActionFromCache(String actionKey) {
+ // on v�rifie que l'action existe bien
+ checkRegistredAction(actionKey);
+
+ // try in cache
+ if (cache.containsKey(actionKey)) {
+ // use cached action
+ MyAbstractAction action = cache.get(actionKey);
+ if (log.isDebugEnabled()) {
+ log.debug("use cache action " + action);
+ }
+ return action;
+ }
+ return null;
+ }
+
+ public void dispose() {
+ if (log.isInfoEnabled()) {
+ log.info(this);
+ }
+ for (String actionKey : getActionNames()) {
+ MyAbstractAction action = getActionFromCache(actionKey);
+ if (action != null) {
+ action.disposeUI();
+ }
+ }
+ resetCache();
+ }
+
+ /**
+ * @param component le button o� rattacher l'action
+ * @param action action
+ * @param initializer initializer
+ */
+ protected void finalizeNewAction(AbstractButton component, MyAbstractAction action, ActionInitializer<?, ?> initializer) {
+
+ if (initializer == null) {
+ // no initializer matching,
+ if (component != null) {
+ action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
+ action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
+ action.putValue(Action.SMALL_ICON, component.getIcon());
+ action.putValue(Action.NAME, component.getText());
+ action.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
+ action.putValue("hideActionText", component.getHideActionText());
+ if (component instanceof JAXXToggleButton) {
+ JAXXToggleButton glueComponent = (JAXXToggleButton) component;
+ action.putValue(Action.SHORT_DESCRIPTION, glueComponent.getNormalTooltipText());
+ action.putValue(Action.NAME, glueComponent.getNormalText());
+ action.putValue(Action.SMALL_ICON, glueComponent.getIcon());
+ action.putValue(Action.MNEMONIC_KEY, glueComponent.getNormalMnemonic());
+ action.putValue(Action.SHORT_DESCRIPTION + 2, glueComponent.getGlueTooltipText());
+ action.putValue(Action.NAME + 2, glueComponent.getGlueText());
+ action.putValue(Action.SMALL_ICON + 2, glueComponent.getSelectedIcon());
+ action.putValue(Action.MNEMONIC_KEY + 2, glueComponent.getGlueMnemonic());
+ }
+ }
+
+ }
+
+ String text = (String) action.getValue(Action.NAME);
+ Integer mnemo = (Integer) action.getValue(Action.MNEMONIC_KEY);
+ if (mnemo != null && mnemo != '\0') {
+ int pos = text.indexOf((char) mnemo.intValue());
+ if (pos == -1) {
+ pos = text.indexOf(Character.toLowerCase((char) mnemo.intValue()));
+ }
+ action.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, pos);
+ }
+
+ }
+
+ /**
+ * @param component le select box o� rattacher l'action
+ * @param action action
+ * @param initializer initializer
+ */
+ protected void finalizeNewAction(JComboBox component, MyAbstractAction action, ActionInitializer<?, ?> initializer) {
+
+ if (initializer == null) {
+ action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
+ action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
+ //result.putValue("selectedIndex", component.getSelectedIndex());
+ }
+
+ }
+
+ protected ActionInitializer findInitializer(Class<? extends AbstractAction> action) {
+ for (ActionInitializer registredInitializer : registredInitializers) {
+ if (registredInitializer.getAnnotation(action) != null) {
+ return registredInitializer;
+ }
+ }
+ return null;
+ }
+
+ protected <I extends AbstractActionInitializer> I registerInitializer(Class<I> initizalizer) {
+ try {
+ I instance = initizalizer.newInstance();
+ registredInitializers.add(instance);
+ return instance;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected void fireAction0(String actionKey, Object source, AbstractAction action) {
+ if (action == null) {
+ log.warn("could not find action " + actionKey);
+ return;
+ }
+ ActionEvent event = new ActionEvent(source, ActionEvent.ACTION_FIRST, actionKey);
+ action.actionPerformed(event);
+ }
+
+ protected void checkRegistredAction(String actionKey) {
+ if (!impls.containsKey(actionKey)) {
+ throw new IllegalStateException("can not find a registered action for key " + actionKey);
+ }
+ }
+
+
+ protected MyAbstractAction newActionInstance(String actionKey) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
+ Class<? extends MyAbstractAction> klazz = impls.get(actionKey);
+ MyAbstractAction result;
+ result = klazz.getConstructor(String.class).newInstance(actionKey);
+ result.putValue(Action.ACTION_COMMAND_KEY, actionKey);
+ return result;
+ }
+}
\ No newline at end of file
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java 2008-07-24 18:48:55 UTC (rev 783)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java 2008-07-24 18:49:25 UTC (rev 784)
@@ -1,386 +0,0 @@
-/*
-* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 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.factory;
-
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.swing.JAXXToggleButton;
-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 javax.swing.AbstractAction;
-import javax.swing.AbstractButton;
-import javax.swing.Action;
-import javax.swing.Icon;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import java.awt.event.ActionEvent;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-/**
- * Action factory using the ActionConfig annotations to configure the action.
- * <p/>
- * The factory is abstract, implements method {@link #init()} to fill the
- * dictonary of known action implementations.
- * <p/>
- * Use after the {@link #loadActions(jaxx.runtime.JAXXObject)} to instanciate
- * actions in ui with id equals a known action...
- * <p/>
- * TODO Finish doc
- *
- * @author chemit
- */
-public abstract class ActionFactory<A extends MyAbstractAction> implements IActionFactory {
-
- protected static Log log = LogFactory.getLog(ActionFactory.class);
-
- /** class of encapsuling action */
- protected Class<A> baseImpl;
-
- /** dictionary of known actions implementations */
- private Map<String, Class<? extends MyAbstractAction>> impls;
-
- /** dictionary of instanciated actions */
- private Map<String, MyAbstractAction> cache;
-
- protected final ActionConfigInitializer actionConfigInitializer;
- protected final ToggleActionConfigInitializer toggleActionConfigInitializer;
- protected final SelectActionConfigInitializer selectActionConfigInitializer;
-
- /**
- * Method to init the dictionary of knwon action implementations.
- *
- * @return the dictionary of known action implementations
- */
- protected abstract Map<String, Class<? extends MyAbstractAction>> init();
-
- protected List<AbstractActionInitializer> registredInitializers;
-
-
- protected ActionFactory(Class<A> baseImpl) {
- this.baseImpl = baseImpl;
- this.impls = init();
- this.cache = new TreeMap<String, MyAbstractAction>();
- this.registredInitializers = new java.util.ArrayList<AbstractActionInitializer>();
-
- this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigInitializer.class);
- this.actionConfigInitializer = registerInitializer(ActionConfigInitializer.class);
- this.selectActionConfigInitializer = registerInitializer(SelectActionConfigInitializer.class);
- }
-
- public void resetCache() {
- cache.clear();
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- resetCache();
- impls.clear();
- }
-
- public MyAbstractAction get(String actionKey) {
- return cache.get(actionKey);
- }
-
- public MyAbstractAction[] loadActions(JAXXObject ui) {
- if (log.isDebugEnabled()) {
- log.debug("for ui " + ui.getClass());
- }
- List<MyAbstractAction> result = new ArrayList<MyAbstractAction>();
- for (Map.Entry<String, Class<? extends MyAbstractAction>> entry : implsEntrySet()) {
- String actionKey = entry.getKey();
- Object comp = ui.getObjectById(actionKey);
- if (comp == null || !(comp instanceof AbstractButton || comp instanceof JComboBox)) {
- // nothing to do
- continue;
- }
- if (log.isTraceEnabled()) {
- log.trace("detect action " + actionKey);
- }
- if (comp instanceof AbstractButton) {
- AbstractButton component = (AbstractButton) comp;
- MyAbstractAction action = newAction(actionKey, component);
-
- component.setAction(action);
-
- if (component instanceof JAXXToggleButton) {
- JAXXToggleButton glueComponent = (JAXXToggleButton) component;
- glueComponent.setIcon((Icon) action.getValue(Action.SMALL_ICON));
- Integer integer = (Integer) action.getValue(Action.MNEMONIC_KEY);
- if (integer != null) {
- glueComponent.setNormalMnemonic(integer);
- }
- glueComponent.setSelectedIcon((Icon) action.getValue(Action.SMALL_ICON + 2));
- integer = (Integer) action.getValue(Action.MNEMONIC_KEY + 2);
- if (integer != null) {
- glueComponent.setGlueMnemonic(integer);
- }
- glueComponent.setGlueText((String) action.getValue(Action.NAME + 2));
- glueComponent.setGlueTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION + 2));
-
- glueComponent.setNormalText((String) action.getValue(Action.NAME));
- glueComponent.setNormalTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION));
- }
-
- Boolean value = (Boolean) action.getValue("hideActionText");
- component.setHideActionText(value != null && value);
- action.setEnabled(true);
- result.add(action);
- continue;
- }
- // is JComboBox
- JComboBox component = (JComboBox) comp;
- MyAbstractAction action = newAction(actionKey, component);
-
- component.setAction(action);
- Integer val = (Integer) action.getValue("selectedIndex");
- if (val != null && val != -1 && val < component.getItemCount() && val != component.getSelectedIndex()) {
- component.setSelectedIndex(val);
- }
- result.add(action);
- }
- return result.toArray(new MyAbstractAction[result.size()]);
- }
-
- /**
- * @param actionKey le nom de l'action tel que d�finie dans le fichier
- * de mapping (sans le prefix action.)
- * @param component le button o� rattacher l'action
- * @return une nouvelle instance de l'action associ�e � sa clef.
- */
- public MyAbstractAction newAction(String actionKey, JComponent component) {
- // try first in cache
- MyAbstractAction result = getActionFromCache(actionKey);
- if (result != null) {
- return result;
- }
-
- try {
- result = newActionInstance(actionKey);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- if (log.isDebugEnabled()) {
- log.debug("create <" + actionKey + " : " + result + ">");
- }
-
- // recherche de l'annotation de configuration
- ActionInitializer<?, ?> initializer = findInitializer(result.getClass());
-
- if (initializer != null) {
- initializer.initAction(component, result);
- }
-
- try {
-
- if (initializer != null) {
- if (AbstractButton.class.isAssignableFrom(initializer.getComponentImpl())) {
- finalizeNewAction((AbstractButton) component, result, initializer);
- }
-
- if (JComboBox.class.isAssignableFrom(initializer.getComponentImpl())) {
- finalizeNewAction((JComboBox) component, result, initializer);
- }
-
- return result;
- }
-
- if (component == null || component instanceof AbstractButton) {
- finalizeNewAction((AbstractButton) component, result, initializer);
- return result;
- }
-
- if (component instanceof JComboBox) {
- finalizeNewAction((JComboBox) component, result, initializer);
- }
- } finally {
- // save result in cache
- cache.put(actionKey, result);
- }
-
- return result;
- }
-
- public String[] getActionNames() {
- return impls.keySet().toArray(new String[impls.size()]);
- }
-
- public Set<Map.Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet() {
- return impls.entrySet();
- }
-
- public Set<Map.Entry<String, MyAbstractAction>> cacheEntrySet() {
- return cache.entrySet();
- }
-
- public void fireAction(String actionKey, Object source, JComponent component) {
- AbstractAction action = newAction(actionKey, component);
- fireAction0(actionKey, source, action);
- }
-
- public void fireAction(String actionKey, Object source) {
- fireAction(actionKey, source, null);
- }
-
- /**
- * @param actionKey la clef de l'action
- * @return l'action deja stockee dans le cache d'action, ou <code>null</code> si non trouv�e.
- */
- public MyAbstractAction getActionFromCache(String actionKey) {
- // on v�rifie que l'action existe bien
- checkRegistredAction(actionKey);
-
- // try in cache
- if (cache.containsKey(actionKey)) {
- // use cached action
- MyAbstractAction action = cache.get(actionKey);
- if (log.isDebugEnabled()) {
- log.debug("use cache action " + action);
- }
- return action;
- }
- return null;
- }
-
- public void dispose() {
- if (log.isInfoEnabled()) {
- log.info(this);
- }
- for (String actionKey : getActionNames()) {
- MyAbstractAction action = getActionFromCache(actionKey);
- if (action != null) {
- action.disposeUI();
- }
- }
- resetCache();
- }
-
- /**
- * @param component le button o� rattacher l'action
- * @param action action
- * @param initializer initializer
- */
- protected void finalizeNewAction(AbstractButton component, MyAbstractAction action, ActionInitializer<?, ?> initializer) {
-
- if (initializer == null) {
- // no initializer matching,
- if (component != null) {
- action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
- action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
- action.putValue(Action.SMALL_ICON, component.getIcon());
- action.putValue(Action.NAME, component.getText());
- action.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
- action.putValue("hideActionText", component.getHideActionText());
- if (component instanceof JAXXToggleButton) {
- JAXXToggleButton glueComponent = (JAXXToggleButton) component;
- action.putValue(Action.SHORT_DESCRIPTION, glueComponent.getNormalTooltipText());
- action.putValue(Action.NAME, glueComponent.getNormalText());
- action.putValue(Action.SMALL_ICON, glueComponent.getIcon());
- action.putValue(Action.MNEMONIC_KEY, glueComponent.getNormalMnemonic());
- action.putValue(Action.SHORT_DESCRIPTION + 2, glueComponent.getGlueTooltipText());
- action.putValue(Action.NAME + 2, glueComponent.getGlueText());
- action.putValue(Action.SMALL_ICON + 2, glueComponent.getSelectedIcon());
- action.putValue(Action.MNEMONIC_KEY + 2, glueComponent.getGlueMnemonic());
- }
- }
-
- }
-
- String text = (String) action.getValue(Action.NAME);
- Integer mnemo = (Integer) action.getValue(Action.MNEMONIC_KEY);
- if (mnemo != null && mnemo != '\0') {
- int pos = text.indexOf((char) mnemo.intValue());
- if (pos == -1) {
- pos = text.indexOf(Character.toLowerCase((char) mnemo.intValue()));
- }
- action.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, pos);
- }
-
- }
-
- /**
- * @param component le select box o� rattacher l'action
- * @param action action
- * @param initializer initializer
- */
- protected void finalizeNewAction(JComboBox component, MyAbstractAction action, ActionInitializer<?, ?> initializer) {
-
- if (initializer == null) {
- action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
- action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
- //result.putValue("selectedIndex", component.getSelectedIndex());
- }
-
- }
-
- protected ActionInitializer findInitializer(Class<? extends AbstractAction> action) {
- for (ActionInitializer registredInitializer : registredInitializers) {
- if (registredInitializer.getAnnotation(action) != null) {
- return registredInitializer;
- }
- }
- return null;
- }
-
- protected <I extends AbstractActionInitializer> I registerInitializer(Class<I> initizalizer) {
- try {
- I instance = initizalizer.newInstance();
- registredInitializers.add(instance);
- return instance;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- protected void fireAction0(String actionKey, Object source, AbstractAction action) {
- if (action == null) {
- log.warn("could not find action " + actionKey);
- return;
- }
- ActionEvent event = new ActionEvent(source, ActionEvent.ACTION_FIRST, actionKey);
- action.actionPerformed(event);
- }
-
- protected void checkRegistredAction(String actionKey) {
- if (!impls.containsKey(actionKey)) {
- throw new IllegalStateException("can not find a registered action for key " + actionKey);
- }
- }
-
-
- protected MyAbstractAction newActionInstance(String actionKey) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
- Class<? extends MyAbstractAction> klazz = impls.get(actionKey);
- MyAbstractAction result;
- result = klazz.getConstructor(String.class).newInstance(actionKey);
- result.putValue(Action.ACTION_COMMAND_KEY, actionKey);
- return result;
- }
-}
\ No newline at end of file
1
0
r783 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 18:48:55 +0000 (Thu, 24 Jul 2008)
New Revision: 783
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/IActionFactory.java
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java
Log:
introduction ActionFactory interface
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java 2008-07-24 18:47:27 UTC (rev 782)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java 2008-07-24 18:48:55 UTC (rev 783)
@@ -56,7 +56,7 @@
*
* @author chemit
*/
-public abstract class ActionFactory<A extends MyAbstractAction> {
+public abstract class ActionFactory<A extends MyAbstractAction> implements IActionFactory {
protected static Log log = LogFactory.getLog(ActionFactory.class);
Added: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/IActionFactory.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/IActionFactory.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/IActionFactory.java 2008-07-24 18:48:55 UTC (rev 783)
@@ -0,0 +1,47 @@
+/**
+ * # #% 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.factory;
+
+import jaxx.runtime.JAXXObject;
+import org.codelutin.jaxx.action.MyAbstractAction;
+
+import javax.swing.JComponent;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/** @author chemit */
+public interface IActionFactory {
+ void resetCache();
+
+ MyAbstractAction get(String actionKey);
+
+ MyAbstractAction[] loadActions(JAXXObject ui);
+
+ MyAbstractAction newAction(String actionKey, JComponent component);
+
+ String[] getActionNames();
+
+ Set<Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet();
+
+ Set<Entry<String, MyAbstractAction>> cacheEntrySet();
+
+ void fireAction(String actionKey, Object source, JComponent component);
+
+ void fireAction(String actionKey, Object source);
+
+ MyAbstractAction getActionFromCache(String actionKey);
+
+ void dispose();
+}
1
0
r782 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: factory initializer
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 18:47:27 +0000 (Thu, 24 Jul 2008)
New Revision: 782
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.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/ToggleActionConfigInitializer.java
Log:
use UIHelper
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java 2008-07-24 18:19:27 UTC (rev 781)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java 2008-07-24 18:47:27 UTC (rev 782)
@@ -33,7 +33,6 @@
import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.Icon;
-import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import java.awt.event.ActionEvent;
@@ -170,15 +169,6 @@
return result.toArray(new MyAbstractAction[result.size()]);
}
- public static ImageIcon createImageIcon(String path) {
- java.net.URL imgURL = ActionFactory.class.getResource("/icons/" + path);
- if (imgURL != null) {
- return new ImageIcon(imgURL);
- } else {
- throw new RuntimeException("could not find icon " + path);
- }
- }
-
/**
* @param actionKey le nom de l'action tel que d�finie dans le fichier
* de mapping (sans le prefix action.)
Modified: 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-24 18:19:27 UTC (rev 781)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigInitializer.java 2008-07-24 18:47:27 UTC (rev 782)
@@ -16,7 +16,6 @@
import static org.codelutin.i18n.I18n._;
import org.codelutin.jaxx.action.ActionConfig;
-import org.codelutin.jaxx.action.ActionFactory;
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
@@ -43,7 +42,7 @@
action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
//}
if (!anno.smallIcon().isEmpty()) {
- action.putValue(Action.SMALL_ICON, ActionFactory.createImageIcon(anno.smallIcon()));
+ action.putValue(Action.SMALL_ICON, org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon()));
}
if (anno.mnemonic() != '\0') {
action.putValue(Action.MNEMONIC_KEY, anno.mnemonic());
Modified: 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-24 18:19:27 UTC (rev 781)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java 2008-07-24 18:47:27 UTC (rev 782)
@@ -15,7 +15,6 @@
package org.codelutin.jaxx.action.initializer;
import static org.codelutin.i18n.I18n._;
-import org.codelutin.jaxx.action.ActionFactory;
import org.codelutin.jaxx.action.ToggleActionConfig;
import javax.swing.AbstractAction;
@@ -52,10 +51,10 @@
}
if (!anno.smallIcon().isEmpty()) {
- action.putValue(Action.SMALL_ICON, ActionFactory.createImageIcon(anno.smallIcon()));
+ action.putValue(Action.SMALL_ICON, org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon()));
}
if (!anno.smallIcon2().isEmpty()) {
- action.putValue(Action.SMALL_ICON + "2", ActionFactory.createImageIcon(anno.smallIcon2()));
+ action.putValue(Action.SMALL_ICON + "2", org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon2()));
}
if (anno.mnemonic() != '\0') {
1
0
r781 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: . factory
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 18:19:27 +0000 (Thu, 24 Jul 2008)
New Revision: 781
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java
Log:
introduce factory package
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java 2008-07-24 18:16:34 UTC (rev 780)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java 2008-07-24 18:19:27 UTC (rev 781)
@@ -1,395 +0,0 @@
-/*
-* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 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;
-
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.swing.JAXXToggleButton;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-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 javax.swing.AbstractAction;
-import javax.swing.AbstractButton;
-import javax.swing.Action;
-import javax.swing.Icon;
-import javax.swing.ImageIcon;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import java.awt.event.ActionEvent;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-/**
- * Action factory using the ActionConfig annotations to configure the action.
- * <p/>
- * The factory is abstract, implements method {@link #init()} to fill the
- * dictonary of known action implementations.
- * <p/>
- * Use after the {@link #loadActions(jaxx.runtime.JAXXObject)} to instanciate
- * actions in ui with id equals a known action...
- * <p/>
- * TODO Finish doc
- *
- * @author chemit
- */
-public abstract class ActionFactory<A extends MyAbstractAction> {
-
- protected static Log log = LogFactory.getLog(ActionFactory.class);
-
- /** class of encapsuling action */
- protected Class<A> baseImpl;
-
- /** dictionary of known actions implementations */
- private Map<String, Class<? extends MyAbstractAction>> impls;
-
- /** dictionary of instanciated actions */
- private Map<String, MyAbstractAction> cache;
-
- protected final ActionConfigInitializer actionConfigInitializer;
- protected final ToggleActionConfigInitializer toggleActionConfigInitializer;
- protected final SelectActionConfigInitializer selectActionConfigInitializer;
-
- /**
- * Method to init the dictionary of knwon action implementations.
- *
- * @return the dictionary of known action implementations
- */
- protected abstract Map<String, Class<? extends MyAbstractAction>> init();
-
- protected List<AbstractActionInitializer> registredInitializers;
-
-
- protected ActionFactory(Class<A> baseImpl) {
- this.baseImpl = baseImpl;
- this.impls = init();
- this.cache = new TreeMap<String, MyAbstractAction>();
- this.registredInitializers = new java.util.ArrayList<AbstractActionInitializer>();
-
- this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigInitializer.class);
- this.actionConfigInitializer = registerInitializer(ActionConfigInitializer.class);
- this.selectActionConfigInitializer = registerInitializer(SelectActionConfigInitializer.class);
- }
-
- public void resetCache() {
- cache.clear();
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- resetCache();
- impls.clear();
- }
-
- public MyAbstractAction get(String actionKey) {
- return cache.get(actionKey);
- }
-
- public MyAbstractAction[] loadActions(JAXXObject ui) {
- if (log.isDebugEnabled()) {
- log.debug("for ui " + ui.getClass());
- }
- List<MyAbstractAction> result = new ArrayList<MyAbstractAction>();
- for (Map.Entry<String, Class<? extends MyAbstractAction>> entry : implsEntrySet()) {
- String actionKey = entry.getKey();
- Object comp = ui.getObjectById(actionKey);
- if (comp == null || !(comp instanceof AbstractButton || comp instanceof JComboBox)) {
- // nothing to do
- continue;
- }
- if (log.isTraceEnabled()) {
- log.trace("detect action " + actionKey);
- }
- if (comp instanceof AbstractButton) {
- AbstractButton component = (AbstractButton) comp;
- MyAbstractAction action = newAction(actionKey, component);
-
- component.setAction(action);
-
- if (component instanceof JAXXToggleButton) {
- JAXXToggleButton glueComponent = (JAXXToggleButton) component;
- glueComponent.setIcon((Icon) action.getValue(Action.SMALL_ICON));
- Integer integer = (Integer) action.getValue(Action.MNEMONIC_KEY);
- if (integer != null) {
- glueComponent.setNormalMnemonic(integer);
- }
- glueComponent.setSelectedIcon((Icon) action.getValue(Action.SMALL_ICON + 2));
- integer = (Integer) action.getValue(Action.MNEMONIC_KEY + 2);
- if (integer != null) {
- glueComponent.setGlueMnemonic(integer);
- }
- glueComponent.setGlueText((String) action.getValue(Action.NAME + 2));
- glueComponent.setGlueTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION + 2));
-
- glueComponent.setNormalText((String) action.getValue(Action.NAME));
- glueComponent.setNormalTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION));
- }
-
- Boolean value = (Boolean) action.getValue("hideActionText");
- component.setHideActionText(value != null && value);
- action.setEnabled(true);
- result.add(action);
- continue;
- }
- // is JComboBox
- JComboBox component = (JComboBox) comp;
- MyAbstractAction action = newAction(actionKey, component);
-
- component.setAction(action);
- Integer val = (Integer) action.getValue("selectedIndex");
- if (val != null && val != -1 && val < component.getItemCount() && val != component.getSelectedIndex()) {
- component.setSelectedIndex(val);
- }
- result.add(action);
- }
- return result.toArray(new MyAbstractAction[result.size()]);
- }
-
- public static ImageIcon createImageIcon(String path) {
- java.net.URL imgURL = org.codelutin.jaxx.action.ActionFactory.class.getResource("/icons/" + path);
- if (imgURL != null) {
- return new ImageIcon(imgURL);
- } else {
- throw new RuntimeException("could not find icon " + path);
- }
- }
-
- /**
- * @param actionKey le nom de l'action tel que d�finie dans le fichier
- * de mapping (sans le prefix action.)
- * @param component le button o� rattacher l'action
- * @return une nouvelle instance de l'action associ�e � sa clef.
- */
- public MyAbstractAction newAction(String actionKey, JComponent component) {
- // try first in cache
- MyAbstractAction result = getActionFromCache(actionKey);
- if (result != null) {
- return result;
- }
-
- try {
- result = newActionInstance(actionKey);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- if (log.isDebugEnabled()) {
- log.debug("create <" + actionKey + " : " + result + ">");
- }
-
- // recherche de l'annotation de configuration
- ActionInitializer<?, ?> initializer = findInitializer(result.getClass());
-
- if (initializer != null) {
- initializer.initAction(component, result);
- }
-
- try {
-
- if (initializer != null) {
- if (AbstractButton.class.isAssignableFrom(initializer.getComponentImpl())) {
- finalizeNewAction((AbstractButton) component, result, initializer);
- }
-
- if (JComboBox.class.isAssignableFrom(initializer.getComponentImpl())) {
- finalizeNewAction((JComboBox) component, result, initializer);
- }
-
- return result;
- }
-
- if (component == null || component instanceof AbstractButton) {
- finalizeNewAction((AbstractButton) component, result, initializer);
- return result;
- }
-
- if (component instanceof JComboBox) {
- finalizeNewAction((JComboBox) component, result, initializer);
- }
- } finally {
- // save result in cache
- cache.put(actionKey, result);
- }
-
- return result;
- }
-
- public String[] getActionNames() {
- return impls.keySet().toArray(new String[impls.size()]);
- }
-
- public Set<Map.Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet() {
- return impls.entrySet();
- }
-
- public Set<Map.Entry<String, MyAbstractAction>> cacheEntrySet() {
- return cache.entrySet();
- }
-
- public void fireAction(String actionKey, Object source, JComponent component) {
- AbstractAction action = newAction(actionKey, component);
- fireAction0(actionKey, source, action);
- }
-
- public void fireAction(String actionKey, Object source) {
- fireAction(actionKey, source, null);
- }
-
- /**
- * @param actionKey la clef de l'action
- * @return l'action deja stockee dans le cache d'action, ou <code>null</code> si non trouv�e.
- */
- public MyAbstractAction getActionFromCache(String actionKey) {
- // on v�rifie que l'action existe bien
- checkRegistredAction(actionKey);
-
- // try in cache
- if (cache.containsKey(actionKey)) {
- // use cached action
- MyAbstractAction action = cache.get(actionKey);
- if (log.isDebugEnabled()) {
- log.debug("use cache action " + action);
- }
- return action;
- }
- return null;
- }
-
- public void dispose() {
- if (log.isInfoEnabled()) {
- log.info(this);
- }
- for (String actionKey : getActionNames()) {
- MyAbstractAction action = getActionFromCache(actionKey);
- if (action != null) {
- action.disposeUI();
- }
- }
- resetCache();
- }
-
- /**
- * @param component le button o� rattacher l'action
- * @param action action
- * @param initializer initializer
- */
- protected void finalizeNewAction(AbstractButton component, MyAbstractAction action, ActionInitializer<?, ?> initializer) {
-
- if (initializer == null) {
- // no initializer matching,
- if (component != null) {
- action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
- action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
- action.putValue(Action.SMALL_ICON, component.getIcon());
- action.putValue(Action.NAME, component.getText());
- action.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
- action.putValue("hideActionText", component.getHideActionText());
- if (component instanceof JAXXToggleButton) {
- JAXXToggleButton glueComponent = (JAXXToggleButton) component;
- action.putValue(Action.SHORT_DESCRIPTION, glueComponent.getNormalTooltipText());
- action.putValue(Action.NAME, glueComponent.getNormalText());
- action.putValue(Action.SMALL_ICON, glueComponent.getIcon());
- action.putValue(Action.MNEMONIC_KEY, glueComponent.getNormalMnemonic());
- action.putValue(Action.SHORT_DESCRIPTION + 2, glueComponent.getGlueTooltipText());
- action.putValue(Action.NAME + 2, glueComponent.getGlueText());
- action.putValue(Action.SMALL_ICON + 2, glueComponent.getSelectedIcon());
- action.putValue(Action.MNEMONIC_KEY + 2, glueComponent.getGlueMnemonic());
- }
- }
-
- }
-
- String text = (String) action.getValue(Action.NAME);
- Integer mnemo = (Integer) action.getValue(Action.MNEMONIC_KEY);
- if (mnemo != null && mnemo != '\0') {
- int pos = text.indexOf((char) mnemo.intValue());
- if (pos == -1) {
- pos = text.indexOf(Character.toLowerCase((char) mnemo.intValue()));
- }
- action.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, pos);
- }
-
- }
-
- /**
- * @param component le select box o� rattacher l'action
- * @param action action
- * @param initializer initializer
- */
- protected void finalizeNewAction(JComboBox component, MyAbstractAction action, ActionInitializer<?, ?> initializer) {
-
- if (initializer == null) {
- action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
- action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
- //result.putValue("selectedIndex", component.getSelectedIndex());
- }
-
- }
-
- protected ActionInitializer findInitializer(Class<? extends AbstractAction> action) {
- for (ActionInitializer registredInitializer : registredInitializers) {
- if (registredInitializer.getAnnotation(action) != null) {
- return registredInitializer;
- }
- }
- return null;
- }
-
- protected <I extends AbstractActionInitializer> I registerInitializer(Class<I> initizalizer) {
- try {
- I instance = initizalizer.newInstance();
- registredInitializers.add(instance);
- return instance;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- protected void fireAction0(String actionKey, Object source, AbstractAction action) {
- if (action == null) {
- log.warn("could not find action " + actionKey);
- return;
- }
- ActionEvent event = new ActionEvent(source, ActionEvent.ACTION_FIRST, actionKey);
- action.actionPerformed(event);
- }
-
- protected void checkRegistredAction(String actionKey) {
- if (!impls.containsKey(actionKey)) {
- throw new IllegalStateException("can not find a registered action for key " + actionKey);
- }
- }
-
-
- protected MyAbstractAction newActionInstance(String actionKey) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
- Class<? extends MyAbstractAction> klazz = impls.get(actionKey);
- MyAbstractAction result;
- result = klazz.getConstructor(String.class).newInstance(actionKey);
- result.putValue(Action.ACTION_COMMAND_KEY, actionKey);
- return result;
- }
-}
\ No newline at end of file
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java 2008-07-24 18:16:34 UTC (rev 780)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java 2008-07-24 18:19:27 UTC (rev 781)
@@ -1,64 +0,0 @@
-/*
-* ##% Copyright (C) 2007, 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;
-
-import org.codelutin.jaxx.action.provider.ActionProvider;
-
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.TreeMap;
-
-/**
- * A simple implementation of {@link ActionFactory} using a properties file to
- * load action mapping.
- * <p/>
- * An entry is in that form : <code>action.actionName=fqn</code> where
- * <p/>
- * <code>actionName</code> is the key of action used in factory, and
- * <code>fqn</code> is the fully qualified name of the implemented action class.
- *
- * @author chemit
- */
-public class ActionFactoryFromProvider<A extends MyAbstractAction> extends ActionFactory<A> {
-
- public static <A extends MyAbstractAction> ActionFactoryFromProvider<A> newInstance(Class<A> klazz) {
- return new ActionFactoryFromProvider<A>(klazz);
- }
-
- protected ActionFactoryFromProvider(Class<A> baseClass) {
- super(baseClass);
- }
-
- protected Map<String, Class<? extends MyAbstractAction>> init() {
- if (log.isDebugEnabled()) {
- log.debug("start loading " + this);
- }
- // obtain a ServiceLoader on ActionProvider
- ServiceLoader<ActionProvider> loader = ServiceLoader.load(ActionProvider.class);
- Map<String, Class<? extends MyAbstractAction>> cache = new TreeMap<String, Class<? extends MyAbstractAction>>();
-
- for (ActionProvider<?> actionProvider : loader) {
- if (log.isDebugEnabled()) {
- log.debug("found " + actionProvider);
- }
- cache.putAll(actionProvider.getClasses());
- }
- return cache;
- }
-
-}
\ No newline at end of file
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java (from rev 780, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java 2008-07-24 18:19:27 UTC (rev 781)
@@ -0,0 +1,396 @@
+/*
+* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 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.factory;
+
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.swing.JAXXToggleButton;
+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 javax.swing.AbstractAction;
+import javax.swing.AbstractButton;
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import java.awt.event.ActionEvent;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+/**
+ * Action factory using the ActionConfig annotations to configure the action.
+ * <p/>
+ * The factory is abstract, implements method {@link #init()} to fill the
+ * dictonary of known action implementations.
+ * <p/>
+ * Use after the {@link #loadActions(jaxx.runtime.JAXXObject)} to instanciate
+ * actions in ui with id equals a known action...
+ * <p/>
+ * TODO Finish doc
+ *
+ * @author chemit
+ */
+public abstract class ActionFactory<A extends MyAbstractAction> {
+
+ protected static Log log = LogFactory.getLog(ActionFactory.class);
+
+ /** class of encapsuling action */
+ protected Class<A> baseImpl;
+
+ /** dictionary of known actions implementations */
+ private Map<String, Class<? extends MyAbstractAction>> impls;
+
+ /** dictionary of instanciated actions */
+ private Map<String, MyAbstractAction> cache;
+
+ protected final ActionConfigInitializer actionConfigInitializer;
+ protected final ToggleActionConfigInitializer toggleActionConfigInitializer;
+ protected final SelectActionConfigInitializer selectActionConfigInitializer;
+
+ /**
+ * Method to init the dictionary of knwon action implementations.
+ *
+ * @return the dictionary of known action implementations
+ */
+ protected abstract Map<String, Class<? extends MyAbstractAction>> init();
+
+ protected List<AbstractActionInitializer> registredInitializers;
+
+
+ protected ActionFactory(Class<A> baseImpl) {
+ this.baseImpl = baseImpl;
+ this.impls = init();
+ this.cache = new TreeMap<String, MyAbstractAction>();
+ this.registredInitializers = new java.util.ArrayList<AbstractActionInitializer>();
+
+ this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigInitializer.class);
+ this.actionConfigInitializer = registerInitializer(ActionConfigInitializer.class);
+ this.selectActionConfigInitializer = registerInitializer(SelectActionConfigInitializer.class);
+ }
+
+ public void resetCache() {
+ cache.clear();
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ resetCache();
+ impls.clear();
+ }
+
+ public MyAbstractAction get(String actionKey) {
+ return cache.get(actionKey);
+ }
+
+ public MyAbstractAction[] loadActions(JAXXObject ui) {
+ if (log.isDebugEnabled()) {
+ log.debug("for ui " + ui.getClass());
+ }
+ List<MyAbstractAction> result = new ArrayList<MyAbstractAction>();
+ for (Map.Entry<String, Class<? extends MyAbstractAction>> entry : implsEntrySet()) {
+ String actionKey = entry.getKey();
+ Object comp = ui.getObjectById(actionKey);
+ if (comp == null || !(comp instanceof AbstractButton || comp instanceof JComboBox)) {
+ // nothing to do
+ continue;
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("detect action " + actionKey);
+ }
+ if (comp instanceof AbstractButton) {
+ AbstractButton component = (AbstractButton) comp;
+ MyAbstractAction action = newAction(actionKey, component);
+
+ component.setAction(action);
+
+ if (component instanceof JAXXToggleButton) {
+ JAXXToggleButton glueComponent = (JAXXToggleButton) component;
+ glueComponent.setIcon((Icon) action.getValue(Action.SMALL_ICON));
+ Integer integer = (Integer) action.getValue(Action.MNEMONIC_KEY);
+ if (integer != null) {
+ glueComponent.setNormalMnemonic(integer);
+ }
+ glueComponent.setSelectedIcon((Icon) action.getValue(Action.SMALL_ICON + 2));
+ integer = (Integer) action.getValue(Action.MNEMONIC_KEY + 2);
+ if (integer != null) {
+ glueComponent.setGlueMnemonic(integer);
+ }
+ glueComponent.setGlueText((String) action.getValue(Action.NAME + 2));
+ glueComponent.setGlueTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION + 2));
+
+ glueComponent.setNormalText((String) action.getValue(Action.NAME));
+ glueComponent.setNormalTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION));
+ }
+
+ Boolean value = (Boolean) action.getValue("hideActionText");
+ component.setHideActionText(value != null && value);
+ action.setEnabled(true);
+ result.add(action);
+ continue;
+ }
+ // is JComboBox
+ JComboBox component = (JComboBox) comp;
+ MyAbstractAction action = newAction(actionKey, component);
+
+ component.setAction(action);
+ Integer val = (Integer) action.getValue("selectedIndex");
+ if (val != null && val != -1 && val < component.getItemCount() && val != component.getSelectedIndex()) {
+ component.setSelectedIndex(val);
+ }
+ result.add(action);
+ }
+ return result.toArray(new MyAbstractAction[result.size()]);
+ }
+
+ public static ImageIcon createImageIcon(String path) {
+ java.net.URL imgURL = ActionFactory.class.getResource("/icons/" + path);
+ if (imgURL != null) {
+ return new ImageIcon(imgURL);
+ } else {
+ throw new RuntimeException("could not find icon " + path);
+ }
+ }
+
+ /**
+ * @param actionKey le nom de l'action tel que d�finie dans le fichier
+ * de mapping (sans le prefix action.)
+ * @param component le button o� rattacher l'action
+ * @return une nouvelle instance de l'action associ�e � sa clef.
+ */
+ public MyAbstractAction newAction(String actionKey, JComponent component) {
+ // try first in cache
+ MyAbstractAction result = getActionFromCache(actionKey);
+ if (result != null) {
+ return result;
+ }
+
+ try {
+ result = newActionInstance(actionKey);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("create <" + actionKey + " : " + result + ">");
+ }
+
+ // recherche de l'annotation de configuration
+ ActionInitializer<?, ?> initializer = findInitializer(result.getClass());
+
+ if (initializer != null) {
+ initializer.initAction(component, result);
+ }
+
+ try {
+
+ if (initializer != null) {
+ if (AbstractButton.class.isAssignableFrom(initializer.getComponentImpl())) {
+ finalizeNewAction((AbstractButton) component, result, initializer);
+ }
+
+ if (JComboBox.class.isAssignableFrom(initializer.getComponentImpl())) {
+ finalizeNewAction((JComboBox) component, result, initializer);
+ }
+
+ return result;
+ }
+
+ if (component == null || component instanceof AbstractButton) {
+ finalizeNewAction((AbstractButton) component, result, initializer);
+ return result;
+ }
+
+ if (component instanceof JComboBox) {
+ finalizeNewAction((JComboBox) component, result, initializer);
+ }
+ } finally {
+ // save result in cache
+ cache.put(actionKey, result);
+ }
+
+ return result;
+ }
+
+ public String[] getActionNames() {
+ return impls.keySet().toArray(new String[impls.size()]);
+ }
+
+ public Set<Map.Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet() {
+ return impls.entrySet();
+ }
+
+ public Set<Map.Entry<String, MyAbstractAction>> cacheEntrySet() {
+ return cache.entrySet();
+ }
+
+ public void fireAction(String actionKey, Object source, JComponent component) {
+ AbstractAction action = newAction(actionKey, component);
+ fireAction0(actionKey, source, action);
+ }
+
+ public void fireAction(String actionKey, Object source) {
+ fireAction(actionKey, source, null);
+ }
+
+ /**
+ * @param actionKey la clef de l'action
+ * @return l'action deja stockee dans le cache d'action, ou <code>null</code> si non trouv�e.
+ */
+ public MyAbstractAction getActionFromCache(String actionKey) {
+ // on v�rifie que l'action existe bien
+ checkRegistredAction(actionKey);
+
+ // try in cache
+ if (cache.containsKey(actionKey)) {
+ // use cached action
+ MyAbstractAction action = cache.get(actionKey);
+ if (log.isDebugEnabled()) {
+ log.debug("use cache action " + action);
+ }
+ return action;
+ }
+ return null;
+ }
+
+ public void dispose() {
+ if (log.isInfoEnabled()) {
+ log.info(this);
+ }
+ for (String actionKey : getActionNames()) {
+ MyAbstractAction action = getActionFromCache(actionKey);
+ if (action != null) {
+ action.disposeUI();
+ }
+ }
+ resetCache();
+ }
+
+ /**
+ * @param component le button o� rattacher l'action
+ * @param action action
+ * @param initializer initializer
+ */
+ protected void finalizeNewAction(AbstractButton component, MyAbstractAction action, ActionInitializer<?, ?> initializer) {
+
+ if (initializer == null) {
+ // no initializer matching,
+ if (component != null) {
+ action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
+ action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
+ action.putValue(Action.SMALL_ICON, component.getIcon());
+ action.putValue(Action.NAME, component.getText());
+ action.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
+ action.putValue("hideActionText", component.getHideActionText());
+ if (component instanceof JAXXToggleButton) {
+ JAXXToggleButton glueComponent = (JAXXToggleButton) component;
+ action.putValue(Action.SHORT_DESCRIPTION, glueComponent.getNormalTooltipText());
+ action.putValue(Action.NAME, glueComponent.getNormalText());
+ action.putValue(Action.SMALL_ICON, glueComponent.getIcon());
+ action.putValue(Action.MNEMONIC_KEY, glueComponent.getNormalMnemonic());
+ action.putValue(Action.SHORT_DESCRIPTION + 2, glueComponent.getGlueTooltipText());
+ action.putValue(Action.NAME + 2, glueComponent.getGlueText());
+ action.putValue(Action.SMALL_ICON + 2, glueComponent.getSelectedIcon());
+ action.putValue(Action.MNEMONIC_KEY + 2, glueComponent.getGlueMnemonic());
+ }
+ }
+
+ }
+
+ String text = (String) action.getValue(Action.NAME);
+ Integer mnemo = (Integer) action.getValue(Action.MNEMONIC_KEY);
+ if (mnemo != null && mnemo != '\0') {
+ int pos = text.indexOf((char) mnemo.intValue());
+ if (pos == -1) {
+ pos = text.indexOf(Character.toLowerCase((char) mnemo.intValue()));
+ }
+ action.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, pos);
+ }
+
+ }
+
+ /**
+ * @param component le select box o� rattacher l'action
+ * @param action action
+ * @param initializer initializer
+ */
+ protected void finalizeNewAction(JComboBox component, MyAbstractAction action, ActionInitializer<?, ?> initializer) {
+
+ if (initializer == null) {
+ action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
+ action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
+ //result.putValue("selectedIndex", component.getSelectedIndex());
+ }
+
+ }
+
+ protected ActionInitializer findInitializer(Class<? extends AbstractAction> action) {
+ for (ActionInitializer registredInitializer : registredInitializers) {
+ if (registredInitializer.getAnnotation(action) != null) {
+ return registredInitializer;
+ }
+ }
+ return null;
+ }
+
+ protected <I extends AbstractActionInitializer> I registerInitializer(Class<I> initizalizer) {
+ try {
+ I instance = initizalizer.newInstance();
+ registredInitializers.add(instance);
+ return instance;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected void fireAction0(String actionKey, Object source, AbstractAction action) {
+ if (action == null) {
+ log.warn("could not find action " + actionKey);
+ return;
+ }
+ ActionEvent event = new ActionEvent(source, ActionEvent.ACTION_FIRST, actionKey);
+ action.actionPerformed(event);
+ }
+
+ protected void checkRegistredAction(String actionKey) {
+ if (!impls.containsKey(actionKey)) {
+ throw new IllegalStateException("can not find a registered action for key " + actionKey);
+ }
+ }
+
+
+ protected MyAbstractAction newActionInstance(String actionKey) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
+ Class<? extends MyAbstractAction> klazz = impls.get(actionKey);
+ MyAbstractAction result;
+ result = klazz.getConstructor(String.class).newInstance(actionKey);
+ result.putValue(Action.ACTION_COMMAND_KEY, actionKey);
+ return result;
+ }
+}
\ No newline at end of file
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java (from rev 777, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java 2008-07-24 18:19:27 UTC (rev 781)
@@ -0,0 +1,65 @@
+/*
+* ##% Copyright (C) 2007, 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.factory;
+
+import org.codelutin.jaxx.action.MyAbstractAction;
+import org.codelutin.jaxx.action.provider.ActionProvider;
+
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.TreeMap;
+
+/**
+ * A simple implementation of {@link ActionFactory} using a properties file to
+ * load action mapping.
+ * <p/>
+ * An entry is in that form : <code>action.actionName=fqn</code> where
+ * <p/>
+ * <code>actionName</code> is the key of action used in factory, and
+ * <code>fqn</code> is the fully qualified name of the implemented action class.
+ *
+ * @author chemit
+ */
+public class ActionFactoryFromProvider<A extends MyAbstractAction> extends ActionFactory<A> {
+
+ public static <A extends MyAbstractAction> ActionFactoryFromProvider<A> newInstance(Class<A> klazz) {
+ return new ActionFactoryFromProvider<A>(klazz);
+ }
+
+ protected ActionFactoryFromProvider(Class<A> baseClass) {
+ super(baseClass);
+ }
+
+ protected Map<String, Class<? extends MyAbstractAction>> init() {
+ if (log.isDebugEnabled()) {
+ log.debug("start loading " + this);
+ }
+ // obtain a ServiceLoader on ActionProvider
+ ServiceLoader<ActionProvider> loader = ServiceLoader.load(ActionProvider.class);
+ Map<String, Class<? extends MyAbstractAction>> cache = new TreeMap<String, Class<? extends MyAbstractAction>>();
+
+ for (ActionProvider<?> actionProvider : loader) {
+ if (log.isDebugEnabled()) {
+ log.debug("found " + actionProvider);
+ }
+ cache.putAll(actionProvider.getClasses());
+ }
+ return cache;
+ }
+
+}
\ No newline at end of file
1
0
r780 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: . initializer
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 18:16:34 +0000 (Thu, 24 Jul 2008)
New Revision: 780
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java
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/SelectActionConfigInitializer.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java
Log:
introduce interface ActionInitializer
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java 2008-07-24 18:14:26 UTC (rev 779)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java 2008-07-24 18:16:34 UTC (rev 780)
@@ -22,6 +22,7 @@
import jaxx.runtime.swing.JAXXToggleButton;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+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;
@@ -79,14 +80,14 @@
*/
protected abstract Map<String, Class<? extends MyAbstractAction>> init();
- protected List<ActionInitializer> registredInitializers;
+ protected List<AbstractActionInitializer> registredInitializers;
protected ActionFactory(Class<A> baseImpl) {
this.baseImpl = baseImpl;
this.impls = init();
this.cache = new TreeMap<String, MyAbstractAction>();
- this.registredInitializers = new java.util.ArrayList<ActionInitializer>();
+ this.registredInitializers = new java.util.ArrayList<AbstractActionInitializer>();
this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigInitializer.class);
this.actionConfigInitializer = registerInitializer(ActionConfigInitializer.class);
@@ -358,7 +359,7 @@
return null;
}
- protected <I extends ActionInitializer> I registerInitializer(Class<I> initizalizer) {
+ protected <I extends AbstractActionInitializer> I registerInitializer(Class<I> initizalizer) {
try {
I instance = initizalizer.newInstance();
registredInitializers.add(instance);
Modified: 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-24 18:14:26 UTC (rev 779)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionInitializer.java 2008-07-24 18:16:34 UTC (rev 780)
@@ -23,7 +23,7 @@
*
* @author chemit
*/
-public abstract class AbstractActionInitializer<A extends java.lang.annotation.Annotation, C extends JComponent> {
+public abstract class AbstractActionInitializer<A extends java.lang.annotation.Annotation, C extends JComponent> implements ActionInitializer<A, C> {
final Class<A> annotationImpl;
final Class<C> componentImpl;
Modified: 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-24 18:14:26 UTC (rev 779)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigInitializer.java 2008-07-24 18:16:34 UTC (rev 780)
@@ -23,7 +23,7 @@
import javax.swing.Action;
/** @author chemit */
-public class ActionConfigInitializer extends ActionInitializer<ActionConfig, AbstractButton> {
+public class ActionConfigInitializer extends AbstractActionInitializer<ActionConfig, AbstractButton> {
public ActionConfigInitializer() {
super(ActionConfig.class, AbstractButton.class);
Added: 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 (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java 2008-07-24 18:16:34 UTC (rev 780)
@@ -0,0 +1,30 @@
+/**
+ * # #% 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 javax.swing.AbstractAction;
+import javax.swing.JComponent;
+
+/** @author chemit */
+public interface ActionInitializer<A extends java.lang.annotation.Annotation, C extends JComponent> {
+
+ A getAnnotation(Class<? extends AbstractAction> action);
+
+ A initAction(JComponent component, AbstractAction action);
+
+ Class<A> getAnnotationImpl();
+
+ Class<C> getComponentImpl();
+}
Modified: 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-24 18:14:26 UTC (rev 779)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigInitializer.java 2008-07-24 18:16:34 UTC (rev 780)
@@ -22,7 +22,7 @@
import javax.swing.JComboBox;
/** @author chemit */
-public class SelectActionConfigInitializer extends ActionInitializer<SelectActionConfig, JComboBox> {
+public class SelectActionConfigInitializer extends AbstractActionInitializer<SelectActionConfig, JComboBox> {
public SelectActionConfigInitializer() {
super(SelectActionConfig.class, JComboBox.class);
Modified: 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-24 18:14:26 UTC (rev 779)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java 2008-07-24 18:16:34 UTC (rev 780)
@@ -23,7 +23,7 @@
import javax.swing.Action;
/** @author chemit */
-public class ToggleActionConfigInitializer extends ActionInitializer<ToggleActionConfig, AbstractButton> {
+public class ToggleActionConfigInitializer extends AbstractActionInitializer<ToggleActionConfig, AbstractButton> {
public ToggleActionConfigInitializer() {
super(ToggleActionConfig.class, AbstractButton.class);
1
0
r779 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 18:14:26 +0000 (Thu, 24 Jul 2008)
New Revision: 779
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionInitializer.java
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java
Log:
rename to abstract
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionInitializer.java (from rev 772, 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/AbstractActionInitializer.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionInitializer.java 2008-07-24 18:14:26 UTC (rev 779)
@@ -0,0 +1,57 @@
+/**
+ * # #% 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 javax.swing.AbstractAction;
+import javax.swing.JComponent;
+
+/**
+ * Initializer of a MyAbstractAction described by a typed Annotation <code>A</code> and for a certain type
+ * <code>C</code> of component.
+ *
+ * @author chemit
+ */
+public abstract class AbstractActionInitializer<A extends java.lang.annotation.Annotation, C extends JComponent> {
+
+ final Class<A> annotationImpl;
+ final Class<C> componentImpl;
+
+ protected abstract A initAction0(C component, AbstractAction action);
+
+ protected AbstractActionInitializer(Class<A> annotationImpl, Class<C> componentImpl) {
+ this.annotationImpl = annotationImpl;
+ this.componentImpl = componentImpl;
+ }
+
+ public A getAnnotation(Class<? extends AbstractAction> action) {
+ return action.getAnnotation(annotationImpl);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public A initAction(JComponent component, AbstractAction action) {
+ if (component != null && componentImpl.isAssignableFrom(component.getClass()))
+ return initAction0((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/ActionInitializer.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java 2008-07-24 16:49:08 UTC (rev 778)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java 2008-07-24 18:14:26 UTC (rev 779)
@@ -1,57 +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 javax.swing.AbstractAction;
-import javax.swing.JComponent;
-
-/**
- * Initializer of a MyAbstractAction described by a typed Annotation <code>A</code> and for a certain type
- * <code>C</code> of component.
- *
- * @author chemit
- */
-public abstract class ActionInitializer<A extends java.lang.annotation.Annotation, C extends JComponent> {
-
- final Class<A> annotationImpl;
- final Class<C> componentImpl;
-
- protected abstract A initAction0(C component, AbstractAction action);
-
- protected ActionInitializer(Class<A> annotationImpl, Class<C> componentImpl) {
- this.annotationImpl = annotationImpl;
- this.componentImpl = componentImpl;
- }
-
- public A getAnnotation(Class<? extends AbstractAction> action) {
- return action.getAnnotation(annotationImpl);
- }
-
- @SuppressWarnings({"unchecked"})
- public A initAction(JComponent component, AbstractAction action) {
- if (component != null && componentImpl.isAssignableFrom(component.getClass()))
- return initAction0((C) component, action);
-
- return null;
- }
-
- public Class<A> getAnnotationImpl() {
- return annotationImpl;
- }
-
- public Class<C> getComponentImpl() {
- return componentImpl;
- }
-}
1
0
r778 - in trunk/lutinjaxx: jaxx-swing-action/src/main/java/org/codelutin/jaxx/action maven/src/main/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 16:49:08 +0000 (Thu, 24 Jul 2008)
New Revision: 778
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java
Log:
update ActionFactory and plugin
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java 2008-07-24 14:10:30 UTC (rev 777)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java 2008-07-24 16:49:08 UTC (rev 778)
@@ -254,6 +254,9 @@
fireAction0(actionKey, source, action);
}
+ public void fireAction(String actionKey, Object source) {
+ fireAction(actionKey, source, null);
+ }
/**
* @param actionKey la clef de l'action
@@ -276,7 +279,9 @@
}
public void dispose() {
-
+ if (log.isInfoEnabled()) {
+ log.info(this);
+ }
for (String actionKey : getActionNames()) {
MyAbstractAction action = getActionFromCache(actionKey);
if (action != null) {
Modified: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java 2008-07-24 14:10:30 UTC (rev 777)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java 2008-07-24 16:49:08 UTC (rev 778)
@@ -20,6 +20,7 @@
package org.codelutin.jaxx;
import org.codelutin.jaxx.action.provider.ActionProvider;
+import org.codelutin.jaxx.action.provider.ActionProviderFromProperties;
import org.codelutin.util.FileUtil;
import java.io.File;
@@ -66,7 +67,7 @@
protected static final String PROVIDER_TEMPLATE =
"package %1$s;\n" +
"\n" +
- "public class %2$s extends org.codelutin.jaxx.action.provider.ActionProviderFromProperties<%3$s> {\n" +
+ "public class %2$s extends " + ActionProviderFromProperties.class.getName() + "<%3$s> {\n" +
"\n" +
" public %2$s() {\n" +
" super(\"%5$s\", %3$s.class, \"%4$s\");\n" +
1
0
r777 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 14:10:30 +0000 (Thu, 24 Jul 2008)
New Revision: 777
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java
Log:
introduce provider package
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java 2008-07-24 14:10:12 UTC (rev 776)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java 2008-07-24 14:10:30 UTC (rev 777)
@@ -17,6 +17,8 @@
* ##% */
package org.codelutin.jaxx.action;
+import org.codelutin.jaxx.action.provider.ActionProvider;
+
import java.util.Map;
import java.util.ServiceLoader;
import java.util.TreeMap;
1
0