KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joshy > html > CustomBlockLayout


1 package org.joshy.html;
2
3 import java.util.*;
4 import java.awt.Dimension JavaDoc;
5 import org.joshy.u;
6 import org.joshy.html.box.*;
7 import org.w3c.dom.*;
8
9 public class CustomBlockLayout extends BoxLayout {
10     public Box createBox(Context c, Node node) {
11         BlockBox box = new BlockBox();
12         box.node = node;
13         return box;
14     }
15
16     /** override this method to return the proper dimensions of your
17     custom page element.
18     */

19     public Dimension JavaDoc getIntrinsicDimensions(Context c, Element elem) {
20         return new Dimension JavaDoc(50,50);
21     }
22     
23     public Box layout(Context c, Element elem) {
24         BlockBox block = (BlockBox)createBox(c,elem);
25         // load the image
26

27         Border border = getBorder(c, block);
28         Border padding = getPadding(c, block);
29         Border margin = getMargin(c, block);
30
31         Dimension JavaDoc dim = this.getIntrinsicDimensions(c,elem);
32         
33         // calculate new contents
34
block.width = (int)dim.getWidth();
35         block.height = (int)dim.getHeight();
36         
37         // calculate the inner width
38
block.width = margin.left + border.left + padding.left + block.width +
39                 padding.right + border.right + margin.right;
40         block.height = margin.top + border.top + padding.top + block.height +
41                 padding.bottom + border.bottom + margin.bottom;
42         
43         block.x = c.getExtents().x;
44         block.y = c.getExtents().y;
45         return block;
46     }
47
48     /** override this to paint your component
49     */

50     public void paintComponent(Context c, Box box) {
51         u.p("Custom components must override paintComponent");
52     }
53
54 }
55
Popular Tags