source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/PresetLabel.java@ 7153

Last change on this file since 7153 was 7128, checked in by simon04, 10 years ago

Fix Sonar issue (package cycle)

File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging;
3
4import javax.swing.JLabel;
5import java.awt.Cursor;
6import java.awt.Font;
7import java.awt.event.MouseEvent;
8import java.awt.event.MouseListener;
9import java.awt.font.TextAttribute;
10import java.util.Collections;
11
12public class PresetLabel extends JLabel {
13
14 protected final TaggingPreset t;
15
16 public PresetLabel(TaggingPreset t) {
17 super(t.getName() + " …");
18 setIcon(t.getIcon());
19 addMouseListener(new PresetLabelMouseListener(this));
20 this.t = t;
21 }
22
23 /**
24 * Small helper class that manages the highlighting of the label on hover as well as opening
25 * the corresponding preset when clicked
26 */
27 public static class PresetLabelMouseListener implements MouseListener {
28 final protected JLabel label;
29 final protected Font hover;
30 final protected Font normal;
31
32 public PresetLabelMouseListener(JLabel lbl) {
33 label = lbl;
34 lbl.setCursor(new Cursor(Cursor.HAND_CURSOR));
35 normal = label.getFont();
36 hover = normal.deriveFont(Collections.singletonMap(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED));
37 }
38 @Override
39 public void mouseClicked(MouseEvent arg0) {
40 }
41
42 @Override
43 public void mouseEntered(MouseEvent arg0) {
44 label.setFont(hover);
45 }
46 @Override
47 public void mouseExited(MouseEvent arg0) {
48 label.setFont(normal);
49 }
50 @Override
51 public void mousePressed(MouseEvent arg0) {}
52 @Override
53 public void mouseReleased(MouseEvent arg0) {}
54 }
55}
Note: See TracBrowser for help on using the repository browser.