KickJava   Java API By Example, From Geeks To Geeks.

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


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 JavaDoc;
6 import javax.swing.JComponent JavaDoc;
7 import java.awt.Color JavaDoc;
8 import java.awt.Graphics JavaDoc;
9 import java.awt.Point JavaDoc;
10 import java.awt.Rectangle JavaDoc;
11 import org.joshy.html.box.*;
12 import java.net.URL JavaDoc;
13
14 public class Context {
15     public Graphics JavaDoc graphics;
16     public Graphics JavaDoc getGraphics() {
17         return graphics;
18     }
19     
20     private Rectangle JavaDoc extents;
21     public Rectangle JavaDoc getExtents() {
22         return this.extents;
23     }
24     public void setExtents(Rectangle JavaDoc rect) {
25         this.extents = rect;
26     }
27     
28     /*
29     public Point origin;
30     public Point getOrigin() {
31         return origin;
32     }
33     
34     public Rectangle bounds;
35     public Rectangle getBounds() {
36         return bounds;
37     }
38     */

39     
40     public Point JavaDoc cursor;
41     public Point JavaDoc getCursor() {
42         return cursor;
43     }
44     
45     public Color JavaDoc color;
46     public Color JavaDoc getColor() {
47         return color;
48     }
49     
50     public Color JavaDoc background_color;
51     public Color JavaDoc 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 JavaDoc canvas;
73     //public Graphics canvas_graphics;
74
public JComponent JavaDoc viewport;
75     public JComponent JavaDoc 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 JavaDoc left_tab = new Point JavaDoc(0,0);
95     private Point JavaDoc right_tab = new Point JavaDoc(0,0);
96     public void setLeftTab(Point JavaDoc pt) {
97         this.left_tab = pt;
98     }
99     public void setRightTab(Point JavaDoc pt) {
100         this.right_tab = pt;
101     }
102     public Point JavaDoc getLeftTab() {
103         return this.left_tab;
104     }
105     public Point JavaDoc getRightTab() {
106         return this.right_tab;
107     }
108     
109     public Point JavaDoc placement_point;
110     public Box parent_box;
111     
112     
113     private URL JavaDoc base_url;
114     public void setBaseURL(URL JavaDoc base_url) {
115         this.base_url = base_url;
116     }
117     public URL JavaDoc 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 JavaDoc extents_stack = new Stack JavaDoc();
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 JavaDoc rect = new Rectangle JavaDoc(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 JavaDoc)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 JavaDoc toString() {
173         return "Context: extents = " + extents //" cursor = " + cursor +
174
//"\n color = " + color + " background color = " + background_color;
175
+ " offset = " + xoff + "," + yoff
176         ;
177     }
178     
179     
180 }
181
Popular Tags