KickJava   Java API By Example, From Geeks To Geeks.

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


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-2006 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.Graphics2D JavaDoc;
24 import java.awt.Insets JavaDoc;
25 import java.awt.Paint JavaDoc;
26 import java.awt.Rectangle JavaDoc;
27 import org.netbeans.api.visual.border.Border;
28 import org.netbeans.api.visual.widget.Widget;
29
30 /**
31  *
32  * @author anjeleevich
33  */

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