1 16 package net.sf.jftp.gui.base.dir; 17 18 import java.awt.Image ; 19 import java.awt.event.ActionListener ; 20 import java.text.DateFormat ; 21 import java.util.Date ; 22 import java.util.Hashtable ; 23 24 import javax.swing.ImageIcon ; 25 import javax.swing.JLabel ; 26 27 import net.sf.jftp.config.Settings; 28 import net.sf.jftp.gui.framework.HImage; 29 import net.sf.jftp.net.FtpConnection; 30 31 32 public class DirEntry 33 { 34 public static final int R = FtpConnection.R; 36 public static final int W = FtpConnection.W; 37 public static final int DENIED = FtpConnection.DENIED; 38 static Hashtable extensionMap = new Hashtable (); 39 final static Object [] extensions = 40 { 41 new String [] 42 { 43 Settings.textFileImage, ".txt", 44 ".doc", ".rtf" 45 }, 46 new String [] 47 { 48 Settings.htmlFileImage, ".htm", 49 ".html" 50 }, 51 new String [] 52 { 53 Settings.zipFileImage, ".arj", 54 ".bz", ".bz2", ".deb", ".jar", 55 ".gz", ".rav", ".rpm", ".tar", 56 ".tgz", ".zip", ".z", ".iso" 57 }, 58 new String [] 59 { 60 Settings.imageFileImage, "bmp", 61 ".gif", ".jpg", ".png", ".xbm", 62 ".xpm" 63 }, 64 new String [] 65 { 66 Settings.codeFileImage, ".c", 67 ".cc", ".h", ".java" 68 }, 69 new String [] 70 { 71 Settings.audioFileImage, ".au", 72 ".mid", ".midi", ".mp3", ".wav" 73 }, 74 new String [] 75 { 76 Settings.execFileImage, ".bat", 77 ".csh", ".cgi", ".com", ".class", 78 ".cmd", ".csh", ".dtksh", ".exe", 79 ".ksh", ".pdksh", ".pl", ".sh", 80 ".tcl", ".tksh", ".zsh" 81 }, 82 new String [] 83 { 84 Settings.presentationFileImage, 85 ".ppt" 86 }, 87 new String [] 88 { 89 Settings.spreadsheetFileImage, 90 ".xls" 91 }, 92 new String [] 93 { 94 Settings.videoFileImage, ".asf", 95 ".avi", ".mpg", "mpeg", ".wmf" 96 } 97 }; 98 99 static 100 { 101 for(int i = 0; i < extensions.length; i++) 102 { 103 String [] temp = (String []) extensions[i]; 104 105 for(int j = 1; j < temp.length; j++) 106 { 107 extensionMap.put(temp[j], temp[0]); 108 } 109 } 110 } 111 112 public String file = ""; 113 private JLabel c = new JLabel (); 114 public boolean selected = false; 115 public ActionListener who = null; 116 private Image img; 118 public boolean isFile = true; 119 private boolean isDirectory = false; 120 private long size = 0; 121 private boolean isLink = false; 122 private int accessible = -1; 123 private boolean noRender = false; 124 public Date date = null; 125 126 public DirEntry(String file, ActionListener who) 127 { 128 this.file = file; 129 this.who = who; 130 setFile(); 131 } 132 133 public void setFile() 134 { 135 String f = file; 136 137 if((f.indexOf("<") >= 0) && (f.indexOf(">") >= 0)) 138 { 139 f = file.substring(file.indexOf("<") + 1); 140 f = f.substring(0, f.lastIndexOf(">")); 141 } 142 143 int lastIndex = f.lastIndexOf("."); 144 String image = Settings.fileImage; 146 if(lastIndex != -1) 147 { 148 String ext = f.substring(lastIndex); 149 String tmp = (String ) extensionMap.get(ext.toLowerCase()); 150 151 if(tmp != null) { 153 image = tmp; 154 } 155 } 156 157 img = HImage.getImage(c, image); 159 160 if(img == null) 161 { 162 img = HImage.getImage(c, Settings.fileImage); 163 } 164 165 isFile = true; 166 isDirectory = false; 167 } 168 169 public void setDirectory() 170 { 171 img = HImage.getImage(c, Settings.dirImage); 172 isFile = false; 173 isDirectory = true; 174 } 175 176 public void setNoRender() 177 { 178 noRender = true; 179 } 180 181 public boolean getNoRender() 182 { 183 return noRender; 184 } 185 186 public void setPermission(int what) 187 { 188 accessible = what; 189 } 190 191 public int getPermission() 192 { 193 return accessible; 194 } 195 196 public void setSelected(boolean state) 197 { 198 selected = state; 199 } 200 201 public boolean isDirectory() 202 { 203 return isDirectory; 204 } 205 206 public boolean isFile() 207 { 208 return isFile; 209 } 210 211 public boolean isSelected() 212 { 213 return selected; 214 } 215 216 public String toString() 217 { 218 return file; 219 } 220 221 public Image getImage() 222 { 223 return img; 224 } 225 226 public ImageIcon getImageIcon() 227 { 228 return new ImageIcon (img); 229 } 230 231 public void setDate(Date d) 232 { 233 date = d; 234 } 235 236 public String getDate() 237 { 238 if(date == null) 239 { 240 return ""; 241 } 242 243 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); 244 245 return df.format(date); 246 } 247 248 public void setFileSize(long s) 249 { 250 size = s; 251 } 252 253 public String getFileSize() 254 { 255 if(isDirectory() || (size < 0)) 256 { 257 return " "; 258 } 259 260 long rsize = size; 261 262 String type = "bs"; 263 264 if(rsize > 1024) 265 { 266 rsize = rsize / 1024; 267 type = "kb"; 268 } 269 270 if(rsize > 1024) 271 { 272 rsize = rsize / 1024; 273 type = "mb"; 274 } 275 276 if(rsize > 1024) 277 { 278 rsize = rsize / 1024; 279 type = "gb"; 280 } 281 282 String x = Long.toString(rsize); 283 284 while(x.length() < 4) 285 { 286 x = " " + x; 287 } 288 289 return x + " " + type + " > "; 290 } 291 292 public long getRawSize() 293 { 294 return size; 295 } 296 297 public void setLink() 298 { 299 img = HImage.getImage(c, Settings.linkImage); 300 file = file.substring(0, file.lastIndexOf("###")); 301 isLink = true; 302 } 303 304 public boolean isLink() 305 { 306 return isLink; 307 } 308 309 310 } 311 | Popular Tags |