/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* JComparator.java
*
* Created on 3-giu-2010, 16.23.22
*/
package jcomparator.graphics;
import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import jcomparator.Comparator;
/**
*
* @author Paolo
*/
public class JComparator
extends javax.
swing.
JFrame {
}
}
}
}
for (int i = 0; i < data.length; i++) {
if (data[i].isFlavorJavaFileListType()) {
try {
List<File> list = (List<File>) obj.getTransferData(data[i]);
if (list.size() <= 2) {
if (list.size() == 1) {
if (primoField.getText().equals("") && !secondoField.getText().equals("")) {
if (!list.get(0).getAbsolutePath().equals(secondoField.getText())) {
primoField.setText(list.get(0).getAbsolutePath());
} else {
JOptionPane.
showMessageDialog(getContentPane
(),
"Errore, i due file coincidono");
}
} else if (!primoField.getText().equals("") && secondoField.getText().equals("")) {
if (!list.get(0).getAbsolutePath().equals(primoField.getText())) {
secondoField.setText(list.get(0).getAbsolutePath());
} else {
JOptionPane.
showMessageDialog(getContentPane
(),
"Errore, i due file coincidono");
}
} else {
primoField.setText(list.get(0).getAbsolutePath());
}
} else if (list.size() == 2) {
primoField.setText(list.get(0).getAbsolutePath());
secondoField.setText(list.get(1).getAbsolutePath());
}
}
}
dtde.dropComplete(true);
return;
}
}
}
}
private class Compara
implements Runnable {
private boolean alive;
public Compara() {
this.alive = true;
}
public void stop() {
this.alive = false;
}
public void start() {
this.
startThread = new Thread(this);
this.startThread.start();
}
public void run() {
File primo
= new File(primoField.
getText());
File secondo
= new File(secondoField.
getText());
if (primo.exists() && secondo.exists()) {
compara.start();
while (this.alive) {
numeroByte.setText(compara.getEqualByte() + "");
percentualeByte.
setValue((int) Double.
parseDouble(compara.
getPercentEqual()));
percentualeByte.setString(compara.getPercentEqual() + "%");
percentualeLetti.
setValue((int) Double.
parseDouble(compara.
getPercentCharging()));
percentualeLetti.setString(compara.getPercentCharging() + "%");
try {
}
if (!compara.isAlive()) {
numeroByte.setText(compara.getEqualByte() + "");
percentualeByte.
setValue((int) Double.
parseDouble(compara.
getPercentEqual()));
percentualeByte.setString(compara.getPercentEqual() + "%");
percentualeLetti.
setValue((int) Double.
parseDouble(compara.
getPercentCharging()));
percentualeLetti.setString(compara.getPercentCharging() + "%");
JOptionPane.
showMessageDialog(rootPane,
"Comparamento utlimato!");
comparaButton.setEnabled(true);
this.stop();
}
}
} else {
JOptionPane.
showMessageDialog(rootPane,
"Errore, uno dei due file non esiste");
this.stop();
comparaButton.setEnabled(true);
}
}
}
/** Creates new form JComparator */
public JComparator() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
primoLabel
= new javax.
swing.
JLabel();
secondoLabel
= new javax.
swing.
JLabel();
sfogliaButton
= new javax.
swing.
JButton();
sfogliaButton1
= new javax.
swing.
JButton();
comparaButton
= new javax.
swing.
JButton();
risultatoLabel
= new javax.
swing.
JLabel();
risultatoLabel2
= new javax.
swing.
JLabel();
numeroByte
= new javax.
swing.
JLabel();
lettiLabel
= new javax.
swing.
JLabel();
setTitle("JComparator - by Paolo Ricciuti (C)");
primoLabel.setText("Primo file:");
secondoLabel.setText("Secondo file:");
sfogliaButton.setText("Sfoglia..");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
sfogliaButtonActionPerformed(evt);
}
});
sfogliaButton1.setText("Sfoglia..");
sfogliaButton1.
addActionListener(new java.
awt.
event.
ActionListener() {
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
sfogliaButton1ActionPerformed(evt);
}
});
comparaButton.setText("Compara");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
comparaButtonActionPerformed(evt);
}
});
risultatoLabel.setText("Numero di byte uguali: ");
risultatoLabel2.setText("Percentuale di byte uguali: ");
percentualeByte.setStringPainted(true);
numeroByte.setText("0");
lettiLabel.setText("Percentuale di byte comparati: ");
percentualeLetti.setStringPainted(true);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(primoLabel)
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
.addComponent(primoField, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(secondoLabel)
.addGap(18, 18, 18)
.addComponent(secondoField, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(sfogliaButton)
.addComponent(sfogliaButton1)))
.addComponent(comparaButton)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(risultatoLabel)
.addComponent(risultatoLabel2))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(numeroByte, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(percentualeByte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(lettiLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(percentualeLetti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.
addContainerGap(44,
Short.
MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(primoLabel)
.addComponent(primoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sfogliaButton))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(secondoLabel)
.addComponent(secondoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sfogliaButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comparaButton)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(risultatoLabel)
.addComponent(numeroByte))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(percentualeByte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(risultatoLabel2))
.addGap(9, 9, 9)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lettiLabel)
.addComponent(percentualeLetti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.
addContainerGap(93,
Short.
MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void sfogliaButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_sfogliaButtonActionPerformed
int retval = this.sfogliaFile.showOpenDialog(this);
String path
= this.
sfogliaFile.
getSelectedFile().
getAbsolutePath();
if (!path.equalsIgnoreCase(this.secondoField.getText())) {
this.primoField.setText(path);
} else {
JOptionPane.
showMessageDialog(rootPane,
"Errore, i due file coincidono");
}
}
}//GEN-LAST:event_sfogliaButtonActionPerformed
private void sfogliaButton1ActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_sfogliaButton1ActionPerformed
int retval = this.sfogliaFile.showOpenDialog(this);
String path
= this.
sfogliaFile.
getSelectedFile().
getAbsolutePath();
if (!path.equalsIgnoreCase(this.primoField.getText())) {
this.secondoField.setText(path);
} else {
JOptionPane.
showMessageDialog(rootPane,
"Errore, i due file coincidono");
}
}
}//GEN-LAST:event_sfogliaButton1ActionPerformed
private void comparaButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_comparaButtonActionPerformed
new Compara().start();
this.comparaButton.setEnabled(false);
}//GEN-LAST:event_comparaButtonActionPerformed
/**
* @param args the command line arguments
*/
public static void main
(String args
[]) {
public void run() {
try {
UIManager.
setLookAndFeel(new NimbusLookAndFeel
());
}
JComparator jc = new JComparator();
int x = (screen.width - jc.getSize().width) / 2;
int y = (screen.height - jc.getSize().height) / 2;
jc.setLocation(x, y);
jc.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.
swing.
JButton comparaButton
;
private javax.
swing.
JLabel lettiLabel
;
private javax.
swing.
JLabel numeroByte
;
private javax.
swing.
JLabel primoLabel
;
private javax.
swing.
JLabel risultatoLabel
;
private javax.
swing.
JLabel risultatoLabel2
;
private javax.
swing.
JLabel secondoLabel
;
private javax.
swing.
JButton sfogliaButton
;
private javax.
swing.
JButton sfogliaButton1
;
// End of variables declaration//GEN-END:variables
}