1 package org.joshy.html; 2 3 import org.joshy.html.css.FontResolver; 4 import org.joshy.html.css.FontResolverTest; 5 import java.util.Stack ; 6 import javax.swing.JComponent ; 7 import java.awt.Color ; 8 import java.awt.Graphics ; 9 import java.awt.Point ; 10 import java.awt.Rectangle ; 11 import org.joshy.html.box.*; 12 import java.net.URL ; 13 14 public class Context { 15 public Graphics graphics; 16 public Graphics getGraphics() { 17 return graphics; 18 } 19 20 private Rectangle extents; 21 public Rectangle getExtents() { 22 return this.extents; 23 } 24 public void setExtents(Rectangle rect) { 25 this.extents = rect; 26 } 27 28 39 40 public Point cursor; 41 public Point getCursor() { 42 return cursor; 43 } 44 45 public Color color; 46 public Color getColor() { 47 return color; 48 } 49 50 public Color background_color; 51 public Color getBackgroundColor() { 52 return background_color; 53 } 54 55 public CSSBank css; 56 57 public boolean debug_draw_boxes; 58 public boolean debugDrawBoxes() { 59 return debug_draw_boxes; 60 } 61 62 public boolean debug_draw_line_boxes; 63 public boolean debugDrawLineBoxes() { 64 return debug_draw_line_boxes; 65 } 66 67 public boolean debug_draw_inline_boxes; 68 public boolean debugDrawInlineBoxes() { 69 return debug_draw_inline_boxes; 70 } 71 72 public JComponent canvas; 73 public JComponent viewport; 75 public JComponent getViewport() { 76 return this.viewport; 77 } 78 79 80 private int xoff = 0; 81 private int yoff = 0; 82 public void translate(int x, int y) { 83 this.graphics.translate(x,y); 84 xoff+=x; 85 yoff+=y; 86 } 87 public int getXoff() { 88 return this.xoff; 89 } 90 public int getYoff() { 91 return this.yoff; 92 } 93 94 private Point left_tab = new Point (0,0); 95 private Point right_tab = new Point (0,0); 96 public void setLeftTab(Point pt) { 97 this.left_tab = pt; 98 } 99 public void setRightTab(Point pt) { 100 this.right_tab = pt; 101 } 102 public Point getLeftTab() { 103 return this.left_tab; 104 } 105 public Point getRightTab() { 106 return this.right_tab; 107 } 108 109 public Point placement_point; 110 public Box parent_box; 111 112 113 private URL base_url; 114 public void setBaseURL(URL base_url) { 115 this.base_url = base_url; 116 } 117 public URL getBaseURL() { 118 return this.base_url; 119 } 120 121 private int max_width; 122 public int getMaxWidth() { 123 return this.max_width; 124 } 125 public void setMaxWidth(int max_width) { 126 this.max_width = max_width; 127 } 128 public void addMaxWidth(int max_width) { 129 if(max_width > this.max_width) { 130 this.max_width = max_width; 131 } 132 } 133 134 Stack extents_stack = new Stack (); 135 public void shrinkExtents(BlockBox block) { 136 extents_stack.push(getExtents()); 137 Border border = block.border; 138 Border padding = block.padding; 139 Border margin = block.margin; 140 141 Rectangle rect = new Rectangle (0,0, 142 getExtents().width - (margin.left + border.left + padding.left) 143 - (margin.right + border.right + padding.right), 144 getExtents().height - (margin.top + border.top + padding.top) 145 - (margin.bottom + border.bottom + padding.bottom)); 146 setExtents(rect); 147 } 148 149 public void unshrinkExtents(BlockBox block) { 150 setExtents((Rectangle )extents_stack.pop()); 151 } 152 153 public void translateInsets(Box box) { 154 translate(box.margin.left + box.border.left + box.padding.left, 155 box.margin.top + box.border.top + box.padding.top); 156 } 157 public void untranslateInsets(Box box) { 158 translate(-(box.margin.left + box.border.left + box.padding.left), 159 -(box.margin.top + box.border.top + box.padding.top)); 160 } 161 162 FontResolver font_resolver; 163 164 public FontResolver getFontResolver() { 165 return font_resolver; 166 } 167 168 public Context() { 169 font_resolver = new FontResolverTest(); 170 } 171 172 public String toString() { 173 return "Context: extents = " + extents + " offset = " + xoff + "," + yoff 176 ; 177 } 178 179 180 } 181 | Popular Tags |