package com.fr.plugin.easyslides.ui;

import com.fr.design.designer.creator.CRPropertyDescriptor;
import com.fr.design.designer.creator.XWidgetCreator;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.widget.editors.*;
import com.fr.form.ui.Widget;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import com.fr.stable.ArrayUtils;

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

import static com.fr.plugin.easyslides.EasySlidesWidget.*;

public class EasySlidesWidgetUI extends XWidgetCreator {
    private UITextField textField;

    public EasySlidesWidgetUI(Widget widget, Dimension dimension) {
        super(widget, dimension);
    }

    @Override
    protected JComponent initEditor() {
        if (this.editor == null) {
            this.editor = FRGUIPaneFactory.createBorderLayout_S_Pane();
            UILabel label = new UILabel();
            label.setIcon(IOUtils.readIcon("/com/fr/plugin/resources/images/display.png"));
            label.setHorizontalAlignment(0);
            label.setVerticalAlignment(0);
            this.editor.add(label, "Center");
            this.textField = new UITextField(5);
            this.textField.setOpaque(false);
            this.editor.add(this.textField, "South");
            this.editor.setBackground(Color.WHITE);
        }
        return this.editor;
    }

    @Override
    public String getIconPath() {
        return "/com/fr/plugin/resources/images/icon.png";
    }

    public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
        String advanced = Inter.getLocText("Plugin-EasySlides_Advanced");
        return ArrayUtils.addAll(super.supportedDescriptor(),
                (new CRPropertyDescriptor("widgetValue", this.data.getClass()))
                        .setI18NName(Inter.getLocText("Plugin-EasySlides_DataSource"))
                        .setEditorClass(SlidesDataSourceEditor.class)
                        .putKeyValue("category", advanced),
                (new CRPropertyDescriptor(SLIDE_STYLE, this.data.getClass()))
                        .setI18NName(Inter.getLocText("Plugin-EasySlides_SlideStyle"))
                        .setEditorClass(SlideStyleEditor.class)
                        .putKeyValue("category", advanced),
                (new CRPropertyDescriptor(BACKGROUND_COLOR, this.data.getClass()))
                        .setI18NName(Inter.getLocText("Plugin-EasySlides_ColorBackground"))
                        .setEditorClass(ColorEditor.class)
                        .putKeyValue("category", advanced),
                (new CRPropertyDescriptor(SLIDE_BACKGROUND_COLOR, this.data.getClass()))
                        .setI18NName(Inter.getLocText("Plugin-EasySlides_SlideColorBackground"))
                        .setEditorClass(ColorEditor.class)
                        .putKeyValue("category", advanced),
                (new CRPropertyDescriptor(SLIDE_FONT_COLOR, this.data.getClass()))
                        .setI18NName(Inter.getLocText("Plugin-EasySlides_SlideFontColor"))
                        .setEditorClass(ColorEditor.class)
                        .putKeyValue("category", advanced),
                (new CRPropertyDescriptor(AUTO_PLAY, this.data.getClass()))
                        .setI18NName(Inter.getLocText("Plugin-EasySlides_AutoPlay"))
                        .setEditorClass(BooleanEditor.class)
                        .putKeyValue("category", advanced),
                (new CRPropertyDescriptor(AUTO_PLAY_INTERVAL_TIME, this.data.getClass()))
                        .setI18NName(Inter.getLocText("Plugin-EasySlides_AutoPlayTime"))
                        .setEditorClass(IntegerPropertyEditor.class)
                        .putKeyValue("category", advanced),
                (new CRPropertyDescriptor(TOOLBAR, this.data.getClass()))
                        .setI18NName(Inter.getLocText("Plugin-EasySlides_ToolBar"))
                        .setEditorClass(BooleanEditor.class)
                        .putKeyValue("category", advanced),
                (new CRPropertyDescriptor(PROGRESSBAR, this.data.getClass()))
                        .setI18NName(Inter.getLocText("Plugin-EasySlides_ProgressBar"))
                        .setEditorClass(BooleanEditor.class)
                        .putKeyValue("category", advanced),
                (new CRPropertyDescriptor(PROGRESS, this.data.getClass()))
                        .setI18NName(Inter.getLocText("Plugin-EasySlides_Progress"))
                        .setEditorClass(BooleanEditor.class)
                        .putKeyValue("category", advanced)
        );
    }
}