Author: tchemit Date: 2008-01-20 23:57:51 +0000 (Sun, 20 Jan 2008) New Revision: 315 Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerActionManager.java Log: introduction GlueActionConfig pour configurer une action de type Glue 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 23:57:08 UTC (rev 314) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerActionManager.java 2008-01-20 23:57:51 UTC (rev 315) @@ -21,6 +21,8 @@ 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 fr.cemagref.simexplorer.is.ui.swing.util.GlueActionConfig; +import fr.cemagref.simexplorer.is.ui.swing.util.MyToggleButton; import jaxx.runtime.JAXXObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -28,6 +30,7 @@ import javax.swing.AbstractButton; import javax.swing.Action; +import javax.swing.Icon; import java.io.IOException; import java.util.Map; import java.util.Properties; @@ -105,6 +108,25 @@ component.setAction(action); + if (component instanceof MyToggleButton) { + MyToggleButton glueComponent = (MyToggleButton) 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); @@ -132,46 +154,37 @@ 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()) { - System.out.println("found action with name : " + anno.name()); - result.putValue(Action.NAME, _(anno.name())); - } - //if (!anno.shortDescription().isEmpty()) { - result.putValue(Action.SHORT_DESCRIPTION, _(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()); - } else if (component!=null) { - result.putValue(Action.MNEMONIC_KEY, component.getMnemonic()); - } - //TODO Convert it from String result.putValue(Action.ACCELERATOR_KEY, anno.accelerator()); + ActionConfig anno = initActionConfig(component, klazz, result); - - result.putValue("hideActionText", anno.hideActionText()); - result.putValue(Action.SELECTED_KEY, anno.selected()); - result.setEnabled(anno.enabled()); - } else { - if (component != null) { + if (anno == null) { + GlueActionConfig anno2 = initGlueActionConfig(component, klazz, result); + if (anno2 == null && component != null) { + result.putValue(Action.ACTION_COMMAND_KEY, component.getName()); result.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText()); result.putValue(Action.SMALL_ICON, component.getIcon()); - result.putValue(Action.ACTION_COMMAND_KEY, component.getName()); result.putValue(Action.NAME, component.getText()); - result.putValue(Action.MNEMONIC_KEY, component.getMnemonic()); + result.putValue(Action.MNEMONIC_KEY, component.getMnemonic()); result.putValue("hideActionText", component.getHideActionText()); + if (component instanceof MyToggleButton) { + MyToggleButton glueComponent = (MyToggleButton) component; + result.putValue(Action.SHORT_DESCRIPTION , glueComponent.getNormalTooltipText()); + result.putValue(Action.NAME , glueComponent.getNormalText()); + result.putValue(Action.SMALL_ICON , glueComponent.getIcon()); + result.putValue(Action.MNEMONIC_KEY , glueComponent.getNormalMnemonic()); + result.putValue(Action.SHORT_DESCRIPTION + 2, glueComponent.getGlueTooltipText()); + result.putValue(Action.NAME + 2, glueComponent.getGlueText()); + result.putValue(Action.SMALL_ICON + 2, glueComponent.getSelectedIcon()); + result.putValue(Action.MNEMONIC_KEY + 2, glueComponent.getGlueMnemonic()); + } } } + String text = (String) result.getValue(Action.NAME); Integer mnemo = (Integer) result.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())); + if (mnemo != null && mnemo != '\0') { + int pos = text.indexOf((char) mnemo.intValue()); + if (pos == -1) { + pos = text.indexOf(Character.toLowerCase((char) mnemo.intValue())); } result.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, pos); } @@ -181,6 +194,80 @@ } } + private static GlueActionConfig initGlueActionConfig(AbstractButton component, Class<? extends SimExplorerAbstractAction> klazz, SimExplorerAbstractAction result) { + GlueActionConfig anno = klazz.getAnnotation(GlueActionConfig.class); + if (anno != null) { + // inject les données + if (!anno.name().isEmpty()) { + //System.out.println("found action with name : " + anno.name()); + result.putValue(Action.NAME, _(anno.name())); + } + if (!anno.name2().isEmpty()) { + //System.out.println("found action with name2 : " + anno.name2()); + result.putValue(Action.NAME + "2", _(anno.name2())); + } + + if (!anno.shortDescription().isEmpty()) { + result.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription())); + } + if (!anno.shortDescription2().isEmpty()) { + result.putValue(Action.SHORT_DESCRIPTION + "2", _(anno.shortDescription2())); + } + + if (!anno.smallIcon().isEmpty()) { + result.putValue(Action.SMALL_ICON, fr.cemagref.simexplorer.is.ui.swing.util.UIHelper.createImageIcon(anno.smallIcon())); + } + if (!anno.smallIcon2().isEmpty()) { + result.putValue(Action.SMALL_ICON + "2", fr.cemagref.simexplorer.is.ui.swing.util.UIHelper.createImageIcon(anno.smallIcon2())); + } + + if (anno.mnemonic() != '\0') { + result.putValue(Action.MNEMONIC_KEY, anno.mnemonic()); + } else if (component != null) { + result.putValue(Action.MNEMONIC_KEY, component.getMnemonic()); + } + if (anno.mnemonic2() != '\0') { + result.putValue(Action.MNEMONIC_KEY + "2", anno.mnemonic2()); + } + //TODO Convert it from String result.putValue(Action.ACCELERATOR_KEY, anno.accelerator()); + + + result.putValue("hideActionText", anno.hideActionText()); + result.putValue(Action.SELECTED_KEY, anno.selected()); + result.setEnabled(anno.enabled()); + } + return anno; + } + + private static ActionConfig initActionConfig(AbstractButton component, Class<? extends SimExplorerAbstractAction> klazz, SimExplorerAbstractAction result) { + ActionConfig anno = klazz.getAnnotation(ActionConfig.class); + if (anno != null) { + // inject les données + if (!anno.name().isEmpty()) { + //System.out.println("found action with name : " + anno.name()); + result.putValue(Action.NAME, _(anno.name())); + } + //if (!anno.shortDescription().isEmpty()) { + result.putValue(Action.SHORT_DESCRIPTION, _(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()); + } else if (component != null) { + result.putValue(Action.MNEMONIC_KEY, component.getMnemonic()); + } + //TODO Convert it from String result.putValue(Action.ACCELERATOR_KEY, anno.accelerator()); + + + result.putValue("hideActionText", anno.hideActionText()); + result.putValue(Action.SELECTED_KEY, anno.selected()); + result.setEnabled(anno.enabled()); + } + return anno; + } + protected static void checkInit() { if (impls == null) { throw new SimExplorerRuntimeException("you must init first the " + SimExplorerActionManager.class.getName() + " class via init method");