KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joshy > html > painter > BorderPainter


1 package org.joshy.html.painter;
2
3 import java.awt.*;
4 import org.w3c.dom.*;
5 import org.joshy.*;
6 import org.joshy.html.*;
7 import org.joshy.html.box.Box;
8
9
10 public class BorderPainter {
11     public void paint(Context ctx, Box box) {
12         Graphics g = ctx.getGraphics();
13         
14         box.border_color = ctx.css.getBorderColor(box.getElement());
15         box.border_style = ctx.css.getStringProperty(box.getElement(), "border-style");
16         
17         Rectangle bounds = new Rectangle(box.x + box.margin.left,
18                                  box.y + box.margin.top,
19                                  box.width - box.margin.left - box.margin.right,
20                                  box.height - box.margin.top - box.margin.bottom
21                                  );
22
23         
24         //u.p("border style = " + border_style);
25
if(box.border_style == null) {
26             box.border_style = "none";
27         }
28         
29         // return if border = none
30
if(box.border_style.equals("none")) {
31             return;
32         }
33         
34         if(box.border_style.equals("ridge")) {
35             Border bd2 = new Border();
36             bd2.top = box.border.top/2;
37             bd2.bottom = box.border.bottom/2;
38             bd2.left = box.border.left/2;
39             bd2.right = box.border.right/2;
40             paintBevel(g,bounds,box.border,box.border_color.darker(),box.border_color.brighter());
41             paintBevel(g,bounds,bd2,box.border_color.brighter(),box.border_color.darker());
42         }
43         
44         if(box.border_style.equals("outset")) {
45             paintBevel(g,bounds,box.border,box.border_color.brighter(),box.border_color.darker());
46         }
47         if(box.border_style.equals("inset")) {
48             paintBevel(g,bounds,box.border,box.border_color.darker(),box.border_color.brighter());
49         }
50         if(box.border_style.equals("solid")) {
51             paintBevel(g,bounds,box.border,box.border_color,box.border_color);
52         }
53     }
54     
55     public void paintBevel(Graphics g, Rectangle bounds, Border border, Color high, Color low) {
56         g.setColor(high);
57         Polygon poly = new Polygon();
58         poly.addPoint(bounds.x,bounds.y);
59         poly.addPoint(bounds.x+bounds.width, bounds.y);
60         poly.addPoint(bounds.x+bounds.width-border.right, bounds.y+border.top);
61         poly.addPoint(bounds.x+border.left, bounds.y+border.top);
62         poly.addPoint(bounds.x+border.left, bounds.y+bounds.height-border.bottom);
63         poly.addPoint(bounds.x,bounds.y+bounds.height);
64         g.fillPolygon(poly);
65
66         g.setColor(low);
67         poly = new Polygon();
68         poly.addPoint(bounds.x+bounds.width, bounds.y);
69         poly.addPoint(bounds.x+bounds.width-border.right, bounds.y+border.top);
70         poly.addPoint(bounds.x+bounds.width-border.right, bounds.y+bounds.height-border.bottom);
71         poly.addPoint(bounds.x+border.left, bounds.y+bounds.height-border.bottom);
72         poly.addPoint(bounds.x,bounds.y+bounds.height);
73         poly.addPoint(bounds.x+bounds.width, bounds.y+bounds.height);
74         g.fillPolygon(poly);
75     }
76 }
77
78
Popular Tags