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.misc;
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.Rectangle;
027: import java.awt.RenderingHints;
028: import java.awt.Shape;
029:
030: import javax.swing.JComponent;
031: import javax.swing.border.Border;
032: import javax.swing.plaf.ComponentUI;
033:
034: /**
035: * Paints the JTaskPaneGroup with a gradient in the title bar.
036: */
037: public class GlossyTaskPaneGroupUI extends BasicTaskPaneGroupUI {
038:
039: public static ComponentUI createUI(JComponent c) {
040: return new GlossyTaskPaneGroupUI();
041: }
042:
043: protected Border createPaneBorder() {
044: return new GlossyPaneBorder();
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 GlossyPaneBorder 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(0f, 0f, //group.getWidth() / 2,
080: titleBackgroundGradientStart, 0f, //group.getWidth(),
081: TITLE_HEIGHT, titleBackgroundGradientEnd);
082:
083: ((Graphics2D) g).setRenderingHint(
084: RenderingHints.KEY_COLOR_RENDERING,
085: RenderingHints.VALUE_COLOR_RENDER_QUALITY);
086: ((Graphics2D) g).setRenderingHint(
087: RenderingHints.KEY_INTERPOLATION,
088: RenderingHints.VALUE_INTERPOLATION_BILINEAR);
089: ((Graphics2D) g).setRenderingHint(
090: RenderingHints.KEY_RENDERING,
091: RenderingHints.VALUE_RENDER_QUALITY);
092: ((Graphics2D) g).setPaint(gradient);
093:
094: g.fillRoundRect(0, 0, group.getWidth(),
095: ROUND_HEIGHT * 2, ROUND_HEIGHT, ROUND_HEIGHT);
096: g.fillRect(0, ROUND_HEIGHT, group.getWidth(),
097: TITLE_HEIGHT - ROUND_HEIGHT);
098: ((Graphics2D) g).setPaint(oldPaint);
099: }
100:
101: Shape oldClip = g.getClip();
102: Rectangle clip = new Rectangle(0, 0, group.getWidth(),
103: TITLE_HEIGHT);
104: g.setClip(clip.intersection(oldClip.getBounds()));
105: g.setColor(borderColor);
106: g.drawRoundRect(0, 0, group.getWidth() - 1, TITLE_HEIGHT
107: + ROUND_HEIGHT, ROUND_HEIGHT, ROUND_HEIGHT);
108: g.drawLine(0, TITLE_HEIGHT - 1, group.getWidth(),
109: TITLE_HEIGHT - 1);
110: g.setClip(oldClip);
111: }
112:
113: protected void paintExpandedControls(JTaskPaneGroup group,
114: Graphics g, int x, int y, int width, int height) {
115: ((Graphics2D) g).setRenderingHint(
116: RenderingHints.KEY_ANTIALIASING,
117: RenderingHints.VALUE_ANTIALIAS_ON);
118:
119: paintOvalAroundControls(group, g, x, y, width, height);
120: g.setColor(getPaintColor(group));
121: paintChevronControls(group, g, x, y, width, height);
122:
123: ((Graphics2D) g).setRenderingHint(
124: RenderingHints.KEY_ANTIALIASING,
125: RenderingHints.VALUE_ANTIALIAS_OFF);
126: }
127:
128: protected boolean isMouseOverBorder() {
129: return true;
130: }
131:
132: }
133:
134: }
|