source: josm/trunk/src/org/openstreetmap/josm/gui/widgets/ImageLabel.java@ 6101

Last change on this file since 6101 was 6101, checked in by akks, 11 years ago

revert 6099: seems it was not the described bug

File size: 1.6 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.gui.widgets;
3
4import java.awt.Color;
5import java.awt.Dimension;
6import java.awt.GridBagLayout;
7import javax.swing.JLabel;
8import javax.swing.JPanel;
9import org.openstreetmap.josm.tools.GBC;
10import 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 */
18public 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}
Note: See TracBrowser for help on using the repository browser.