-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathObjAttribute.java
More file actions
executable file
·481 lines (407 loc) · 12.6 KB
/
Copy pathObjAttribute.java
File metadata and controls
executable file
·481 lines (407 loc) · 12.6 KB
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Point;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.Arrays;
//Written by: Michael Zimmer - mike@zimmerdesignservices.com
/*
Copyright 2007 Zimmer Design Services
This file is part of Fizzim.
Fizzim is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Fizzim is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
public class ObjAttribute implements Cloneable {
private String name = null;
private String value = null;
private int visibility;
private String type = null;
private String useratts = null;
private String resetval = null;
private Color currColor = Color.black;
private String comment = "";
public static int NO = 0, YES = 1, NONDEFAULT = 2;
//global fix: fixed in global attributes
//global var: take value from global attribute
//local: override global attribute
//abs: hard-coded
public static int GLOBAL_FIXED = 3, GLOBAL_VAR = 4, LOCAL = 5, ABS = 6;
// all field editable by default
private int[] editable = {GLOBAL_VAR,GLOBAL_VAR,GLOBAL_VAR,GLOBAL_VAR,GLOBAL_VAR,GLOBAL_VAR,GLOBAL_VAR,GLOBAL_VAR};
//for drawing
private int x2Obj = 0,y2Obj = 0,tX,tY,tW,tH,myPage = -1,currPage;
private int selectStatus;
private int xTemp,yTemp;
private int selectboxLeft,selectboxRight,selectboxBottom,selectboxTop;
boolean outputTypeReg = false;
boolean outputTypeFlag = false;
public boolean getVisible()
{
if(visibility == YES)
return true;
if(visibility == NONDEFAULT && (editable[1] == LOCAL))
return true;
else
return false;
}
public ObjAttribute(String na, String va, int vi, String ty, String comm, Color color, String useratt, String resetvalue)
{
name = na;
value = va;
visibility = vi;
type = ty;
useratts = useratt;
resetval = resetvalue;
currColor = color;
comment = comm;
}
public ObjAttribute(String na, String va, int vi, String ty, String comm,Color color, String useratt, String resetvalue, int[] edit)
{
name = na;
value = va;
visibility = vi;
type = ty;
useratts = useratt;
resetval = resetvalue;
currColor = color;
comment = comm;
editable = edit;
}
public ObjAttribute(String name2, String nameStatus, String value2,
String valueStatus, String vis, String visStatus, String type2,
String typeStatus, String comm, String commStatus, Color color, String colorStatus, String useratts2, String userattsStatus, String resetval2, String resetvalStatus, int x2, int y2, int p) {
name = name2;
value = value2;
visibility = Integer.parseInt(vis);
type = type2;
useratts = useratts2;
resetval = resetval2;
editable[0] = getEditableValue(nameStatus);
editable[1] = getEditableValue(valueStatus);
editable[2] = getEditableValue(visStatus);
editable[3] = getEditableValue(typeStatus);
editable[4] = getEditableValue(commStatus);
editable[5] = getEditableValue(colorStatus);
editable[6] = getEditableValue(userattsStatus);
editable[7] = getEditableValue(resetvalStatus);
x2Obj = x2;
y2Obj = y2;
myPage = p;
currColor = color;
comment = comm;
}
public Object clone ()
throws CloneNotSupportedException
{
ObjAttribute copy = (ObjAttribute)super.clone();
copy.editable = editable.clone();
//TODO color?
return copy;
}
public Object get(int i)
{
if(i == 0)
return name;
else if(i == 1)
return value;
else if(i == 2)
return new Integer(visibility);
else if(i == 3)
return type;
else if(i == 4)
return comment;
else if(i == 5)
return currColor;
else if(i == 6)
return useratts;
else if(i == 7)
return resetval;
else
return null;
}
public void set(int col, Object val) {
if(col == 0)
name = (String) val;
else if(col == 1)
value = (String) val;
else if(col == 2)
{
Integer i = (Integer) val;
visibility = i.intValue();
}
else if(col == 3)
type = (String) val;
else if(col == 4)
comment = (String) val;
else if(col == 5)
currColor = (Color) val;
else if(col == 6)
useratts = (String) val;
else if(col == 7)
resetval = (String) val;
}
public String getName()
{
return name;
}
public void setName(String str)
{
name = str;
}
public String getValue()
{
return value;
}
public void setValue(String str)
{
value = str;
}
public int getVisibility()
{
return visibility;
}
public void setVisibility(int i)
{
visibility = i;
}
public String getType()
{
return type;
}
public void setType(String str)
{
type = str;
}
public String getComment()
{
return comment;
}
public void setComment(String str)
{
comment = str;
}
public String getUserAtts()
{
return useratts;
}
public void setUserAtts(String str)
{
useratts = str;
}
public String getresetval()
{
return resetval;
}
public void setresetval(String str)
{
resetval = str;
}
public int getEditable(int i)
{
return editable[i];
}
//set index i to variable j
public void setEditable(int i, int j)
{
if(i < 8)
editable[i] = j;
}
// for opening
private int getEditableValue(String s)
{
if(s.equals("GLOBAL_FIXED"))
return 3;
else if(s.equals("GLOBAL_VAR"))
return 4;
else if(s.equals("LOCAL"))
return 5;
else
return 6;
}
//for saving
private String getEditableName(int col)
{
int i = editable[col];
if(i == 3)
return "GLOBAL_FIXED";
if(i == 4)
return "GLOBAL_VAR";
if(i == 5)
return "LOCAL";
if(i == 6)
return "ABS";
else
return null;
}
//indentation (also exists in FizzimGui.java and GeneralObj.java
public String i(int indent)
{
String ind = "";
for(int i=0; i<indent; i++)
{
ind = ind + " ";
}
return ind;
}
public void save(BufferedWriter writer, int ind) throws IOException
{
writer.write(i(ind+1) + "<" + name + ">\n"
+ i(ind+3) + "<status>\n" + i(ind+3) + getEditableName(0)+ "\n" + i(ind+3) + "</status>\n"
+ i(ind+2) + "<value>\n" + i(ind+2) + value + "\n"
+ i(ind+3) + "<status>\n" + i(ind+3) + getEditableName(1)+ "\n" + i(ind+3) + "</status>\n"
+ i(ind+2) + "</value>\n"
+ i(ind+2) + "<vis>\n" + i(ind+2) + visibility + "\n"
+ i(ind+3) + "<status>\n" + i(ind+3) + getEditableName(2)+ "\n" + i(ind+3) + "</status>\n"
+ i(ind+2) + "</vis>\n"
+ i(ind+2) + "<type>\n" + i(ind+2) + type + "\n"
+ i(ind+3) + "<status>\n" + i(ind+3) + getEditableName(3)+ "\n" + i(ind+3) + "</status>\n"
+ i(ind+2) + "</type>\n"
+ i(ind+2) + "<comment>\n" + i(ind+2) + comment + "\n"
+ i(ind+3) + "<status>\n" + i(ind+3) + getEditableName(4)+ "\n" + i(ind+3) + "</status>\n"
+ i(ind+2) + "</comment>\n"
+ i(ind+2) + "<color>\n" + i(ind+2) + currColor.getRGB() + "\n"
+ i(ind+3) + "<status>\n" + i(ind+3) + getEditableName(5)+ "\n" + i(ind+3) + "</status>\n"
+ i(ind+2) + "</color>\n"
+ i(ind+2) + "<useratts>\n" + i(ind+2) + useratts + "\n"
+ i(ind+3) + "<status>\n" + i(ind+3) + getEditableName(3)+ "\n" + i(ind+3) + "</status>\n"
+ i(ind+2) + "</useratts>\n"
+ i(ind+2) + "<resetval>\n" + i(ind+2) + resetval + "\n"
+ i(ind+3) + "<status>\n" + i(ind+3) + getEditableName(3)+ "\n" + i(ind+3) + "</status>\n"
+ i(ind+2) + "</resetval>\n"
);
writer.write(i(ind+2) + "<x2Obj>\n" +i(ind+2) + x2Obj + "\n" + i(ind+2) + "</x2Obj>\n");//23 +12
writer.write(i(ind+2) + "<y2Obj>\n" + i(ind+2) + y2Obj + "\n" + i(ind+2) + "</y2Obj>\n");//26
writer.write(i(ind+2) + "<page>\n" + i(ind+2) + myPage + "\n" + i(ind+2) + "</page>\n");//29
writer.write(i(ind+1) + "</" + name + ">\n");
}
public void paintComponent(Graphics g, int curr,
Point point, int parentSelectStatus, int step) {
currPage = curr;
if (myPage == currPage && getVisible()) {
g.setColor(currColor);
FontMetrics fm1 = g.getFontMetrics();
// dont show "name =" or "equation =", just show value
String text;
if(name.equals("name") || name.equals("equation")) {
text = value;
} else {
if(outputTypeReg || outputTypeFlag)
text = name + " <= " + value;
else
text = name + " = " + value;
}
tH = fm1.getHeight();
tW = fm1.stringWidth(text);
tX = (int) point.getX();
tY = (int) point.getY() + tH*step;
int txbase = tX+x2Obj-tW/2;
int tybase = tY+y2Obj;
int yoffset = 0;
if(text.indexOf("\\n")==-1) {
g.drawString(text,txbase,tybase);
} else {
/* split lines on \n */
tW = 0;
String tempText = text;
while(tempText.indexOf("\\n")>-1) {
String line = tempText.substring(0,tempText.indexOf("\\n"));
g.drawString(line,txbase,tybase+yoffset);
if(fm1.stringWidth(line)>tW)
tW = fm1.stringWidth(line);
tempText = tempText.substring(tempText.indexOf("\\n")+2);
yoffset += tH;
}
g.drawString(tempText,txbase,tybase+yoffset);
if(fm1.stringWidth(tempText)>tW)
tW = fm1.stringWidth(tempText);
}
// Since box corners are needed by setSelectStatus, set
// them here.
selectboxLeft = txbase-4;
selectboxRight = txbase+tW+3;
selectboxBottom = tybase+yoffset+4;
selectboxTop = tybase-tH+2;
//if object is selected, draw red selection box around it
if(selectStatus != 0 || parentSelectStatus != 0) {
g.setColor(Color.red);
g.drawLine(selectboxLeft,selectboxTop,selectboxRight,selectboxTop); // Top
g.drawLine(selectboxLeft,selectboxBottom,selectboxRight,selectboxBottom); // Bottom
g.drawLine(selectboxLeft,selectboxTop,selectboxLeft,selectboxBottom); // Left
g.drawLine(selectboxRight,selectboxTop,selectboxRight,selectboxBottom); // Right
}
}
}
//unselects object
public void unselect() {
selectStatus = 0;
}
public boolean setSelectStatus(int x, int y) {
if(myPage == currPage && getVisible())
{
xTemp = x;
yTemp = y;
selectStatus = 0;
// check if inside red selection square
/*
if(x >= tX+x2Obj-tW/2-4 && x <= tX+x2Obj-tW/2+tW+3 && y >= tY+y2Obj-tH+2 && y <= tY+y2Obj+4)
selectStatus = 1;
*/
if(x >= selectboxLeft && x <= selectboxRight && y >= selectboxTop && y <= selectboxBottom)
selectStatus = 1;
}
if(selectStatus == 1)
return true;
else
return false;
}
public int getSelectStatus() {
return selectStatus;
}
public void adjustShapeOrPosition(int x, int y) {
if(myPage == currPage && getVisible())
{
if(selectStatus == 1)
{
x2Obj += x - xTemp;
y2Obj += y - yTemp;
xTemp = x;
yTemp = y;
}
}
}
public int getPage()
{
return myPage;
}
public void setPage(int i, String s)
{
if(myPage == -1)
myPage = i;
}
public void setPage(int i) {
myPage = i;
}
public void setOutputTypeReg(boolean b)
{
outputTypeReg = b;
}
public void setOutputTypeFlag(boolean b)
{
outputTypeFlag = b;
}
public String getIndent(int i)
{
char[] temp = new char[i];
Arrays.fill(temp, ' ');
return temp.toString();
}
}