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

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

fix Sonar issue squid:ModifiersOrderCheck - Modifiers should be declared in the correct order

  • Property svn:eol-style set to native
File size: 2.0 KB
RevLine 
[7128]1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging;
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
[8130]11import javax.swing.JLabel;
12
[7128]13public class PresetLabel extends JLabel {
14
15 protected final TaggingPreset t;
16
[8130]17 /**
18 * Constructs a new {@code PresetLabel}.
19 * @param t the tagging preset
20 */
[7128]21 public PresetLabel(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 {
[8130]33 protected final JLabel label;
34 protected final Font hover;
35 protected final Font normal;
[7128]36
[8130]37 /**
38 * Constructs a new {@code PresetLabelMouseListener}.
39 * @param lbl Label to highlight
40 */
[7128]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 }
[8130]47
[7128]48 @Override
[8130]49 public void mouseClicked(MouseEvent e) {
50 // Do nothing
[7128]51 }
52
53 @Override
[8130]54 public void mouseEntered(MouseEvent e) {
[7128]55 label.setFont(hover);
56 }
[8130]57
[7128]58 @Override
[8130]59 public void mouseExited(MouseEvent e) {
[7128]60 label.setFont(normal);
61 }
[8130]62
[7128]63 @Override
[8130]64 public void mousePressed(MouseEvent e) {
65 // Do nothing
66 }
67
[7128]68 @Override
[8130]69 public void mouseReleased(MouseEvent e) {
70 // Do nothing
71 }
[7128]72 }
73}
Note: See TracBrowser for help on using the repository browser.