KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > HeaderTableRenderer


1 package com.calipso.reportgenerator.userinterface;
2 import javax.swing.table.TableCellRenderer JavaDoc;
3 import javax.swing.*;
4 import javax.swing.border.LineBorder JavaDoc;
5 import java.awt.*;
6 import java.net.URL JavaDoc;
7
8 /**
9  * HeaderTableRenderer define las propiedades de los componentes que van a ser ubicados en las tablas
10  */

11 public class HeaderTableRenderer extends JPanel implements TableCellRenderer JavaDoc {
12   private JLabel cellLabel;
13   private Icon collapsedIcon;
14   private Icon expandedIcon;
15 /**
16  * Crea un objeto HeaderTableRenderer
17  */

18   public HeaderTableRenderer() {
19     cellLabel = new JLabel();
20     setLayout(new BorderLayout());
21     add(cellLabel, BorderLayout.NORTH);
22     setBackground(new Color(204, 204, 204));
23     setBorder(new LineBorder JavaDoc(Color.GRAY, 1));
24   }
25
26   /**
27    * Setea el valor del JLable cellLabel
28    * @param value
29    */

30   protected void setValue(Object JavaDoc value) {
31     cellLabel.setText((value == null) ? "" : value.toString());
32   }
33   /**
34    * Retorna el componente a insertar el la tabla
35    * @param table
36    * @param value
37    * @param isCollapsable
38    * @param isCollapsed
39    * @return
40    */

41   public Component getCellComponent(JTable table, Object JavaDoc value, boolean isCollapsable, boolean isCollapsed){
42     cellLabel.setFont(table.getFont());
43     if (isCollapsable){
44       cellLabel.setIcon(getIcon(isCollapsed));
45     }
46     else {
47       cellLabel.setIcon(null);
48     }
49     setValue(value);
50     return this;
51   }
52
53   /**
54    * Retorna el ícono de la celda
55    * @param collapsed
56    * @return
57    */

58   private Icon getIcon(boolean collapsed) {
59     if (collapsed){
60       return getCollapsedIcon();
61     }
62     else {
63       return getExpandedIcon();
64     }
65   }
66
67   /**
68    * Retorna el ancho del ícono
69    * @return
70    */

71   public int getIconWidth(){
72     return getCollapsedIcon().getIconWidth();
73   }
74
75   /**
76    * Retorna el alto del ícono
77    * @return
78    */

79   public int getIconHeight(){
80     return getCollapsedIcon().getIconHeight();
81   }
82
83
84   /**
85    * Retorna el ícono expandedIcon
86     * @return
87    */

88   private Icon getExpandedIcon() {
89     if (expandedIcon == null){
90       ClassLoader JavaDoc loader = this.getClass().getClassLoader();
91       URL JavaDoc url = loader.getResource("com/calipso/reportgenerator/userinterface/images/collapse.gif");
92       expandedIcon = new ImageIcon(url);
93     }
94     return expandedIcon;
95   }
96
97   /**
98    * Retorna el ícono collapsedIcon
99    * @return
100    */

101   private Icon getCollapsedIcon() {
102     if (collapsedIcon == null){
103       ClassLoader JavaDoc loader = this.getClass().getClassLoader();
104       URL JavaDoc url = loader.getResource("com/calipso/reportgenerator/userinterface/images/expand.gif");
105       collapsedIcon = new ImageIcon(url);
106     }
107     return collapsedIcon;
108   }
109
110   /**
111    * Implementación de la interface TableCellRenderer
112    * @param table
113    * @param value
114    * @param isSelected
115    * @param hasFocus
116    * @param row
117    * @param column
118    * @return
119    */

120   public Component getTableCellRendererComponent(JTable table, Object JavaDoc value,
121                                                  boolean isSelected, boolean hasFocus,
122                                                  int row, int column) {
123     return null;
124   }
125
126
127 }
Popular Tags