KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > AnnotatedBorderPanel


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

28
29 package org.netbeans.modules.xml.schema.abe;
30
31 import java.awt.BasicStroke JavaDoc;
32 import java.awt.Color JavaDoc;
33 import java.awt.Font JavaDoc;
34 import java.awt.Graphics JavaDoc;
35 import java.awt.Graphics2D JavaDoc;
36 import java.awt.Point JavaDoc;
37 import java.awt.Rectangle JavaDoc;
38 import java.awt.Stroke JavaDoc;
39 import javax.swing.JLabel JavaDoc;
40 import javax.swing.SwingUtilities JavaDoc;
41
42 /**
43  *
44  * @author girix
45  */

46 public abstract class AnnotatedBorderPanel extends ABEBaseDropPanel{
47     
48     private static final long serialVersionUID = 7526472295622776147L;
49     private boolean drawAnnotation = true;
50     
51     /** Creates a new instance of AnnotatedBorderPanel */
52     public AnnotatedBorderPanel(InstanceUIContext context) {
53         super(context);
54     }
55     
56     public void setDrawAnnotation(boolean drawAnnotation){
57         this.drawAnnotation = drawAnnotation;
58     }
59     
60     Point JavaDoc startPoint = null;
61     void setStartDrawPoint(Point JavaDoc startPoint){
62         this.startPoint = startPoint;
63     }
64     
65     String JavaDoc annotationString;
66     void setAnnotationString(String JavaDoc annotationString){
67         this.annotationString = annotationString;
68     }
69     
70     public void paintComponent(Graphics JavaDoc g){
71         Graphics2D JavaDoc g2d = (Graphics2D JavaDoc) g;
72         super.paintComponent(g2d);
73         
74         //dont draw anthing if not required
75
if(!drawAnnotation){
76             return;
77         }
78         
79         Rectangle JavaDoc area = getBounds();
80         //int width = area.width - 10;
81
int height = area.height;
82         Stroke JavaDoc stroke = g2d.getStroke();
83         if(shouldDrawBorder()){
84             Color JavaDoc oldColor = g2d.getColor();
85             g2d.setColor(borderColor);
86             Stroke JavaDoc drawingStroke2 =
87                     new BasicStroke JavaDoc(
88                     2,
89                     BasicStroke.CAP_BUTT,
90                     BasicStroke.JOIN_MITER,
91                     10,
92                     new float[] {5},
93                     0
94                     );
95             
96             g2d.setStroke((drawingStroke2));
97             g2d.drawRoundRect(area.x, area.y+1, area.width , area.height -2 , 10, 10);
98             g2d.setColor(oldColor);
99         }
100         
101         
102         
103         g2d.setPaint(Color.lightGray);
104         float[] dashPattern = { 2, 2 };
105         g2d.setStroke(new BasicStroke JavaDoc(1, BasicStroke.CAP_BUTT,
106                 BasicStroke.JOIN_MITER, 10,
107                 dashPattern, 0));
108         //left
109
g2d.drawLine(startPoint.x, startPoint.y, startPoint.x, startPoint.y + height);
110         
111         int FONTSIZE = new JLabel JavaDoc().getFont().getSize();
112         
113         Font JavaDoc oldFont = g2d.getFont();
114         Color JavaDoc stringColor = Color.lightGray;
115         if(drawBoldString){
116             Font JavaDoc font = new Font JavaDoc(oldFont.getName(), Font.BOLD, oldFont.getSize());
117             g2d.setFont(font);
118             stringColor = Color.BLACK;
119         }
120         
121         int fWidth = SwingUtilities.computeStringWidth(g2d.getFontMetrics(), "s");
122         int strH = (FONTSIZE) * annotationString.length();
123         int segments = height / (strH);
124         boolean strSeg = false;
125         int currentY = startPoint.y;
126         int fixedX = startPoint.x - 2 - fWidth;
127         for(int i = 0; i<segments; i++){
128             if(strSeg){
129                 //g2d.setPaint(Color.WHITE);
130
//clear the area
131
//g2d.fillRect(fixedX, currentY, fWidth + 4, strH);
132
g2d.setPaint(stringColor);
133                 currentY += 8;
134                 //draw chars one below another
135
for(char c: annotationString.toCharArray()){
136                     g2d.drawString(""+c, fixedX, currentY);
137                     currentY += FONTSIZE;
138                 }
139                 currentY += FONTSIZE;
140                 strSeg = false;
141             }else{
142                 strSeg = true;
143                 currentY += strH;
144             }
145             
146         }
147         g2d.setStroke(stroke);
148         g2d.setFont(oldFont);
149     }
150     
151     public boolean shouldDrawBorder(){
152         return this.drawBorder;
153     }
154     
155     private boolean drawBorder = false;
156     
157     public void setDrawBorder(boolean drawBorder){
158         this.drawBorder = drawBorder;
159     }
160     
161     private Color JavaDoc borderColor = InstanceDesignConstants.XP_ORANGE;
162     public void setBorderColor(Color JavaDoc borderColor){
163         this.borderColor = borderColor;
164     }
165     
166     boolean drawBoldString = false;
167     public void drawBoldString(boolean drawBoldString){
168         this.drawBoldString = drawBoldString;
169     }
170     
171 }
172
Popular Tags