2 import javax
.swing
.event
.ListSelectionEvent
;
3 import javax
.swing
.event
.ListSelectionListener
;
5 import java
.util
.Arrays
;
7 public class EyeView
extends JPanel
implements ListSelectionListener
{
10 private JList colorsList
;
17 this.label
= new JLabel();
18 this.label
.setText("Eyes color");
19 this.colorsList
= new JList
<>(this.getEyeObj().getColorsList());
20 this.colorsList
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
21 this.colorsList
.setLayoutOrientation(JList
.VERTICAL
);
22 this.colorsList
.setSelectedIndex(Arrays
.asList(this.getEyeObj().getColorsList()).indexOf(this.getEyeObj().getStrColor()));
23 this.colorsList
.setCellRenderer(new EyeCellRenderer());
24 this.colorsList
.addListSelectionListener(this);
32 public Eye
getEyeObj() {
39 public void setEyeObj(Eye eyeObj
) {
43 public JList
getColorsList() {
48 public void valueChanged(ListSelectionEvent listSelectionEvent
) {
49 Eye currentEye
= new Eye((String
) getColorsList().getSelectedValue());
50 PersonLeftPanel personLeftPanel
= MainWindowsView
.getInstance().getCurrentPersonView().getPersonPanel().getLeftPanel();
51 personLeftPanel
.drawEyes(currentEye
.getColor());
54 private static class EyeCellRenderer
extends DefaultListCellRenderer
{
55 public Component
getListCellRendererComponent(JList list
, Object value
, int index
, boolean isSelected
, boolean cellHasFocus
) {
56 Component c
= super.getListCellRendererComponent(list
, value
, index
, isSelected
, cellHasFocus
);
57 Eye currentEye
= new Eye((String
) list
.getModel().getElementAt(index
));
58 c
.setBackground(currentEye
.getColor());
59 c
.setForeground(Color
.WHITE
);
61 setBackground(getBackground().darker());