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.laf;
024:
025: import java.awt.Color;
026: import java.awt.Graphics;
027: import java.awt.Insets;
028: import java.awt.Rectangle;
029:
030: import javax.swing.UIManager;
031: import javax.swing.plaf.basic.BasicTreeUI;
032: import javax.swing.tree.TreePath;
033:
034: import org.isqlviewer.swing.outline.JOutline;
035:
036: /**
037: * This TreeUI does some nicer things when it comes to dealing with the JOutline (JTreeTable) making it appear as a
038: * single component.
039: * <p>
040: * This UI mainly addresses selection issues at this time where there is a distinct visual disconnect between the tree
041: * being rendered within the table and the table itself.
042: *
043: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
044: * @version 1.0
045: */
046: public class EnhancedTreeUI extends BasicTreeUI {
047:
048: private JOutline outline = null;
049:
050: public EnhancedTreeUI(JOutline outline) {
051:
052: this .outline = outline;
053: setExpandedIcon(UIManager.getIcon("Tree.expandedIcon"));
054: setCollapsedIcon(UIManager.getIcon("Tree.collapsedIcon"));
055: }
056:
057: /**
058: * Paints the renderer part of a row. The receiver should NOT modify <code>clipBounds</code>, or
059: * <code>insets</code>.
060: */
061: @Override
062: protected void paintRow(Graphics g, Rectangle clipBounds,
063: Insets insets, Rectangle bounds, TreePath path, int row,
064: boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) {
065:
066: boolean isSelected = false;
067: for (int selection : outline.getSelectedRows()) {
068: if (selection == row) {
069: isSelected = true;
070: break;
071: }
072: }
073:
074: if (isSelected) {
075: if (outline.hasFocus()) {
076: g
077: .setColor(EnhancedTableCellRenderer.selectedFocusedColor);
078: g.fillRect(clipBounds.x, clipBounds.y,
079: clipBounds.width, clipBounds.height);
080: } else {
081: g
082: .setColor(EnhancedTableCellRenderer.selectedNotFocusedColor);
083: g.fillRect(clipBounds.x, clipBounds.y,
084: clipBounds.width, clipBounds.height);
085: }
086: } else {
087: Color color = row % 2 == 0 ? EnhancedTableCellRenderer.evenRowColor
088: : EnhancedTableCellRenderer.oddRowColor;
089: g.setColor(color);
090: g.fillRect(clipBounds.x, clipBounds.y, clipBounds.width,
091: clipBounds.height);
092: }
093: if (shouldPaintExpandControl(path, row, isExpanded,
094: hasBeenExpanded, isLeaf)) {
095: paintExpandControl(g, clipBounds, insets, bounds, path,
096: row, isExpanded, hasBeenExpanded, isLeaf);
097: }
098: super.paintRow(g, clipBounds, insets, bounds, path, row,
099: isExpanded, hasBeenExpanded, isLeaf);
100: }
101: }
|