/** * MyColHeaderCellRenderer.java * * Copyright 2000 Eliad Technologies, Inc. All Rights Reserved. * * This software is the proprietary information of Eliad Technologies, Inc. */ package MultiDimTable; import java.awt.*; import javax.swing.*; import javax.swing.border.Border; import com.eliad.model.*; import com.eliad.model.defaults.*; public class MyColHeaderCellRenderer extends DefaultGridCellRenderer { private final static Font subTitleFont_ = new Font("Dialog", Font.PLAIN, 12); private final static Font titleFont_ = subTitleFont_.deriveFont(Font.BOLD); private final static Color bannerBkg_ = new Color(255, 255, 204); private final static Color titleBkg_ = new Color( 36, 38, 116); private final static Color subtitleBkg_ = new Color(156, 154, 252); public Component getComponent(Object value, boolean isSelected, boolean hasFocus, boolean isEditable, int row, int column, GridContext context) { final StyleContextModel base = context.getDefaultStyleContext(); final boolean condition = context.getColumnCount() == 1; final boolean isBanner = context.getRow() == 0; StyleContextModel styleContext = new StyleContextModel() { public Border getBorder() { return base.getBorder(); } public Font getFont() { if (condition) return subTitleFont_; return titleFont_; } public Color getForegroundColor() { if (isBanner) return Color.black; return Color.white; } public Color getBackgroundColor() { if (condition) return subtitleBkg_; if (isBanner) return bannerBkg_; else return titleBkg_; } public Color getFocusForegroundColor() { return getForegroundColor(); } public Color getFocusBackgroundColor() { return getBackgroundColor(); } public Border getFocusHighlightBorder() { return base.getFocusHighlightBorder(); } public Border getSelectionCellBorder() { return base.getSelectionCellBorder(); } public Color getSelectionForegroundColor() { return getForegroundColor(); } public Color getSelectionBackgroundColor() { return getBackgroundColor(); } }; if (isSelected) { super.setForeground( styleContext.getSelectionForegroundColor() ); super.setBackground( styleContext.getSelectionBackgroundColor() ); } else { super.setForeground( styleContext.getForegroundColor() ); super.setBackground( styleContext.getBackgroundColor() ); } setFont(styleContext.getFont()); if (hasFocus) { setBorder( styleContext.getFocusHighlightBorder() ); if (isEditable) { super.setForeground(styleContext.getFocusForegroundColor()); super.setBackground(styleContext.getFocusBackgroundColor()); } } else { if (isSelected) setBorder(styleContext.getSelectionCellBorder()); else setBorder(styleContext.getBorder()); } setValue(value); Color back = getBackground(); boolean colorMatch = back != null && back.equals(context.getComponent().getBackground()) && context.getComponent().isOpaque(); setOpaque(!colorMatch); return this; } }