package Common.Visual.Menus;
import Common.Utils.Utils_;
import Common.Visual.UI;

import javax.swing.*;
import java.awt.event.ActionEvent;
public class TextComboBoxMenu extends StyledPopupMenu {
    protected JComboBox<String> box;
    protected String selectedText = null;
    //-------------------------------------------------
    JMenuItem m_copy;
    JMenuItem m_paste;
    //-------------------------------------------------
    public TextComboBoxMenu(JComboBox<String> box_in) {
        box = box_in;
        m_copy = new VisualiserMenuItem("Копировать", "/icons/Editor/Copy.png");
        m_copy.addActionListener(
                new AbstractAction() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Utils_.CopyToClipboard(box.getSelectedItem().toString());
                    }
                });
        add(m_copy);
        m_paste = new VisualiserMenuItem("Вставить", "/icons/Editor/Paste.png");
        m_paste.addActionListener(
                new AbstractAction() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        UI.TrySelect(box, Utils_.getFromClipboard());
                    }
                });
        add(m_paste);
    }
    @Override
    public void CheckElementsVisibility() {
        boolean visible_ = box.getSelectedIndex() >= 0;
        m_paste.setVisible(visible_);
        m_copy.setVisible(visible_);
        super.CheckElementsVisibility();
    }
}
