View Javadoc

1   /***
2    * 
3    */
4   package org.telscenter.pas.common.ui.border;
5   
6   import java.awt.Color;
7   import java.awt.Component;
8   import java.awt.Graphics;
9   import java.awt.Insets;
10  
11  import javax.swing.border.AbstractBorder;
12  
13  /***
14   * @author aperritano
15   *
16   */
17  public class CustomLineBorder extends AbstractBorder {
18  
19  	
20  	protected Color topColor;
21  	protected int topThickness;
22  	protected Color rightColor;
23  	protected int rightThickness;
24  	protected Color bottomColor;
25  	protected int bottomThickness;
26  	protected Color leftColor;
27  	protected int leftThickness;
28  	
29  	
30  
31  	/***
32  	 * @param color
33  	 */
34  	public CustomLineBorder(Color topColor,int topThickness,Color rightColor,int rightThickness,Color bottomColor,int bottomThickness,Color leftColor,int leftThickness) {
35  		
36  		this.topColor = topColor;
37  		this.topThickness = topThickness;
38  		
39  		this.rightColor = rightColor;
40  		this.rightThickness = rightThickness;
41  		
42  		this.bottomColor = bottomColor;
43  		this.bottomThickness = bottomThickness;
44  		
45  		this.leftColor = leftColor;
46  		this.leftThickness = leftThickness;
47  	}
48  	 /***
49       * Paints the border for the specified component with the 
50       * specified position and size.
51       * @param c the component for which this border is being painted
52       * @param g the paint graphics
53       * @param x the x position of the painted border
54       * @param y the y position of the painted border
55       * @param width the width of the painted border
56       * @param height the height of the painted border
57       */
58      public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
59         
60  
61        //  g.translate(x, y);
62  
63  //        System.out.println("Height: " + height + " width: " + width);
64  //        System.out.println("x: " + x + " y: " + y);
65          //out hightlight
66          
67          //top
68          for(int i = 0; i < topThickness; i++)  {
69          
70          	int newX = x+i;
71          	int newY = y+i; 
72          	int newWidth = width;
73          	int newHeight = height-i-i;
74          	/// System.out.println("NEW Height: " + newHeight + " width: " + newWidth);
75          	g.setColor(topColor);
76          	g.drawLine(0, newY, (newX + newWidth), newY);
77          	
78          }// for
79          //right
80          for(int k = 0; k < rightThickness; k++)  {
81          	int newX = x-k;
82          	//int newY = y+k; 
83          	int newWidth = width-1;
84          	int newHeight = height;
85          	//System.out.println("X: " + x + "y: " + y + "K: " + k + " RIGHT NEW Height: " + newHeight + " width: " + newWidth);
86          	g.setColor(rightColor);
87          	g.drawLine(newX+newWidth, 0, newX+newWidth, newHeight);
88          }// for
89          //left
90          for(int i = 0; i < leftThickness; i++)  {
91          	int newX = x+i;
92          	int newY = y; 
93          	int newWidth = width-i-i;
94          	
95          	int newHeight = height;
96          	
97          	//System.out.println("NEW Height: " + newHeight + " width: " + newWidth);
98          	g.setColor(leftColor);
99          	g.drawLine(newX,0, newX, newY+newHeight );
100         }// for
101         //bottom
102         for(int i = 0; i < bottomThickness; i++)  {
103         	int newX = x;
104         	int newY = y-i;
105         	int newWidth = width;
106         	int newHeight = height-1;
107         	//System.out.println("X: " + newX + "y: " + newY + "K: " + i + " RIGHT NEW Height: " + newHeight + " width: " + newWidth);
108         	//System.out.println("NEW Height: " + newHeight + " width: " + newWidth);
109         	g.setColor(bottomColor);
110         	g.drawLine(0, newY+newHeight, (newX + newWidth), newY+newHeight);
111         	//g.drawLine(0, newY + newHeight, newWidth, newY + newHeight);
112         }// for
113     }
114 
115     /***
116      * Returns the insets of the border.
117      * @param c the component for which this border insets value applies
118      */
119     public Insets getBorderInsets(Component c)       {
120         return new Insets(topThickness, leftThickness, bottomThickness, rightThickness);
121     }
122 
123     /*** 
124      * Reinitialize the insets parameter with this Border's current Insets. 
125      * @param c the component for which this border insets value applies
126      * @param insets the object to be reinitialized
127      */
128     public Insets getBorderInsets(Component c, Insets insets) {
129         insets.left = this.leftThickness;
130         insets.top = this.topThickness;
131         insets.right = this.rightThickness;
132         insets.bottom = this.bottomThickness;
133         return insets;
134     }
135 }