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
|
public class DataTableauCellEditor extends AbstractCellEditor
implements TableCellEditor, Serializable
{
/**
* serialVersionUID
*/
private static final long serialVersionUID = -4042935954426383895L;
protected JCheckBox box;
protected MonObjetDate date;
protected MonObjetNombre entier;
protected MonObjetMontantCent montant;
protected JTextField text;
protected Infos inf = null;
Object objetCourant;
/**
*
*/
public DataTableauCellEditor( ) {
}
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected,
int row, int column)
{
Component retour = null;
// apporte un mieux, les Composants devenant éditable avec touche clavier pressée
table.setSurrendersFocusOnKeystroke(true);
if (!isSelected) {
retour = null;
} else {
// On récupère le type de composant contenu dans la cellule
// pour lui affecter son Editor
inf = (Infos) value;
switch (inf.getType())
{
case Infos.TYPE_BOOLEEN :
{
box = new JCheckBox();
if( inf.getAlignment()!=null ) {
box.setHorizontalAlignment(inf.getAlignment().intValue());
}
if( inf.getValeur() == Boolean.TRUE ) { box.setSelected(true);
} else { box.setSelected(false);
}
box.setHorizontalAlignment(SwingConstants.CENTER);
box.setEnabled(true);
box.setBorder(null);
objetCourant = box;
retour = box;
break;
}
case Infos.TYPE_STRING :
{
Infos cel = new Infos();
text = new JTextField();
if (value != null) { cel = (Infos) value;
} else { cel.setValeur("");
}
text.setBorder(BorderFactory.createEmptyBorder());
text.setText(cel.getValeur().toString());
text.getCaret().setVisible(true);
text.setEnabled(true);
text.setEditable(true);
objetCourant = text;
retour = text;
break;
}
case InfosCellule.TYPE_DATE :
{
date = new MonObjetDate();
date.setBorder(null);
date.setEnabled(true);
date.setEditable(true);
objetCourant = date;
retour = date;
break;
}
case InfosCellule.TYPE_ENTIER :
{
entier = new MonObjetNombre();
entier.setBorder(null);
entier.setEnabled(true);
entier.setEditable(true);
entier.setCaretHidden(false);
entier.setTextNonFormate(inf.getValeur().toString());
objetCourant = entier;
retour = entier;
break;
}
case InfosCellule.TYPE_MONTANT :
{
montant = new MonObjetMontant();
montant.setBorder(null);
montant.setEnabled(true);
montant.setEditable(true);
montant.setTextNonFormate(inf.getValeur().toString());
objetCourant = montant;
retour = montant;
break;
}
default: {retour = new JLabel(""); }
}
}
return retour;
}
public Object getCellEditorValue(){
if (objetCourant.equals(box)) {
return new Boolean(box.isSelected());
} else if (objetCourant.equals(text)) {
return text.getText();
} else if (objetCourant.equals(entier) ) {
return entier.getTextNonFormate();
} else if (objetCourant.equals(montant)) {
return montant.getTextNonFormate();
} else if (objetCourant.equals(date) ) {
return date.getText();
} else {
return new JLabel ("PAR DEFAUT");
}
}
// ... plus tous les listeners nécessaires de la forme super.le_listener(); |
Partager