Author: tchemit Date: 2008-01-22 01:56:03 +0000 (Tue, 22 Jan 2008) New Revision: 357 Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ToggleTabAbstractAction.java Log: dispatch action Copied: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ToggleTabAbstractAction.java (from rev 317, trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ToggleTabAction.java) =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ToggleTabAbstractAction.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ToggleTabAbstractAction.java 2008-01-22 01:56:03 UTC (rev 357) @@ -0,0 +1,77 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit, Gabriel Landais +* +* 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.action; + +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerActionManager; + +import javax.swing.AbstractAction; +import javax.swing.AbstractButton; +import javax.swing.JTabbedPane; +import java.awt.event.ActionEvent; + +/** + * Action pour siwtcher un tab + * + * @author chemit + */ +public abstract class ToggleTabAbstractAction extends SimExplorerAbstractTabAction { + + private static final long serialVersionUID = -5457476021698351850L; + + AbstractAction showAction; + AbstractAction closeAction; + + AbstractAction action; + + public ToggleTabAbstractAction(String name) { + super(name, "toggleTab"); + } + + @Override + protected boolean beforeAction(ActionEvent e) throws Exception { + super.beforeAction(e); + // find real action to perform + JTabbedPane container = getMainUI().getContent(); + if (tab.isTabVisible(container) ) { + action = getCloseAction(); + } else { + action = getShowAction(); + } + return action != null; + } + + @Override + protected void doAction(ActionEvent e) throws Exception { + action.actionPerformed(e); + } + + public AbstractAction getCloseAction() { + if (closeAction == null) { + closeAction = SimExplorerActionManager.newAction("closeTab_" + tab.name(), (AbstractButton) null); + } + return closeAction; + } + + public AbstractAction getShowAction() { + if (showAction == null) { + showAction = SimExplorerActionManager.newAction("showTab_" + tab.name(), (AbstractButton) null); + } + return showAction; + } +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org