File: AbstractButtonAction.java

package info (click to toggle)
libtoolbutton-java 0.2-2
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 100 kB
  • ctags: 126
  • sloc: java: 508; makefile: 59
file content (61 lines) | stat: -rw-r--r-- 1,502 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * AbstractButtonAction.java
 *
 * Created on 02 March 2003, 00:26
 */

package org.tigris.toolbutton;

import javax.swing.AbstractAction;
import javax.swing.Icon;

/**
 * The abstract class for all button actions that wish to detect double click events
 *
 * @author Bob Tarling
 */
abstract public class AbstractButtonAction extends AbstractAction implements ModalAction {
    
    private String name;
    private Icon _icon;
    
    private static AbstractButtonAction lastClickedAction = null;
    private long lastTimeClicked = 0;

    private boolean doubleClick;
    
    protected boolean isDoubleClick() {
        return doubleClick;
    }
    
    public AbstractButtonAction() {
        super();
    }
    /**
     * Creates a new instance of AbstractButtonAction
     */
    public AbstractButtonAction(String name, Icon icon) {
        super(name, icon);
        this._icon = icon;
        this.name = name;
    }

    public String getName() {
        return name;
    }
    
    public Icon getIcon() {
        return _icon;
    }
    
    public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
        long timeClicked = System.currentTimeMillis();
        if (lastClickedAction == this && (timeClicked - lastTimeClicked) < 1000) {
            doubleClick = true;
        } else {
            doubleClick = false;
        }
        lastTimeClicked = timeClicked;
        lastClickedAction = this;
    }
}