-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBPage.java
293 lines (279 loc) · 7.33 KB
/
BPage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author claudiu
*
*/
public class BPage extends ModelPrimitiva{
private String path;//Calea catre fisier
private Page p = new Page();//Pagina clona pentru "pagina" curenta
/**
* Constructorul clasei BPage, initializeaza campurile path, nume si body si construieste corpul obiectului(body)
* @param path - calea catre fisier
* @param name - numele noului obiect
*/
public BPage(String path, String name){
super();
this.path = path;
this.nume = name;
body = new char[30][60];
MakeBody();//Construieste corpul obiectului
}
/**
* Redimensioneaza obiectul pagina
* @param i
* @param j - noile dimensiuni ale obiectului pagina
*/
public void resize (int i, int j){
super.resize(i, j);
p.resizePage(i, j);//Redimensionez si pagina clona
}
/**
* Construieste corpul obiectului pagina
*/
public void MakeBody(){
Plugins plg = new Plugins();
Manager m = new Manager();//Lista proprie de obiecte care vor fi adaugate in pagina obiect
Scanner sc;
try{
sc = new Scanner(new FileInputStream(new File(path)));//Citesc din fisier
}
catch (Exception e){
e.printStackTrace();
return;
}
String s = sc.nextLine();//Citesc prima linie
ArrayList<String> a = new ArrayList<String>();//Lista de cuvinte din fiecare comanda
//Procedeul de citire este asemenea celui din clasa MainClass
while (s.equals("quit") == false){ //Cat timp continui sa citesc comenzi
//Analizez linia de comanda:
int i = 0,l;
char ap = "'".charAt(0);
boolean pass = false;
while (i<s.length()){
String c = "";
char pss = s.charAt(i);
l=0;
pass = false;
//Daca e spatiu sari:
if (pss == ' ') {
i++;
pass = true;
continue;
}
//Daca e apostrof:
if (ap == pss){
i++;
pass = true;
while(s.charAt(i) != ap){
c += s.charAt(i);
i++;
l++;
}
i++;
a.add(c);
}
//Daca e litera sau altceva
if (pass == false){
while (s.charAt(i)!=' '){
c += s.charAt(i);
i++;
l++;
if (i == s.length()) break;
}
a.add(c);
}
if (i == s.length()) break;
}
if (a.get(0).equals("new") == true){
//Creez un model nou:
ModelPrimitiva tl;
String ce, name, text,split;
char x;
ce = a.get(1);
name = a.get(2);
if (ce.equals("TextLine") == true){
text = a.get(3);
tl = new TextLine(name,text); //Creez un TextLine
m.add(tl);//Adaug in manager
}
if (ce.equals("TextArea")== true){
split = a.get(3);
text = a.get(4);
if (split.equals("true")==true){
tl = new TextArea(name,true,text);
}
else tl = new TextArea(name,false,text);
m.add(tl);//Adaug in manager
}
if (ce.equals("TextBox")==true){
split = a.get(3);
x = a.get(4).charAt(0);
text = a.get(5);
if (split.equals("true")==true){
tl = new TextBox(name,true,x,text);
}
else tl = new TextBox(name,false,x,text);
m.add(tl);//Adaug in manager
}
if (ce.equals("List")==true){
ArrayList<String> aux = new ArrayList<String>();
for (int k =4; k<a.size();k++){
aux.add(a.get(k));
}
x = a.get(3).charAt(0);
tl = new Lista(name,x,aux);
m.add(tl);//Adaug in manager
}
if (ce.equals("Title")== true){
x = a.get(3).charAt(0);
text = a.get(4);
tl = new Title(name, x,text);
m.add(tl);//Adaug in manager
}
if (ce.equals("Rectangle")==true){
x = a.get(3).charAt(0);
tl = new Rectangle(name,x);
m.add(tl);//Adaug in manager
}
//Creare BonusPage:
if (ce.equals("Page")==true){
String path = a.get(3);
tl = new BPage(path, name);
m.add(tl);
}
//Termin creare obiect nou
}
//Operatia MOVE:
if (a.get(0).equals("move")==true){
String name = a.get(1);
int i2 = Integer.parseInt(a.get(2));
int j = Integer.parseInt(a.get(3));
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
m.lista[k].move(i2,j);
}
}
}
//Operatia RESIZE:
if (a.get(0).equals("resize")==true){
String name = a.get(1);
int i2 = Integer.parseInt(a.get(2));
int j = Integer.parseInt(a.get(3));
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
m.lista[k].resize(i2, j);
}
}
}
//Operatia resizePage
if (a.get(0).equals("resizePage")==true){
int i2 = Integer.parseInt(a.get(1));
int j = Integer.parseInt(a.get(2));
p.resizePage(i2, j);
}
//Operatia bringFront:
if (a.get(0).equals("bringFront")==true){
String name = a.get(1);
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
m.lista[k].bringFront(m);
}
}
}
//Operatia sendBack:
if (a.get(0).equals("sendBack")==true){
String name = a.get(1);
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
m.lista[k].sendBack(m);
}
}
}
//Operatia DELETE:
if (a.get(0).equals("delete")==true){
String name = a.get(1);
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
m.lista[k].delete(m);
}
}
}
//Plugin-uri:
if (a.get(0).equals("invoke")== true){
if (a.get(1).equals("doubleWidth")==true){
String name = a.get(2);
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
plg.doubleWidth(m.lista[k]);
}
}
}
if (a.get(1).equals("doubleHeight")==true){
String name = a.get(2);
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
plg.doubleHeight(m.lista[k]);
}
}
}
if (a.get(1).equals("maximize")==true){
String name = a.get(2);
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
plg.maximize(m.lista[k],p);
}
}
}
if (a.get(1).equals("center")==true){
String name = a.get(2);
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
plg.center(m.lista[k],p);
}
}
}
if (a.get(1).equals("makeSquare")==true){
String name = a.get(2);
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
plg.makeSquare(m.lista[k]);
}
}
}
if (a.get(1).equals("toLowerCase")==true){
String name = a.get(2);
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
plg.toLowerCase(m.lista[k]);
}
}
}
if (a.get(1).equals("toUpperCase")==true){
String name = a.get(2);
for (int k=0; k<m.getNo(); k++){
if (m.lista[k].nume.equals(name)==true){
plg.toUpperCase(m.lista[k]);
}
}
}
}//S-a terminat Plugin-uri
a.removeAll(a);
s = sc.nextLine();
}//S-a terminat bucla, am lista manager cu toate obiectele
//Creare corp:
for (int i=0; i<p.getHeight() ; i++){
for (int j=0; j<p.getWidth(); j++){
p.finalpage[i][j] = ' ';//Initializez corpul paginii clona cu spatii
}
}
int i = m.getNo();
for (int j=0;j<i;j++){//Parcurg lista si desenez fiecare obiect din ea pe pagina clona
m.lista[j].draw(p);
}
body = p.finalpage.clone();//Copiez corpul paginii clona in corpul paginii obiect
}//S-a terminat MakeBody
}