KickJava   Java API By Example, From Geeks To Geeks.

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


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  * RoundDashedBorder.java
21  *
22  * Created on August 19, 2006, 4:46 PM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27
28 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.border;
29
30 import java.awt.BasicStroke JavaDoc;
31 import java.awt.Color JavaDoc;
32 import java.awt.Graphics2D JavaDoc;
33 import java.awt.Insets JavaDoc;
34 import java.awt.Rectangle JavaDoc;
35 import java.awt.Stroke JavaDoc;
36 import java.awt.geom.Rectangle2D JavaDoc;
37 import java.awt.geom.RoundRectangle2D JavaDoc;
38 import org.netbeans.api.visual.border.Border;
39
40 /**
41  *
42  * @author useradmin
43  */

44 public class RoundDashedBorder implements Border {
45     
46     private int mArcWidth;
47     private int mArcHeight;
48     float[] mDash;
49     int mThickness = 0;
50     Insets JavaDoc mInsets;
51     Color JavaDoc mFillColor;
52     Color JavaDoc mDrawColor;
53     Stroke JavaDoc mStroke;
54     
55     /** Creates a new instance of RoundDashedBorder */
56     public RoundDashedBorder (int arcWidth,
57                               int arcHeight,
58                               float[] dash,
59                               int thickness,
60                               Insets JavaDoc insets,
61                               Color JavaDoc fillColor,
62                               Color JavaDoc drawColor ) {
63         
64         this.mArcWidth = arcWidth;
65         this.mArcHeight = arcHeight;
66         this.mDash = dash;
67         this.mThickness = thickness;
68         this.mInsets = insets;
69         this.mFillColor = fillColor;
70         this.mDrawColor = drawColor;
71         
72         if (thickness < 1) {
73             throw new IllegalArgumentException JavaDoc("Invalid thickness: " + thickness);
74         }
75         
76         mStroke = new BasicStroke JavaDoc(mThickness,
77                                   BasicStroke.CAP_BUTT,
78                                   BasicStroke.JOIN_ROUND,
79                                   BasicStroke.JOIN_MITER,
80                                   mDash,
81                                   0);
82     
83     }
84
85     public Insets JavaDoc getInsets() {
86         if(this.mInsets == null) {
87             this.mInsets = new Insets JavaDoc(mThickness,mThickness,mThickness,mThickness);
88         }
89         return this.mInsets;
90     }
91
92     public void paint(Graphics2D JavaDoc gr, Rectangle JavaDoc bounds) {
93         Stroke JavaDoc oldStroke = gr.getStroke();
94         Color JavaDoc oldColor = gr.getColor();
95         gr.setStroke(mStroke);
96         
97         if (mFillColor != null) {
98             gr.setColor (mFillColor);
99             gr.fill (new RoundRectangle2D.Float JavaDoc (bounds.x, bounds.y, bounds.width, bounds.height, mArcWidth, mArcHeight));
100         }
101         if (mDrawColor != null) {
102             gr.setColor (mDrawColor);
103             gr.drawRect(bounds.x,bounds.y,bounds.width-mThickness,bounds.height-mThickness);
104         
105             //gr.draw (new RoundRectangle2D.Float (bounds.x + 0.5f, bounds.y + 0.5f, bounds.width - mThickness, bounds.height - mThickness, mArcWidth, mArcHeight));
106
//gr.drawRoundRect(bounds.x, bounds.y, bounds.width - mThickness, bounds.height -mThickness, mArcWidth, mArcHeight);
107
}
108         
109 // gr.setStroke(oldStroke);
110
// gr.setColor(oldColor);
111
}
112
113     public boolean isOpaque() {
114         return true;
115     }
116  
117
118 }
119
Popular Tags