001package org.vishia.commander; 002 003import java.io.File; 004import java.util.LinkedList; 005import java.util.List; 006import java.util.Map; 007import java.util.TreeMap; 008 009import org.vishia.fileRemote.FileRemote; 010import org.vishia.gral.base.GralButton; 011import org.vishia.gral.base.GralPos; 012import org.vishia.gral.base.GralValueBar; 013import org.vishia.gral.base.GralWidget; 014import org.vishia.gral.base.GralWindow; 015import org.vishia.gral.ifc.GralTextField_ifc; 016import org.vishia.gral.ifc.GralUserAction; 017import org.vishia.gral.ifc.GralWindow_ifc; 018import org.vishia.util.FileCompare; 019import org.vishia.util.KeyCode; 020 021 022public final class FcmdFilesCp { 023 024 /**Version, history and license 025 * <ul> 026 * <li>2012-04-17 Compares only mid and right panel. 027 * <li>2011-12-00 Hartmut creation. 028 * </ul> 029 * 030 * <b>Copyright/Copyleft</b>: 031 * For this source the LGPL Lesser General Public License, 032 * published by the Free Software Foundation is valid. 033 * It means: 034 * <ol> 035 * <li> You can use this source without any restriction for any desired purpose. 036 * <li> You can redistribute copies of this source to everybody. 037 * <li> Every user of this source, also the user of redistribute copies 038 * with or without payment, must accept this license for further using. 039 * <li> But the LPGL ist not appropriate for a whole software product, 040 * if this source is only a part of them. It means, the user 041 * must publish this part of source, 042 * but don't need to publish the whole source of the own product. 043 * <li> You can study and modify (improve) this source 044 * for own using or for redistribution, but you have to license the 045 * modified sources likewise under this LGPL Lesser General Public License. 046 * You mustn't delete this Copyright/Copyleft inscription in this source file. 047 * </ol> 048 * If you are intent to use this sources without publishing its usage, you can get 049 * a second license subscribing a special contract with the author. 050 * 051 * @author Hartmut Schorrig = hartmut.schorrig@vishia.de 052 */ 053 public final static int version = 20120417; 054 055 056 final Fcmd main; 057 058 GralWindow_ifc windConfirmCompare; 059 060 GralTextField_ifc widgPath1, widgPath2; 061 062 GralValueBar widgProgression; 063 064 /**Buttons. */ 065 GralButton widgSyncWalk, widgGetDir, widgCompare; 066 067 068 069 /**Composition of the comparer. */ 070 final FileCompare comparer = new FileCompare(0, null, 0); 071 072 /**List for results of comparison as tree. */ 073 List<FileCompare.Result> result = new LinkedList<FileCompare.Result>(); 074 075 /**List for results of comparison as index sorted to local file paths. */ 076 final Map<String, FileCompare.Result> idxFilepath4Result = new TreeMap<String, FileCompare.Result>(); 077 078 /**The both selected file cards which are used for comparison. 079 * For that file cards a synchronous walk through files may be done. 080 */ 081 FcmdFileCard card1, card2; 082 083 /**The both directories where the comparison was started. */ 084 FileRemote file1, file2; 085 086 FcmdFilesCp(Fcmd main){ 087 this.main = main; 088 } 089 090 void buildGraphic(){ 091 main.gui.addMenuBarArea9ItemGThread("menuFilesCpBar", main.idents.menuFilesCpBar, actionConfirmCp); 092 main._gralMng.selectPanel("primaryWindow"); 093 main._gralMng.setPosition(-19, 0, -47, 0, 1, 'r'); //right buttom, about half less display width and hight. 094 095 windConfirmCompare = main._gralMng.createWindow("windConfirmCompare", main.idents.windConfirmCompare, GralWindow.windConcurrently); 096 //System.out.println(" window: " + main.gralMng.pos.panel.getPixelPositionSize().toString()); 097 098 main._gralMng.setPosition(4, GralPos.size -3.5f, 1, -1, 0, 'd', 0.5f); 099 widgPath1 = main._gralMng.addTextField("comparePath1", true, "compare:", "t"); 100 widgPath1.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.folderCmp."); 101 widgPath2 = main._gralMng.addTextField("comparePath2", true, "with:", "t"); 102 widgPath2.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.folderCmp."); 103 104 main._gralMng.setPosition(-1, GralPos.size - 3, 1, GralPos.size + 8, 0, 'r',2); 105 main._gralMng.addButton(null, actionFilesCp, "esc", null, "esc"); 106 //widgSyncWalk = main.gralMng.addSwitchButton(null, null, "sync", null, null, "sync", "wh", "gn"); 107 //widgSyncWalk.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.folderCmp."); 108 widgGetDir = main._gralMng.addButton(null, actionFilesCp, "get", null, "get dir"); 109 widgGetDir.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.folderCmp."); 110 widgCompare = main._gralMng.addButton(null, actionFilesCp, "cp", null, "compare"); 111 widgCompare.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.folderCmp."); 112 widgCompare.setPrimaryWidgetOfPanel(); 113 } 114 115 116 117 118 119 120 121 private void buildIdxResult(FileCompare.Result item, int recursion){ 122 if(recursion > 100) 123 throw new IllegalArgumentException("too many deepness of file tree"); 124 String relpath; 125 if(item.file1 !=null){ 126 int posRel = file1.getAbsolutePath().length() +1; //after / starts the local path 127 relpath = item.file1.getAbsolutePath().substring(posRel); 128 } else { 129 int posRel = file2.getAbsolutePath().length() +1; //after / starts the local path 130 relpath = item.file2.getAbsolutePath().substring(posRel); 131 } 132 idxFilepath4Result.put(relpath, item); 133 if(item.subFiles !=null && item.subFiles.size() >0){ 134 for(FileCompare.Result sub: item.subFiles){ 135 buildIdxResult(sub, recursion +1); 136 } 137 } 138 } 139 140 141 142 /**Action if button "get dirs" is pressed. 143 * 144 */ 145 void setDirs(){ 146 FcmdFileCard[] lastFileCards = main.getLastSelectedFileCards(); 147 card1 = lastFileCards[0]; 148 card2 = lastFileCards[1]; 149 if(card1 !=null && card2 !=null){ 150 card1.otherFileCardtoSync = card2; //cross connect this file cards. 151 card2.otherFileCardtoSync = card1; 152 file1 = card1.currentFile(); 153 file2 = card2.currentFile(); 154 card1.sDirSync = file1.getAbsolutePath(); 155 card2.sDirSync = file2.getAbsolutePath(); 156 card1.zDirSync = card1.sDirSync.length(); 157 card2.zDirSync = card2.sDirSync.length(); 158 widgPath1.setText(card1.sDirSync); 159 widgPath2.setText(card2.sDirSync); 160 } else { 161 if(card1 !=null){ card1.otherFileCardtoSync = null; } 162 if(card2 !=null){ card2.otherFileCardtoSync = null; } 163 card1 = card2 = null; 164 widgPath1.setText(""); 165 widgPath2.setText(""); 166 } 167 widgCompare.setText("compare"); 168 widgCompare.sCmd = "cp"; 169 170 } 171 172 173 174 175 GralUserAction actionConfirmCp = new GralUserAction("actionConfirmCp") { 176 @Override public boolean userActionGui(int key, GralWidget infos, Object... params) 177 { 178 if(KeyCode.isControlFunctionMouseUpOrMenu(key)){ 179 setDirs(); 180 windConfirmCompare.setFocus(); //setWindowVisible(true); 181 } 182 return true; 183 } }; 184 185 186 GralUserAction actionFilesCp = new GralUserAction("actionFilesCp") { 187 @Override public boolean userActionGui(int key, GralWidget infos, Object... params) 188 { 189 if(KeyCode.isControlFunctionMouseUpOrMenu(key)){ 190 if(infos.sCmd.equals("get")){ 191 setDirs(); 192 } else 193 if(infos.sCmd.equals("cp")){ 194 //filesCp(); 195 } else if(infos.sCmd.equals("stop")){ 196 widgCompare.setText("stopped"); 197 widgCompare.sCmd = "stop"; 198 //TODO 199 } else if(infos.sCmd.equals("esc")){ 200 windConfirmCompare.setFocus(); //setWindowVisible(false); 201 } 202 } 203 return true; 204 } }; 205 206 207}