1 package org.joshy.html.forms; 2 3 import java.util.*; 4 import java.awt.Dimension ; 5 import java.awt.Point ; 6 import javax.swing.JComponent ; 7 import org.joshy.u; 8 import org.joshy.html.box.Box; 9 import org.joshy.html.box.*; 10 import org.joshy.html.*; 11 import org.w3c.dom.*; 12 13 public abstract class FormItemLayout extends CustomBlockLayout { 14 15 abstract public JComponent createComponent(Element elem); 16 17 private JComponent comp; 18 19 public Box createBox(Context c, Node node) { 20 Element elem = (Element)node; 21 comp = createComponent(elem); 22 c.canvas.add(comp); 23 comp.setLocation(100,100); 24 InputBox box = new InputBox(); 27 box.node = node; 28 box.component = comp; 29 return box; 30 } 31 32 public Dimension getIntrinsicDimensions(Context c, Element elem) { 33 Dimension dim = comp.getPreferredSize(); 35 return dim; 38 } 39 40 public void doInlinePaint(Context c, InlineBox block) { 41 44 Border border = getBorder(c,block); 46 Border padding = getPadding(c,block); 47 Border margin = getMargin(c, block); 48 49 int top_inset = margin.top + border.top + padding.top; 51 int left_inset = margin.left + border.left + padding.left; 52 53 c.getExtents().width = block.width; 55 56 paintBackground(c,block); 58 c.getGraphics().translate(left_inset,top_inset); 60 paintComponent(c,block.sub_block); 61 c.getGraphics().translate(-left_inset,-top_inset); 62 paintBorder(c,block); 63 64 c.getExtents().y = c.getExtents().y + block.height; 66 67 } 69 70 71 public void paint(Context c, Box box) { 72 if(box instanceof InlineBox) { 73 InlineBox block = (InlineBox)box; 74 doInlinePaint(c,block); 77 } else { 78 super.paint(c,box); 79 } 80 113 } 114 115 public void paintComponent(Context c, Box box) { 116 InputBox ib = (InputBox)box; 118 122 125 Point coords = absCoords(box); 127 128 133 coords.x += box.totalLeftPadding()+box.getParent().totalLeftPadding(); 134 coords.y += box.totalTopPadding()+box.getParent().totalTopPadding(); 135 138 Point loc = ib.component.getLocation(); 139 if(loc.y != coords.y || 140 loc.x != coords.x) { 141 loc.y = coords.y; 144 loc.x = coords.x; 145 ib.component.setLocation(coords); 146 ib.component.invalidate(); 147 } 149 150 157 158 } 159 160 public Point absCoords(Box box) { 161 Point pt = new Point (0,0); 165 pt.x += box.x; 166 pt.y += box.y; 167 168 if(box.getParent() != null) { 169 Point pt_parent = absCoords(box.getParent()); 170 pt.x += pt_parent.x; 171 pt.y += pt_parent.y; 172 } 174 return pt; 175 } 176 177 178 } 179 | Popular Tags |