1 16 package net.sf.jftp.gui.base.dir; 17 18 import net.sf.jftp.config.Settings; 19 import net.sf.jftp.system.logging.Log; 20 import net.sf.jftp.gui.base.LocalDir; 21 import net.sf.jftp.gui.base.RemoteDir; 22 import net.sf.jftp.gui.framework.GUIDefaults; 23 24 import java.awt.*; 25 import java.awt.event.*; 26 27 import java.text.*; 28 29 import java.util.*; 30 31 import javax.swing.*; 32 33 34 public class DirCellRenderer extends DefaultListCellRenderer 37 { 38 final static ImageIcon longIcon = new ImageIcon(Settings.dirImage); 39 final static ImageIcon shortIcon = new ImageIcon(Settings.fileImage); 40 private Object value; 41 42 public DirCellRenderer() 43 { 44 } 45 46 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 53 57 super.getListCellRendererComponent(list, value, index, isSelected, 58 cellHasFocus); 59 60 ImageIcon i = new ImageIcon(((DirEntry) value).getImage()); 61 62 if(i == null) 63 { 64 System.out.println("Img null: " + ((DirEntry) value).toString() + 65 "/" + ((DirEntry) value).getImage()); 66 } 67 else 68 { 69 setIcon((Icon) i); 70 } 71 72 this.value = value; 73 Log.devnull(this.value); 75 if(!((DirEntry) list.getModel().getElementAt(index)).getNoRender()) 76 { 77 String size = ""; 78 79 if(Settings.showFileSize) 80 { 81 size = ((DirEntry) list.getModel().getElementAt(index)).getFileSize(); 82 } 83 84 setFont(GUIDefaults.monospaced); 85 86 String s = value.toString(); 87 88 String date = ""; 89 90 if(Settings.showDateNoSize && 91 (((DirEntry) list.getModel().getElementAt(index)).who instanceof RemoteDir)) 92 { 93 size = ((DirEntry) list.getModel().getElementAt(index)).getDate(); 94 95 int x = 12 - size.length(); 96 97 for(int j = 0; j < x; j++) 98 { 99 size += " "; 100 } 101 } 102 else if(Settings.showLocalDateNoSize && 103 (((DirEntry) list.getModel().getElementAt(index)).who instanceof LocalDir)) 104 { 105 size = ((DirEntry) list.getModel().getElementAt(index)).getDate(); 106 107 int x = 12 - size.length(); 108 109 for(int j = 0; j < x; j++) 110 { 111 size += " "; 112 } 113 } 114 115 setText(size + s); 116 } 117 else 118 { 119 setFont(GUIDefaults.small); 120 121 String s = value.toString(); 122 setText(s); 123 } 124 125 int ok = ((DirEntry) value).getPermission(); 126 127 if(ok == DirEntry.DENIED) 128 { 129 setForeground(GUIDefaults.deniedColor); 130 } 131 else if(ok == DirEntry.W) 132 { 133 setForeground(GUIDefaults.writableColor); 134 } 135 else 136 { 137 setForeground(GUIDefaults.defaultColor); 138 } 139 140 if(((DirEntry) value).file.equals("..")) 141 { 142 setBackground(GUIDefaults.cdColor); 143 } 144 145 return this; 146 } 147 } 148 | Popular Tags |