001package org.vishia.commander; 002 003import java.io.File; 004import java.text.DateFormat; 005import java.text.SimpleDateFormat; 006import java.util.Date; 007 008import org.vishia.fileRemote.FileRemote; 009import org.vishia.gral.base.GralMenu; 010import org.vishia.gral.base.GralTextField; 011import org.vishia.gral.base.GralWidget; 012import org.vishia.gral.ifc.GralUserAction; 013import org.vishia.util.KeyCode; 014 015public class FcmdStatusLine 016{ 017 018 /**Version, history and license 019 * <ul> 020 * <li>2012-03-09 Hartmut new: {@link #widgSyncInfo} 021 * <li>2012-03-04 Hartmut created as extra class. Functionality was in {@link FcmdFileCard} (setText) 022 * and {@link FcmdButtons} (initialization of widgets) 023 * </ul> 024 * 025 * 026 * <b>Copyright/Copyleft</b>: 027 * For this source the LGPL Lesser General Public License, 028 * published by the Free Software Foundation is valid. 029 * It means: 030 * <ol> 031 * <li> You can use this source without any restriction for any desired purpose. 032 * <li> You can redistribute copies of this source to everybody. 033 * <li> Every user of this source, also the user of redistribute copies 034 * with or without payment, must accept this license for further using. 035 * <li> But the LPGL ist not appropriate for a whole software product, 036 * if this source is only a part of them. It means, the user 037 * must publish this part of source, 038 * but don't need to publish the whole source of the own product. 039 * <li> You can study and modify (improve) this source 040 * for own using or for redistribution, but you have to license the 041 * modified sources likewise under this LGPL Lesser General Public License. 042 * You mustn't delete this Copyright/Copyleft inscription in this source file. 043 * </ol> 044 * If you are intent to use this sources without publishing its usage, you can get 045 * a second license subscribing a special contract with the author. 046 * 047 * @author Hartmut Schorrig = hartmut.schorrig@vishia.de 048 * 049 * 050 */ 051 public static final int version = 0x20120309; 052 053 054 private final Fcmd main; 055 056 boolean showBackslash = false; 057 058 GralTextField widgFileInfo, widgFilePath, widgRunInfo, widgSyncInfo; 059 060 final DateFormat formatDateInfo = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss"); 061 062 063 String sPath = ""; 064 065 FcmdStatusLine(Fcmd main){ 066 this.main = main; 067 } 068 069 070 071 void buildGraphic(){ 072 main._gralMng.setPosition(0, 2, 0, 0, 1, 'r'); 073 widgFilePath = main._gralMng.addTextField(main.nameTextFieldFilePath, false, null, null); 074 widgFilePath.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.layout.pathCurr."); 075 widgFilePath.setDragEnable(main.actionDragFileFromStatusLine, KeyCode.dragFiles); 076 GralMenu menuWidg = widgFilePath.getContextMenu(); 077 menuWidg.addMenuItem("menuContextShowBackslash", main.idents.menuContextShowBackslash, actionShowBackslash); 078 menuWidg.addMenuItem("menuContextShowSlash", main.idents.menuContextShowSlash, actionShowSlash); 079 main._gralMng.setPosition(2, 4, 0, 9.8f, 1, 'r'); 080 widgRunInfo = main._gralMng.addTextField(main.nameTextFieldRunInfo, false, null, null); 081 widgRunInfo.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.layout.runInfo."); 082 main._gralMng.setPosition(2, 4, 10, -8, 1, 'r'); 083 widgFileInfo = main._gralMng.addTextField(main.nameTextFieldInfo, false, null, null); 084 widgFileInfo.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.layout.fileInfo."); 085 main._gralMng.setPosition(2, 4, -8, 0, 1, 'r'); 086 widgSyncInfo = main._gralMng.addTextField(main.nameTextFieldInfo, false, null, null); 087 widgSyncInfo.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.layout.syncInfo."); 088 089 } 090 091 092 void setFileInfo(FileRemote file){ 093 long lastModified = file.lastModified(); 094 String sDate = formatDateInfo.format(new Date(lastModified)); 095 String sLenShort = //String.format("", file.length) 096 file.length() >= (1024 * 1024) ? String.format("%2.3f MByte = %d Byte", file.length()/(1024 * 1024.0), file.length()) : 097 file.length() >= 1024 ? String.format("%3.2f kByte = %d Byte", file.length()/1024.0, file.length()) : 098 String.format("%3d Byte", file.length()); 099 StringBuilder info = new StringBuilder(100); 100 info.append(sDate)/*.append(" = ").append(lastModified)*/; 101 if(file instanceof FileRemote){ 102 FileRemote filer = file; 103 FileRemote filep = file.getParentFile(); 104 int parentId = filep !=null ? filep.ident(): 0; 105 info.append(" #").append(filer.ident()).append('/').append(parentId).append(" flags=0x") 106 .append(Integer.toHexString(filer.getFlags())); 107 if(file.mark !=null){ 108 int mark = file.mark.getMark(); 109 info.append(" sel=").append(Integer.toHexString((mark >>16) & 0xffff)).append('\'').append(Integer.toHexString(mark & 0xffff)); 110 if(file.isDirectory()){ 111 info.append("; files=").append(file.mark.nrofFilesSelected()); 112 } 113 } 114 } 115 long creationTime = file.creationTime(); 116 if(creationTime !=0){ 117 sDate = formatDateInfo.format(new Date(creationTime)); 118 info.append("; creation=").append(sDate); 119 } 120 long lastAccess = file.lastAccessTime(); 121 if(lastAccess !=0){ 122 sDate = formatDateInfo.format(new Date(lastAccess)); 123 info.append("; lastAccess=").append(sDate); 124 } 125 info.append(", length= ").append(sLenShort); 126 main.statusLine.widgFileInfo.setText(info); 127 sPath = file.getAbsolutePath(); 128 if(showBackslash){ 129 sPath = sPath.replace('/', '\\'); 130 } 131 main.statusLine.widgFilePath.setText(sPath); 132 if(main.filePropsCmd.isVisible){ 133 main.filePropsCmd.showFileInfos(file); 134 } 135 main.viewCmd.quickView(); 136 137 } 138 139 GralUserAction actionShowBackslash = new GralUserAction("actionShowBackslash"){ 140 @Override public boolean userActionGui(int key, GralWidget infos, Object... params) { 141 showBackslash = true; 142 sPath = sPath.replace('/', '\\'); 143 main.statusLine.widgFilePath.setText(sPath); 144 return true; 145 } 146 }; 147 148 GralUserAction actionShowSlash = new GralUserAction("actionShowSlash"){ 149 @Override public boolean userActionGui(int key, GralWidget infos, Object... params) { 150 showBackslash = false; 151 sPath = sPath.replace('\\', '/'); 152 main.statusLine.widgFilePath.setText(sPath); 153 return true; 154 } 155 }; 156 157 158 159}