Revision 1887 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/DropDownLabel.java
DropDownLabel.java | ||
---|---|---|
9 | 9 |
import java.awt.event.MouseAdapter; |
10 | 10 |
import java.awt.event.MouseEvent; |
11 | 11 |
import java.util.HashSet; |
12 |
import java.util.List; |
|
12 | 13 |
import java.util.Objects; |
13 | 14 |
import java.util.Set; |
14 | 15 |
import javax.swing.ComboBoxModel; |
16 |
import javax.swing.ImageIcon; |
|
15 | 17 |
import javax.swing.JComponent; |
16 | 18 |
import javax.swing.JLabel; |
17 | 19 |
import javax.swing.JMenuItem; |
... | ... | |
29 | 31 |
private ComboBoxModel model; |
30 | 32 |
private int selectedIndex; |
31 | 33 |
private JPopupMenu popup; |
34 |
private List<ImageIcon>icons; |
|
32 | 35 |
|
33 | 36 |
public DropDownLabel(final JLabel label) { |
34 | 37 |
this.label = label; |
... | ... | |
40 | 43 |
doShowPopup(); |
41 | 44 |
} |
42 | 45 |
}); |
46 |
this.icons=null; |
|
43 | 47 |
} |
44 | 48 |
|
45 | 49 |
@Override |
... | ... | |
64 | 68 |
popup.show(label, 0, label.getHeight()); |
65 | 69 |
} |
66 | 70 |
|
71 |
@Override |
|
72 |
public void setIcons(List<ImageIcon> icons) { |
|
73 |
this.icons= icons; |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public List<ImageIcon> getIcons() { |
|
78 |
return this.icons; |
|
79 |
} |
|
80 |
|
|
81 |
private ImageIcon getIcon(int index) { |
|
82 |
if( this.icons == null || index<0 || index>this.icons.size() ) { |
|
83 |
return null; |
|
84 |
} |
|
85 |
return this.icons.get(index); |
|
86 |
} |
|
87 |
|
|
67 | 88 |
private JMenuItem createItem(final int index) { |
68 | 89 |
JMenuItem item = new JMenuItem(Objects.toString(model.getElementAt(index), "")); |
90 |
item.setIcon(this.getIcon(index)); |
|
69 | 91 |
item.addActionListener(new ActionListener() { |
70 | 92 |
@Override |
71 | 93 |
public void actionPerformed(ActionEvent e) { |
Also available in: Unified diff