source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetLabel.java@ 9465

Last change on this file since 9465 was 8863, checked in by Don-vip, 9 years ago

major code cleanup/refactoring of tagging presets: slay the monster TaggingPresetItems (60 Kb, 1600 lines) and extract all its internal classes to a new package gui.tagging.presets.items

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging.presets;
3
4import java.awt.Cursor;
5import java.awt.Font;
6import java.awt.event.MouseEvent;
7import java.awt.event.MouseListener;
8import java.awt.font.TextAttribute;
9import java.util.Collections;
10
11import javax.swing.JLabel;
12
13public class TaggingPresetLabel extends JLabel {
14
15 protected final TaggingPreset t;
16
17 /**
18 * Constructs a new {@code PresetLabel}.
19 * @param t the tagging preset
20 */
21 public TaggingPresetLabel(TaggingPreset t) {
22 super(t.getName() + " …");
23 setIcon(t.getIcon());
24 addMouseListener(new PresetLabelMouseListener(this));
25 this.t = t;
26 }
27
28 /**
29 * Small helper class that manages the highlighting of the label on hover as well as opening
30 * the corresponding preset when clicked
31 */
32 public static class PresetLabelMouseListener implements MouseListener {
33 protected final JLabel label;
34 protected final Font hover;
35 protected final Font normal;
36
37 /**
38 * Constructs a new {@code PresetLabelMouseListener}.
39 * @param lbl Label to highlight
40 */
41 public PresetLabelMouseListener(JLabel lbl) {
42 label = lbl;
43 lbl.setCursor(new Cursor(Cursor.HAND_CURSOR));
44 normal = label.getFont();
45 hover = normal.deriveFont(Collections.singletonMap(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED));
46 }
47
48 @Override
49 public void mouseClicked(MouseEvent e) {
50 // Do nothing
51 }
52
53 @Override
54 public void mouseEntered(MouseEvent e) {
55 label.setFont(hover);
56 }
57
58 @Override
59 public void mouseExited(MouseEvent e) {
60 label.setFont(normal);
61 }
62
63 @Override
64 public void mousePressed(MouseEvent e) {
65 // Do nothing
66 }
67
68 @Override
69 public void mouseReleased(MouseEvent e) {
70 // Do nothing
71 }
72 }
73}
Note: See TracBrowser for help on using the repository browser.