<commit_before>package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import javax.accessibility.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.plaf.basic.*;

public final class MainPanel extends JPanel {
    public static final Color BACKGROUND = Color.BLACK;
    public static final Color FOREGROUND = Color.WHITE;
    public static final Color SELECTIONFOREGROUND = Color.ORANGE;
    public static final Color PANEL_BACKGROUND = Color.GRAY;

    private MainPanel() {
        super(new BorderLayout());

        UIManager.put("ComboBox.foreground", FOREGROUND);
        UIManager.put("ComboBox.background", BACKGROUND);
        UIManager.put("ComboBox.selectionForeground", SELECTIONFOREGROUND);
        UIManager.put("ComboBox.selectionBackground", BACKGROUND);

        UIManager.put("ComboBox.buttonDarkShadow", BACKGROUND);
        UIManager.put("ComboBox.buttonBackground", FOREGROUND);
        UIManager.put("ComboBox.buttonHighlight",  FOREGROUND);
        UIManager.put("ComboBox.buttonShadow",     FOREGROUND);

        JComboBox<String> combo0 = new JComboBox<String>(makeModel()) {
            @Override public void updateUI() {
                UIManager.put("ComboBox.border", BorderFactory.createLineBorder(FOREGROUND));
                super.updateUI();
                setUI(new BasicComboBoxUI());
                Object o = getAccessibleContext().getAccessibleChild(0);
                if (o instanceof JComponent) {
                    JComponent c = (JComponent) o;
                    c.setBorder(BorderFactory.createLineBorder(FOREGROUND));
                    c.setForeground(FOREGROUND);
                    c.setBackground(BACKGROUND);
                }
            }
        };

        JComboBox<String> combo1 = new JComboBox<String>(makeModel()) {
            private transient PopupMenuListener listener;
            @Override public void updateUI() {
                removePopupMenuListener(listener);
                UIManager.put("ComboBox.border", new RoundedCornerBorder());
                super.updateUI();
                setUI(new BasicComboBoxUI());
                listener = new HeavyWeightContainerListener();
                addPopupMenuListener(listener);
                Object o = getAccessibleContext().getAccessibleChild(0);
                if (o instanceof JComponent) {
                    JComponent c = (JComponent) o;
                    c.setBorder(new RoundedCornerBorder());
                    c.setForeground(FOREGROUND);
                    c.setBackground(BACKGROUND);
                }
            }
        };

        JComboBox<String> combo2 = new JComboBox<String>(makeModel()) {
            private transient MouseListener handler;
            private transient PopupMenuListener listener;
            @Override public void updateUI() {
                removeMouseListener(handler);
                removePopupMenuListener(listener);
                UIManager.put("ComboBox.border", new TopRoundedCornerBorder());
                super.updateUI();
                setUI(new BasicComboBoxUI() {
                    @Override protected JButton createArrowButton() {
                        JButton b = new JButton(new ArrowIcon(BACKGROUND, FOREGROUND));
                        b.setContentAreaFilled(false);
                        b.setFocusPainted(false);
                        b.setBorder(BorderFactory.createEmptyBorder());
                        return b;
                    }
                });
                handler = new ComboRolloverHandler();
                addMouseListener(handler);
                listener = new HeavyWeightContainerListener();
                addPopupMenuListener(listener);
                Object o = getAccessibleContext().getAccessibleChild(0);
                if (o instanceof JComponent) {
                    JComponent c = (JComponent) o;
                    c.setBorder(new BottomRoundedCornerBorder());
                    c.setForeground(FOREGROUND);
                    c.setBackground(BACKGROUND);
                }
            }
        };

        JPanel p = new JPanel(new GridLayout(0, 1, 15, 15));
        p.setOpaque(true);
        p.setBackground(PANEL_BACKGROUND);
        p.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
        p.add(combo0);
        p.add(combo1);
        p.add(combo2);

        add(p, BorderLayout.NORTH);
        setOpaque(true);
        setBackground(PANEL_BACKGROUND);
        setPreferredSize(new Dimension(320, 240));
    }
    private static DefaultComboBoxModel<String> makeModel() {
        DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
        model.addElement("1234");
        model.addElement("5555555555555555555555");
        model.addElement("6789000000000");
        model.addElement("aaa");
        model.addElement("bbbbbb");
        return model;
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
//         try {
//             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//         } catch (ClassNotFoundException | InstantiationException
//                | IllegalAccessException | UnsupportedLookAndFeelException ex) {
//             ex.printStackTrace();
//         }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class HeavyWeightContainerListener implements PopupMenuListener {
    @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                JComboBox combo = (JComboBox) e.getSource();
                Accessible a = combo.getUI().getAccessibleChild(combo, 0);
                if (a instanceof BasicComboPopup) {
                    BasicComboPopup pop = (BasicComboPopup) a;
                    Container top = pop.getTopLevelAncestor();
                    if (top instanceof JWindow) {
                        //http://ateraimemo.com/Swing/DropShadowPopup.html
                        System.out.println("HeavyWeightContainer");
                        ((JWindow) top).setBackground(new Color(0x0, true));
                    }
                }
            }
        });
    }
    @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { /* not needed */ }
    @Override public void popupMenuCanceled(PopupMenuEvent e) { /* not needed */ }
}

