Author: tchemit Date: 2008-01-22 01:02:59 +0000 (Tue, 22 Jan 2008) New Revision: 348 Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabManager.java Log: utilisation de la factory Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabManager.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabManager.java 2008-01-22 01:02:40 UTC (rev 347) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabManager.java 2008-01-22 01:02:59 UTC (rev 348) @@ -18,235 +18,90 @@ * \#\#% */ 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.tab.JApplicationDetailTab; import fr.cemagref.simexplorer.is.ui.swing.tab.JApplicationListTab; import fr.cemagref.simexplorer.is.ui.swing.tab.JApplicationSynchronizeTab; -import fr.cemagref.simexplorer.is.ui.swing.util.MyTabHeader; -import fr.cemagref.simexplorer.is.ui.swing.util.MyToggleButton; -import fr.cemagref.simexplorer.is.ui.swing.util.TabContent; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import static org.codelutin.i18n.I18n._; -import static org.codelutin.i18n.I18n.n_; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.builder.TabContentConfig; +import jaxx.runtime.builder.TabModel; +import jaxx.runtime.builder.TabFactory; import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; import javax.swing.JTabbedPane; -import java.awt.Component; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import jaxx.runtime.JAXXObject; - /** @author tony */ -public class SimExplorerTabManager { - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(SimExplorerTabManager.class); +public enum SimExplorerTabManager { - public enum Tab { + @TabContentConfig( + impl = JApplicationDetailTab.class, + model=TabModel.class, + parentImpl = JTabbedPane.class, + name = "simexplorer.tab.detail", + shortDescription = "simexplorer.tab.detail.tooltip" + )detail, - @TabContent(impl = JApplicationDetailTab.class, parentImpl = JTabbedPane.class) - detail(n_("simexplorer.tab.detail"), n_("simexplorer.tab.detail.tooltip")) { - public JApplicationDetailTab get() { - return (JApplicationDetailTab) get0(); - } - }, + @TabContentConfig( + impl = JApplicationListTab.class, + parentImpl = JTabbedPane.class, + model=TabModel.class, + useToogle = true, + name = "simexplorer.tab.local", + shortDescription = "simexplorer.tab.local.tooltip" + )local, - @TabContent(impl = JApplicationListTab.class, parentImpl = JTabbedPane.class, useToogle = true) - local(n_("simexplorer.tab.local"), n_("simexplorer.tab.local.tooltip")) { - public JApplicationListTab get() { - return (JApplicationListTab) get0(); - } - }, + @TabContentConfig( + impl = JApplicationListTab.class, + parentImpl = JTabbedPane.class, + model=TabModel.class, + useToogle = true, + name = "simexplorer.tab.remote", + shortDescription = "simexplorer.tab.remote.tooltip" + )remote, - @TabContent(impl = JApplicationListTab.class, parentImpl = JTabbedPane.class, useToogle = true) - remote(n_("simexplorer.tab.remote"), n_("simexplorer.tab.remote.tooltip")) { - public JApplicationListTab get() { - return (JApplicationListTab) get0(); - } - }, + @TabContentConfig( + impl = JApplicationSynchronizeTab.class, + parentImpl = JTabbedPane.class, + model=TabModel.class, + useToogle = true, + name = "simexplorer.tab.synchronize", + shortDescription = "simexplorer.tab.synchronize.tooltip" + )synchronize; - @TabContent(impl = JApplicationSynchronizeTab.class, parentImpl = JTabbedPane.class, useToogle = true) - synchronize(n_("simexplorer.tab.synchronize"), n_("simexplorer.tab.synchronize.tooltip")) { - public JApplicationSynchronizeTab get() { - return (JApplicationSynchronizeTab) get0(); - } - }; + /** l'usine de tabs */ + private static TabFactory factory; - - public abstract JComponent get(); - - private final String text; - - private final String toolTipText; - - private JComponent instance; - - private TabContent annotation; - - Tab(String text, String toolTipText) { - this.text = text; - this.toolTipText = toolTipText; + public static TabFactory getFactory() { + if (factory == null) { + factory = new SimExplorerTabFactory(); } - - public String getText() { - return _(text); - } - - public String getToolTipText() { - return _(toolTipText); - } - - public boolean isUseToggle() { - return getAnnotation().useToogle(); - } - - JComponent get0() { - if (instance == null) { - try { - instance = getAnnotation().impl().newInstance(); - log.info("new tab : "+instance); - // chargement dans l'ui des actions - if (instance instanceof JAXXObject) { - JAXXObject ui = (JAXXObject) instance; - SimExplorerActionManager.loadActions(ui); - Object toolbar = ui.getObjectById("toolbar"); - if (toolbar!=null && toolbar instanceof JAXXObject) { - SimExplorerActionManager.loadActions((JAXXObject) toolbar); - } - } - } catch (InstantiationException e) { - throw new SimExplorerRuntimeException(e); - } catch (IllegalAccessException e) { - throw new SimExplorerRuntimeException(e); - } - } - return instance; - } - - TabContent getAnnotation() { - if (annotation == null) { - try { - annotation = getClass().getField(name()).getAnnotation(TabContent.class); - } catch (NoSuchFieldException e) { - throw new SimExplorerRuntimeException("could not found annotation " + TabContent.class + " on enum " + this); - } - } - if (annotation == null) { - throw new SimExplorerRuntimeException("could not found annotation " + TabContent.class + " on enum " + this); - } - return annotation; - } - + return factory; } - public static void reloadUI() { - for (Tab tab : Tab.values()) { - tab.instance = null; - } + public JAXXObject getUI() { + return (JAXXObject) getFactory().getUI(name()); } - public static void showTab(final JTabbedPane container, Tab tab) { - - final JComponent comp = tab.get(); - int index = getTabIndex(container, tab); - if (index == -1) { - addTab(container, tab, comp); - } - container.setSelectedComponent(comp); - - int index1 = getTabIndex(container, tab); - log.debug(tab + " index " + index1); - if (tab.isUseToggle()) { - MyToggleButton buton = (MyToggleButton) SimExplorer.getUI().getObjectById("toggleTab_" + tab.name()); - buton.setSelected(true); - } + public TabModel getModel() { + return getFactory().getModel(name()); } - public static void closeTab(JTabbedPane container, Tab tab) { - - int index = getTabIndex(container, tab); - if (index != -1) { - container.removeTabAt(index); - log.debug(tab + " index " + index); - } - if (tab.isUseToggle()) { - MyToggleButton buton = (MyToggleButton) SimExplorer.getUI().getObjectById("toggleTab_" + tab.name()); - buton.setSelected(false); - } + public boolean isTabVisible(JTabbedPane container) { + JAXXObject ui = getUI(); + return ui != null && getFactory().getTabIndex(container, (JComponent) ui) > -1; } - public static void toggleTab(JTabbedPane container, Tab tab) { - if (getTabIndex(container, tab) > -1) { - closeTab(container, tab); - } else { - showTab(container, tab); - } + public int getTabIndex(JTabbedPane container) { + JAXXObject ui = getUI(); + return ui == null ? -1 : getFactory().getTabIndex(container, (JComponent) ui); } - protected static void addTab(final JTabbedPane container, final Tab tab, final JComponent comp) { - - container.addTab(tab.getText(), comp); - final MyTabHeader panel = new MyTabHeader(); - - // add a dynamic reference to tab close button to enable - // dynamic action instanciation - panel.get$objectMap().put(panel.getCloseTab().getName() + "_" + tab.name(), panel.getCloseTab()); - - // chargement dans l'ui des actions - SimExplorerActionManager.loadActions(panel); - - panel.setToolTipText(tab.getToolTipText()); - panel.getLabel().setText(tab.getText()); - - panel.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - Component compOld = container.getSelectedComponent(); - if (!comp.equals(compOld)) { - container.setSelectedComponent(comp); - } - } - }); - - container.setTabComponentAt(container.getTabCount() - 1, panel); - container.repaint(); + public void showTab(final JTabbedPane container) { + getFactory().showTab(container, name()); } - public static int getTabIndex(final JTabbedPane container, Tab tab) { - if (container != null) { - for (int i = 0; i < container.getTabCount(); i++) { - Component o = container.getComponentAt(i); - if (o.equals(tab.instance)) { - return i; - } - } - } - return -1; + public void closeTab(JTabbedPane container) { + getFactory().closeTab(container, name()); } - - protected SimExplorerTabManager() { - // do not instanciate - } - - public static void main(String[] args) { - SimExplorer.init(); - JTabbedPane container = SimExplorer.getUI().getContent(); - - JDialog dialog = new JDialog(); - dialog.setSize(800, 600); - dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - dialog.setContentPane(container); - - for (Tab tab : Tab.values()) { - SimExplorerTabManager.showTab(container, tab); - } - dialog.setVisible(true); - } - }
participants (1)
-
tchemit@users.labs.libre-entreprise.org