KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > message > viewer > MessageBorder


1 package org.columba.mail.gui.message.viewer;
2
3 import java.awt.Color JavaDoc;
4 import java.awt.Component JavaDoc;
5 import java.awt.Graphics JavaDoc;
6 import java.awt.Insets JavaDoc;
7
8 import javax.swing.border.AbstractBorder JavaDoc;
9
10 public class MessageBorder extends AbstractBorder JavaDoc {
11
12     protected Color JavaDoc lineColor;
13
14     protected int thickness;
15
16     protected boolean roundedCorners;
17
18     protected int arc = 6;
19     
20     public MessageBorder(Color JavaDoc lineColor, int thickness, boolean roundedCorners) {
21         super();
22
23         this.lineColor = lineColor;
24         this.thickness = thickness;
25         this.roundedCorners = roundedCorners;
26
27     }
28
29     /**
30      * Paints the border for the specified component with the specified position
31      * and size.
32      *
33      * @param c
34      * the component for which this border is being painted
35      * @param g
36      * the paint graphics
37      * @param x
38      * the x position of the painted border
39      * @param y
40      * the y position of the painted border
41      * @param width
42      * the width of the painted border
43      * @param height
44      * the height of the painted border
45      */

46     public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int width,
47             int height) {
48         Color JavaDoc oldColor = g.getColor();
49         int i;
50
51         g.setColor(lineColor);
52         for (i = 0; i < thickness; i++) {
53             if (!roundedCorners)
54                 g.drawRect(x + i, y + i, width - i - i - 1, height - i - i - 1);
55             else
56                 g.drawRoundRect(x + i, y + i, width - i - i - 1, height - i - i
57                         - 1, arc, arc);
58         }
59         g.setColor(oldColor);
60     }
61
62     /**
63      * Returns the insets of the border.
64      *
65      * @param c
66      * the component for which this border insets value applies
67      */

68     public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
69         return new Insets JavaDoc(thickness, thickness, thickness, thickness);
70     }
71
72     /**
73      * Reinitialize the insets parameter with this Border's current Insets.
74      *
75      * @param c
76      * the component for which this border insets value applies
77      * @param insets
78      * the object to be reinitialized
79      */

80     public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc insets) {
81         insets.left = insets.top = insets.right = insets.bottom = thickness;
82         return insets;
83     }
84
85     /**
86      * Returns the color of the border.
87      */

88     public Color JavaDoc getLineColor() {
89         return lineColor;
90     }
91
92     /**
93      * Returns the thickness of the border.
94      */

95     public int getThickness() {
96         return thickness;
97     }
98
99 }
100
Popular Tags