PageRenderTime 36ms CodeModel.GetById 33ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/bsh/commands/thinBorder.bsh

#
Unknown | 80 lines | 67 code | 13 blank | 0 comment | 0 complexity | e5f8248b0f5ee283fd8081f3a560cfde 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		Color oldColor = g.getColor();
25		
26		//g.color=topLeft;
27		g.setColor(topLeft);
28		g.drawLine(x, y, x+width-1, y);
29		g.drawLine(x, y, x, y+height-1);
30		
31		//g.color=bottomRight;
32		g.setColor(bottomRight);
33		g.drawLine(x+width-1, y, x+width-1, y+height-1);
34		g.drawLine(x, y+height-1, x+width-1, y+height-1);		
35		
36		//g.color=oldColor;
37		g.setColor(oldColor);
38	}
39		
40	public void paintBorder(c, g, x, y, width, height) 
41	{	
42	// Access to the background color is protected on the Mac for
43	// some reason... workaround
44	try {
45		Color bgColor = c.background;	
46
47		Color dark = (darkColor==null) ? bgColor.darker().darker() :
48				darkColor;
49		Color light = (lightColor==null) ? bgColor.brighter() :
50				lightColor;			
51
52		if(c instanceof AbstractButton) {
53			if(c.rolloverEnabled && !c.model.rollover && c.opaque)	{
54				drawBorder(g, x, y, width, height, bgColor, bgColor);					
55			} else {
56				if(c.model.isPressed())
57					drawBorder(g, x, y, width, height, dark, light);
58				else
59					drawBorder(g, x, y, width, height, light, dark);
60			}
61		} else {
62			drawBorder(g, x, y, width, height, light, dark);		
63		}
64	} catch ( SecurityException e ) { }
65	}
66
67	/**
68	 * Returns the insets of the border.
69	 *
70	 * @param c the component for which this border insets value applies
71	 */
72	public Insets getBorderInsets(Component c) { return INSETS; } 
73	
74	/**
75	 * Always returns false
76	 */
77	public boolean isBorderOpaque() { return false; }
78	
79	return this;
80}