001/* 002 * $Id: WindowsTaskPaneUI.java 3448 2009-08-19 08:12:23Z kleopatra $ 003 * 004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 020 */ 021package org.jdesktop.swingx.plaf.windows; 022 023import java.awt.GradientPaint; 024import java.awt.Graphics; 025import java.awt.Graphics2D; 026import java.awt.Paint; 027import java.awt.RenderingHints; 028 029import javax.swing.JComponent; 030import javax.swing.border.Border; 031import javax.swing.plaf.ComponentUI; 032 033import org.jdesktop.swingx.JXTaskPane; 034import org.jdesktop.swingx.plaf.basic.BasicTaskPaneUI; 035 036/** 037 * Windows implementation of the TaskPaneUI. 038 * 039 * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a> 040 */ 041public class WindowsTaskPaneUI extends BasicTaskPaneUI { 042 043 public static ComponentUI createUI(JComponent c) { 044 return new WindowsTaskPaneUI(); 045 } 046 047 @Override 048 protected Border createPaneBorder() { 049 return new XPPaneBorder(); 050 } 051 052 /** 053 * Overriden to paint the background of the component but keeping the rounded 054 * corners. 055 */ 056 @Override 057 public void update(Graphics g, JComponent c) { 058 if (c.isOpaque()) { 059 g.setColor(c.getParent().getBackground()); 060 g.fillRect(0, 0, c.getWidth(), c.getHeight()); 061 g.setColor(c.getBackground()); 062 g.fillRect(0, getRoundHeight(), c.getWidth(), c.getHeight() - getRoundHeight()); 063 } 064 paint(g, c); 065 } 066 067 /** 068 * The border of the taskpane group paints the "text", the "icon", the 069 * "expanded" status and the "special" type. 070 * 071 */ 072 class XPPaneBorder extends PaneBorder { 073 074 @Override 075 protected void paintTitleBackground(JXTaskPane group, Graphics g) { 076 if (group.isSpecial()) { 077 g.setColor(specialTitleBackground); 078 g.fillRoundRect( 079 0, 080 0, 081 group.getWidth(), 082 getRoundHeight() * 2, 083 getRoundHeight(), 084 getRoundHeight()); 085 g.fillRect( 086 0, 087 getRoundHeight(), 088 group.getWidth(), 089 getTitleHeight(group) - getRoundHeight()); 090 } else { 091 Paint oldPaint = ((Graphics2D)g).getPaint(); 092 GradientPaint gradient = new GradientPaint( 093 0f, 094 group.getWidth() / 2, 095 group.getComponentOrientation().isLeftToRight()? 096 titleBackgroundGradientStart 097 :titleBackgroundGradientEnd, 098 group.getWidth(), 099 getTitleHeight(group), 100 group.getComponentOrientation().isLeftToRight()? 101 titleBackgroundGradientEnd 102 :titleBackgroundGradientStart); 103 104 ((Graphics2D)g).setRenderingHint( 105 RenderingHints.KEY_COLOR_RENDERING, 106 RenderingHints.VALUE_COLOR_RENDER_QUALITY); 107 ((Graphics2D)g).setRenderingHint( 108 RenderingHints.KEY_INTERPOLATION, 109 RenderingHints.VALUE_INTERPOLATION_BILINEAR); 110 ((Graphics2D)g).setRenderingHint( 111 RenderingHints.KEY_RENDERING, 112 RenderingHints.VALUE_RENDER_QUALITY); 113 ((Graphics2D)g).setPaint(gradient); 114 g.fillRoundRect( 115 0, 116 0, 117 group.getWidth(), 118 getRoundHeight() * 2, 119 getRoundHeight(), 120 getRoundHeight()); 121 g.fillRect( 122 0, 123 getRoundHeight(), 124 group.getWidth(), 125 getTitleHeight(group) - getRoundHeight()); 126 ((Graphics2D)g).setPaint(oldPaint); 127 } 128 } 129 130 @Override 131 protected void paintExpandedControls(JXTaskPane group, Graphics g, int x, 132 int y, int width, int height) { 133 ((Graphics2D)g).setRenderingHint( 134 RenderingHints.KEY_ANTIALIASING, 135 RenderingHints.VALUE_ANTIALIAS_ON); 136 137 paintOvalAroundControls(group, g, x, y, width, height); 138 g.setColor(getPaintColor(group)); 139 paintChevronControls(group, g, x, y, width, height); 140 141 ((Graphics2D)g).setRenderingHint( 142 RenderingHints.KEY_ANTIALIASING, 143 RenderingHints.VALUE_ANTIALIAS_OFF); 144 } 145 146 @Override 147 protected boolean isMouseOverBorder() { 148 return true; 149 } 150 151 } 152 153}