1+ package HTMLrenderer ;
2+
3+ import java .awt .Color ;
4+
5+ public interface HTMLObject {
6+ void implement (PictureCreator pc );
7+
8+ }
9+
10+ class BRObject implements HTMLObject {
11+
12+ @ Override
13+ public void implement (PictureCreator pc ) {
14+ pc .operateBR ();
15+
16+ }
17+
18+ }
19+
20+ class TitleObject implements HTMLObject {
21+ String title ;
22+ TitleObject (String title ) {
23+ this .title =title ;
24+ }
25+
26+ @ Override
27+ public void implement (PictureCreator pc ) {
28+ pc .operateTitle (title );
29+
30+ }
31+ }
32+
33+ class FontStyleObject implements HTMLObject {
34+ private int type ; // 1 for i, 2 for u, 3 for b
35+ private boolean status ; // true for start, false for end
36+ private Color color ;
37+
38+ FontStyleObject (int t , boolean st ) {
39+ type = t ;
40+ status = st ;
41+ }
42+
43+ public void addAttribute (Color a ) { //Builder
44+ color =a ;
45+ }
46+
47+ @ Override
48+ public void implement (PictureCreator pc ) {
49+ pc .updatestyle (type , status , color );
50+
51+ }
52+
53+ }
54+
55+ class HeaderObject implements HTMLObject {
56+ private String header ;
57+ private int type ;
58+ private Color color ;
59+
60+ HeaderObject (int t , String header ) {
61+ this .type =t ;
62+ this .header =header ;
63+ }
64+
65+ public void addAttribute (Color a ) { //Builder
66+ color =a ;
67+ }
68+
69+ @ Override
70+ public void implement (PictureCreator pc ) {
71+ pc .operateheader (type , header , color );
72+
73+ }
74+ }
75+
76+ class TextObject implements HTMLObject {
77+ protected String text ;
78+
79+ TextObject (String txt ) {
80+ text = txt ;
81+ }
82+
83+ @ Override
84+ public void implement (PictureCreator pc ) {
85+ pc .operateText (text );
86+
87+ }
88+
89+ }
90+
91+ class ParagraphObject implements HTMLObject {
92+ private int attribute ; //0,1,2 for left, center, right
93+ private boolean status ;
94+
95+ ParagraphObject (boolean m ) {
96+ status =m ;
97+ }
98+
99+ public void setAttribute (int attr ) { //Builder
100+ attribute =attr ;
101+ }
102+
103+
104+ @ Override
105+ public void implement (PictureCreator pc ) {
106+ pc .operateParagraph (status , attribute );
107+
108+ }
109+
110+
111+ }
112+
113+ class ImgObject implements HTMLObject {
114+ private String source ;
115+ private int width ;
116+ private int height ;
117+
118+ ImgObject (String src ) {
119+ source = src ;
120+ }
121+
122+ public void setWidthAndHeight (int w , int h ) {
123+ width =w ;
124+ height =h ;
125+ }
126+
127+ @ Override
128+ public void implement (PictureCreator pc ) {
129+ pc .operatePic (source , width , height );
130+ }
131+ }
132+
133+
134+ class BodyObject implements HTMLObject {
135+ private Color bgcolor ;
136+ private Color textcolor ;
137+ private int leftmargin ;
138+ private int topmargin ;
139+ private int rightmargin ;
140+ private int bottommargin ;
141+ private String fontfamily ;
142+ private int fontsize ;
143+ private boolean status ;
144+
145+ BodyObject (boolean status ) {
146+ this .status = status ;
147+ }
148+
149+ public void setBgcolor (Color color ) { // Builder
150+ bgcolor = color ;
151+ }
152+
153+ public void setTextcolor (Color color ) {
154+ textcolor = color ;
155+ }
156+
157+ public void setLeftmargin (int a ) {
158+ leftmargin = a ;
159+ }
160+
161+ public void setTopmargin (int a ) {
162+ topmargin = a ;
163+ }
164+
165+ public void setRightmargin (int a ) {
166+ rightmargin = a ;
167+ }
168+
169+ public void setBottommargin (int a ) {
170+ bottommargin = a ;
171+ }
172+
173+ public void setFontsize (int a ) {
174+ fontsize = a ;
175+ }
176+
177+ public void setFontFamily (String a ) {
178+ fontfamily = a ;
179+ }
180+
181+ @ Override
182+ public void implement (PictureCreator pc ) {
183+ if (status ) {
184+ pc .operateBody (bgcolor , textcolor , leftmargin , bottommargin , rightmargin , topmargin , fontfamily , fontsize );
185+ }
186+ }
187+
188+ }
189+
190+ class HTMLHeadObject implements HTMLObject {
191+ @ SuppressWarnings ("unused" )
192+ private boolean status ; // open/close
193+ @ SuppressWarnings ("unused" )
194+ private int type ; // 1 for HTML, 2 for Head
195+
196+ HTMLHeadObject (int typ , boolean stat ) {
197+ status = stat ;
198+ type = typ ;
199+ }
200+
201+ @ Override
202+ public void implement (PictureCreator pc ) {
203+ }
204+
205+ }
0 commit comments