class ComboRolloverHandler extends MouseAdapter {<commit_msg>refactor: use JPopupMenu instead of BasicComboPopup<commit_after>package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import javax.accessibility.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.plaf.basic.*;

public final class MainPanel extends JPanel {
    public static final Color BACKGROUND = Color.BLACK;
    public static final Color FOREGROUND = Color.WHITE;
    public static final Color SELECTIONFOREGROUND = Color.ORANGE;
    public static final Color PANEL_BACKGROUND = Color.GRAY;

    private MainPanel() {
        super(new BorderLayout());

        UIManager.put("ComboBox.foreground", FOREGROUND);
        UIManager.put("ComboBox.background", BACKGROUND);
        UIManager.put("ComboBox.selectionForeground", SELECTIONFOREGROUND);
        UIManager.put("ComboBox.selectionBackground", BACKGROUND);

        UIManager.put("ComboBox.buttonDarkShadow", BACKGROUND);
        UIManager.put("ComboBox.buttonBackground", FOREGROUND);
        UIManager.put("ComboBox.buttonHighlight",  FOREGROUND);
        UIManager.put("ComboBox.buttonShadow",     FOREGROUND);

        JComboBox<String> combo0 = new JComboBox<String>(makeModel()) {
            @Override public void updateUI() {
                UIManager.put("ComboBox.border", BorderFactory.createLineBorder(FOREGROUND));
                super.updateUI();
                setUI(new BasicComboBoxUI());
                Object o = getAccessibleContext().getAccessibleChild(0);
                if (o instanceof JComponent) {
                    JComponent c = (JComponent) o;
                    c.setBorder(BorderFactory.createLineBorder(FOREGROUND));
                    c.setForeground(FOREGROUND);
                    c.setBackground(BACKGROUND);
                }
            }
        };

        JComboBox<String> combo1 = new JComboBox<String>(makeModel()) {
            private transient PopupMenuListener listener;
            @Override public void updateUI() {
                removePopupMenuListener(listener);
                UIManager.put("ComboBox.border", new RoundedCornerBorder());
                super.updateUI();
                setUI(new BasicComboBoxUI());
                listener = new HeavyWeightContainerListener();
                addPopupMenuListener(listener);
                Object o = getAccessibleContext().getAccessibleChild(0);
                if (o instanceof JComponent) {
                    JComponent c = (JComponent) o;
                    c.setBorder(new RoundedCornerBorder());
                    c.setForeground(FOREGROUND);
                    c.setBackground(BACKGROUND);
                }
            }
        };

        JComboBox<String> combo2 = new JComboBox<String>(makeModel()) {
            private transient MouseListener handler;
            private transient PopupMenuListener listener;
            @Override public void updateUI() {
                removeMouseListener(handler);
                removePopupMenuListener(listener);
                UIManager.put("ComboBox.border", new TopRoundedCornerBorder());
                super.updateUI();
                setUI(new BasicComboBoxUI() {
                    @Override protected JButton createArrowButton() {
                        JButton b = new JButton(new ArrowIcon(BACKGROUND, FOREGROUND));
                        b.setContentAreaFilled(false);
                        b.setFocusPainted(false);
                        b.setBorder(BorderFactory.createEmptyBorder());
                        return b;
                    }
                });
                handler = new ComboRolloverHandler();
                addMouseListener(handler);
                listener = new HeavyWeightContainerListener();
                addPopupMenuListener(listener);
                Object o = getAccessibleContext().getAccessibleChild(0);
                if (o instanceof JComponent) {
                    JComponent c = (JComponent) o;
                    c.setBorder(new BottomRoundedCornerBorder());
                    c.setForeground(FOREGROUND);
                    c.setBackground(BACKGROUND);
                }
            }
        };

        JPanel p = new JPanel(new GridLayout(0, 1, 15, 15));
        p.setOpaque(true);
        p.setBackground(PANEL_BACKGROUND);
        p.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
        p.add(combo0);
        p.add(combo1);
        p.add(combo2);

        add(p, BorderLayout.NORTH);
        setOpaque(true);
        setBackground(PANEL_BACKGROUND);
        setPreferredSize(new Dimension(320, 240));
    }
    private static DefaultComboBoxModel<String> makeModel() {
        DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
        model.addElement("1234");
        model.addElement("5555555555555555555555");
        model.addElement("6789000000000");
        model.addElement("aaa");
        model.addElement("bbbbbb");
        return model;
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
//         try {
//             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//         } catch (ClassNotFoundException | InstantiationException
//                | IllegalAccessException | UnsupportedLookAndFeelException ex) {
//             ex.printStackTrace();
//         }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class HeavyWeightContainerListener implements PopupMenuListener {
    @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                JComboBox combo = (JComboBox) e.getSource();
                Accessible a = combo.getUI().getAccessibleChild(combo, 0);
                if (a instanceof JPopupMenu) {
                    JPopupMenu pop = (JPopupMenu) a;
                    Container top = pop.getTopLevelAncestor();
                    if (top instanceof JWindow) {
                        //http://ateraimemo.com/Swing/DropShadowPopup.html
                        System.out.println("HeavyWeightContainer");
                        ((JWindow) top).setBackground(new Color(0x0, true));
                    }
                }
            }
        });
    }
    @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { /* not needed */ }
    @Override public void popupMenuCanceled(PopupMenuEvent e) { /* not needed */ }
}

class ComboRolloverHandler extends MouseAdapter {
{'fraction_non_alphanumeric': 0.10119260158537456, 'fraction_numerical': 0.01042633721345426, 'mean_word_length': 2.0417028670721113, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3012773', 'n_tokens_mistral': 3818, 'n_tokens_neox': 3529, 'n_words': 681}