import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*; import javax.swing.tree.*; import javax.swing.event.*; public class SyncGUI{ static JFrame f = new JFrame(); static MyTree puu1; static MyTree puu2 = new MyTree(); static MyTree puu3 = new MyTree(); static JTextField tb1 = new JTextField("Local GUI map",10); static JTextField tb2 = new JTextField("Foreign GUI map",10); static JTextField tb3 = new JTextField("New GUI map",10); static Button add1 = new Button("Add"); static Button add2 = new Button("Add"); static Button remove = new Button("Remove"); static Button edit = new Button("Edit"); static JScrollPane pan1; static Vector window1 = new Vector(1,1); static Vector guiObj1 = new Vector(1,1); static Vector window2 = new Vector(1,1); static Vector guiObj2 = new Vector(1,1); static Vector window3 = new Vector(1,1); static Vector guiObj3 = new Vector(1,1); public static void main(String args[]) { organize(read("C:\\PT_GUI.gui")); organize2(read("C:\\PT_GUI.old")); autoSync(); puu1 = new MyTree(); puu1.setModel(new DefaultTreeModel(looPuu(window1,guiObj1))); puu2.setModel(new DefaultTreeModel(looPuu(window2,guiObj2))); puu3.setModel(new DefaultTreeModel(looPuu(window3,guiObj3))); Container p = f.getContentPane(); puu1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); puu1.putClientProperty("JTree.lineStyle", "Angled"); puu2.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); puu2.putClientProperty("JTree.lineStyle", "Angled"); puu3.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); puu3.putClientProperty("JTree.lineStyle", "Angled"); f.setSize(600,450); f.setResizable(false); JPanel asi = new JPanel(); asi.add(tb1); asi.add(tb2); asi.add(tb3); asi.add(add1); asi.add(add2); asi.add(remove); asi.add(edit); pan1 = new JScrollPane(puu1); asi.add(pan1); pan1.setPreferredSize(new Dimension(190, 300)); JScrollPane pan2 = new JScrollPane(puu2); asi.add(pan2); pan2.setPreferredSize(new Dimension(190, 300)); JScrollPane pan3 = new JScrollPane(puu3); asi.add(pan3); pan3.setPreferredSize(new Dimension(190, 300)); p.add(asi); f.show(); tb1.setLocation(40,2); tb2.setLocation(240,2); tb3.setLocation(440,2); add1.setLocation(0,330); add2.setLocation(200,330); remove.setLocation(400,330); edit.setLocation(500,330); pan1.setLocation(0,25); pan2.setLocation(200,25); pan3.setLocation(400,25); f.addWindowListener (new WindowAdapter(){ public void windowClosing(WindowEvent e){ f.dispose(); System.exit(0); } }); } static void organize(Vector in){ int i = 0, w = 1, g = 0, d = 0, wd = 0; boolean nobracket = true; boolean desc = false; boolean windesc = true; String tmp = new String((String)in.get(0)); String tmp2 = new String(); Vector temp = new Vector(1,1); Vector temp2 = new Vector(1,1); Vector win = new Vector(1,1); win.add(tmp.substring(0,tmp.length()-1)); tmp2 = tmp.substring(0,tmp.length()-1); for (i = 1; i tmp2.length()) && (tmp.substring(0, tmp2.length()).equals(tmp2))){ if (temp2.size() != 0) { temp.add(new Vector((Collection)temp2)); } temp2.removeAllElements(); temp2.add(tmp.substring(tmp2.length()+1)); } else { window1.add(new Vector((Collection)win)); win.removeAllElements(); win.add(tmp.substring(0, tmp.length()-1)); temp.add(new Vector((Collection)temp2)); temp2.removeAllElements(); guiObj1.add(new Vector((Collection)temp)); temp.removeAllElements(); tmp2 = tmp.substring(0,tmp.length()-1); w++; windesc=true; } } nobracket = true; } System.out.println("Organize online: "); } static void organize2(Vector in){ int i = 0, w = 1, g = 0, d = 0, wd = 0; boolean nobracket = true; boolean desc = false; boolean windesc = true; String tmp = new String((String)in.get(0)); String tmp2 = new String(); Vector temp = new Vector(1,1); Vector temp2 = new Vector(1,1); Vector win = new Vector(1,1); win.add(tmp.substring(0,tmp.length()-1)); tmp2 = tmp.substring(0,tmp.length()-1); for (i = 1; i tmp2.length()) && (tmp.substring(0, tmp2.length()).equals(tmp2))){ if (temp2.size() != 0) { temp.add(new Vector((Collection)temp2)); } temp2.removeAllElements(); temp2.add(tmp.substring(tmp2.length()+1)); } else { window2.add(new Vector((Collection)win)); win.removeAllElements(); win.add(tmp.substring(0, tmp.length()-1)); temp.add(new Vector((Collection)temp2)); temp2.removeAllElements(); guiObj2.add(new Vector((Collection)temp)); temp.removeAllElements(); tmp2 = tmp.substring(0,tmp.length()-1); w++; windesc=true; } } nobracket = true; } System.out.println("Organize online: "); } static Vector read(String filename){ Vector out = new Vector(1,1); String tmp = new String(); int i = 0; try { FileInputStream uc = new FileInputStream(filename); BufferedReader input = new BufferedReader(new InputStreamReader(uc)); while((tmp = input.readLine()) != null){ out.add(tmp); i++; } input.close(); System.out.println("Lugemine läbi "+i); }catch(Exception e){ System.err.println("A mistake was encountered while trying to read the source file "+filename+" : "+e); } return(removeCrap(out)); } static Vector removeCrap(Vector in){ int i = 0, a = 0; Vector temp = new Vector(1,1); String tmp = new String(); boolean was = true; for (i = 0; i 0) { tempGTree = new DefaultMutableTreeNode(tmp.get(0)); for (b = 1; b < tmp.size(); b++) { tempGTree.add(new DefaultMutableTreeNode(tmp.get(b))); } tempTree.add(tempGTree); } } tree.add(tempTree); } return(tree); } public static void autoSync() { int i = 0, a = 0, b = 0, c = 0, d = 0, e = 0; Vector temp1 = new Vector(1,1); Vector temp2 = new Vector(1,1); Vector gtmp1 = new Vector(1,1); Vector gtmp2 = new Vector(1,1); Vector otmp1 = new Vector(1,1); Vector otmp2 = new Vector(1,1); Vector winTemp = new Vector(1,1); boolean was,wasg; for (i = 0; i < window1.size(); i++){ temp1 = (Vector)window1.get(i); was = false; for (a = 0; a < window2.size(); a++) { temp2 = (Vector)window2.get(a); if (temp1.size() == temp2.size()) { if (i==69){ } was = true; for (b = 0; b < temp1.size(); b++) { if (!temp1.get(b).equals(temp2.get(b))) { was = false; } } if (was){ window3.add(new Vector((Collection)temp1)); gtmp1 = (Vector)guiObj1.get(i); gtmp2 = (Vector)guiObj2.get(a); for (c = 0; c < gtmp1.size(); c++) { otmp1 = (Vector)gtmp1.get(c); for (d = 0; d < gtmp2.size(); d++){ otmp2 = (Vector)gtmp2.get(d); if (otmp1.size() == otmp2.size()){ wasg = true; for (e = 0; e < otmp1.size(); e++){ if (!otmp1.get(e).equals(otmp2.get(e))) { wasg = false; } } if (wasg) { winTemp.add(new Vector((Collection)otmp1)); } } } } guiObj3.add(new Vector((Collection)winTemp)); winTemp.removeAllElements(); window1.remove(i); i--; window2.remove(a); a--; } } } } System.out.println(guiObj1); } } class MyTree extends JTree implements TreeSelectionListener, TreeExpansionListener{ public MyTree() { this.addTreeExpansionListener(this); this.addTreeSelectionListener(this); } public MyTree(Vector value) { this.addTreeExpansionListener(this); this.addTreeSelectionListener(this); } public void valueChanged(TreeSelectionEvent e) { SyncGUI.syncSel(this.getRowForPath(e.getPath())); } public void treeExpanded(TreeExpansionEvent e) { // System.out.println(e.getPath()); } public void treeCollapsed(TreeExpansionEvent e) { // System.out.println(e.getPath()); } }