Author: tchemit Date: 2008-01-22 01:02:40 +0000 (Tue, 22 Jan 2008) New Revision: 347 Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabFactory.java Log: la factory de tab de SimExplorer Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabFactory.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabFactory.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabFactory.java 2008-01-22 01:02:40 UTC (rev 347) @@ -0,0 +1,129 @@ +/* +* \#\#% 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; + +import fr.cemagref.simexplorer.is.ui.SimExplorer; +import fr.cemagref.simexplorer.is.ui.SimExplorerRuntimeException; +import fr.cemagref.simexplorer.is.ui.swing.util.MyTabHeader; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.builder.TabContentConfig; +import jaxx.runtime.builder.TabFactory; +import static org.codelutin.i18n.I18n._; + +import javax.swing.AbstractButton; +import javax.swing.JComponent; +import javax.swing.JTabbedPane; +import java.awt.Component; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.lang.reflect.Field; +import java.util.Map; +import java.util.TreeMap; + +/** + * L'implatantion pour SimExplorer de la factory de Tab + * + * @author chemit + * @see TabFactory + */ +public class SimExplorerTabFactory extends TabFactory { + + protected Map<String, TabContentConfig> initFactory() { + Map<String, TabContentConfig> result = new TreeMap<String, TabContentConfig>(); + for (SimExplorerTabManager tab : SimExplorerTabManager.values()) { + try { + String tabName = tab.name(); + Field field = tab.getClass().getField(tabName); + result.put(tabName, field.getAnnotation(TabContentConfig.class)); + } catch (NoSuchFieldException e) { + throw new SimExplorerRuntimeException(e); + } + } + return result; + } + + protected void initTab(JComponent tab, String tabName, TabContentConfig config) { + SimExplorerActionManager.loadActions((JAXXObject) tab, getTab(tabName)); + } + + protected SimExplorerTabManager getTab(String tabName) { + return SimExplorerTabManager.valueOf(tabName); + } + + @Override + protected JComponent addTabHeader(final JTabbedPane container, + String tabName, + TabContentConfig tab, + final JComponent comp) { + + final MyTabHeader panel = new MyTabHeader(); + + // add a dynamic reference to tab close button to enable + // dynamic action instanciation + //TODO add the ActionManager mecanism ? + String actionName = panel.getCloseTab().getName() + "_" + tabName; + + panel.get$objectMap().put(actionName, panel.getCloseTab()); + + // chargement dans l'ui des actions + SimExplorerActionManager.loadActions(panel, getTab(tabName)); + + panel.setToolTipText(_(tab.shortDescription())); + panel.getLabel().setText(_(tab.name())); + + panel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + Component compOld = container.getSelectedComponent(); + if (!comp.equals(compOld)) { + container.setSelectedComponent(comp); + } + } + }); + return panel; + } + + @Override + public void showTab(final JTabbedPane container, String tabName) { + + super.showTab(container, tabName); + + switchToggleButton(tabName, true); + } + + @Override + public void closeTab(JTabbedPane container, String tabName) { + + super.closeTab(container, tabName); + + switchToggleButton(tabName, false); + } + + protected void switchToggleButton(String tabName, boolean b) { + + TabContentConfig tab = getConfig(tabName); + + if (tab.useToogle()) { + AbstractButton buton; + buton = (AbstractButton) SimExplorer.getUI().getObjectById("toggleTab_" + tabName); + buton.setSelected(b); + } + } + +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org