001: /*
002: * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.java.swing.plaf.windows;
027:
028: import java.awt.*;
029: import javax.swing.*;
030: import javax.swing.border.*;
031: import javax.swing.plaf.*;
032: import javax.swing.plaf.basic.*;
033: import javax.swing.table.*;
034:
035: import static com.sun.java.swing.plaf.windows.TMSchema.*;
036: import static com.sun.java.swing.plaf.windows.XPStyle.*;
037: import sun.swing.table.*;
038:
039: public class WindowsTableHeaderUI extends BasicTableHeaderUI {
040: private TableCellRenderer originalHeaderRenderer;
041:
042: public static ComponentUI createUI(JComponent h) {
043: return new WindowsTableHeaderUI();
044: }
045:
046: public void installUI(JComponent c) {
047: super .installUI(c);
048:
049: if (XPStyle.getXP() != null) {
050: originalHeaderRenderer = header.getDefaultRenderer();
051: if (originalHeaderRenderer instanceof UIResource) {
052: header.setDefaultRenderer(new XPDefaultRenderer());
053: }
054: }
055: }
056:
057: public void uninstallUI(JComponent c) {
058: if (header.getDefaultRenderer() instanceof XPDefaultRenderer) {
059: header.setDefaultRenderer(originalHeaderRenderer);
060: }
061: super .uninstallUI(c);
062: }
063:
064: @Override
065: protected void rolloverColumnUpdated(int oldColumn, int newColumn) {
066: if (XPStyle.getXP() != null) {
067: header.repaint(header.getHeaderRect(oldColumn));
068: header.repaint(header.getHeaderRect(newColumn));
069: }
070: }
071:
072: private class XPDefaultRenderer extends
073: DefaultTableCellHeaderRenderer {
074: Skin skin;
075: boolean isSelected, hasFocus, hasRollover;
076: int column;
077:
078: XPDefaultRenderer() {
079: setHorizontalAlignment(LEADING);
080: }
081:
082: public Component getTableCellRendererComponent(JTable table,
083: Object value, boolean isSelected, boolean hasFocus,
084: int row, int column) {
085: super .getTableCellRendererComponent(table, value,
086: isSelected, hasFocus, row, column);
087: this .isSelected = isSelected;
088: this .hasFocus = hasFocus;
089: this .column = column;
090: this .hasRollover = (column == getRolloverColumn());
091: if (skin == null || skin.getContentMargin() == null) {
092: skin = XPStyle.getXP().getSkin(header,
093: Part.HP_HEADERITEM);
094: }
095: Insets margins = skin.getContentMargin();
096: if (margins == null) {
097: margins = new Insets(0, 0, 0, 0);
098: }
099: setBorder(new EmptyBorder(margins));
100: return this ;
101: }
102:
103: private int viewIndexForColumn(TableColumn aColumn) {
104: if (aColumn != null) {
105: return header.getTable().convertColumnIndexToView(
106: aColumn.getModelIndex());
107: }
108: return -1;
109: }
110:
111: public void paint(Graphics g) {
112: Dimension size = getSize();
113: State state = State.NORMAL;
114: if (column == viewIndexForColumn(header.getDraggedColumn())) {
115: state = State.PRESSED;
116: } else if (isSelected || hasFocus || hasRollover) {
117: state = State.HOT;
118: }
119: skin.paintSkin(g, 0, 0, size.width - 1, size.height - 1,
120: state);
121: super.paint(g);
122: }
123: }
124: }
|