KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > grapheditor > border > GradientFillBorder


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.border;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.GradientPaint JavaDoc;
24 import java.awt.Graphics2D JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import java.awt.Paint JavaDoc;
27 import java.awt.Rectangle JavaDoc;
28 import org.netbeans.api.visual.border.Border;
29
30 /**
31  *
32  * @author anjeleevich
33  */

34 public class GradientFillBorder implements Border {
35
36     private Insets JavaDoc borderWidth;
37     private Insets JavaDoc padding;
38     
39     private Color JavaDoc borderColor;
40     private Color JavaDoc gradientTopColor;
41     private Color JavaDoc gradientBottomColor;
42     
43     
44     public GradientFillBorder(int vBorderWidth, int hBorderWidth,
45             int vPadding, int hPadding, Color JavaDoc borderColor,
46             Color JavaDoc gradientTopColor, Color JavaDoc gradientBottomColor)
47     {
48         this.borderWidth = new Insets JavaDoc(vBorderWidth, hBorderWidth,
49                 vBorderWidth, hBorderWidth);
50         this.padding = new Insets JavaDoc(vPadding, hPadding, vPadding, hPadding);
51         
52         this.borderColor = borderColor;
53         this.gradientTopColor = gradientTopColor;
54         this.gradientBottomColor = gradientBottomColor;
55     }
56     
57     
58     public GradientFillBorder(Insets JavaDoc borderWidth, Insets JavaDoc padding,
59             Color JavaDoc borderColor, Color JavaDoc gradientTopColor,
60             Color JavaDoc gradientBottomColor)
61     {
62         this.borderWidth = (Insets JavaDoc) borderWidth.clone();
63         this.padding = (Insets JavaDoc) padding.clone();
64         
65         this.borderColor = borderColor;
66         this.gradientTopColor = gradientTopColor;
67         this.gradientBottomColor = gradientBottomColor;
68     }
69
70     
71     public Insets JavaDoc getInsets() {
72         return new Insets JavaDoc(
73                 borderWidth.top + padding.top,
74                 borderWidth.left + padding.left,
75                 borderWidth.bottom + padding.bottom,
76                 borderWidth.right + padding.right);
77     }
78
79     
80     public void paint(Graphics2D JavaDoc g2, Rectangle JavaDoc rect) {
81         Paint JavaDoc oldPaint = g2.getPaint();
82         
83         if (borderColor != null) {
84             g2.setPaint(borderColor);
85             g2.fill(rect);
86         }
87         
88         if (gradientTopColor != null && gradientBottomColor != null) {
89             int y1 = rect.y + borderWidth.top;
90             int y2 = rect.y + rect.height - borderWidth.bottom;
91                     
92             
93             g2.setPaint(new GradientPaint JavaDoc(0, y1, gradientTopColor,
94                     0, y2, gradientBottomColor, false));
95             g2.fillRect(rect.x + borderWidth.left, y1,
96                     rect.width - borderWidth.left - borderWidth.right,
97                     y2 - y1);
98         }
99         
100         g2.setPaint(oldPaint);
101     }
102
103     
104     public boolean isOpaque() {
105         return true;
106     }
107 }
108
Popular Tags