KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > modeler > userperspective > ResourceListRenderer


1 /*
2  * Created on 8-apr-03
3  *
4  * To change this generated comment go to
5  * Window>Preferences>Java>Code Generation>Code Template
6  */

7 package com.genimen.djeneric.tools.modeler.userperspective;
8
9 import java.awt.Component JavaDoc;
10
11 import javax.swing.DefaultListCellRenderer JavaDoc;
12 import javax.swing.ImageIcon JavaDoc;
13 import javax.swing.JList JavaDoc;
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 JavaDoc
20 {
21   private static final long serialVersionUID = 1L;
22   ImageIcon JavaDoc _gif = ModelEditor.getImageIcon("gif.gif");
23   ImageIcon JavaDoc _class = ModelEditor.getImageIcon("class.gif");
24   ImageIcon JavaDoc _binary = ModelEditor.getImageIcon("binary.gif");
25   ImageIcon JavaDoc _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 JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected,
40                                                 boolean cellHasFocus)
41   {
42
43     Component JavaDoc 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 JavaDoc(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 JavaDoc name = new StringBuffer JavaDoc();
70       name.append(def.getName());
71       name.append(".");
72       name.append(def.getType());
73
74       name = DjString.appendToLength(name, " ", 40);
75       StringBuffer JavaDoc bytes = new StringBuffer JavaDoc();
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