001/* 002 * $Id: GlossyTaskPaneUI.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.misc; 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 * Paints the JXTaskPane with a gradient in the title bar. 038 * 039 * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a> 040 */ 041public class GlossyTaskPaneUI extends BasicTaskPaneUI { 042 043 public static ComponentUI createUI(JComponent c) { 044 return new GlossyTaskPaneUI(); 045 } 046 047 @Override 048 protected Border createPaneBorder() { 049 return new GlossyPaneBorder(); 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 GlossyPaneBorder 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 = 093 new GradientPaint( 094 0f, 095 0f, //group.getWidth() / 2, 096 titleBackgroundGradientStart, 097 0f, //group.getWidth(), 098 getTitleHeight(group), 099 titleBackgroundGradientEnd); 100 101 ((Graphics2D)g).setRenderingHint( 102 RenderingHints.KEY_COLOR_RENDERING, 103 RenderingHints.VALUE_COLOR_RENDER_QUALITY); 104 ((Graphics2D)g).setRenderingHint( 105 RenderingHints.KEY_INTERPOLATION, 106 RenderingHints.VALUE_INTERPOLATION_BILINEAR); 107 ((Graphics2D)g).setRenderingHint( 108 RenderingHints.KEY_RENDERING, 109 RenderingHints.VALUE_RENDER_QUALITY); 110 ((Graphics2D)g).setPaint(gradient); 111 112 g.fillRoundRect( 113 0, 114 0, 115 group.getWidth(), 116 getRoundHeight() * 2, 117 getRoundHeight(), 118 getRoundHeight()); 119 g.fillRect( 120 0, 121 getRoundHeight(), 122 group.getWidth(), 123 getTitleHeight(group) - getRoundHeight()); 124 ((Graphics2D)g).setPaint(oldPaint); 125 } 126 127 g.setColor(borderColor); 128 g.drawRoundRect( 129 0, 130 0, 131 group.getWidth() - 1, 132 getTitleHeight(group) + getRoundHeight(), 133 getRoundHeight(), 134 getRoundHeight()); 135 g.drawLine(0, getTitleHeight(group) - 1, group.getWidth(), getTitleHeight(group) - 1); 136 } 137 138 @Override 139 protected void paintExpandedControls(JXTaskPane group, Graphics g, int x, 140 int y, int width, int height) { 141 ((Graphics2D)g).setRenderingHint( 142 RenderingHints.KEY_ANTIALIASING, 143 RenderingHints.VALUE_ANTIALIAS_ON); 144 145 paintOvalAroundControls(group, g, x, y, width, height); 146 g.setColor(getPaintColor(group)); 147 paintChevronControls(group, g, x, y, width, height); 148 149 ((Graphics2D)g).setRenderingHint( 150 RenderingHints.KEY_ANTIALIASING, 151 RenderingHints.VALUE_ANTIALIAS_OFF); 152 } 153 154 @Override 155 protected boolean isMouseOverBorder() { 156 return true; 157 } 158 159 } 160 161}