package Common.Visual;
import Common.Database.Tables.DataSet;
import Common.Visual.Menus.DataMenuBar;
import Common.Visual.Menus.FastAccessMenuBar;
import Common.Visual.Themes.DefaultTheme;
import Common.Visual.Themes.VisualiserTheme;
import Common.Visual.Windows.PassForm;

import javax.swing.*;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import java.awt.*;
import java.util.LinkedHashMap;
import java.util.Stack;
public class UIModule_ {
    public LinkedHashMap<Class<? extends DataSet>, DataMenuBar> menuBars = new LinkedHashMap<>();
    public Stack<Component> windowsStack = new Stack<>();
    protected LinkedHashMap<Class, TableCellRenderer> tableRenderers = new LinkedHashMap<>();
    protected LinkedHashMap<Class, TableCellEditor> tableEditors = new LinkedHashMap<>();
    protected LinkedHashMap<Class, TreeCellRenderer> treeRenderers = new LinkedHashMap<>();
    //--
    VisualiserTheme theme = new DefaultTheme();
    FastAccessMenuBar fastAccessMenuBar = new FastAccessMenuBar();
    PassForm passForm = null;//текущая форма прохода. нужна для
    public UIModule_() {
        //<editor-fold desc="Локализация компонентов окна JFileChooser">
        UIManager.put("FileChooser.openButtonText", "Открыть");
        UIManager.put("FileChooser.cancelButtonText", "Отмена");
        UIManager.put("FileChooser.lookInLabelText", "Смотреть в");
        UIManager.put("FileChooser.fileNameLabelText", "Имя файла");
        UIManager.put("FileChooser.filesOfTypeLabelText", "Тип файла");
        UIManager.put("FileChooser.saveButtonText", "Сохранить");
        UIManager.put("FileChooser.saveButtonToolTipText", "Сохранить");
        UIManager.put("FileChooser.openButtonToolTipText", "Открыть");
        UIManager.put("FileChooser.cancelButtonText", "Отмена");
        UIManager.put("FileChooser.cancelButtonToolTipText", "Отмена");
        UIManager.put("FileChooser.lookInLabelText", "Папка");
        UIManager.put("FileChooser.saveInLabelText", "Папка");
        UIManager.put("FileChooser.fileNameLabelText", "Имя файла");
        UIManager.put("FileChooser.filesOfTypeLabelText", "Тип файлов");
        UIManager.put("FileChooser.upFolderToolTipText", "На один уровень вверх");
        UIManager.put("FileChooser.newFolderToolTipText", "Создание новой папки");
        UIManager.put("FileChooser.listViewButtonToolTipText", "Список");
        UIManager.put("FileChooser.detailsViewButtonToolTipText", "Таблица");
        UIManager.put("FileChooser.fileNameHeaderText", "Имя");
        UIManager.put("FileChooser.fileSizeHeaderText", "Размер");
        UIManager.put("FileChooser.fileTypeHeaderText", "Тип");
        UIManager.put("FileChooser.fileDateHeaderText", "Изменен");
        UIManager.put("FileChooser.fileAttrHeaderText", "Атрибуты");
        UIManager.put("FileChooser.acceptAllFileFilterText", "Все файлы");
        //</editor-fold>
        //<editor-fold desc="Локализация компонентов окна подтверждения">
        UIManager.put("OptionPane.yesButtonText", "Да");
        UIManager.put("OptionPane.noButtonText", "Нет");
        UIManager.put("OptionPane.cancelButtonText", "Отмена");
        UIManager.put("OptionPane.okButtonText", "Готово");
        //</editor-fold>
    }
    //--
    public VisualiserTheme getTheme() {
        return theme;
    }
    public void setTheme(VisualiserTheme theme_in) {
        theme = theme_in;
    }
    //--
    public boolean HasPassForm() {
        return passForm != null;
    }
    public PassForm GetPassForm() {
        return passForm;
    }
    public PassForm SetPassForm(PassForm passForm_in) {
        return passForm = passForm_in;
    }
    public void DropPassForm() {
        passForm = null;
    }
    public FastAccessMenuBar getFastAccessMenuBar() {
        return fastAccessMenuBar;
    }
    public Component getFrontWindow() {
        Component res = null;
        try {
            res = windowsStack.peek();
        } catch (Exception ignored) {
        }
        return res;
    }
    public TableCellRenderer getTableRenderer(Class key) {
        TableCellRenderer res = null;
        if (tableRenderers.containsKey(key))
            res = tableRenderers.get(key);
        else {
            try {
                res = (TableCellRenderer) key.newInstance();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            tableRenderers.put(key, res);
        }
        return res;
    }
    public TableCellEditor getTableEditor(Class key) {
        TableCellEditor res = null;
        if (tableEditors.containsKey(key))
            res = tableEditors.get(key);
        else {
            try {
                res = (TableCellEditor) key.newInstance();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            tableEditors.put(key, res);
        }
        return res;
    }
    public TreeCellRenderer getTreeRenderer(Class key) {
        TreeCellRenderer res = null;
        if (treeRenderers.containsKey(key))
            res = treeRenderers.get(key);
        else {
            try {
                res = (TreeCellRenderer) key.newInstance();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            treeRenderers.put(key, res);
        }
        return res;
    }
}
