001: /*
002: * The contents of this file are subject to the Mozilla Public License
003: * Version 1.1 (the "License"); you may not use this file except in
004: * compliance with the License. You may obtain a copy of the License at
005: * http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
009: * License for the specific language governing rights and limitations
010: * under the License.
011: *
012: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
013: *
014: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
015: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
016: *
017: * Contributor(s):
018: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
019: *
020: * If you didn't download this code from the following link, you should check
021: * if you aren't using an obsolete version: http://www.isqlviewer.com
022: */
023: /*
024: * A custom table cell renderer to simulate the look of cells in
025: * Apple's brushed metal applications.
026: * <p/>
027: * Copyright (C) 2005 by Jon Lipsky
028: * <p/>
029: * Licensed under the Apache License, Version 2.0 (the "License");
030: * you may not use this file except in compliance with the License. You may
031: * obtain a copy of the License at
032: * <p/>
033: * http://www.apache.org/licenses/LICENSE-2.0
034: * <p/>
035: * Unless required by applicable law or agreed to in writing, software d
036: * istributed under the License is distributed on an "AS IS" BASIS,
037: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
038: * See the License for the specific language governing permissions and
039: * limitations under the License.
040: */
041: package org.isqlviewer.ui.laf;
042:
043: import java.awt.Color;
044: import java.awt.Component;
045: import java.awt.Font;
046:
047: import javax.swing.Icon;
048: import javax.swing.JTable;
049: import javax.swing.table.DefaultTableCellRenderer;
050:
051: import org.isqlviewer.swing.SwingUtilities;
052: import org.isqlviewer.swing.table.EnhancedTableModel;
053:
054: /**
055: * Modified version of the Aqua&cop; metal look and feel.
056: * <p>
057: *
058: * @author Jon Lipsky, Mark Kobold
059: * @version 1.0
060: */
061: public class EnhancedTableCellRenderer extends DefaultTableCellRenderer {
062:
063: private static final long serialVersionUID = -6332850927184223196L;
064: public static final Color selectedFocusedColor = Color
065: .decode("#3D80DF");
066: public static final Color selectedNotFocusedColor = Color
067: .decode("#C0C0C0");
068: public static final Color evenRowColor = Color.decode("#EDF3FE");
069: public static final Color oddRowColor = Color.WHITE;
070: public static final Color gridColor = new Color(150, 150, 150);
071:
072: // ------------------------------------------------------------------------------------------------------------------
073: // Constructors and Getter/Setter methods
074: // ------------------------------------------------------------------------------------------------------------------
075: public EnhancedTableCellRenderer() {
076:
077: }
078:
079: public Icon getIcon(Object aObject) {
080:
081: if (aObject == null) {
082: setHorizontalAlignment(CENTER);
083: } else {
084: setHorizontalAlignment(LEFT);
085: }
086: return aObject == null ? SwingUtilities.loadIconResource(
087: "null_data", 16) : null;
088: }
089:
090: public String getText(Object aObject) {
091:
092: return aObject == null ? null : aObject.toString();
093: }
094:
095: // ------------------------------------------------------------------------------------------------------------------
096: // Overwridden methods from the superclass(es)
097: // ------------------------------------------------------------------------------------------------------------------
098: @Override
099: public Component getTableCellRendererComponent(final JTable table,
100: Object value, boolean isSelected, boolean hasFocus,
101: final int row, int column) {
102:
103: super .getTableCellRendererComponent(table, value, isSelected,
104: hasFocus, row, column);
105: if (isSelected) {
106: if (table.hasFocus()) {
107: setBackground(selectedFocusedColor);
108: setForeground(Color.WHITE);
109: } else {
110: setBackground(selectedNotFocusedColor);
111: setForeground(Color.BLACK);
112: }
113: } else {
114: Color color = row % 2 == 0 ? evenRowColor : oddRowColor;
115: setBackground(color);
116: setForeground(Color.BLACK);
117: }
118: setText(getText(value));
119: setIcon(getIcon(value));
120:
121: if (table.getModel() instanceof EnhancedTableModel) {
122: EnhancedTableModel model = (EnhancedTableModel) table
123: .getModel();
124: Font fnt = table.getFont();
125: if (model.matchesFilter(row, column)) {
126: // increase the font by one point so we have size and hue for highlighting searches//
127: setFont(fnt.deriveFont(Font.BOLD, fnt.getSize2D() + 1f));
128: } else {
129: setFont(fnt);
130: }
131: }
132: return this;
133: }
134: }
|