package editor.gui.generic;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.Timer;

import editor.util.MouseListenerFactory;

@SuppressWarnings("serial")
public class RepeatButton extends JButton
{
    private int defaultInitial;
    private int defaultTick;

    public RepeatButton(int initial, int tick)
    {
        super();
        defaultInitial = initial;
        defaultTick = tick;
    }

    public RepeatButton(int delay)
    {
        this(delay, delay);
    }

    public RepeatButton()
    {
        this(0);
    }

    public void addRepeatListener(int initial, int tick, ActionListener l)
    {
        Timer timer = new Timer(tick, l);
        timer.setRepeats(true);
        timer.setInitialDelay(initial);
        addMouseListener(MouseListenerFactory.createHoldListener((e) -> {
            l.actionPerformed(new ActionEvent(e.getSource(), e.getID(), e.paramString(), e.getWhen(), e.getModifiersEx()));
            timer.start();
        }, (e) -> timer.stop()));
    }

    public void addRepeatListener(int delay, ActionListener l)
    {
        addRepeatListener(delay, delay, l);
    }

    public void addRepeatListener(ActionListener l)
    {
        addRepeatListener(defaultInitial, defaultTick, l);
    }
}
@@ -197,993 +197,2774 @@
 y;%0A%0A
-@SuppressWarnings(%22serial%22)%0Apublic class RepeatButton extends JButton%0A%7B%0A    private int defaultInitial;%0A    private int defaultTick;%0A%0A    public RepeatButton(int initial, int tick)%0A    %7B%0A        super();%0A        defaultInitial = initial;%0A        defaultTick = tick;%0A    %7D%0A%0A    public RepeatButton(int delay)%0A    %7B%0A        this(delay, delay);%0A    %7D%0A%0A    public RepeatButton()%0A    %7B%0A        this(0);%0A    %7D%0A%0A    public void addRepeatListener(int initial, int tick, ActionListener l)%0A    %7B%0A        Timer timer = new Timer(tick, l);%0A        timer.setRepeats(true);%0A        timer.setInitialDelay(initial);%0A        addMouseListener(MouseListenerFactory.createHoldListener((e) -%3E %7B%0A            l.actionPerformed(new ActionEvent(e.getSource(), e.getID(), e.paramString(), e.getWhen(), e.getModifiersEx()));%0A            timer.start();%0A        %7D, (e) -%3E timer.stop()));%0A    %7D%0A%0A    public void addRepeatListener(int delay, ActionListener l)%0A    %7B%0A        addRepeatListener(delay, delay, l);%0A    %7D%0A
+/**%0A * This class is a button that can repeat its action when held down after a customizable delay.%0A * If the mouse is moved off the button while held down, actions will still continue until it%0A * is released.  Default delays set by constructors can be overrided by using the appropriate%0A * methods.%0A * %0A * @author Alec Roelke%0A */%0A@SuppressWarnings(%22serial%22)%0Apublic class RepeatButton extends JButton%0A%7B%0A    /**%0A     * Default delay before starting repetition.%0A     */%0A    private int defaultInitial;%0A    /**%0A     * Default delay between repetitions.%0A     */%0A    private int defaultTick;%0A%0A    /**%0A     * Create a new RepeatButton with specified default delays.%0A     * %0A     * @param initial default initial delay%0A     * @param tick default delay between repetitions%0A     */%0A    public RepeatButton(int initial, int tick)%0A    %7B%0A        super();%0A        defaultInitial = initial;%0A        defaultTick = tick;%0A    %7D%0A%0A    /**%0A     * Create a new RepeatButton with the same default delay before and between repeating%0A     * actions.%0A     * %0A     * @param delay default delay%0A     */%0A    public RepeatButton(int delay)%0A    %7B%0A        this(delay, delay);%0A    %7D%0A%0A    /**%0A     * Create a new RepeatButton with no delay before and between repeating actions.%0A     */%0A    public RepeatButton()%0A    %7B%0A        this(0);%0A    %7D%0A%0A    /**%0A     * Add an action that will be performed upon clicking the button, after an initial delay,%0A     * and repeated after another delay until the mouse is released.%0A     * %0A     * @param initial delay after first pressing the mouse button to start repeating%0A     * @param tick delay between repetitions%0A     * @param l action to perform when pressing the button%0A     */%0A    public void addRepeatListener(int initial, int tick, ActionListener l)%0A    %7B%0A        Timer timer = new Timer(tick, l);%0A        timer.setRepeats(true);%0A        timer.setInitialDelay(initial);%0A        addMouseListener(MouseListenerFactory.createHoldListener((e) -%3E %7B%0A            l.actionPerformed(new ActionEvent(e.getSource(), e.getID(), e.paramString(), e.getWhen(), e.getModifiersEx()));%0A            timer.start();%0A        %7D, (e) -%3E timer.stop()));%0A    %7D%0A%0A    /**%0A     * Add an action that will be performed upon clicking the button and repeated with a%0A     * specified delay as long as the button is held down.%0A     * %0A     * @param delay delay between repetitions%0A     * @param l action to perform%0A     */%0A    public void addRepeatListener(int delay, ActionListener l)%0A    %7B%0A        addRepeatListener(delay, delay, l);%0A    %7D%0A%0A    /**%0A     * Add an action that will be performed upon clicking the button, after an initial delay,%0A     * and repeated after another delay until the mouse is released. The delays are the defaults%0A     * set by RepeatButton's constructor.%0A     */
 %0A   

Comment RepeatButton