OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 74 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
74 ilm 1
package org.openconcerto.modules.extensionbuilder;
2
 
3
import java.awt.Color;
4
import java.awt.Cursor;
5
import java.awt.Graphics;
6
import java.awt.Rectangle;
7
import java.awt.event.MouseEvent;
8
import java.awt.event.MouseListener;
9
import java.awt.event.MouseMotionListener;
10
 
11
import javax.swing.JLabel;
12
 
13
public class ClickableLabel extends JLabel implements MouseListener, MouseMotionListener {
14
 
15
    private Runnable runnable;
16
    private boolean mouseOver;
17
 
18
    public ClickableLabel(String text, final Runnable r) {
19
        super(text);
20
        this.runnable = r;
21
        this.addMouseListener(this);
22
        this.addMouseMotionListener(this);
23
        this.setForeground(Color.BLUE);
24
    }
25
 
26
    public void paint(Graphics g) {
27
        super.paint(g);
181 ilm 28
        if (this.mouseOver) {
74 ilm 29
            Rectangle r = g.getClipBounds();
30
            final int y1 = r.height - getFontMetrics(getFont()).getDescent() + 1;
31
            g.drawLine(0, y1, getFontMetrics(getFont()).stringWidth(getText()), y1);
32
        }
33
    }
34
 
35
    @Override
36
    public void mouseClicked(MouseEvent e) {
37
        if (this.runnable != null) {
38
            this.runnable.run();
39
        }
40
    }
41
 
42
    @Override
43
    public void mousePressed(MouseEvent e) {
44
 
45
    }
46
 
47
    @Override
48
    public void mouseReleased(MouseEvent e) {
49
    }
50
 
51
    @Override
52
    public void mouseEntered(MouseEvent e) {
53
        this.mouseOver = true;
54
        this.setCursor(new Cursor(Cursor.HAND_CURSOR));
55
        repaint();
56
    }
57
 
58
    @Override
59
    public void mouseExited(MouseEvent e) {
60
        this.mouseOver = false;
61
        this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
62
        repaint();
63
    }
64
 
65
    @Override
66
    public void mouseDragged(MouseEvent e) {
67
    }
68
 
69
    @Override
70
    public void mouseMoved(MouseEvent e) {
71
    }
72
}