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/DropDownComboBox.java | ||
---|---|---|
1 | 1 |
package org.gvsig.tools.swing.impl; |
2 | 2 |
|
3 | 3 |
import java.awt.event.ItemListener; |
4 |
import java.util.List; |
|
4 | 5 |
import javax.swing.ComboBoxModel; |
6 |
import javax.swing.ImageIcon; |
|
5 | 7 |
import javax.swing.JComboBox; |
6 | 8 |
import javax.swing.JComponent; |
7 | 9 |
import org.gvsig.tools.swing.api.DropDown; |
... | ... | |
13 | 15 |
public class DropDownComboBox implements DropDown { |
14 | 16 |
|
15 | 17 |
final JComboBox combo; |
18 |
private List<ImageIcon> icons; |
|
16 | 19 |
|
17 | 20 |
public DropDownComboBox(JComboBox combo) { |
18 | 21 |
this.combo = combo; |
... | ... | |
68 | 71 |
this.combo.removeItemListener(l); |
69 | 72 |
} |
70 | 73 |
|
74 |
@Override |
|
75 |
public void setIcons(List<ImageIcon> icons){ |
|
76 |
// TODO: guardar los iconos y crear un renderer para presentarlos |
|
77 |
this.icons = icons; |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public List<ImageIcon> getIcons() { |
|
82 |
return this.icons; |
|
83 |
} |
|
84 |
|
|
71 | 85 |
} |
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 | ||
---|---|---|
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) { |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/DropDown.java | ||
---|---|---|
1 | 1 |
package org.gvsig.tools.swing.api; |
2 | 2 |
|
3 | 3 |
import java.awt.ItemSelectable; |
4 |
import java.util.List; |
|
4 | 5 |
import javax.swing.ComboBoxModel; |
6 |
import javax.swing.ImageIcon; |
|
5 | 7 |
|
6 | 8 |
/** |
7 | 9 |
* |
... | ... | |
20 | 22 |
public Object getSelectedItem(); |
21 | 23 |
|
22 | 24 |
public void setEnabled(boolean enabled); |
25 |
|
|
26 |
public void setIcons(List<ImageIcon> icons); |
|
27 |
|
|
28 |
public List<ImageIcon> getIcons(); |
|
23 | 29 |
|
24 | 30 |
} |
Also available in: Unified diff