KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > plaf > metal > StatusLineBorder


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  * StatusLineBorder.java
20  *
21  * Created on March 14, 2004, 4:36 AM
22  */

23
24 package org.netbeans.swing.plaf.metal;
25
26 import javax.swing.*;
27 import javax.swing.border.AbstractBorder JavaDoc;
28 import java.awt.*;
29
30 /**
31  *
32  * @author Dafe Simonek
33  */

34 class StatusLineBorder extends AbstractBorder JavaDoc {
35
36     /** Constants for sides of status line border */
37     public static final int LEFT = 1;
38     public static final int TOP = 2;
39     public static final int RIGHT = 4;
40
41     private Insets insets;
42
43     private int type;
44
45     /** Constructs new status line border of specified type. Type is bit
46      * mask specifying which sides of border should be visible */

47     public StatusLineBorder (int type) {
48         this.type = type;
49     }
50
51     public void paintBorder(Component c, Graphics g, int x, int y,
52     int w, int h) {
53         g.translate(x, y);
54         Color shadowC = UIManager.getColor("controlShadow"); //NOI18N
55
Color highlightC = UIManager.getColor("controlHighlight"); //NOI18N
56
Color middleC = UIManager.getColor("control"); //NOI18N
57
// top
58
if ((type & TOP) != 0) {
59             g.setColor(shadowC);
60             g.drawLine(0, 0, w - 1, 0);
61             g.drawLine(0, 3, w - 1, 3);
62             g.setColor(highlightC);
63             g.drawLine(0, 1, w - 1, 1);
64             g.setColor(middleC);
65             g.drawLine(0, 2, w - 1, 2);
66         }
67         // left side
68
if ((type & LEFT) != 0) {
69             g.setColor(middleC);
70             g.drawLine(0, 2, 0, h - 1);
71             g.setColor(shadowC);
72             g.drawLine(1, 3, 1, h - 1);
73         }
74         // right side
75
if ((type & RIGHT) != 0) {
76             g.setColor(shadowC);
77             g.drawLine(w - 2, 3, w - 2, h - 1);
78             g.setColor(highlightC);
79             g.drawLine(w - 1, 4, w - 1, h - 1);
80             g.setColor(middleC);
81             g.drawLine(w - 1, 3, w - 1, 3);
82         }
83
84         g.translate(-x, -y);
85     }
86
87     public Insets getBorderInsets(Component c) {
88         if (insets == null) {
89             insets = getBorderInsets(c, new Insets(0, 0, 0, 0));
90         }
91         return insets;
92     }
93
94     public Insets getBorderInsets(Component c, Insets insets) {
95         insets.left = (type & LEFT) != 0 ? 2 : 0;
96         insets.top = (type & TOP) != 0 ? 4 : 0;
97         insets.right = (type & RIGHT) != 0 ? 2 : 0;
98         insets.bottom = 0;
99         return insets;
100     }
101
102 }
103
Popular Tags