001 /*
002 * $Id: WindowsTaskPaneUI.java 2973 2008-07-02 03:01:38Z kschaefe $
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.windows;
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 * Windows implementation of the TaskPaneUI.
038 *
039 * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
040 */
041 public class WindowsTaskPaneUI extends BasicTaskPaneUI {
042
043 public static ComponentUI createUI(JComponent c) {
044 return new WindowsTaskPaneUI();
045 }
046
047 protected Border createPaneBorder() {
048 return new XPPaneBorder();
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 XPPaneBorder 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 = new GradientPaint(
090 0f,
091 group.getWidth() / 2,
092 group.getComponentOrientation().isLeftToRight()?
093 titleBackgroundGradientStart
094 :titleBackgroundGradientEnd,
095 group.getWidth(),
096 getTitleHeight(group),
097 group.getComponentOrientation().isLeftToRight()?
098 titleBackgroundGradientEnd
099 :titleBackgroundGradientStart);
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 g.fillRoundRect(
112 0,
113 0,
114 group.getWidth(),
115 getRoundHeight() * 2,
116 getRoundHeight(),
117 getRoundHeight());
118 g.fillRect(
119 0,
120 getRoundHeight(),
121 group.getWidth(),
122 getTitleHeight(group) - getRoundHeight());
123 ((Graphics2D)g).setPaint(oldPaint);
124 }
125 }
126
127 protected void paintExpandedControls(JXTaskPane group, Graphics g, int x,
128 int y, int width, int height) {
129 ((Graphics2D)g).setRenderingHint(
130 RenderingHints.KEY_ANTIALIASING,
131 RenderingHints.VALUE_ANTIALIAS_ON);
132
133 paintOvalAroundControls(group, g, x, y, width, height);
134 g.setColor(getPaintColor(group));
135 paintChevronControls(group, g, x, y, width, height);
136
137 ((Graphics2D)g).setRenderingHint(
138 RenderingHints.KEY_ANTIALIASING,
139 RenderingHints.VALUE_ANTIALIAS_OFF);
140 }
141
142 @Override
143 protected boolean isMouseOverBorder() {
144 return true;
145 }
146
147 }
148
149 }