1 7 package com.genimen.djeneric.tools.modeler.userperspective; 8 9 import java.awt.Component ; 10 11 import javax.swing.DefaultListCellRenderer ; 12 import javax.swing.ImageIcon ; 13 import javax.swing.JList ; 14 15 import com.genimen.djeneric.structure.ResourceDefinition; 16 import com.genimen.djeneric.tools.modeler.ModelEditor; 17 import com.genimen.djeneric.util.DjString; 18 19 public class ResourceListRenderer extends DefaultListCellRenderer 20 { 21 private static final long serialVersionUID = 1L; 22 ImageIcon _gif = ModelEditor.getImageIcon("gif.gif"); 23 ImageIcon _class = ModelEditor.getImageIcon("class.gif"); 24 ImageIcon _binary = ModelEditor.getImageIcon("binary.gif"); 25 ImageIcon _jar = ModelEditor.getImageIcon("jar.gif"); 26 27 boolean _displayDetails; 28 29 public ResourceListRenderer() 30 { 31 this(true); 32 } 33 34 public ResourceListRenderer(boolean displayDetails) 35 { 36 _displayDetails = displayDetails; 37 } 38 39 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, 40 boolean cellHasFocus) 41 { 42 43 Component retValue = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 44 45 ResourceDefinition def = (ResourceDefinition) value; 46 if (def != null && def.getType() != null) 47 { 48 if (def.getType().equals("gif")) 49 { 50 if (def.getBytes().length < 10000) 51 { 52 setIcon(new ImageIcon (def.getBytes())); 53 } 54 else setIcon(_gif); 55 } 56 else if (def.getType().equals("jar")) 57 { 58 setIcon(_jar); 59 } 60 else if (def.getType().equals("class")) 61 { 62 setIcon(_class); 63 } 64 else setIcon(_binary); 65 } 66 67 if (_displayDetails) 68 { 69 StringBuffer name = new StringBuffer (); 70 name.append(def.getName()); 71 name.append("."); 72 name.append(def.getType()); 73 74 name = DjString.appendToLength(name, " ", 40); 75 StringBuffer bytes = new StringBuffer (); 76 bytes.append(String.valueOf(def.getBytes().length)); 77 while (bytes.length() < 8) 78 bytes.insert(0, " "); 79 bytes.append(" "); 80 bytes.append(def.getTimeStamp()); 81 bytes.insert(0, name); 82 setText(bytes.toString()); 83 } 84 else 85 { 86 setText(def.toString()); 87 } 88 89 return retValue; 90 } 91 } | Popular Tags |