View Javadoc

1   package com.explosion.datastream.exql.gui.table.editandrender;
2   
3   /*
4    * =============================================================================
5    * 
6    * Copyright 2004 Stephen Cowx
7    * 
8    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
9    * use this file except in compliance with the License. You may obtain a copy of
10   * the License at
11   * 
12   * http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   * 
20   * =============================================================================
21   */
22  
23  import java.awt.Color;
24  import java.awt.Component;
25  
26  import javax.swing.JTable;
27  import javax.swing.table.DefaultTableCellRenderer;
28  import javax.swing.table.TableCellRenderer;
29  
30  import com.explosion.datastream.exql.EXQLConstants;
31  import com.explosion.datastream.exql.EXQLModuleManager;
32  import com.explosion.expfmodules.rdbmsconn.dbom.DBEntityColumn;
33  
34  
35  /***
36   * @author Steve.Cowx
37   * Used for rendering cells whose values have been updated
38   */
39  public class DisplayValueCellRenderer extends DefaultTableCellRenderer implements TableCellRenderer {
40  
41      private JTable table;
42      private DBEntityColumn dbColumn;
43      protected Color fore;
44      protected Color back;
45      
46  	public DisplayValueCellRenderer(DBEntityColumn dbColumn, JTable table) {
47  		super();
48  		this.setFont(table.getFont());
49  		this.table = table;
50  		this.dbColumn = dbColumn;
51  		fore = (Color) EXQLModuleManager.instance().getPreference(
52  				EXQLConstants.TABLE_COLORS_FOREGROUND).getValue();
53  		back = (Color) EXQLModuleManager.instance().getPreference(
54  				EXQLConstants.TABLE_COLORS_BACKGROUND).getValue();
55  
56  		this.setBackground(back);
57  		this.setForeground(fore);
58  	}
59  
60  	/***
61      *
62      * Returns the default table cell renderer.
63      *
64      * @param table  the <code>JTable</code>
65      * @param value  the value to assign to the cell at
66      *			<code>[row, column]</code>
67      * @param isSelected true if cell is selected
68      * @param hasFocus true if cell has focus
69      * @param row  the row of the cell to render
70      * @param column the column of the cell to render
71      * @return the default table cell renderer
72      */
73     public Component getTableCellRendererComponent(JTable table, Object value,
74                           boolean isSelected, boolean hasFocus, int row, int column) {
75      return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
76     }
77  	
78      
79      /***
80       * Sets the value for this component.  Actually, it interperets what is in the table into text
81       * @param data
82       * @return
83       */
84      public void setValue(Object data) {
85          String text = null;
86  	    if (data == null)
87          {
88  	        this.setBackground((Color) EXQLModuleManager.instance().getPreference(
89  					EXQLConstants.TABLE_NULL_INDICATOR_BACKGROUND).getValue());
90  	        text = "";
91          }
92          else
93          {
94              if (dbColumn != null)
95  		    {
96  		          text = EditorAndRenderFactory.renderValueForColumn(data, dbColumn);
97  		    }
98  		    else
99  		    {
100 		        text = data.toString();
101 		    }
102         }   
103 	    
104         this.setText(text);
105     }
106 	
107 	
108     
109 }