PageRenderTime 58ms CodeModel.GetById 55ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/bsh/commands/thinBorder.bsh

#
Unknown | 70 lines | 57 code | 13 blank | 0 comment | 0 complexity | 7c3f8caf414c9ef4813b1661c8dc7920 MD5 | raw file
 1/** 
 2 * A one pixel wide bevel border.  This border works for buttons (with optional
 3 * rollover) and other components
 4 *
 5 * @author Daniel Leuck
 6 */
 7import javax.swing.border.*;
 8
 9Insets INSETS = new Insets(1,1,1,1);
10
11public thinBorder() { return thinBorder(null, null, false); }
12
13public thinBorder(Color lightColor, Color darkColor) {
14	return thinBorder(lightColor, darkColor, false);	
15}
16
17public thinBorder(Color lightColor, Color darkColor, boolean rollOver) {			
18			
19	/**
20	 * Draw a 1 pixel border given a color for topLeft and bottomRight.	
21	 */
22	drawBorder(g, x, y, width, height, topLeft, bottomRight) {
23		Color oldColor = g.color;
24		
25		g.color=topLeft;
26		g.drawLine(x, y, x+width-1, y);
27		g.drawLine(x, y, x, y+height-1);
28		
29		g.color=bottomRight;
30		g.drawLine(x+width-1, y, x+width-1, y+height-1);
31		g.drawLine(x, y+height-1, x+width-1, y+height-1);		
32		
33		g.color=oldColor;
34	}
35		
36	public void paintBorder(c, g, x, y, width, height) {	
37		Color bgColor = c.background;	
38		Color dark = (darkColor==null) ? bgColor.darker().darker() :
39				darkColor;
40		Color light = (lightColor==null) ? bgColor.brighter() :
41				lightColor;			
42		
43		if(c instanceof AbstractButton) {
44			if(c.rolloverEnabled && !c.model.rollover && c.opaque)	{
45				drawBorder(g, x, y, width, height, bgColor, bgColor);					
46			} else {
47				if(c.model.pressed)
48					drawBorder(g, x, y, width, height, dark, light);
49				else
50					drawBorder(g, x, y, width, height, light, dark);
51			}
52		} else {
53			drawBorder(g, x, y, width, height, light, dark);		
54		}
55	}
56
57	/**
58	 * Returns the insets of the border.
59	 *
60	 * @param c the component for which this border insets value applies
61	 */
62	public Insets getBorderInsets(Component c) { return INSETS; } 
63	
64	/**
65	 * Always returns false
66	 */
67	public boolean isBorderOpaque() { return false; }
68	
69	return this;
70}