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
|
public class Model extends AbstractTableModel implements TableModelListener, TableCellRenderer
{
/**
*
*/
private static final long serialVersionUID = 3961249787453440907L;
public Xml arbre;
private static Color COULEUR_LIGNE_SELECTION_SIMPLE = new Color(10, 10, 100, 50);
private static Color COULEUR_LIGNE_TITRE = new Color(10, 120, 10, 50);
public Model(Xml arbre, String famillePiece, String familleEvent, int mois_sele)
{
this.arbre = arbre;
this.arbre.mois_selec = mois_sele;
this.arbre.makeTableauLigneColonne(famillePiece, familleEvent);
addTableModelListener(this);
}
public void tableChanged(TableModelEvent e)
{
}
public Component getComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
JLabel label = new JLabel("");
label.setHorizontalAlignment(JLabel.CENTER);
label.setFont(new Font("Arial", Font.BOLD, 12));
label.setBackground(new Color(220, 220, 220, 100));
Component compo = null;
// initialisation du composant
// Composant pour afficher du texte
label.setText(value == null ? "" : value.toString());
label.setOpaque(true);
compo = label;
if (isSelected || hasFocus)
{
compo.setBackground(COULEUR_LIGNE_SELECTION_SIMPLE);
}
else if (column == 0)
{
compo.setBackground(COULEUR_LIGNE_TITRE);
}
else
{
int couleur = Integer.parseInt(arbre.getValue(row, column, true));
couleur = couleur*50;
if (couleur < 0)
{
couleur = 0;
}
if (couleur > 255)
{
couleur = 255;
}
compo.setForeground(new Color(couleur,0,0,255));
}
String message= arbre.getValue(row, column, false);
((JComponent)compo).setToolTipText(message);
return compo;
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
return getComponent(table, value, isSelected, hasFocus, row, column);
}
public Class<?> getColumnClass(int col)
{
return String.class;
}
public boolean isCellEditable(int row, int col)
{
return false;
}
public int getColumnCount()
{
return arbre.getTabEvent().size()+1;
}
public int getRowCount()
{
return arbre.getTabPiece().size();
}
public Object getValueAt(int rowIndex, int columnIndex)
{
return arbre.getValue(rowIndex, columnIndex, true);
}
public String getColumnName(int col)
{
if (col == 0)
{
return "Lieu";
}
else
{
return arbre.getTabEvent().get(col-1);
}
}
} |
Partager