001/* 002 * $Id$ 003 * 004 * Copyright 2009 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 */ 022package org.jdesktop.swingx.plaf.nimbus; 023 024import java.awt.Color; 025import java.awt.Graphics; 026import java.awt.Graphics2D; 027import java.awt.LinearGradientPaint; 028import java.awt.Paint; 029import java.awt.RenderingHints; 030 031import javax.swing.JComponent; 032import javax.swing.border.Border; 033import javax.swing.plaf.ComponentUI; 034import javax.swing.plaf.FontUIResource; 035 036import org.jdesktop.swingx.JXTaskPane; 037import org.jdesktop.swingx.plaf.basic.BasicTaskPaneUI; 038 039/** 040 * Nimbus implementation of the <code>JXTaskPane</code> UI. <br> 041 * 042 * @author <a href="mailto:Radu.Dumitrescu@pss.ro">Radu Dumitrescu</a> 043 */ 044public class NimbusTaskPaneUI extends BasicTaskPaneUI { 045 046 public static ComponentUI createUI(JComponent c) { 047 return new NimbusTaskPaneUI(); 048 } 049 050 @Override 051protected Border createPaneBorder() { 052 return new NimbusPaneBorder(); 053 } 054 055 /** 056 * Overriden to paint the background of the component but keeping the rounded 057 * corners. 058 */ 059 @Override 060public void update(Graphics g, JComponent c) { 061 if (c.isOpaque()) { 062 g.setColor(c.getParent().getBackground()); 063 g.fillRect(0, 0, c.getWidth(), c.getHeight()); 064 g.setColor(c.getBackground()); 065 g.fillRect(0, getRoundHeight(), c.getWidth(), c.getHeight() - 066getRoundHeight()); 067 } 068 paint(g, c); 069 } 070 071 /** 072 * The border of the task pane group paints the "text", the "icon", the 073 * "expanded" status and the "special" type. 074 * 075 */ 076 class NimbusPaneBorder extends PaneBorder { 077 078 @Override 079 protected void paintTitleBackground(JXTaskPane group, Graphics g) { 080 081 Paint oldPaint = ((Graphics2D) g).getPaint(); 082 083 roundHeight = 7; 084 085 if (group.isSpecial()) { 086 g.setColor(specialTitleBackground); 087 088 g.fillRoundRect(0, 0, group.getWidth(), getRoundHeight() * 2, 089 getRoundHeight(), getRoundHeight()); 090 g.fillRect(0, getRoundHeight(), group.getWidth(), 091 getTitleHeight(group) - getRoundHeight()); 092 093 } else { 094 Color[] colors = { titleBackgroundGradientStart, 095 titleBackgroundGradientEnd }; 096 097 float[] fractions = { 0.0f, 1.0f }; 098 099 LinearGradientPaint gradient = new LinearGradientPaint(group 100 .getWidth() / 2, 0.0f, group.getWidth() / 2, 101 getTitleHeight(group), fractions, colors); 102 103 ((Graphics2D) g).setPaint(gradient); 104 105 ((Graphics2D) g).setRenderingHint( 106 RenderingHints.KEY_COLOR_RENDERING, 107 RenderingHints.VALUE_COLOR_RENDER_QUALITY); 108 ((Graphics2D) g).setRenderingHint( 109 RenderingHints.KEY_INTERPOLATION, 110 RenderingHints.VALUE_INTERPOLATION_BILINEAR); 111 ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_RENDERING, 112 RenderingHints.VALUE_RENDER_QUALITY); 113 ((Graphics2D) g).setRenderingHint( 114 RenderingHints.KEY_ANTIALIASING, 115 RenderingHints.VALUE_ANTIALIAS_ON); 116 117 g.fillRoundRect(0, 0, group.getWidth(), 118 getTitleHeight(group) / 2, getRoundHeight(), 119 getRoundHeight()); 120 121 g.fillRect(0, getRoundHeight(), group.getWidth(), 122 getTitleHeight(group) - getRoundHeight()); 123 124 } 125 126 // draw the border around the title area 127 g.setColor(borderColor); 128 129 g.drawRoundRect(0, 0, group.getWidth() - 1, getTitleHeight(group) 130 + getRoundHeight(), getRoundHeight(), getRoundHeight()); 131 g.drawLine(0, getTitleHeight(group) - 1, group.getWidth(), 132 getTitleHeight(group) - 1); 133 134 ((Graphics2D) g).setPaint(oldPaint); 135 } 136 137 @Override 138 protected void paintExpandedControls(JXTaskPane group, Graphics g, 139 int x, int y, int width, int height) { 140 ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, 141 RenderingHints.VALUE_ANTIALIAS_ON); 142 143 g.setColor(getPaintColor(group)); 144 paintChevronControls(group, g, x, y, width, height); 145 146 ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, 147 RenderingHints.VALUE_ANTIALIAS_OFF); 148 } 149 150 @Override 151 protected void paintTitle(JXTaskPane group, Graphics g, 152 Color textColor, int x, int y, int width, int height) { 153 configureLabel(group); 154 // Nimbus has some issues with ColorUIResource 155 label.setForeground(new Color(textColor.getRGB())); 156 if (group.getFont() != null 157 && !(group.getFont() instanceof FontUIResource)) { 158 label.setFont(group.getFont()); 159 } 160 g.translate(x, y); 161 label.setBounds(0, 0, width, height); 162 label.paint(g); 163 g.translate(-x, -y); 164 } 165 166 @Override 167 protected boolean isMouseOverBorder() { 168 return true; 169 } 170 } 171 172} 173