source: josm/src/org/openstreetmap/josm/gui/annotation/AnnotationCellRenderer.java@ 177

Last change on this file since 177 was 177, checked in by imi, 17 years ago
  • fixed NPE when open the annotation preset plugin with an invalid annotation preset
File size: 1.3 KB
Line 
1/**
2 *
3 */
4package org.openstreetmap.josm.gui.annotation;
5
6import java.awt.Component;
7
8import javax.swing.DefaultListCellRenderer;
9import javax.swing.JComponent;
10import javax.swing.JLabel;
11import javax.swing.JList;
12
13import org.openstreetmap.josm.tools.ImageProvider;
14
15final public class AnnotationCellRenderer extends DefaultListCellRenderer {
16 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
17 AnnotationPreset a = (AnnotationPreset)value;
18 if (a == null || a.name == null)
19 return super.getListCellRendererComponent(list, "", index, false, false);
20 JComponent c = (JComponent)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
21 JLabel l = new JLabel((a).name);
22 l.setForeground(c.getForeground());
23 l.setBackground(c.getBackground());
24 l.setFont(c.getFont());
25 l.setBorder(c.getBorder());
26 if (a.types == null)
27 l.setIcon(ImageProvider.get("data", "empty"));
28 else if (a.types.size() != 1)
29 l.setIcon(ImageProvider.get("data", "object"));
30 else
31 l.setIcon(ImageProvider.get("data", a.types.iterator().next().getSimpleName().toLowerCase()));
32 l.setOpaque(true);
33 return l;
34 }
35}
Note: See TracBrowser for help on using the repository browser.