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: package org.isqlviewer.ui.renderer;
024:
025: import java.awt.Color;
026: import java.awt.Component;
027: import java.text.DateFormat;
028: import java.util.Date;
029:
030: import javax.swing.JTree;
031: import javax.swing.tree.DefaultTreeCellRenderer;
032:
033: import org.isqlviewer.history.CommandType;
034: import org.isqlviewer.history.HistoricalCommand;
035: import org.isqlviewer.swing.SwingUtilities;
036: import org.isqlviewer.swing.outline.JOutline;
037: import org.isqlviewer.ui.laf.EnhancedTableCellRenderer;
038:
039: /**
040: * Tree cell renderer for command history within the iSQL-Viewer program.
041: * <p>
042: *
043: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
044: * @version 1.0
045: */
046: public class HistoryTreeCellRenderer extends DefaultTreeCellRenderer {
047:
048: private static final long serialVersionUID = 3928225003637084625L;
049: private JOutline outline = null;
050:
051: public HistoryTreeCellRenderer(JOutline outline) {
052:
053: this .outline = outline;
054: setTextSelectionColor(Color.WHITE);
055: setClosedIcon(SwingUtilities.loadIconResource("day_of_month",
056: 16));
057: setBackgroundSelectionColor(EnhancedTableCellRenderer.selectedFocusedColor);
058: setBorderSelectionColor(EnhancedTableCellRenderer.selectedFocusedColor);
059: }
060:
061: @Override
062: public Component getTreeCellRendererComponent(JTree t, Object o,
063: boolean s, boolean x, boolean l, int r, boolean f) {
064:
065: boolean focusSelected = outline.getSelectedRow() == r;
066: super .getTreeCellRendererComponent(t, o, focusSelected, x, l,
067: r, focusSelected);
068:
069: if (focusSelected) {
070: if (outline.hasFocus()) {
071: setBackgroundSelectionColor(EnhancedTableCellRenderer.selectedFocusedColor);
072: setBorderSelectionColor(EnhancedTableCellRenderer.selectedFocusedColor);
073: setBackground(EnhancedTableCellRenderer.selectedFocusedColor);
074: setForeground(Color.WHITE);
075: } else {
076: setBorderSelectionColor(EnhancedTableCellRenderer.selectedNotFocusedColor);
077: setBackgroundSelectionColor(EnhancedTableCellRenderer.selectedNotFocusedColor);
078: setBackground(EnhancedTableCellRenderer.selectedNotFocusedColor);
079: setForeground(Color.BLACK);
080: }
081: } else {
082: Color color = r % 2 == 0 ? EnhancedTableCellRenderer.evenRowColor
083: : EnhancedTableCellRenderer.oddRowColor;
084: setBackground(color);
085: setBackgroundSelectionColor(color);
086: setBackgroundNonSelectionColor(color);
087: setForeground(Color.BLACK);
088: }
089:
090: if (o instanceof HistoricalCommand) {
091: HistoricalCommand historyNode = (HistoricalCommand) o;
092: CommandType nodeType = historyNode.getType();
093: String iconName = nodeType.getPreferredIcon();
094: if (iconName != null && iconName.length() > 0) {
095: setIcon(SwingUtilities.loadIconResource(iconName, 16));
096: } else {
097: setIcon(null);
098: }
099: setText(nodeType.name());
100: } else if (o instanceof Date) {
101: DateFormat format = DateFormat
102: .getDateInstance(DateFormat.MEDIUM);
103: setText(format.format((Date) o));
104: setIcon(getClosedIcon());
105: }
106: return this;
107: }
108: }
|