001 /*
002 * $Id: GlossyTaskPaneUI.java,v 1.4 2005/10/10 18:03:15 rbair Exp $
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.Rectangle;
028 import java.awt.RenderingHints;
029
030 import javax.swing.JComponent;
031 import javax.swing.border.Border;
032 import javax.swing.plaf.ComponentUI;
033
034 import org.jdesktop.swingx.JXTaskPane;
035 import org.jdesktop.swingx.plaf.basic.BasicTaskPaneUI;
036
037 /**
038 * Paints the JXTaskPane with a gradient in the title bar.
039 *
040 * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
041 */
042 public class GlossyTaskPaneUI extends BasicTaskPaneUI {
043
044 public static ComponentUI createUI(JComponent c) {
045 return new GlossyTaskPaneUI();
046 }
047
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 public void update(Graphics g, JComponent c) {
057 if (c.isOpaque()) {
058 g.setColor(c.getParent().getBackground());
059 g.fillRect(0, 0, c.getWidth(), c.getHeight());
060 g.setColor(c.getBackground());
061 g.fillRect(0, ROUND_HEIGHT, c.getWidth(), c.getHeight() - ROUND_HEIGHT);
062 }
063 paint(g, c);
064 }
065
066 /**
067 * The border of the taskpane group paints the "text", the "icon", the
068 * "expanded" status and the "special" type.
069 *
070 */
071 class GlossyPaneBorder extends PaneBorder {
072
073 protected void paintTitleBackground(JXTaskPane group, Graphics g) {
074 if (group.isSpecial()) {
075 g.setColor(specialTitleBackground);
076 g.fillRoundRect(
077 0,
078 0,
079 group.getWidth(),
080 ROUND_HEIGHT * 2,
081 ROUND_HEIGHT,
082 ROUND_HEIGHT);
083 g.fillRect(
084 0,
085 ROUND_HEIGHT,
086 group.getWidth(),
087 TITLE_HEIGHT - ROUND_HEIGHT);
088 } else {
089 Paint oldPaint = ((Graphics2D)g).getPaint();
090 GradientPaint gradient =
091 new GradientPaint(
092 0f,
093 0f, //group.getWidth() / 2,
094 titleBackgroundGradientStart,
095 0f, //group.getWidth(),
096 TITLE_HEIGHT,
097 titleBackgroundGradientEnd);
098
099 ((Graphics2D)g).setRenderingHint(
100 RenderingHints.KEY_COLOR_RENDERING,
101 RenderingHints.VALUE_COLOR_RENDER_QUALITY);
102 ((Graphics2D)g).setRenderingHint(
103 RenderingHints.KEY_INTERPOLATION,
104 RenderingHints.VALUE_INTERPOLATION_BILINEAR);
105 ((Graphics2D)g).setRenderingHint(
106 RenderingHints.KEY_RENDERING,
107 RenderingHints.VALUE_RENDER_QUALITY);
108 ((Graphics2D)g).setPaint(gradient);
109
110 g.fillRoundRect(
111 0,
112 0,
113 group.getWidth(),
114 ROUND_HEIGHT * 2,
115 ROUND_HEIGHT,
116 ROUND_HEIGHT);
117 g.fillRect(
118 0,
119 ROUND_HEIGHT,
120 group.getWidth(),
121 TITLE_HEIGHT - ROUND_HEIGHT);
122 ((Graphics2D)g).setPaint(oldPaint);
123 }
124
125 Rectangle oldRect = g.getClipBounds();
126 g.setClip(0, 0, group.getWidth(), TITLE_HEIGHT);
127 g.setColor(borderColor);
128 g.drawRoundRect(
129 0,
130 0,
131 group.getWidth() - 1,
132 TITLE_HEIGHT + ROUND_HEIGHT,
133 ROUND_HEIGHT,
134 ROUND_HEIGHT);
135 g.drawLine(0, TITLE_HEIGHT - 1, group.getWidth(), TITLE_HEIGHT - 1);
136 g.setClip(oldRect);
137 }
138
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 }