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

Last change on this file since 8002 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 1.8 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;
7
8import javax.swing.JLabel;
9import javax.swing.JPanel;
10
11import org.openstreetmap.josm.tools.GBC;
12import org.openstreetmap.josm.tools.ImageProvider;
13
14/**
15 * A small user interface component that consists of an image label and
16 * a fixed text content to the right of the image.
17 * @since 5965
18 */
19public class ImageLabel extends JPanel {
20 private JLabel tf;
21 private int charCount;
22
23 /**
24 * Constructs a new {@code ImageLabel}.
25 * @param img Image name (without .png extension) to find in {@code statusline} directory
26 * @param tooltip Tooltip text to display
27 * @param charCount Character count used to compute min/preferred size
28 * @param background The background color
29 */
30 public ImageLabel(String img, String tooltip, int charCount, Color background) {
31 setLayout(new GridBagLayout());
32 setBackground(background);
33 add(new JLabel(ImageProvider.get("statusline/"+img+".png")), GBC.std().anchor(GBC.WEST).insets(0,1,1,0));
34 add(tf = new JLabel(), GBC.std().fill(GBC.BOTH).anchor(GBC.WEST).insets(2,1,1,0));
35 setToolTipText(tooltip);
36 this.charCount = charCount;
37 }
38
39 /**
40 * Sets the text to display.
41 * @param t text to display
42 */
43 public void setText(String t) {
44 tf.setText(t);
45 }
46
47 @Override
48 public Dimension getPreferredSize() {
49 return new Dimension(25 + charCount*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getPreferredSize().height);
50 }
51
52 @Override
53 public Dimension getMinimumSize() {
54 return new Dimension(25 + charCount*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getMinimumSize().height);
55 }
56}
Note: See TracBrowser for help on using the repository browser.