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 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
|
package syncronisationdeficher;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class SyncronisationDeFicherView extends FrameView {
private MouseEvent evt;
ArrayList ListeFichierACopier = new ArrayList();
ArrayList<JCheckBox> ListeCases = new ArrayList<JCheckBox>();
String CheminSource;
String CheminDestination;
public SyncronisationDeFicherView(SingleFrameApplication app) {
super(app);
initComponents();
this.test();
this.affichecomposant();
// status bar initialization - message timeout, idle icon and busy animation, etc
ResourceMap resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
messageTimer = new Timer(messageTimeout, new ActionListener() {
public void actionPerformed(ActionEvent e) {
statusMessageLabel.setText("");
}
});
messageTimer.setRepeats(false);
int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
for (int i = 0; i < busyIcons.length; i++) {
busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
}
busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
public void actionPerformed(ActionEvent e) {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
}
});
idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
// connecting action tasks to status bar via TaskMonitor
TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("started".equals(propertyName)) {
if (!busyIconTimer.isRunning()) {
statusAnimationLabel.setIcon(busyIcons[0]);
busyIconIndex = 0;
busyIconTimer.start();
}
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
progressBar.setValue(0);
} else if ("message".equals(propertyName)) {
String text = (String)(evt.getNewValue());
statusMessageLabel.setText((text == null) ? "" : text);
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer)(evt.getNewValue());
progressBar.setVisible(true);
progressBar.setIndeterminate(false);
progressBar.setValue(value);
}
}
});
}
@Action
public void showAboutBox() {
if (aboutBox == null) {
JFrame mainFrame = SyncronisationDeFicherApp.getApplication().getMainFrame();
aboutBox = new SyncronisationDeFicherAboutBox(mainFrame);
aboutBox.setLocationRelativeTo(mainFrame);
}
SyncronisationDeFicherApp.getApplication().show(aboutBox);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
mainPanel = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextFieldSource = new javax.swing.JTextField();
jTextFielddestination = new javax.swing.JTextField();
BouttonParcourir1 = new javax.swing.JButton();
BoutonParcourrir2 = new javax.swing.JButton();
BoutonComparer = new javax.swing.JButton();
jButtonCopier = new javax.swing.JButton();
menuBar = new javax.swing.JMenuBar();
javax.swing.JMenu fileMenu = new javax.swing.JMenu();
javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
javax.swing.JMenu helpMenu = new javax.swing.JMenu();
javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
statusPanel = new javax.swing.JPanel();
javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
statusMessageLabel = new javax.swing.JLabel();
statusAnimationLabel = new javax.swing.JLabel();
progressBar = new javax.swing.JProgressBar();
jDialog1 = new javax.swing.JDialog();
jDialog2 = new javax.swing.JDialog();
jFrame1 = new javax.swing.JFrame();
buttonGroup1 = new javax.swing.ButtonGroup();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
mainPanel.setFocusTraversalPolicyProvider(true);
mainPanel.setName("mainPanel"); // NOI18N
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(syncronisationdeficher.SyncronisationDeFicherApp.class).getContext().getResourceMap(SyncronisationDeFicherView.class);
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
jLabel2.setName("jLabel2"); // NOI18N
jTextFieldSource.setText(resourceMap.getString("jTextFieldSource.text")); // NOI18N
jTextFieldSource.setName("jTextFieldSource"); // NOI18N
jTextFielddestination.setText(resourceMap.getString("jTextFielddestination.text")); // NOI18N
jTextFielddestination.setName("jTextFielddestination"); // NOI18N
BouttonParcourir1.setText(resourceMap.getString("BouttonParcourir1.text")); // NOI18N
BouttonParcourir1.setName("BouttonParcourir1"); // NOI18N
BouttonParcourir1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
BouttonParcourir1MouseClicked(evt);
}
});
BoutonParcourrir2.setText(resourceMap.getString("BoutonParcourrir2.text")); // NOI18N
BoutonParcourrir2.setName("BoutonParcourrir2"); // NOI18N
BoutonParcourrir2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
afficheDestination(evt);
}
});
BoutonComparer.setText(resourceMap.getString("BoutonComparer.text")); // NOI18N
BoutonComparer.setName("BoutonComparer"); // NOI18N
BoutonComparer.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
BoutonComparerMouseClicked(evt);
}
});
jButtonCopier.setText(resourceMap.getString("jButtonCopier.text")); // NOI18N
jButtonCopier.setName("jButtonCopier"); // NOI18N
jButtonCopier.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButtonCopierMouseClicked(evt);
}
});
org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup()
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jButtonCopier, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(mainPanelLayout.createSequentialGroup()
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.add(jLabel1))
.add(mainPanelLayout.createSequentialGroup()
.add(122, 122, 122)
.add(jTextFieldSource, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 224, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.add(jLabel2)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jTextFielddestination, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)))
.add(18, 18, 18)
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(BoutonParcourrir2)
.add(BouttonParcourir1)
.add(BoutonComparer))))
.add(485, 485, 485))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.add(31, 31, 31)
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(jTextFieldSource, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(BouttonParcourir1))
.add(18, 18, 18)
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(jTextFielddestination, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(BoutonParcourrir2))
.add(28, 28, 28)
.add(BoutonComparer)
.add(164, 164, 164)
.add(jButtonCopier)
.add(255, 255, 255))
);
menuBar.setName("menuBar"); // NOI18N
fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
fileMenu.setName("fileMenu"); // NOI18N
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(syncronisationdeficher.SyncronisationDeFicherApp.class).getContext().getActionMap(SyncronisationDeFicherView.class, this);
exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
exitMenuItem.setName("exitMenuItem"); // NOI18N
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
helpMenu.setName("helpMenu"); // NOI18N
aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
aboutMenuItem.setName("aboutMenuItem"); // NOI18N
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
statusPanel.setName("statusPanel"); // NOI18N
statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
statusMessageLabel.setName("statusMessageLabel"); // NOI18N
statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
progressBar.setName("progressBar"); // NOI18N
org.jdesktop.layout.GroupLayout statusPanelLayout = new org.jdesktop.layout.GroupLayout(statusPanel);
statusPanel.setLayout(statusPanelLayout);
statusPanelLayout.setHorizontalGroup(
statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
.add(statusPanelLayout.createSequentialGroup()
.addContainerGap()
.add(statusMessageLabel)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 331, Short.MAX_VALUE)
.add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(statusAnimationLabel)
.addContainerGap())
);
statusPanelLayout.setVerticalGroup(
statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(statusPanelLayout.createSequentialGroup()
.add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(statusMessageLabel)
.add(statusAnimationLabel)
.add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(3, 3, 3))
);
jDialog1.setName("jDialog1"); // NOI18N
org.jdesktop.layout.GroupLayout jDialog1Layout = new org.jdesktop.layout.GroupLayout(jDialog1.getContentPane());
jDialog1.getContentPane().setLayout(jDialog1Layout);
jDialog1Layout.setHorizontalGroup(
jDialog1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jDialog1Layout.setVerticalGroup(
jDialog1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
jDialog2.setName("jDialog2"); // NOI18N
org.jdesktop.layout.GroupLayout jDialog2Layout = new org.jdesktop.layout.GroupLayout(jDialog2.getContentPane());
jDialog2.getContentPane().setLayout(jDialog2Layout);
jDialog2Layout.setHorizontalGroup(
jDialog2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jDialog2Layout.setVerticalGroup(
jDialog2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
jFrame1.setName("jFrame1"); // NOI18N
org.jdesktop.layout.GroupLayout jFrame1Layout = new org.jdesktop.layout.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
jScrollPane1.setName("jScrollPane1"); // NOI18N
jList1.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jList1.setName("jList1"); // NOI18N
jScrollPane1.setViewportView(jList1);
setComponent(mainPanel);
setMenuBar(menuBar);
setStatusBar(statusPanel);
}// </editor-fold>
PageSource t = new PageSource ();
String varretour =t.vcv();
PageDestination Desti = new PageDestination();
String Recup = Desti.retourneChemin();
public void test(){
jTextFieldSource.setText(varretour);
System.out.println ("1 " +varretour);
jTextFielddestination.setText(Recup);
System.out.println ("2" + Recup);
}
public void affichecomposant(){
PanneauCheckBox.setBackground(Color.WHITE);
mainPanel.add(PanneauCheckBox);
PanneauCheckBox.setVisible(true);
}
private void BouttonParcourir1MouseClicked(java.awt.event.MouseEvent evt) {
PageSource PageS = new PageSource();
PageS.setVisible(true);
}
private void afficheDestination(java.awt.event.MouseEvent evt) {
PageDestination PageD = new PageDestination();
PageD.setVisible(true);
}
private void BoutonComparerMouseClicked(java.awt.event.MouseEvent evt) {
//recuperation du répertoire source et destination
CheminSource = "C://Users//Marie//Desktop//test1";
CheminDestination = "C://Users//Marie//Desktop//Test2";
//ouveerture des repertoire
File repSource = new File(CheminSource);
File repDestination = new File(CheminDestination);
//declaration des liste de fichier pour récupérer les fichiers de chaque répertoire
String[] ListeSource = repSource.list();
String[] ListeDestination = repDestination.list();
//declaration dArraylist pour récupérer les fichiers de chaque liste
ArrayList ListeSources = new ArrayList();
ArrayList ListeDestinations = new ArrayList();
int i;
//Affiche la liste des fichier du répertoire source
for(i=0;i< ListeSource.length;i++){
System.out.println("voici les fichier du dossier source :"+ ListeSource[i]);
ListeSources.add(ListeSource[i]);
}
int j;
//Affiche la liste des fichier du répertoire destination
for(j=0;j< ListeDestination.length;j++){
System.out.println("voici les fichier du dossier destination :"+ ListeDestination[j]);
ListeDestinations.add(ListeDestination[j]);
}
int k ;
boolean trouve;
for(k=0;k< ListeSource.length;k++){
trouve = false;
for(int m=0; m < ListeDestination.length; m++) {
if( ListeSource[k].equals( ListeDestination[m])) {
// si les deux chaines correspondent, on met la variable à true et on interrompe la boucle
trouve = true;
break;
}
}
if (trouve == false) {
// dans ce cas, la chaine n'existe pas dans ListeDestination
ListeFichierACopier.add(ListeSource[k]);
}
}
//boucle qui permet d'afficher des bouton ecoutou en fonction des document qui reste a copier
for (int l = 0 ;l < ListeFichierACopier.size(); l++){
//jTextArea1.setText ("\n"+(String) ListeFichierACopier.get(l)+ "\n");
JCheckBox c = new JCheckBox();
c.setText((String) ListeFichierACopier.get(l));
c.setSelected(true);
ListeCases.add(c);
PanneauCheckBox.add(c);
System.out.println("doc" +ListeFichierACopier.get(l));
//jCheckBox1.setText((String) ListeFichierACopier.get(l));
}
}
private void jButtonCopierMouseClicked(java.awt.event.MouseEvent evt) {
File l_fichierin = null;
File l_fichierout = null;
for (int y = 0 ; y < ListeFichierACopier.size(); y++){
try {
String CheminS = CheminSource + "//" + ListeFichierACopier.get(y);
String CheminD = CheminDestination + "//" + ListeFichierACopier.get(y);
l_fichierin = new File(CheminS);
l_fichierout = new File(CheminD);
FileChannel in = null;
FileChannel out = null;
in = new FileInputStream(CheminS).getChannel();
out = new FileOutputStream(CheminD).getChannel();
try {
in.transferTo(0, in.size(), out);
} catch (IOException ex) {
Logger.getLogger(SyncronisationDeFicherView.class.getName()).log(Level.SEVERE, null, ex);
}
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ex) {
Logger.getLogger(SyncronisationDeFicherView.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
// Variables declaration - do not modify
private javax.swing.JButton BoutonComparer;
private javax.swing.JButton BoutonParcourrir2;
private javax.swing.JButton BouttonParcourir1;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton jButtonCopier;
private javax.swing.JDialog jDialog1;
private javax.swing.JDialog jDialog2;
private javax.swing.JFrame jFrame1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JList jList1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextFieldSource;
private javax.swing.JTextField jTextFielddestination;
private javax.swing.JPanel mainPanel;
private javax.swing.JMenuBar menuBar;
private javax.swing.JProgressBar progressBar;
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
private javax.swing.JPanel statusPanel;
// End of variables declaration
private final Timer messageTimer;
private final Timer busyIconTimer;
private final Icon idleIcon;
private final Icon[] busyIcons = new Icon[15];
private int busyIconIndex = 0;
JPanel PanneauCheckBox = new JPanel();
private JDialog aboutBox;
} |
Partager