This is an automated email from the git hooks/post-receive script. New commit to branch feature/6690 in repository tutti. See http://git.codelutin.com/tutti.git commit 9a1d0d58ecc6989a06e7ad715e9c66332edbc2c1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Feb 19 11:47:23 2015 +0100 ajout de méthodes utiles pour créer des actions --- .../ifremer/tutti/ui/swing/util/TuttiUIUtil.java | 56 +++++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java index e94ce78..2fcd826 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java @@ -34,8 +34,15 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.jaxx.application.ApplicationBusinessException; import org.nuiton.jaxx.application.swing.util.ApplicationUIUtil; -import javax.swing.*; -import java.awt.*; +import javax.swing.AbstractAction; +import javax.swing.AbstractButton; +import javax.swing.Action; +import javax.swing.ImageIcon; +import javax.swing.JComponent; +import java.awt.Color; +import java.awt.Desktop; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -154,6 +161,7 @@ public final class TuttiUIUtil extends ApplicationUIUtil { /** * Computes the brightness of a color. This can be useful to determine the text color according to the backgound. * (e.g. if the backgound's brightness is over 125, the text could be written in black, otherwise in white) + * * @param c the color * @return the brightness of the color: 0 the darkest, 255 the brightest */ @@ -166,4 +174,48 @@ public final class TuttiUIUtil extends ApplicationUIUtil { green * green * .691 + blue * blue * .068); } + + public static void prepareAction(AbstractButton button, Action action, String actionName) { + + action.putValue(Action.SMALL_ICON, button.getIcon()); + action.putValue(Action.LARGE_ICON_KEY, button.getIcon()); + action.putValue(Action.ACTION_COMMAND_KEY, actionName); + action.putValue(Action.NAME, button.getText()); + action.putValue(Action.SHORT_DESCRIPTION, button.getToolTipText()); + action.putValue(Action.MNEMONIC_KEY, button.getMnemonic()); + + button.setAction(action); + + } + + public static Action addDelegateAction(AbstractButton button, String actionName) { + + Action action = new AbstractAction() { + + private static final long serialVersionUID = 1L; + + @Override + public void actionPerformed(ActionEvent e) { + + AbstractButton source = (AbstractButton) e.getSource(); + + ActionListener[] actionListeners = source.getActionListeners(); + + for (ActionListener actionListener : actionListeners) { + if (this != actionListener) { + if (log.isDebugEnabled()) { + log.debug("Do actionPerformed on listener: " + actionListener); + } + actionListener.actionPerformed(e); + } + } + + } + + }; + + prepareAction(button, action, actionName); + return action; + + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.