package Common.Visual.Controls;
import Common.MainModule_;
import Common.Utils.Utils_;
import Common.Visual.Menus.VisualiserMenuItem;

import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicMenuItemUI;
//неичезающий меню итем. нужен для настроек
//https://translated.turbopages.org/proxy_u/en-ru.ru.64537f6c-6460c460-8e74a1ab-74722d776562/https/tips4java.wordpress.com/2010/09/12/keeping-menus-open/
class StableItemUI extends BasicMenuItemUI {
    public static ComponentUI createUI(JComponent c) {
        return new StableItemUI();
    }
    @Override
    protected void doClick(MenuSelectionManager msm) {
        menuItem.doClick(0);
        if (MainModule_.instance.hasLastMenuPath())
            MenuSelectionManager.defaultManager().setSelectedPath(MainModule_.instance.getLastMenuPath());
    }
}
public class StableMenuItem extends VisualiserMenuItem {
    {
        getModel().addChangeListener(e -> {
            if (getModel().isArmed() && isShowing())
                MainModule_.instance.setLastMenuPath(MenuSelectionManager.defaultManager().getSelectedPath());
        });
    }
    public StableMenuItem(String text) {
        super(text);
        setUI(new StableItemUI());
    }
    public StableMenuItem(String text, String icon_path) {
        super(text);
        setIcon(Utils_.getIcon(icon_path));
        setUI(new StableItemUI());
    }
    public StableMenuItem() {
        setUI(new StableItemUI());
    }
}
