001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.vmd.screen;
043:
044: import java.awt.*;
045: import java.awt.geom.RoundRectangle2D;
046: import javax.swing.border.AbstractBorder;
047:
048: /**
049: * Painting algorithm copied from VMDNodeBorder
050: *
051: * @author Anton Chechel
052: * @version 1.0
053: */
054: public class GradientBorder extends AbstractBorder {
055:
056: static final Color COLOR_BORDER = new Color(0xBACDF0);
057: static final Color COLOR_SELECTION = Color.BLUE;
058:
059: private static final int INSET_SIZE = 2;
060: private static final Insets INSETS = new Insets(INSET_SIZE,
061: INSET_SIZE, INSET_SIZE, INSET_SIZE);
062: private static final Color COLOR1 = new Color(221, 235, 246, 64);
063: private static final Color COLOR2 = new Color(255, 255, 255, 64);
064: private static final Color COLOR3 = new Color(214, 235, 255, 64);
065: private static final Color COLOR4 = new Color(241, 249, 253, 64);
066: private static final Color COLOR5 = new Color(255, 255, 255, 64);
067:
068: private boolean isSelected;
069:
070: public GradientBorder(boolean isSelected) {
071: this .isSelected = isSelected;
072: }
073:
074: public void paintBorder(Component c, Graphics g, int x, int y,
075: int width, int height) {
076: Graphics2D gr = (Graphics2D) g;
077: Shape previousClip = gr.getClip();
078: gr.clip(new RoundRectangle2D.Float(x, y, width, height, 4, 4));
079:
080: Rectangle bounds = new Rectangle(x, y, width, height);
081: drawGradient(gr, bounds, COLOR1, COLOR2, 0f, 0.3f);
082: drawGradient(gr, bounds, COLOR2, COLOR3, 0.3f, 0.764f);
083: drawGradient(gr, bounds, COLOR3, COLOR4, 0.764f, 0.927f);
084: drawGradient(gr, bounds, COLOR4, COLOR5, 0.927f, 1f);
085:
086: gr.setColor(COLOR_BORDER);
087: gr.draw(new RoundRectangle2D.Float(x + 0.5f, y + 0.5f,
088: width - 1, height - 1, 4, 4));
089:
090: if (isSelected) {
091: gr.setColor(COLOR_SELECTION);
092: gr.drawRect(x + 3, y + 3, width - 7, height - 7);
093: }
094:
095: gr.setClip(previousClip);
096: }
097:
098: private void drawGradient(Graphics2D gr, Rectangle bounds,
099: Color color1, Color color2, float y1, float y2) {
100: y1 = bounds.y + y1 * bounds.height;
101: y2 = bounds.y + y2 * bounds.height;
102: gr.setPaint(new GradientPaint(bounds.x, y1, color1, bounds.x,
103: y2, color2));
104: gr.fill(new Rectangle.Float(bounds.x, y1, bounds.x
105: + bounds.width, y2));
106: }
107:
108: public Insets getBorderInsets(Component c) {
109: return INSETS;
110: }
111:
112: public Insets getBorderInsets(Component c, Insets insets) {
113: insets.left = insets.top = insets.right = insets.bottom = INSET_SIZE;
114: return insets;
115: }
116:
117: public boolean isBorderOpaque() {
118: return true;
119: }
120: }
|