r292 - trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing
Author: tchemit Date: 2008-01-20 18:40:17 +0000 (Sun, 20 Jan 2008) New Revision: 292 Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerActionManager.java Log: utilisation ActionConfig pour configurer les actions Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerActionManager.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerActionManager.java 2008-01-20 18:39:07 UTC (rev 291) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerActionManager.java 2008-01-20 18:40:17 UTC (rev 292) @@ -18,21 +18,22 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing; +import fr.cemagref.simexplorer.is.ui.SimExplorerRuntimeException; +import fr.cemagref.simexplorer.is.ui.swing.action.SimExplorerAbstractAction; +import fr.cemagref.simexplorer.is.ui.swing.util.ActionConfig; +import jaxx.runtime.JAXXObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import static org.codelutin.i18n.I18n._; +import org.codelutin.i18n.I18n; import javax.swing.AbstractButton; -import javax.swing.Icon; +import javax.swing.Action; import java.io.IOException; import java.util.Map; import java.util.Properties; import java.util.TreeMap; -import jaxx.runtime.JAXXObject; -import fr.cemagref.simexplorer.is.ui.swing.action.SimExplorerAbstractAction; -import fr.cemagref.simexplorer.is.ui.SimExplorerRuntimeException; - /** * La classe responsable de l'enregistrement des actions disponibles * dans l'application ({@link #init()} . @@ -69,9 +70,36 @@ // on récupère la classe d'implantation de l'action Class<? extends SimExplorerAbstractAction> klazz = impls.get(actionKey); + try { SimExplorerAbstractAction result = klazz.getConstructor(String.class).newInstance(actionKey); + result.putValue(Action.ACTION_COMMAND_KEY, actionKey); + log.debug(actionKey + " : " + result); + // recherche de l'annotation de configuration + ActionConfig anno = klazz.getAnnotation(ActionConfig.class); + if (anno != null) { + // inject les données + if (!anno.name().isEmpty()) { + result.putValue(Action.NAME, I18n._(anno.name())); + } + //if (!anno.shortDescription().isEmpty()) { + result.putValue(Action.SHORT_DESCRIPTION, I18n._(anno.shortDescription())); + //} + if (!anno.smallIcon().isEmpty()) { + result.putValue(Action.SMALL_ICON, fr.cemagref.simexplorer.is.ui.swing.util.UIHelper.createImageIcon(anno.smallIcon())); + } + if (anno.mnemonic() != '\0') { + result.putValue(Action.MNEMONIC_KEY, anno.mnemonic()); + } + result.putValue(Action.ACCELERATOR_KEY, anno.accelerator()); + result.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, anno.displayedMnemonicIndex()); + + result.putValue("hideActionText", anno.hideActionText()); + result.putValue(Action.SELECTED_KEY, anno.selected()); + result.setEnabled(anno.enabled()); + + } return result; } catch (Exception e) { throw new SimExplorerRuntimeException(e); @@ -123,14 +151,18 @@ } AbstractButton component = (AbstractButton) comp; SimExplorerAbstractAction action = newAction(actionKey); - String text = component.getText(); - String tooltip = component.getToolTipText(); - Icon icon = component.getIcon(); + //String text = component.getText(); + //String tooltip = component.getToolTipText(); + //Icon icon = component.getIcon(); component.setAction(action); - component.setText(text); - component.setToolTipText(tooltip); - component.setIcon(icon); - component.setEnabled(true); + Boolean value = (Boolean) action.getValue("hideActionText"); + if (value != null && value) { + component.setHideActionText(true); + } + //component.setText(text); + //component.setToolTipText(tooltip); + //component.setIcon(icon); + //component.setEnabled(true); } }
participants (1)
-
tchemit@users.labs.libre-entreprise.org