1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
| package model;
import interfaces.ListeOT;
import java.awt.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.*;
import javax.swing.table.*;
import bd.BD;
import annexes.LanguageChooser;
public class MonTableCellRenderer implements TableCellRenderer {
LanguageChooser lc;
boolean alertenvot;
BD bd;
private JLabel label = new JLabel();
public MonTableCellRenderer(BD bd, boolean alertenvot) {
lc = new LanguageChooser();
this.alertenvot = alertenvot;
this.bd = bd;
}
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int ligne, int colonne) {
label.setOpaque(true);
label.setFont(new Font("Arial",Font.PLAIN,10));
ligne = table.convertRowIndexToModel(ligne);
int dr = table.getColumn(LanguageChooser.getAnInternationalizeString("Date_reception")).getModelIndex();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S");
if(table.getValueAt(ligne, dr)!=null){
try {
Date r;
if(dr==-1)
r = bd.recupDateReception((String)table.getValueAt(ligne, 0), (String)table.getValueAt(ligne, 1));
else
r = df.parse((String)table.getValueAt(ligne, dr));
int modif = table.getColumn(LanguageChooser.getAnInternationalizeString("Compteur_modifications")).getModelIndex();
if(alertenvot && r.after(ListeOT.dateDernierFiltrage)){
label.setFont(new Font("Arial",Font.BOLD,10));
int nbmodif = bd.recupCompteurModifications((String)table.getValueAt(ligne, 0), (String)table.getValueAt(ligne, 1));
if(nbmodif>0){
table.setValueAt("m", ligne, modif);
}
else{
table.setValueAt("a", ligne, modif);
}
}
else{
if(table.getValueAt(ligne, modif).equals(">>"))
table.setValueAt(">>", ligne, modif);
else
table.setValueAt("", ligne, modif);
}
} catch (ParseException e) {
e.printStackTrace();
}
int i = table.getColumn(LanguageChooser.getAnInternationalizeString("Etat_interne")).getModelIndex();
String etat;
if(i==-1){
etat = bd.getEtat((String)table.getValueAt(ligne, 0), (String)table.getValueAt(ligne, 1));
}
else{
etat = (String)table.getValueAt(ligne, i);
}
if(isSelected){
label.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.black));
}
else{
label.setBorder(null);
}
if(etat!=null){
if(etat.equals(LanguageChooser.getAnInternationalizeString("nontraite")) || etat.equals(LanguageChooser.getAnInternationalizeString("pretraite"))){
label.setBackground(Color.white);
label.setForeground(Color.black);
}
else if(etat.equals(LanguageChooser.getAnInternationalizeString("nonconforme")) || etat.equals(LanguageChooser.getAnInternationalizeString("erreursystemeft")) || etat.equals(LanguageChooser.getAnInternationalizeString("erreurretourft"))){
label.setBackground(Color.red);
label.setForeground(Color.white);
}
else if(etat.equals(LanguageChooser.getAnInternationalizeString("nonaffecte"))){
label.setBackground(Color.yellow);
label.setForeground(Color.black);
}
else if(etat.equals(LanguageChooser.getAnInternationalizeString("affectationprovisoire")) || etat.equals(LanguageChooser.getAnInternationalizeString("affectationprovisoirest"))){
label.setBackground(Color.pink);
label.setForeground(Color.black);
}
else if(etat.equals(LanguageChooser.getAnInternationalizeString("affecte")) || etat.equals(LanguageChooser.getAnInternationalizeString("affectest"))){
label.setBackground(new Color(51,204,255));
label.setForeground(Color.black);
}
else if(etat.equals(LanguageChooser.getAnInternationalizeString("transmis")) || etat.equals(LanguageChooser.getAnInternationalizeString("transmisst"))){
label.setBackground(new Color(51,51,153));
label.setForeground(Color.black);
}
else if(etat.equals(LanguageChooser.getAnInternationalizeString("encours"))){
label.setBackground(new Color(0,255,51));
label.setForeground(Color.black);
}
else if(etat.equals(LanguageChooser.getAnInternationalizeString("effectue"))){
label.setBackground(new Color(0,153,51));
label.setForeground(Color.black);
}
else if(etat.equals(LanguageChooser.getAnInternationalizeString("infructueux")) || etat.equals(LanguageChooser.getAnInternationalizeString("aterminer"))){
label.setBackground(Color.red);
label.setForeground(Color.black);
}
else if(etat.equals(LanguageChooser.getAnInternationalizeString("prefinalise"))){
label.setBackground(Color.orange);
label.setForeground(Color.black);
}
else if(etat.equals(LanguageChooser.getAnInternationalizeString("validation"))){
label.setBackground(Color.gray);
label.setForeground(Color.black);
}
else if(((String)etat).contains(LanguageChooser.getAnInternationalizeString("finalise"))){
label.setBackground(Color.white);
label.setForeground(Color.gray);
}
else if(((String)etat).contains(LanguageChooser.getAnInternationalizeString("stoppe"))){
label.setBackground(Color.white);
label.setForeground(Color.red);
}
else if(((String)etat).contains(LanguageChooser.getAnInternationalizeString("facture"))){
label.setBackground(Color.white);
label.setForeground(new Color(102,0,102));
}
else if(((String)etat).contains(LanguageChooser.getAnInternationalizeString("paye"))){
label.setBackground(Color.white);
label.setForeground(new Color(0,153,51));
}
}
}
else {
label.setBackground(Color.black);
label.setForeground(Color.white);
}
if(value!=null)
label.setText(value.toString());
else
label.setText("");
if(table.getValueAt(ligne, 3)!=null){
if(table.getValueAt(ligne, 3).equals("+") && colonne==3){
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setForeground(Color.white);
label.setText("+");
}
else if(table.getValueAt(ligne, 3).equals("-") && colonne==3){
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setForeground(Color.white);
label.setText("-");
}
}
return label;
}
} |