001: /**
002: * L2FProd.com Common Components 7.3 License.
003: *
004: * Copyright 2005-2007 L2FProd.com
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package com.l2fprod.common.swing.plaf.windows;
018:
019: import com.l2fprod.common.swing.JTaskPaneGroup;
020: import com.l2fprod.common.swing.plaf.basic.BasicTaskPaneGroupUI;
021:
022: import java.awt.GradientPaint;
023: import java.awt.Graphics;
024: import java.awt.Graphics2D;
025: import java.awt.Paint;
026: import java.awt.RenderingHints;
027:
028: import javax.swing.JComponent;
029: import javax.swing.border.Border;
030: import javax.swing.plaf.ComponentUI;
031:
032: /**
033: * Windows implementation of the WindowsTaskPaneUI.
034: *
035: * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
036: */
037: public class WindowsTaskPaneGroupUI extends BasicTaskPaneGroupUI {
038:
039: public static ComponentUI createUI(JComponent c) {
040: return new WindowsTaskPaneGroupUI();
041: }
042:
043: protected Border createPaneBorder() {
044: return new XPPaneBorder();
045: }
046:
047: /**
048: * Overriden to paint the background of the component but keeping the rounded
049: * corners.
050: */
051: public void update(Graphics g, JComponent c) {
052: if (c.isOpaque()) {
053: g.setColor(c.getParent().getBackground());
054: g.fillRect(0, 0, c.getWidth(), c.getHeight());
055: g.setColor(c.getBackground());
056: g.fillRect(0, ROUND_HEIGHT, c.getWidth(), c.getHeight()
057: - ROUND_HEIGHT);
058: }
059: paint(g, c);
060: }
061:
062: /**
063: * The border of the taskpane group paints the "text", the "icon", the
064: * "expanded" status and the "special" type.
065: *
066: */
067: class XPPaneBorder extends PaneBorder {
068:
069: protected void paintTitleBackground(JTaskPaneGroup group,
070: Graphics g) {
071: if (group.isSpecial()) {
072: g.setColor(specialTitleBackground);
073: g.fillRoundRect(0, 0, group.getWidth(),
074: ROUND_HEIGHT * 2, ROUND_HEIGHT, ROUND_HEIGHT);
075: g.fillRect(0, ROUND_HEIGHT, group.getWidth(),
076: TITLE_HEIGHT - ROUND_HEIGHT);
077: } else {
078: Paint oldPaint = ((Graphics2D) g).getPaint();
079: GradientPaint gradient = new GradientPaint(
080: 0f,
081: group.getWidth() / 2,
082: group.getComponentOrientation().isLeftToRight() ? titleBackgroundGradientStart
083: : titleBackgroundGradientEnd,
084: group.getWidth(),
085: TITLE_HEIGHT,
086: group.getComponentOrientation().isLeftToRight() ? titleBackgroundGradientEnd
087: : titleBackgroundGradientStart);
088:
089: ((Graphics2D) g).setRenderingHint(
090: RenderingHints.KEY_COLOR_RENDERING,
091: RenderingHints.VALUE_COLOR_RENDER_QUALITY);
092: ((Graphics2D) g).setRenderingHint(
093: RenderingHints.KEY_INTERPOLATION,
094: RenderingHints.VALUE_INTERPOLATION_BILINEAR);
095: ((Graphics2D) g).setRenderingHint(
096: RenderingHints.KEY_RENDERING,
097: RenderingHints.VALUE_RENDER_QUALITY);
098: ((Graphics2D) g).setPaint(gradient);
099: g.fillRoundRect(0, 0, group.getWidth(),
100: ROUND_HEIGHT * 2, ROUND_HEIGHT, ROUND_HEIGHT);
101: g.fillRect(0, ROUND_HEIGHT, group.getWidth(),
102: TITLE_HEIGHT - ROUND_HEIGHT);
103: ((Graphics2D) g).setPaint(oldPaint);
104: }
105: }
106:
107: protected void paintExpandedControls(JTaskPaneGroup group,
108: Graphics g, int x, int y, int width, int height) {
109: ((Graphics2D) g).setRenderingHint(
110: RenderingHints.KEY_ANTIALIASING,
111: RenderingHints.VALUE_ANTIALIAS_ON);
112:
113: paintOvalAroundControls(group, g, x, y, width, height);
114: g.setColor(getPaintColor(group));
115: paintChevronControls(group, g, x, y, width, height);
116:
117: ((Graphics2D) g).setRenderingHint(
118: RenderingHints.KEY_ANTIALIASING,
119: RenderingHints.VALUE_ANTIALIAS_OFF);
120: }
121:
122: protected boolean isMouseOverBorder() {
123: return true;
124: }
125:
126: }
127:
128: }
|