001package jmri.util.swing;
002
003import java.awt.event.MouseEvent;
004
005/**
006 * Replacement for {@link java.awt.event.MouseListener}.
007 * This class is used to replace {@link java.awt.event.MouseEvent} with
008 * {@link jmri.util.swing.JmriMouseEvent}.
009 *
010 * @author Daniel Bergqvist (C) 2022
011 */
012public interface JmriMouseListener extends java.util.EventListener {
013
014    /**
015     * Adapt a JmriMouseListener to a MouseListener.
016     * @param listener the JmriMouseListener
017     * @return the MouseListener
018     */
019    static java.awt.event.MouseListener adapt(JmriMouseListener listener) {
020        return new java.awt.event.MouseListener() {
021            @Override
022            public void mouseClicked(MouseEvent e) {
023                listener.mouseClicked(new JmriMouseEvent(e));
024            }
025
026            @Override
027            public void mousePressed(MouseEvent e) {
028                listener.mousePressed(new JmriMouseEvent(e));
029            }
030
031            @Override
032            public void mouseReleased(MouseEvent e) {
033                listener.mouseReleased(new JmriMouseEvent(e));
034            }
035
036            @Override
037            public void mouseEntered(MouseEvent e) {
038                listener.mouseEntered(new JmriMouseEvent(e));
039            }
040
041            @Override
042            public void mouseExited(MouseEvent e) {
043                listener.mouseExited(new JmriMouseEvent(e));
044            }
045        };
046    }
047
048    /**
049     * Invoked when the mouse button has been clicked (pressed
050     * and released) on a component.
051     * @param e the event to be processed
052     */
053    void mouseClicked(JmriMouseEvent e);
054
055    /**
056     * Invoked when a mouse button has been pressed on a component.
057     * @param e the event to be processed
058     */
059    void mousePressed(JmriMouseEvent e);
060
061    /**
062     * Invoked when a mouse button has been released on a component.
063     * @param e the event to be processed
064     */
065    void mouseReleased(JmriMouseEvent e);
066
067    /**
068     * Invoked when the mouse enters a component.
069     * @param e the event to be processed
070     */
071    void mouseEntered(JmriMouseEvent e);
072
073    /**
074     * Invoked when the mouse exits a component.
075     * @param e the event to be processed
076     */
077    void mouseExited(JmriMouseEvent e);
078
079}