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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
| package IHM;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableColumn;
import Model.Mousse;
import Model.Outil;
import Model.Produit;
import chargement.FichierCSV;
public class PanelChoixMousse extends PanelProduit {
//VARIABLES
private static final long serialVersionUID = 1L;
JPanel panelTableMousse = new PanelAvecInsets(0,20,0,20);
JPanel panelTableOutil = new PanelAvecInsets(0,20,0,20);
JTable tableMousse,tableOutil;
Vector<String> mousses = FichierCSV.LectureFichierCSV("Data/Mousses.csv");
//CONSTRUCTEUR
public PanelChoixMousse(Produit model) {
this.model = model;
this.setLayout(new GridLayout(7,1));
this.add(creerTitre1());
this.add(demanderNBMousse());
panelTableMousse.setLayout(new BoxLayout(panelTableMousse,BoxLayout.PAGE_AXIS));
this.add(panelTableMousse);
this.add(creerTitre2());
this.add(idemanderNBOutill());
panelTableOutil.setLayout(new BoxLayout(panelTableOutil,BoxLayout.PAGE_AXIS));
this.add(panelTableOutil);
this.add(creerValider());
System.out.println("elements "+model.elements);
}
//METHODES
private JPanel creerTitre1() {
JPanel indication = new PanelAvecInsets(30,0,00,0);
indication.setLayout(new GridLayout(3,1));
indication.add(new JLabel("MOUSSES", JLabel.CENTER));
indication.add(Box.createVerticalGlue());
return indication;
}
public JPanel demanderNBMousse() {
JPanel panelCombienMousse = new JPanel();
panelCombienMousse.setLayout(new BoxLayout(panelCombienMousse,BoxLayout.PAGE_AXIS));
JPanel indication = new JPanel();
indication.add(new JLabel("Combien d'éléments en mousses voulez-vous? "));
final JTextField elementsMousse = new JTextField(30);
elementsMousse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ajouterChoixMousse(elementsMousse.getText());
}
});
indication.add(elementsMousse);
panelCombienMousse.add(indication);
return panelCombienMousse;
}
private JPanel creerTitre2() {
JPanel sud = new PanelAvecInsets(30,0,00,0);
sud.setLayout(new GridLayout(5,1));
sud.add(new JLabel("OUTIL", JLabel.CENTER));
sud.add(Box.createVerticalGlue());
this.add(sud,BorderLayout.SOUTH);
return sud;
}
private JPanel idemanderNBOutill() {
JPanel demandeNB = new JPanel();
demandeNB.setLayout(new BoxLayout(demandeNB,BoxLayout.PAGE_AXIS));
JPanel indication = new JPanel();
indication.add(new JLabel("Combien d'outils de découpe allez vous utiliser ? "));
final JTextField jc1 = new JTextField(30);
jc1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ajouterChoixOutil(jc1.getText());
}
});
indication.add(jc1);
demandeNB.add(indication);
return demandeNB;
}
public void ajouterChoixOutil(String num) {
int i = Integer.parseInt(num);
panelTableOutil.removeAll();
String[] colonne = {"type","L","Prix au metre"};
Object[][] grille = new Object[i][3];
for (int j=0;j<i;j++){
grille[j][0] = ""+(j+1);
grille[j][1] = "0";
grille[j][2] = "0";
}
tableOutil = new JTable(grille,colonne);
JScrollPane js = new JScrollPane(tableOutil);
panelTableOutil.add(js);
ajouterTextFieldOutil(1);
ajouterTextFieldOutil(2);
panelTableOutil.add(Box.createVerticalGlue());
validate();
}
public void ajouterChoixMousse(String num) {
int i = Integer.parseInt(num);
panelTableMousse.removeAll();
String[] colonne = {"type","L","P","ref matière","nb"};
Object[][] grille = new Object[i][5];
for (int j=0;j<i;j++){
grille[j][0] = "type "+(j+1);
for (int k = 1; k<5;k++) {
grille[j][k] = null;
}
}
tableMousse = new JTable(grille,colonne);
JScrollPane js = new JScrollPane(tableMousse);
panelTableMousse.add(js);
ajouterTextField(1);
ajouterTextField(2);
ajouterRefMousse();
ajouterTextField(4);
panelTableMousse.add(Box.createVerticalGlue());
validate();
}
private void ajouterRefMousse() {
Vector<String> ref = new Vector<String>();
for (String s: mousses) {
String[] l = s.split(";");
ref.add(l[0]);
}
JComboBox jc = new JComboBox(ref);
TableColumn tc = tableMousse.getColumnModel().getColumn(3);
tc.setCellEditor(new DefaultCellEditor(jc));
}
private void ajouterTextField(int index){
TableColumn tc = tableMousse.getColumnModel().getColumn(index);
JTextField jc = new JTextField(30);
jc.setEditable(true);
tc.setCellEditor(new DefaultCellEditor(jc));
}
private void ajouterTextFieldOutil(int index){
TableColumn tc = tableOutil.getColumnModel().getColumn(index);
JTextField jc = new JTextField(30);
jc.setEditable(true);
tc.setCellEditor(new DefaultCellEditor(jc));
}
private JPanel creerValider() {
JPanel panel = new JPanel();
JButton valider = new JButton("VALIDER");
panel.add(valider);
valider.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//{"type","L","P","ref matière","nb"};
for (int i = 0; i<tableMousse.getModel().getRowCount(); i++) {
try{
int L = Integer.parseInt((String)tableMousse.getModel().getValueAt(i, 1));
int P = Integer.parseInt((String)tableMousse.getModel().getValueAt(i, 2));
String ref = (String)tableMousse.getModel().getValueAt(i, 3);
int nb = Integer.parseInt((String)tableMousse.getModel().getValueAt(i, 4));
System.out.println("VOICI P"+P);
model.mousses.add(new Mousse(nb,ref,L,P,"Mousse "+i));
} catch (Exception arg){}
}
//{"type","L","prix au metre"};
for (int i = 0; i<tableOutil.getModel().getRowCount(); i++) {
try{
//TODO IL FAUT TAPER ENTER
String ref = (String)tableOutil.getModel().getValueAt(i,0);
double L = Double.parseDouble((String)tableOutil.getModel().getValueAt(i,1));
double prixAuMetre = Double.parseDouble((String)tableOutil.getModel().getValueAt(i,2));
Outil outil = new Outil(ref,L,prixAuMetre);
model.outilDecoupe.add(outil);
} catch (Exception arg){}
}
removeAll();
setLayout(new BorderLayout());
add(new PanelClientQuantite(model),BorderLayout.CENTER);
validate();
}
});
return panel;
}
} |
Partager