package com.fr.design.form.mobile;

import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.form.main.mobile.FormMobileAttr;
import com.fr.general.Inter;

import javax.swing.*;
import java.awt.*;

/**
 * Created by fanglei on 2016/11/17.
 */
public class FormMobileAttrPane extends BasicBeanPane<FormMobileAttr>{
    //工具栏容器
    private MobileToolBarPane mobileToolBarPane;
    // 模版设置面板
    private FormMobileTemplateSettingsPane formMobileTemplateSettingsPane;
    // 其他
    private FormMobileOthersPane formMobileOthersPane;

    private static final int PADDING = 10;

    public FormMobileAttrPane() {
        this.initComponents();
    }

    private void initComponents() {
        this.setLayout(FRGUIPaneFactory.createBorderLayout());
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.setBorder(BorderFactory.createEmptyBorder(PADDING, PADDING, PADDING, PADDING));

        panel.add(formMobileTemplateSettingsPane = new FormMobileTemplateSettingsPane());
        panel.add(mobileToolBarPane = new MobileToolBarPane());
        panel.add(formMobileOthersPane = new FormMobileOthersPane());

        JPanel panelWrapper = FRGUIPaneFactory.createBorderLayout_S_Pane();
        panelWrapper.add(panel, BorderLayout.NORTH);
        UIScrollPane scrollPane = new UIScrollPane(panelWrapper);
        this.add(scrollPane);
    }

    @Override
    public void populateBean(FormMobileAttr ob) {
        if (ob == null) {
            ob = new FormMobileAttr();
        }
        this.mobileToolBarPane.populateBean(ob);
        this.formMobileTemplateSettingsPane.populateBean(ob);
        this.formMobileOthersPane.populateBean(ob);
    }

    @Override
    public FormMobileAttr updateBean() {
        FormMobileAttr formMobileAttr = new FormMobileAttr();
        this.mobileToolBarPane.updateBean(formMobileAttr);
        this.formMobileTemplateSettingsPane.updateBean(formMobileAttr);
        this.formMobileOthersPane.updateBean(formMobileAttr);
        return formMobileAttr;
    }

    @Override
    protected String title4PopupWindow() {
        return Inter.getLocText("FR-Designer_Mobile-Attr");
    }
}
