1 | // License: GPL. See LICENSE file for details.
|
---|
2 | package org.openstreetmap.josm.gui.widgets;
|
---|
3 |
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.awt.Dimension;
|
---|
6 | import java.awt.GridBagLayout;
|
---|
7 | import javax.swing.JLabel;
|
---|
8 | import javax.swing.JPanel;
|
---|
9 | import org.openstreetmap.josm.tools.GBC;
|
---|
10 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
11 |
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * A small user interface component that consists of an image label and
|
---|
15 | * a fixed text content to the right of the image.
|
---|
16 | * Moved from @link org.openstreetmap.josm.gui.MapStatus @since 5965
|
---|
17 | */
|
---|
18 | public class ImageLabel extends JPanel {
|
---|
19 | public static final Color backColor = Color.decode("#b8cfe5");
|
---|
20 | public static final Color backColorActive = Color.decode("#aaff5e");
|
---|
21 |
|
---|
22 | private JLabel tf;
|
---|
23 | private int charCount;
|
---|
24 |
|
---|
25 | public ImageLabel(String img, String tooltip, int charCount) {
|
---|
26 | super();
|
---|
27 | setLayout(new GridBagLayout());
|
---|
28 | setBackground(backColor);
|
---|
29 | add(new JLabel(ImageProvider.get("statusline/"+img+".png")), GBC.std().anchor(GBC.WEST).insets(0,1,1,0));
|
---|
30 | add(tf = new JLabel(), GBC.std().fill(GBC.BOTH).anchor(GBC.WEST).insets(2,1,1,0));
|
---|
31 | setToolTipText(tooltip);
|
---|
32 | this.charCount = charCount;
|
---|
33 | }
|
---|
34 |
|
---|
35 | public void setText(String t) {
|
---|
36 | tf.setText(t);
|
---|
37 | }
|
---|
38 | @Override public Dimension getPreferredSize() {
|
---|
39 | return new Dimension(25 + charCount*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getPreferredSize().height);
|
---|
40 | }
|
---|
41 | @Override public Dimension getMinimumSize() {
|
---|
42 | return new Dimension(25 + charCount*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getMinimumSize().height);
|
---|
43 | }
|
---|
44 | }
|
---|