/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.shedule.reception;
import clips.delegate.shedule.reception.SheduleReceptionData;
import framework.utils.Converter;
import cli_fmw.main.ClipsException;
import clips.delegate.directory.ro.DirectoryCollaboratorItem;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
/**
*
* @author axe
*/
public class ReceptionListCellRenderer extends JPanel implements ListCellRenderer {
private JLabel label = new JLabel();
private JLabel img = new JLabel();
private JPanel internalPanel = new JPanel();
private JPanel topPanel = new JPanel();
private JPanel bottomPanel = new JPanel();
ImageIcon defaultImage = new ImageIcon(ReceptionListCellRenderer.class.getResource("/resources/img/doctor.jpg"));
public ReceptionListCellRenderer() {
BorderLayout borderLayout = new BorderLayout();
borderLayout.setHgap(5);
borderLayout.setVgap(5);
setLayout(borderLayout);
add(internalPanel, BorderLayout.CENTER);
add(topPanel, BorderLayout.NORTH);
add(bottomPanel, BorderLayout.SOUTH);
label.setHorizontalAlignment(JLabel.CENTER);
label.setVerticalAlignment(JLabel.CENTER);
img.setHorizontalAlignment(JLabel.CENTER);
img.setVerticalAlignment(JLabel.CENTER);
internalPanel.setLayout(new BorderLayout());
internalPanel.add(img, BorderLayout.WEST);
internalPanel.add(label, BorderLayout.CENTER);
}
@Override
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
SheduleReceptionData item = (SheduleReceptionData) value;
String str = "Ошибка";
ImageIcon icon = null;
try {
DirectoryCollaboratorItem coll = item.getCollaborator();
str = String.format("<html><p><u>Врач:</u><br>%s</p><p><u>Дата:</u><br>%s</p></html>",
coll.toString(), Converter.dateToString(item.getBegin()));
icon = coll.getImage();
if(icon == null) {
icon = defaultImage;
}
} catch (ClipsException ex) {
ex.printStackTrace();
}
label.setText(str);
if(icon != null) {
img.setIcon(icon);
}
Color color;
if(isSelected || cellHasFocus) {
color = list.getSelectionBackground();
} else {
color = list.getBackground();
}
topPanel.setBackground(color);
bottomPanel.setBackground(color);
internalPanel.setBackground(color);
setBackground(color);
return this;
}
}