Author: tchemit Date: 2008-01-19 14:40:53 +0000 (Sat, 19 Jan 2008) New Revision: 220 Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerAbstractTabAction.java Log: dispatch action (appel introspectif ?\195?\160 partir du nom de la m?\195?\169thode) utilis?\195?\169e pour les actions d'ouverture, fermeture, toggle de'onglets de TabbedPane Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerAbstractTabAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerAbstractTabAction.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerAbstractTabAction.java 2008-01-19 14:40:53 UTC (rev 220) @@ -0,0 +1,77 @@ +/* +* \#\#% 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 fr.cemagref.simexplorer.is.ui.swing; + +import org.apache.commons.beanutils.Converter; +import org.codelutin.i18n.I18n; +import org.codelutin.util.ConverterUtil; + +import javax.swing.JTabbedPane; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** @author tony */ +public class SimExplorerAbstractTabAction extends SimExplorerAbstractAction { + + protected SimExplorerTabManager.Tab tab; + + protected String methodName; + + protected Method method; + + private static final long serialVersionUID = 5285229914266682509L; + + + protected SimExplorerAbstractTabAction(String name, String prefixPatternName) { + super(name); + methodName = prefixPatternName; + Pattern patternName = Pattern.compile(prefixPatternName + "_(\\w+)"); + Matcher matcher = patternName.matcher(name); + if (!matcher.matches()) { + throw new IllegalArgumentException(I18n._("{0} should have a name like this {1}, but was {2}", getClass().getName(), patternName, name)); + } + Converter convertorLanguage = ConverterUtil.getConverter(SimExplorerTabManager.Tab.class); + tab = (SimExplorerTabManager.Tab) convertorLanguage.convert(SimExplorerTabManager.Tab.class, matcher.group(1)); + } + + public void actionPerformed(java.awt.event.ActionEvent e) { + log.info(this + " tab " + tab); + try { + getMethod().invoke(null, getMainUI().getContent(), tab); + } catch (IllegalAccessException e1) { + throw new RuntimeException(e1); + } catch (InvocationTargetException e1) { + throw new RuntimeException(e1); + } + } + + protected Method getMethod() { + if (method == null) { + try { + method = SimExplorerTabManager.class.getMethod(methodName, JTabbedPane.class, SimExplorerTabManager.Tab.class); + } catch (NoSuchMethodException e) { + throw new RuntimeException("could not found method '" + methodName + "' on " + SimExplorerTabManager.class); + } + } + return method; + } + +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org