001 /* 002 * $Id: GlossyTaskPaneUI.java 2488 2007-12-05 07:36:31Z rah003 $ 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 */ 021 package org.jdesktop.swingx.plaf.misc; 022 023 import java.awt.GradientPaint; 024 import java.awt.Graphics; 025 import java.awt.Graphics2D; 026 import java.awt.Paint; 027 import java.awt.RenderingHints; 028 029 import javax.swing.JComponent; 030 import javax.swing.border.Border; 031 import javax.swing.plaf.ComponentUI; 032 033 import org.jdesktop.swingx.JXTaskPane; 034 import 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 */ 041 public class GlossyTaskPaneUI extends BasicTaskPaneUI { 042 043 public static ComponentUI createUI(JComponent c) { 044 return new GlossyTaskPaneUI(); 045 } 046 047 protected Border createPaneBorder() { 048 return new GlossyPaneBorder(); 049 } 050 051 /** 052 * Overriden to paint the background of the component but keeping the rounded 053 * corners. 054 */ 055 public void update(Graphics g, JComponent c) { 056 if (c.isOpaque()) { 057 g.setColor(c.getParent().getBackground()); 058 g.fillRect(0, 0, c.getWidth(), c.getHeight()); 059 g.setColor(c.getBackground()); 060 g.fillRect(0, getRoundHeight(), c.getWidth(), c.getHeight() - getRoundHeight()); 061 } 062 paint(g, c); 063 } 064 065 /** 066 * The border of the taskpane group paints the "text", the "icon", the 067 * "expanded" status and the "special" type. 068 * 069 */ 070 class GlossyPaneBorder extends PaneBorder { 071 072 protected void paintTitleBackground(JXTaskPane group, Graphics g) { 073 if (group.isSpecial()) { 074 g.setColor(specialTitleBackground); 075 g.fillRoundRect( 076 0, 077 0, 078 group.getWidth(), 079 getRoundHeight() * 2, 080 getRoundHeight(), 081 getRoundHeight()); 082 g.fillRect( 083 0, 084 getRoundHeight(), 085 group.getWidth(), 086 getTitleHeight(group) - getRoundHeight()); 087 } else { 088 Paint oldPaint = ((Graphics2D)g).getPaint(); 089 GradientPaint gradient = 090 new GradientPaint( 091 0f, 092 0f, //group.getWidth() / 2, 093 titleBackgroundGradientStart, 094 0f, //group.getWidth(), 095 getTitleHeight(group), 096 titleBackgroundGradientEnd); 097 098 ((Graphics2D)g).setRenderingHint( 099 RenderingHints.KEY_COLOR_RENDERING, 100 RenderingHints.VALUE_COLOR_RENDER_QUALITY); 101 ((Graphics2D)g).setRenderingHint( 102 RenderingHints.KEY_INTERPOLATION, 103 RenderingHints.VALUE_INTERPOLATION_BILINEAR); 104 ((Graphics2D)g).setRenderingHint( 105 RenderingHints.KEY_RENDERING, 106 RenderingHints.VALUE_RENDER_QUALITY); 107 ((Graphics2D)g).setPaint(gradient); 108 109 g.fillRoundRect( 110 0, 111 0, 112 group.getWidth(), 113 getRoundHeight() * 2, 114 getRoundHeight(), 115 getRoundHeight()); 116 g.fillRect( 117 0, 118 getRoundHeight(), 119 group.getWidth(), 120 getTitleHeight(group) - getRoundHeight()); 121 ((Graphics2D)g).setPaint(oldPaint); 122 } 123 124 g.setColor(borderColor); 125 g.drawRoundRect( 126 0, 127 0, 128 group.getWidth() - 1, 129 getTitleHeight(group) + getRoundHeight(), 130 getRoundHeight(), 131 getRoundHeight()); 132 g.drawLine(0, getTitleHeight(group) - 1, group.getWidth(), getTitleHeight(group) - 1); 133 } 134 135 protected void paintExpandedControls(JXTaskPane group, Graphics g, int x, 136 int y, int width, int height) { 137 ((Graphics2D)g).setRenderingHint( 138 RenderingHints.KEY_ANTIALIASING, 139 RenderingHints.VALUE_ANTIALIAS_ON); 140 141 paintOvalAroundControls(group, g, x, y, width, height); 142 g.setColor(getPaintColor(group)); 143 paintChevronControls(group, g, x, y, width, height); 144 145 ((Graphics2D)g).setRenderingHint( 146 RenderingHints.KEY_ANTIALIASING, 147 RenderingHints.VALUE_ANTIALIAS_OFF); 148 } 149 150 @Override 151 protected boolean isMouseOverBorder() { 152 return true; 153 } 154 155 } 156 157 }