Search in sources :

Example 1 with RuntimeTabPanel

use of com.servoy.j2db.ui.scripting.RuntimeTabPanel in project servoy-client by Servoy.

the class ComponentFactory method createTabPanel.

private static IComponent createTabPanel(IApplication application, Form form, TabPanel meta, IScriptExecuter el) {
    // HACK:To set the selected color on a tabpanel
    Color oldColor = null;
    if (meta.getSelectedTabColor() != null) {
        oldColor = UIManager.getColor("TabbedPane.selected");
        UIManager.put("TabbedPane.selected", meta.getSelectedTabColor());
    }
    int orient = meta.getTabOrientation();
    AbstractRuntimeTabPaneAlike scriptable = null;
    ITabPanel tabs;
    if (meta.getTabOrientation() == TabPanel.ACCORDION_PANEL) {
        scriptable = new RuntimeAccordionPanel(application.getItemFactory().createChangesRecorder(), application);
        tabs = application.getItemFactory().createAccordionPanel((RuntimeAccordionPanel) scriptable, getWebID(form, meta));
    } else {
        scriptable = new RuntimeTabPanel(application.getItemFactory().createChangesRecorder(), application);
        tabs = application.getItemFactory().createTabPanel((RuntimeTabPanel) scriptable, getWebID(form, meta), orient, meta.hasOneTab());
    }
    scriptable.setComponent(tabs, meta);
    if (meta.getScrollTabs()) {
        tabs.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    } else {
        tabs.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
    }
    if (el != null && meta.getOnTabChangeMethodID() > 0) {
        tabs.setOnTabChangeMethodCmd(Integer.toString(meta.getOnTabChangeMethodID()), Utils.parseJSExpressions(meta.getFlattenedMethodArguments("onTabChangeMethodID")));
        tabs.addScriptExecuter(el);
    }
    applyBasicComponentProperties(application, tabs, meta, getStyleForBasicComponent(application, meta, form));
    if (meta.getHorizontalAlignment() >= 0) {
        tabs.setHorizontalAlignment(meta.getHorizontalAlignment());
    }
    // HACK:restore so not all tabpanel get that color!
    if (meta.getSelectedTabColor() != null)
        UIManager.put("TabbedPane.selected", oldColor);
    try {
        int index = 0;
        Iterator<IPersist> it = meta.getTabs();
        while (it.hasNext()) {
            Tab tab = (Tab) it.next();
            Form f = application.getFlattenedSolution().getForm(tab.getContainsFormID());
            if (f != null) {
                IFormLookupPanel flp = tabs.createFormLookupPanel(tab.getName(), tab.getRelationName(), f.getName());
                tabs.addTab(application.getI18NMessageIfPrefixed(tab.getText()), tab.getImageMediaID(), flp, application.getI18NMessageIfPrefixed(tab.getToolTipText()));
                Color fg = tab.getForeground();
                Color bg = tab.getBackground();
                if (fg != null)
                    tabs.setTabForegroundAt(index, fg);
                if (bg != null)
                    tabs.setTabBackgroundAt(index, bg);
                String mnemonic = application.getI18NMessageIfPrefixed(tab.getMnemonic());
                if (mnemonic != null && mnemonic.length() > 0) {
                    tabs.setMnemonicAt(index, mnemonic.charAt(0));
                }
                index++;
            }
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
    return tabs;
}
Also used : AbstractRuntimeTabPaneAlike(com.servoy.j2db.ui.scripting.AbstractRuntimeTabPaneAlike) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) Color(java.awt.Color) ITabPanel(com.servoy.j2db.ui.ITabPanel) RuntimeAccordionPanel(com.servoy.j2db.ui.scripting.RuntimeAccordionPanel) JSONException(org.json.JSONException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IFormLookupPanel(com.servoy.j2db.ui.IFormLookupPanel) Tab(com.servoy.j2db.persistence.Tab) RuntimeTabPanel(com.servoy.j2db.ui.scripting.RuntimeTabPanel) IPersist(com.servoy.j2db.persistence.IPersist)

Aggregations

IForm (com.servoy.j2db.IForm)1 Form (com.servoy.j2db.persistence.Form)1 IPersist (com.servoy.j2db.persistence.IPersist)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 Tab (com.servoy.j2db.persistence.Tab)1 IFormLookupPanel (com.servoy.j2db.ui.IFormLookupPanel)1 ITabPanel (com.servoy.j2db.ui.ITabPanel)1 AbstractRuntimeTabPaneAlike (com.servoy.j2db.ui.scripting.AbstractRuntimeTabPaneAlike)1 RuntimeAccordionPanel (com.servoy.j2db.ui.scripting.RuntimeAccordionPanel)1 RuntimeTabPanel (com.servoy.j2db.ui.scripting.RuntimeTabPanel)1 Color (java.awt.Color)1 IOException (java.io.IOException)1 JSONException (org.json.JSONException)1