001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui;
003
004import static org.openstreetmap.josm.tools.I18n.trc;
005
006import java.beans.PropertyChangeListener;
007
008import javax.swing.Action;
009import javax.swing.JButton;
010import javax.swing.JCheckBoxMenuItem;
011import javax.swing.JMenu;
012import javax.swing.JMenuItem;
013
014/**
015 * Mode menu. Unlike traditional menus, default menu item is based on {@link JCheckBoxMenuItem}.
016 * @since 15445
017 */
018public class ModeMenu extends JMenu {
019
020    /**
021     * Constructs a new {@code ModeMenu}.
022     */
023    public ModeMenu() {
024        /* I18N: mnemonic: M */
025        super(trc("menu", "Mode"));
026    }
027
028    @Override
029    protected JMenuItem createActionComponent(Action a) {
030        JCheckBoxMenuItem mi = new JCheckBoxMenuItem() {
031            @Override
032            protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
033                PropertyChangeListener pcl = createActionChangeListener(this);
034                if (pcl == null) {
035                    pcl = super.createActionPropertyChangeListener(a);
036                }
037                return pcl;
038            }
039        };
040        mi.setHorizontalTextPosition(JButton.TRAILING);
041        mi.setVerticalTextPosition(JButton.CENTER);
042        return mi;
043    }
044}