01: /*
02: * The contents of this file are subject to the Mozilla Public License
03: * Version 1.1 (the "License"); you may not use this file except in
04: * compliance with the License. You may obtain a copy of the License at
05: * http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
09: * License for the specific language governing rights and limitations
10: * under the License.
11: *
12: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
13: *
14: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
15: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
16: *
17: * Contributor(s):
18: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
19: *
20: * If you didn't download this code from the following link, you should check
21: * if you aren't using an obsolete version: http://www.isqlviewer.com
22: */
23: package org.isqlviewer.ui.renderer;
24:
25: import java.awt.Color;
26: import java.awt.Component;
27:
28: import javax.swing.JTree;
29: import javax.swing.tree.DefaultTreeCellRenderer;
30:
31: import org.isqlviewer.swing.SwingUtilities;
32: import org.isqlviewer.swing.outline.JOutline;
33: import org.isqlviewer.ui.laf.EnhancedTableCellRenderer;
34:
35: /**
36: * Tree cell renderer for stack-traces history within the iSQL-Viewer program.
37: * <p>
38: *
39: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
40: * @version 1.0
41: */
42: public class ThrowableTreeCellRenderer extends DefaultTreeCellRenderer {
43:
44: private static final long serialVersionUID = 3928225003637084625L;
45: private JOutline outline = null;
46:
47: public ThrowableTreeCellRenderer(JOutline outline) {
48:
49: this .outline = outline;
50: setTextSelectionColor(Color.WHITE);
51: setBackgroundSelectionColor(EnhancedTableCellRenderer.selectedFocusedColor);
52: setBorderSelectionColor(EnhancedTableCellRenderer.selectedFocusedColor);
53: }
54:
55: @Override
56: public Component getTreeCellRendererComponent(JTree t, Object o,
57: boolean s, boolean x, boolean l, int r, boolean f) {
58:
59: boolean focusSelected = outline.getSelectedRow() == r;
60: super .getTreeCellRendererComponent(t, o, focusSelected, x, l,
61: r, focusSelected);
62:
63: if (focusSelected) {
64: if (outline.hasFocus()) {
65: setBackgroundSelectionColor(EnhancedTableCellRenderer.selectedFocusedColor);
66: setBorderSelectionColor(EnhancedTableCellRenderer.selectedFocusedColor);
67: setBackground(EnhancedTableCellRenderer.selectedFocusedColor);
68: setForeground(Color.WHITE);
69: } else {
70: setBorderSelectionColor(EnhancedTableCellRenderer.selectedNotFocusedColor);
71: setBackgroundSelectionColor(EnhancedTableCellRenderer.selectedNotFocusedColor);
72: setBackground(EnhancedTableCellRenderer.selectedNotFocusedColor);
73: setForeground(Color.BLACK);
74: }
75: } else {
76: Color color = r % 2 == 0 ? EnhancedTableCellRenderer.evenRowColor
77: : EnhancedTableCellRenderer.oddRowColor;
78: setBackground(color);
79: setBackgroundSelectionColor(color);
80: setBackgroundNonSelectionColor(color);
81: setForeground(Color.BLACK);
82: }
83:
84: if (o instanceof Throwable) {
85: Throwable error = (Throwable) o;
86: setIcon(SwingUtilities.loadIconResource("fatal_error", 16));
87: setText(error.toString());
88: } else {
89: setIcon(SwingUtilities.loadIconResource(
90: "stack_trace_element", 16));
91: }
92: return this;
93: }
94: }
|