1 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 ; 14 import java.awt.Component ; 15 import java.awt.GridBagLayout ; 16 import java.awt.GridLayout ; 17 import javax.swing.JLabel ; 18 import javax.swing.JList ; 19 import javax.swing.JPanel ; 20 import javax.swing.ListCellRenderer ; 21 import javax.swing.SwingConstants ; 22 23 27 public class ItemRenderer extends JPanel implements ListCellRenderer 29 { 30 private JLabel [] labels = null; 31 int columns = 0; 34 35 public ItemRenderer(int columns) 36 { 37 setOpaque(true); 38 GridLayout g = new GridLayout (1,columns); 40 setLayout(g); 41 42 this.columns = columns; 43 labels = new JLabel [columns]; 44 45 47 for (int i=0; i<columns; ++i) 48 { 49 labels[i] = new JLabel (" "); 50 55 add(labels[i]); } 57 } 58 59 60 public Component getListCellRendererComponent( 61 JList list, 62 Object 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 s = " "; 76 try { 77 if (icqdr.getColumnValues().get(i) != null) 78 { 79 s = ""+icqdr.getColumnValues().get(i); 80 81 } 82 } catch (Exception 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 [] getLabels() { 124 return labels; 125 } 126 127 public void setLabels(JLabel [] labels) { 128 this.labels = labels; 129 } 130 } 131 | Popular Tags |