001 /* 002 * Copyright 2002-2004 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.richclient.table.renderer; 017 018 import java.awt.Color; 019 import java.awt.Component; 020 import java.awt.Graphics; 021 022 import javax.swing.JTable; 023 import javax.swing.UIManager; 024 import javax.swing.border.Border; 025 import javax.swing.table.DefaultTableCellRenderer; 026 027 /** 028 * A table cell renderer that has been optimized for performance 029 * 030 * @author Keith Donald 031 * <p> 032 * XXX: please describe what is being optimized here and how it should be used. 033 * 034 * @deprecated OptimizedTableCellRenderer messes up cell rendering see 035 * {@linkplain http://opensource.atlassian.com/projects/spring/browse/RCP-354} 036 * 037 */ 038 public class OptimizedTableCellRenderer extends DefaultTableCellRenderer { 039 protected Border focusBorder = UIManager.getBorder("Table.focusCellHighlightBorder"); 040 041 protected Color background = UIManager.getColor("Table.focusCellBackground"); 042 043 protected Color foreground = UIManager.getColor("Table.focusCellForeground"); 044 045 protected Color editableForeground; 046 047 protected Color editableBackground; 048 049 protected void doPrepareRenderer(JTable table, boolean isSelected, boolean hasFocus, int row, int column) { 050 if (isSelected) { 051 setForeground(table.getSelectionForeground()); 052 setBackground(table.getSelectionBackground()); 053 } 054 else { 055 setForeground(table.getForeground()); 056 setBackground(table.getBackground()); 057 } 058 setFont(table.getFont()); 059 if (hasFocus) { 060 setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") ); 061 if (table.isCellEditable(row, column)) { 062 super.setForeground( UIManager.getColor("Table.focusCellForeground") ); 063 super.setBackground( UIManager.getColor("Table.focusCellBackground") ); 064 } 065 } else { 066 setBorder(noFocusBorder); 067 } 068 } 069 070 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, 071 int row, int column) { 072 super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 073 // doPrepareRenderer(table, isSelected, hasFocus, row, column); 074 setValue(value); 075 return this; 076 } 077 078 protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { 079 // As long as you don't have any HTML text, this override is ok. 080 } 081 082 // This override is only appropriate if this will never contain any 083 // children AND the Graphics is not clobbered during painting. 084 public void paint(Graphics g) { 085 ui.update(g, this); 086 } 087 088 public void setBackground(Color c) { 089 this.background = c; 090 } 091 092 public Color getBackground() { 093 return background; 094 } 095 096 public void setForeground(Color c) { 097 this.foreground = c; 098 } 099 100 public Color getForeground() { 101 return foreground; 102 } 103 104 public boolean isOpaque() { 105 return (background != null); 106 } 107 108 // This is generally ok for non-Composite components (like Labels) 109 public void invalidate() { 110 111 } 112 113 // Can be ignored, we don't exist in the containment hierarchy. 114 public void repaint() { 115 116 } 117 }