Import Java.awt.Button;
Import Java.awt.Frame;
Import Java.awt.GridLayout;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import Java.awt.event.WindowAdapter;
Import java.awt.event.WindowEvent;
Import Java.io.File;
Import Java.util.HashSet;
Import Java.util.Set;
Import Javax.swing.JButton;
Import Javax.swing.JFileChooser;
Import Javax.swing.JTextField;
public class Filecompareapplication {
private static String Englishurl = "";
private static String Otherlanguageurl = "";
private static String Writertofile = "";
private static String exceloutput= "";
private static String Excelfirstpath = "";
private static String Excelsecondpath = "";
private static String OutputPath = "";
private static String Excelfilepath = "";
private static String Exceldirpath = "";
private static String Exceloutputpath = "";
private static String Originalexcelfilepath = "";
private static String Filterexceldirpath = "";
private static String GetFilePath (JFileChooser choose) {
String FILEURL = null;
Choose.setfileselectionmode (jfilechooser.directories_only);
Choose.setcurrentdirectory (New File ("."));
Decide whether to click on the Open button
if (Choose.showopendialog (null) = Jfilechooser.approve_option) {
FILEURL = Choose.getselectedfile (). GetAbsolutePath ();//absolute path to open file
}
return FILEURL;
}
private static String Getexcelpath (JFileChooser choose) {
String FILEURL = null;
Choose.setfileselectionmode (jfilechooser.files_only);
Choose.setcurrentdirectory (New File ("."));
Decide whether to click on the Open button
if (Choose.showopendialog (null) = Jfilechooser.approve_option) {
FILEURL = Choose.getselectedfile (). GetAbsolutePath ();//absolute path to open file
}
return FILEURL;
}
/**
*
* @param args
*/
public static void Main (string[] args) {
Create a Form Object
Frame f = new Frame ("add button");
Setting properties
F.setbounds (800, 400, 800, 600);
Set layout to flow layout
F.setlayout (New GridLayout (18, 2, 10, 10));
JButton Jfilebutton = new JButton ("Choose English Folder");
JButton jFileButton1 = new JButton ("Select a Foreign Language folder");
JButton jFileButton2 = new JButton ("Key-value output folder");
JButton jFileButton6 = new JButton ("folder for Excel output");
JButton JFileButton3 = new JButton ("First Excel file");
JButton jFileButton4 = new JButton ("second Excel file");
JButton jFileButton5 = new JButton ("Excel File Generation folder");
JButton jFileButton7 = new JButton ("The company already has Excel standard file");
JButton jFileButton8 = new JButton ("Excel folders can have only one file");
JButton JFileButton9 = new JButton ("Generate words not in company standard files");
JButton jFileButton10 = new JButton ("original Excel file");
JButton jFileButton11 = new JButton ("Filtered Excel file");
Final JTextField txtfile = new JTextField ("Folder path");
Final JTextField txtfile1 = new JTextField ("Folder path");
Final JTextField txtfile2 = new JTextField ("Folder path");
Final JTextField txtfile6 = new JTextField ("Excel generates folder path");
Final JTextField txtfile3 = new JTextField ("Excel file path");
Final JTextField txtfile4 = new JTextField ("Excel file path");
Final JTextField txtfile5 = new JTextField ("Excel generates folder path");
Final JTextField Txtfile7 = new JTextField ("Path of company standard document");
Final JTextField Txtfile8 = new JTextField ("Folder path for Excel");
Final JTextField txtfile9 = new JTextField ("Folder path for Excel");
Final JTextField txtfile10 = new JTextField ("File path for original Excel");
Final JTextField txtfile11 = new JTextField ("Filter file path for Excel");
F.add (txtfile);
F.add (Jfilebutton);
F.add (TXTFILE1);
F.add (JFileButton1);
F.add (Txtfile2);
F.add (JFileButton2);
F.add (TXTFILE6);
F.add (JFILEBUTTON6);
Jfilebutton.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser Englishdir = new JFileChooser ();
Englishurl = GetFilePath (Englishdir);
Txtfile.settext (Englishurl);
System.out.println (Englishurl);
}
});
Jfilebutton1.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser Otherlanguagedir = new JFileChooser ();
Otherlanguageurl = GetFilePath (Otherlanguagedir);
Txtfile1.settext (Otherlanguageurl);
System.out.println (Otherlanguageurl);
}
});
Jfilebutton2.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser OutputDir = new JFileChooser ();
Writertofile = GetFilePath (OutputDir);
Txtfile2.settext (Writertofile);
System.out.println (Writertofile);
}
});
Jfilebutton6.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser OutputDir = new JFileChooser ();
Exceloutput = GetFilePath (OutputDir);
Txtfile2.settext (Exceloutput);
System.out.println (Exceloutput);
}
});
Create a Button object
Button bu = new button ("File Compare and build");
Button bu1 = New button ("");
Add a button to a form
F.add (BU);
Add a button to a form
F.add (BU1);
Set the form to close
F.addwindowlistener (New Windowadapter () {
@Override
public void windowclosing (WindowEvent e) {
System.exit (0);//Exit JVM
}
});
Bu.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Comparefiles.comparefile (Englishurl, Otherlanguageurl,
Writertofile, Exceloutput);
}
});
F.add (TXTFILE3);
F.add (JFileButton3);
F.add (TXTFILE4);
F.add (JFILEBUTTON4);
F.add (TXTFILE5);
F.add (JFILEBUTTON5);
Jfilebutton3.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser Otherlanguagedir = new JFileChooser ();
Excelfirstpath = Getexcelpath (Otherlanguagedir);
Txtfile3.settext (Excelfirstpath);
System.out.println (Excelfirstpath);
}
});
Jfilebutton4.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser OutputDir = new JFileChooser ();
Excelsecondpath = Getexcelpath (OutputDir);
Txtfile4.settext (Excelsecondpath);
System.out.println (Excelsecondpath);
}
});
Jfilebutton5.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser OutputDir = new JFileChooser ();
OutputPath = GetFilePath (OutputDir);
Txtfile4.settext (OutputPath);
System.out.println (OutputPath);
}
});
Button Exchangebutton = New button ("Two Excel file comparisons to rebuild the newer Excel");
Add a button to a form
F.add (Exchangebutton);
Exchangebutton.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Set<string> First=excelutils.readexcel (Excelfirstpath);
Set<string> Second=excelutils.readexcel (Excelsecondpath);
First.addall (second);
Excelutils.createfixationsheet (outputpath+file.separator+ system.currenttimemillis () + ". xls");
}
});
Button ExchangeButton1 = New button ("");
F.add (ExchangeButton1);
F.add (TXTFILE7);
F.add (jFileButton7);
F.add (Txtfile8);
F.add (JFILEBUTTON8);
F.add (TXTFILE9);
F.add (JFILEBUTTON9);
Jfilebutton7.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser Otherlanguagedir = new JFileChooser ();
Excelfilepath = Getexcelpath (Otherlanguagedir);
Txtfile7.settext (Excelfilepath);
System.out.println (Excelfilepath);
}
});
Jfilebutton8.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser OutputDir = new JFileChooser ();
Exceldirpath = Getexcelpath (OutputDir);
Txtfile8.settext (Exceldirpath);
System.out.println (Exceldirpath);
}
});
Jfilebutton9.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser OutputDir = new JFileChooser ();
Exceloutputpath = GetFilePath (OutputDir);
Txtfile9.settext (Exceloutputpath);
System.out.println (Exceloutputpath);
}
});
Button ExchangeButton2 = New Button ("set company standard and external language difference sets and output to Excel file");
F.add (ExchangeButton2);
Exchangebutton2.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Comparefiles.intersecttwoexcel (Excelfilepath, Exceldirpath, Exceloutputpath);
}
});
Button ExchangeButton3 = New button ("");
F.add (ExchangeButton3);
F.add (TXTFILE10);
F.add (JFILEBUTTON10);
F.add (TXTFILE11);
F.add (JFILEBUTTON11);
Jfilebutton10.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser Otherlanguagedir = new JFileChooser ();
Originalexcelfilepath = Getexcelpath (Otherlanguagedir);
Txtfile10.settext (Originalexcelfilepath);
System.out.println (Originalexcelfilepath);
}
});
Jfilebutton11.addmouselistener (New Java.awt.event.MouseAdapter () {
public void mouseclicked (Java.awt.event.MouseEvent e) {
JFileChooser OutputDir = new JFileChooser ();
Filterexceldirpath = GetFilePath (OutputDir);
Txtfile11.settext (Filterexceldirpath);
System.out.println (Filterexceldirpath);
}
});
Button ExchangeButton4 = New button ("File filter");
F.add (EXCHANGEBUTTON4);
Exchangebutton4.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Set<string> Values=excelutils.readexcelfilterblank (New File (Originalexcelfilepath));
Excelutils.createfixationsheet (values, filterexceldirpath+file.separator+ "filter" +system.currenttimemillis () + ". xls" );
}
});
form display
F.setvisible (TRUE);
}
}
Import Java.io.File;
Import Java.util.HashMap;
Import Java.util.HashSet;
Import Java.util.Iterator;
Import Java.util.Map;
Import Java.util.Set;
Import Com.google.common.collect.Sets;
Import Com.google.common.collect.Sets.SetView;
public class Comparefiles {
Static set<string> res = new hashset<string> ();
/**
* Compare the specified 7 files
*
*/
private static final string[] FileNames = new string[] {"Cec_strings.xml",
"Menu_strings.xml", "Mmp_strings.xml", "Nav_strings.xml",
"Strings.xml", "Thr_menu_strings.xml", "Timeshift_strings.xml"};
/**
*
* @param Englishpath
* Address of the English directory
* @param Otherlanguagepath
* Address in other languages
* @return results are saved in the specified file file
*/
public static void Comparefile (String englishpath,
String Otherlanguagepath, string output, String translateoutput) {
file[] Englishfiles = Fileutils.getfiles (Englishpath);
file[] Otherlanguagefiles = Fileutils.getfiles (Otherlanguagepath);
for (String filename:filenames) {
File englishfile = Fileutils.getfilebyfilename (Englishfiles,
FileName);
File otherlanguagefile = Fileutils.getfilebyfilename (
Otherlanguagefiles, FileName);
map<string, string> 中文版 = Xmlparser.parsexml (englishfile);
map<string, string> otherlanguage = Xmlparser
. Parsexml (Otherlanguagefile);
set<string> Englishkey = English.keyset ();
set<string> Otherlanguagekey = Otherlanguage.keyset ();
Filter out Englishkey-specific key
setview<string> Differenec = sets.difference (Englishkey,
Otherlanguagekey);
Filter out the intersection of Englishkey and Otherlanguagekey
Setview<string> Union = sets.intersection (Englishkey,
Otherlanguagekey);
map<string, string> englishres = Setviewcoverttohashmap (Differenec,
中文版);
map<string, string> otherlanguageres = getdiffvaluebysamekey (Union,
中文版, Otherlanguage);
set<string> Englishresvalue = Getvaluebykey (englishres);
set<string> Otherlanguageresvalue = Getvaluebykey (otherlanguageres);
Res.addall (Englishresvalue);
Res.addall (Otherlanguageresvalue);
Fileutils.writerhashmaptofile (englishres, Output + file.separator
+ filename.substring (0, Filename.lastindexof (". xml"));
Fileutils.writerhashmaptofile (
Otherlanguageres,
Output
+ File.separator
+ filename.substring (0,
Filename.lastindexof (". xml"));
}
Excelutils.createfixationsheet (res, translateoutput + file.separator
+ system.currenttimemillis () + ". xls");
Res.clear ();
}
public static void Printviewset (Setview<string> views) {
Iterator iterator = Views.iterator ();
while (Iterator.hasnext ()) {
System.out.println (Iterator.next ());
}
}
/**
* Converts the value in the map to a collection
*
* @param originalmap
* @return
*/
public static set<string> Getvaluebykey (map<string, string> originalmap) {
set<string> values = new hashset<string> ();
Iterator<string> iterator = Originalmap.keyset (). iterator ();
while (Iterator.hasnext ()) {
String value = Iterator.next ();
Values.add (Originalmap.get (value));
}
return values;
}
/**
* If key is the same but value is different, a new set is formed
*
* @param views
* @param 中文版
* @param otherlanguage
* @return
*/
public static map<string, string> Getdiffvaluebysamekey (
setview<string> views, map<string, string> 中文版,
Map<string, string> otherlanguage) {
map<string, string> res = new hashmap<string, string> ();
Iterator<string> iterator = Views.iterator ();
while (Iterator.hasnext ()) {
String value = Iterator.next ();
if (English.get (value). Equals (Otherlanguage.get (value)) {
Res.put (value, English.get (value));
}
}
return res;
}
/**
* Filter the unique key in the original map to the new collection
*
* @param views
* Filter out the collection
* @param originalmap
* Original Map Collection
* @return
*/
public static map<string, string> Setviewcoverttohashmap (
setview<string> views, map<string, string> originalmap) {
map<string, string> res = new hashmap<string, string> ();
Iterator<string> iterator = Views.iterator ();
while (Iterator.hasnext ()) {
String value = Iterator.next ();
Res.put (value, Originalmap.get (value));
}