KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > subdataset > SortFieldCellRenderer


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  *
21  *
22  * SortFieldCellRenderer.java
23  *
24  * Created on November 13, 2006, 6:10 PM
25  *
26  * To change this template, choose Tools | Template Manager
27  * and open the template in the editor.
28  */

29
30 package it.businesslogic.ireport.gui.subdataset;
31
32 import it.businesslogic.ireport.SortField;
33 import javax.swing.DefaultListCellRenderer JavaDoc;
34 import javax.swing.ImageIcon JavaDoc;
35 import javax.swing.JLabel JavaDoc;
36
37 /**
38  *
39  * @author gtoffoli
40  */

41 public class SortFieldCellRenderer extends DefaultListCellRenderer JavaDoc {
42     
43     static ImageIcon JavaDoc ascIcon;
44     static ImageIcon JavaDoc descIcon;
45     
46     /** Creates a new instance of SortFieldCellRenderer */
47     public SortFieldCellRenderer() {
48         if (ascIcon == null) ascIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/datasource/arrow_down.png"));
49         if (descIcon == null) descIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/datasource/arrow_up.png"));
50     }
51
52     public java.awt.Component JavaDoc getListCellRendererComponent(javax.swing.JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
53
54         java.awt.Component JavaDoc retValue;
55         
56         retValue = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
57         
58         if (value instanceof SortField && retValue instanceof JLabel JavaDoc)
59         {
60             SortField sf = (SortField)value;
61             JLabel JavaDoc label = (JLabel JavaDoc)retValue;
62             label.setText( sf.getFieldName() );
63             
64             label.setIcon( sf.isDesc() ? descIcon : ascIcon );
65         }
66         
67         return retValue;
68     }
69     
70     
71     
72 }
73
Popular Tags