KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > irplugin > gui > inputcontrols > ui > ItemRenderer


1 /*
2  * ItemRenderer.java
3  *
4  * Created on August 23, 2006, 6:02 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package com.jaspersoft.jasperserver.irplugin.gui.inputcontrols.ui;
11
12 import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.InputControlQueryDataRow;
13 import java.awt.Color JavaDoc;
14 import java.awt.Component JavaDoc;
15 import java.awt.GridBagLayout JavaDoc;
16 import java.awt.GridLayout JavaDoc;
17 import javax.swing.JLabel JavaDoc;
18 import javax.swing.JList JavaDoc;
19 import javax.swing.JPanel JavaDoc;
20 import javax.swing.ListCellRenderer JavaDoc;
21 import javax.swing.SwingConstants JavaDoc;
22
23 /**
24  *
25  * @author gtoffoli
26  */

27 public // The combobox's renderer...
28
class ItemRenderer extends JPanel JavaDoc implements ListCellRenderer JavaDoc
29     {
30         private JLabel JavaDoc[] labels = null;
31         //private JLabel nameLabel = new JLabel(" ");
32
//private JLabel valueLabel = new JLabel(" ");
33
int columns = 0;
34  
35         public ItemRenderer(int columns)
36         {
37             setOpaque(true);
38             //setLayout(new GridBagLayout());
39
GridLayout JavaDoc g = new GridLayout JavaDoc(1,columns);
40                         setLayout(g);
41
42                         this.columns = columns;
43             labels = new JLabel JavaDoc[columns];
44                         
45                         //java.awt.GridBagConstraints gridBagConstraints = null;
46

47             for (int i=0; i<columns; ++i)
48             {
49                labels[i] = new JLabel JavaDoc(" ");
50                            //gridBagConstraints = new java.awt.GridBagConstraints();
51
//gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
52
//gridBagConstraints.weightx = 1.0;
53
//gridBagConstraints.weighty = 1.0;
54

55                add(labels[i]); //, gridBagConstraints);
56
}
57         }
58  
59  
60         public Component JavaDoc getListCellRendererComponent(
61                             JList JavaDoc list,
62                             Object JavaDoc value,
63                             int index,
64                             boolean isSelected,
65                             boolean cellHasFocus )
66         {
67                     
68                         if (value != null && value instanceof InputControlQueryDataRow)
69                         {
70                             InputControlQueryDataRow icqdr = (InputControlQueryDataRow)value;
71                             if (value != null)
72                             {
73                                 for (int i=0; i<this.columns; ++i)
74                                 {
75                                     String JavaDoc s = " ";
76                                     try {
77                                        if (icqdr.getColumnValues().get(i) != null)
78                                        {
79                                            s = ""+icqdr.getColumnValues().get(i);
80                                            
81                                        }
82                                     } catch (Exception JavaDoc ex) { }
83                                     
84                                     getLabels()[i].setText( s );
85                                 
86                                 }
87                                 this.updateUI();
88                             }
89                             
90                         }
91                         else
92                         {
93                             getLabels()[0].setText(value+"");
94                             
95                             for (int i=1; i<this.columns; ++i)
96                             {
97                                 getLabels()[i].setText(" ");
98                             }
99                         }
100                      
101             
102             if (isSelected)
103             {
104                 setBackground(Color.black);
105                                 for (int i=0; i<this.columns; ++i)
106                                 {
107                                     getLabels()[i].setForeground(Color.white);
108                                 }
109             }
110  
111             else
112             {
113                 setBackground(Color.white);
114                                 for (int i=0; i<this.columns; ++i)
115                                 {
116                                     getLabels()[i].setForeground(Color.black);
117                                 }
118             }
119             
120             return this;
121         }
122
123     public JLabel JavaDoc[] getLabels() {
124         return labels;
125     }
126
127     public void setLabels(JLabel JavaDoc[] labels) {
128         this.labels = labels;
129     }
130     }
131
Popular Tags