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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
|
public class ControleReporter extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
private JTable tableau;
private DefaultTableModel dtm;
private JButton validDate;
private JTextField date;
private String dateFormate;
private JButton aide;
public ControleReporter()
{
this.resize(1024,768);
initComponents1();
initComponents2();
this.show();
}
public void initComponents1()
{
getContentPane().setLayout(null);
String[] columns = {"contrôle","Univ A","date A","bilan A","Univ B","date B","bilan B","Univ C","date C","bilan C","Univ D","date D","bilan D","Univ E","date E","bilan E","Univ F","date F","bilan F","Univ G","date G","bilan G","Univ H","date H","bilan H","Univ P","date P","bilan P"};
ArrayList strLR=new ArrayList();
String tmpBuff= "nil";
try {
BufferedReader brLR = new BufferedReader(new FileReader(new File("C:\\controlReporter\\listRequetes.txt")));
while(!tmpBuff.equals(";"))
{
tmpBuff = brLR.readLine();
if (!tmpBuff.equals(";"))
{strLR.add(tmpBuff);}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[][] data = new String[strLR.size()][];
for(int i=0; i<data.length;i++)
{
data[i]= new String[]{ (String)strLR.get(i),"","","","","","","","","","","","","","","","","","","","","","","","","","",""};
}
tableau = new JTable();
dtm=new DefaultTableModel();
tableau.setModel(dtm);
tableau.setAutoResizeMode(0);
tableau.setSize(new Dimension(1024,768));
JScrollPane sp=new JScrollPane(tableau);
sp.setBounds(0,40,1024,700);
dtm.setNumRows(15);
dtm.setDataVector(data,columns);
tableau.getColumnModel().getColumn(0).setPreferredWidth(260);
for(int i=2;i<=27;i=i+3)
{
tableau.getColumnModel().getColumn(i).setPreferredWidth(68);
}
for(int i=3;i<=27;i=i+3)
{
tableau.getColumnModel().getColumn(i).setPreferredWidth(60);
}
for(int i=1;i<=27;i=i+3)
{
tableau.getColumnModel().getColumn(i).setPreferredWidth(165);
}
this.getContentPane().add(sp);
aide = new JButton();
aide.setBounds(220,5,60,20);
aide.setText("Aide");
this.getContentPane().add(aide);
aide.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
try {
Runtime.getRuntime().exec(new String[]{"cmd.exe","/c","start winword C:\\COntrolReporter\\Control_Reporter_Aide.doc"});
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
}
public void initComponents2()
{
date = new JTextField();
date.setBounds(5,5,80,20);
date.setText("JJ/MM/AAAA");
this.getContentPane().add(date);
validDate = new JButton();
validDate.setBounds(90,5,120,20);
validDate.setText("faire le bilan");
addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent arg0) {
if(arg0.getKeyCode()==KeyEvent.VK_ENTER)
{
System.out.println("test");
}
}
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
public void keyTyped(KeyEvent arg0) {
if(arg0.getKeyCode()==KeyEvent.VK_ENTER)
{
scanControl();
}
}});
validDate.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0)
{
scanControl();
}
});
getContentPane().add(validDate);
}
public void scanControl() {
String dateBrute = date.getText();
StringTokenizer stkdate = new StringTokenizer(dateBrute,"/");
StringBuffer sbfdate=new StringBuffer();
while (stkdate.hasMoreTokens())
{
sbfdate.append(stkdate.nextToken());
}
dateFormate = sbfdate.toString();
System.out.println(dateFormate);
for(int j=1;j<=9;j++)
{
for(int i=0;i<dtm.getRowCount();i++)
{
StringBuffer sbf=new StringBuffer();
sbf.append("C:\\User\\Bov5\\Repertoire");
sbf.append(j);
sbf.append("\\Resultats\\HTML\\");
sbf.append(dtm.getValueAt(i,0));
sbf.append(dateFormate);
sbf.append("\\resultat\\0.htm");
String path = sbf.toString();
System.out.println(path);
try {
BufferedReader brA = new BufferedReader(new FileReader(new File(path)));
String strA="nil";
StringBuffer sb=new StringBuffer();
while(!strA.equals("</HTML>"))
{
strA = brA.readLine();
sb.append(strA);
}
String fullFileA=sb.toString();
StringTokenizer stk=new StringTokenizer(fullFileA,"=,<,>");
while(stk.hasMoreElements())
{
String tmp=stk.nextToken();
if(tmp.equals("date"))
{
String dateA=stk.nextToken();
dtm.setValueAt(dateA,i,j*3-1);
}
if(tmp.equals("bilan"))
{
String bilanA=stk.nextToken();
ButtonRenderer button = new ButtonRenderer();
tableau.getColumnModel().getColumn(j*3).setCellRenderer(button);
tableau.getColumnModel().getColumn(j*3).setCellEditor(new ButtonEditor(new JCheckBox()));
//button.setBackground(new Color(0,255,234));
tableau.setValueAt(bilanA,i,j*3);
}
if(tmp.equals("univ"))
{
String univA=stk.nextToken();
dtm.setValueAt(univA,i,j*3-2);
}
}
System.out.println(fullFileA);
} catch (FileNotFoundException e) {
tableau.setValueAt("pas de controle à cette date",i,j*3-2);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public class ButtonRenderer extends JButton implements TableCellRenderer, TableCellEditor{
/**
*
*/
private static final long serialVersionUID = 1L;
private Object value;
public void setText(String text)
{
super.setText(text);
}
public Component getTableCellRendererComponent(JTable arg0, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
setText((value==null)?"":value.toString());
String bilan = (String)tableau.getValueAt(row,column);
String isControled = (String)tableau.getValueAt(row,column-2);
if(isControled.equals("pas de controle à cette date"))
{
setBackground(Color.white);
setEnabled(false);
setText("");
tableau.setValueAt("",row,column-1);
}
else{
if(bilan.equals("O"))
{
setBackground(Color.green);
setText("OK");
}
if(bilan.equals("N"))
{
setBackground(Color.red);
setText("ANO");
}
}
return this;
}
public Component getTableCellEditorComponent(JTable arg0, Object arg1, boolean arg2, int arg3, int arg4) {
setText((value==null)?"":value.toString());
addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
return this;
}
public Object getCellEditorValue() {
return value;
}
public boolean isCellEditable(EventObject arg0) {
return true;
}
public boolean shouldSelectCell(EventObject arg0) {
return false;
}
public boolean stopCellEditing() {
return false;
}
public void cancelCellEditing() {
}
public void addCellEditorListener(CellEditorListener arg0) {
}
public void removeCellEditorListener(CellEditorListener arg0) {
}}
public class ButtonEditor extends DefaultCellEditor
{
/**
*
*/
private static final long serialVersionUID = 1306962899153387642L;
protected JButton button;
private String label;
private boolean isPushed;
public ButtonEditor(JCheckBox checkbox)
{
super(checkbox);
button = new JButton();
button.setOpaque(true);
button.setText("ANO");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
fireEditingStopped();
}
});
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
{
button.setForeground(new Color(255,255,255));
button.setBackground(new Color(0,0,0));
label=(value==null)?"":value.toString();
button.setText(label);
isPushed=true;
return button;
}
public Object getCellEditorValue()
{
if(isPushed)
{
//lancer le .rep (passer par row et column)
int row = tableau.getSelectedRow();
int col = tableau.getSelectedColumn();
col=col/3;
StringBuffer sbf = new StringBuffer();
sbf.append("C:\\User\\Bov5\\Repertoire");
sbf.append(col);
sbf.append("\\Resultats\\REP\\");
sbf.append(tableau.getValueAt(row,0));
sbf.append("_");
sbf.append(dateFormate);
sbf.append(".rep");
String path=sbf.toString();
try {
Runtime.getRuntime().exec(new String[]{"cmd.exe","/c","start iexplore "+path});
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println(tableau.getValueAt(row,0)+String.valueOf(col));
}
isPushed = false;
return new String(label);
}
public boolean stopCellEditing()
{
isPushed=false;
return super.stopCellEditing();
}
protected void fireEditingStopped()
{
super.fireEditingStopped();
}
}
public static void main(String[] args) {
new ControleReporter();
}
} |
Partager