KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xam > ui > column > ArrowBorder


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.xam.ui.column;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Graphics JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import javax.swing.border.Border JavaDoc;
27
28 /**
29  * Border that draws an arrow on the right side, pointing to the right.
30  *
31  * @author Nathan Fiedler
32  */

33 public class ArrowBorder implements Border JavaDoc {
34
35     /**
36      * Creates a new instance of ArrowBorder.
37      */

38     /**
39      * If true arrow will be black, grey otherwise
40      */

41     private boolean enabled;
42     public ArrowBorder(boolean enabled) {
43         this.enabled=enabled;
44     }
45
46     public boolean isBorderOpaque() {
47         return true;
48     }
49
50     public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
51         // 4 for arrow, plus 8 for padding on either side
52
return new Insets JavaDoc(0, 0, 0, 12);
53     }
54
55     public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y,
56             int width, int height) {
57         // 4 for arrow, plus 4 for padding on right
58
int tx = width - 8;
59         int ty = (height - 8) / 2;
60         g.translate(tx, ty);
61         g.setColor(enabled?Color.BLACK:Color.LIGHT_GRAY);
62         g.drawLine(0, 0, 0, 7);
63         g.drawLine(1, 1, 1, 6);
64         g.drawLine(2, 2, 2, 5);
65         g.drawLine(3, 3, 3, 4);
66         g.translate(-tx, -ty);
67     }
68 }
69
Popular Tags