-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdit_panel.java
381 lines (333 loc) · 10.5 KB
/
Edit_panel.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
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
/**
* 2011 November Author: Manuel
*/
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Edit_panel extends JPanel{
//private Edit_panel edit_panel = new Edit_panel(); //& why are you so stupid?
private int MODE = 0;
// private List<List<drawing_class >> Object_status_history = new ArrayList<List<drawing_class >>(); //Object Status History �ܦ����@�Ӿ�v���ΡG1. �[�F2�� 2.Group ���@�� 3. �S�[�F�@��...
private List<drawing_class > Current_object_status13 = new ArrayList<drawing_class >();//CRITICAL: �ثeCanvas�W�� ������
private List<drawing_class > Next_object_status13 ; //C.F: Next_object_status13 �O�C���hnew �@�ӥ[�Jhistory �� //�o�Ӥ@�}�l�N�n���A�_�h�@�}�lnew �@��class ��ָˡH
private List<Connection_line> Connection_line_manager13= new ArrayList<Connection_line>();//�`��Panel �W�Ҧ�line���Ѽ�
// private List<Connection_line> Nxt_cn_ln_st = new ArrayList<Connection_line>();
// private List<Connection_line> current_move_connection_line = new ArrayList<Connection_line>(); //�ثe�n�Q���ʪ��u.
private drawing_class press_obj;
//Group parameter:
// private List<List<Connection_line >> record_inner_lines = new ArrayList<List<Connection_line >>();
private List<Connection_line > a_inner_line_record= new ArrayList<Connection_line>();
private int press_x = 0;
private int press_y = 0;
Mouse_Mode Current_Event;
private Graphics g = this.getGraphics();
private boolean press_on_obj = false;
private int Depth = 100;
//Group
private drawing_class a_new_composite_obj;
private int Group_Degree = 0;
// private Point move_vector = new Point(0,0);
/**
* @param event :new Selection_Mode() as a parameter.
*/
public void Set_Mouse_Event(Mouse_Mode event)
{
Current_Event = event;
this.addMouseListener(event);
this.addMouseMotionListener(event);
}
public void Add_To_Line_Mang(Connection_line added_line)
{
Connection_line_manager13.add(added_line);
}
/**
* @return canvas
*/
public List<drawing_class > get_Current_Obj_Status()
{
return Current_object_status13;
}
/**
* Update depth.
* @return depth.
*/
public int update_depth()
{
Depth--;
return Depth;
}
public void Remove_Mouse_Event()
{
this.removeMouseListener(Current_Event);
this.removeMouseMotionListener(Current_Event);
}
public void set_MODE(int mode)
{
if( mode>= 1 && mode <= 6)
{
MODE = mode;
System.out.print(MODE + "\n");
}
else //FATAL ERROR.
{
System.out.println("Input-Mode Error!\n");
System.out.println("And MODE remains: " + MODE);
}
}//set_MODE
public Edit_panel() {} //Edit_panel constructor.
public void set_graphics(Graphics to_draw)
{
g = to_draw;
}
//clear_panel:
public void clear_panel()
{
g= this.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0,0, UML_Editor_13.getPanel_width(), UML_Editor_13.getPanel_height());
g.setColor(Color.BLACK);
g.drawRect(0,0, UML_Editor_13.getPanel_width()-1, UML_Editor_13.getPanel_height()-1);
}
//Clear && repaint!
public void Repaint()
{
clear_panel();
for(int i = 0; i < Current_object_status13.size(); i++) //FC! Form get Confirmed already!
{
Current_object_status13.get(i).draw();
}
//to repaint all the connection line
for(int i = 0; i < Connection_line_manager13.size(); i++) //FC!
{
Connection_line_manager13.get(i).draw();
}
}
public void Paint_Moved_Obj_Lines(drawing_class activated_obj)
{
clear_panel();
activated_obj.draw();
activated_obj.Draw_Link_Lines();
}
public boolean update_objects_state(int x, int y)
{
int index = Current_object_status13.size() - 1;
boolean rt_value = false;
while(index >= 0)
{
if( Current_object_status13.get(index).is_selected(x, y) )
{
System.out.println("Item: "+ index +"in Current_object_status13 is selected.\n");
Current_object_status13.get(index).select();
rt_value = true;
for(int j= index -1; j >= 0; j--)
{
Current_object_status13.get(j).unselect();
}
break;
}
else
{
Current_object_status13.get(index).unselect();
}
index--;
}//while loop
return rt_value;
}
/**
* return null
* @return A selected obj or null.
*/
public drawing_class Return_Pressed_Obj(int x, int y)
{
for(int i = Current_object_status13.size() -1; i >= 0; i--)
{
if(Current_object_status13.get(i).is_selected(x, y))
{
return Current_object_status13.get(i);
}
}
return null;
}
//return a index in the Object_manger13 to get which object is selected.
public int Select_which_object()
{
for(int index = Current_object_status13.size()-1; index >=0 ; index --)
{
if(Current_object_status13.get(index).is_selected == true)
{
return index;
}
}
// if no ""return"" happens, it means that no true condition happens.
return -2;
}
/**
* Scenario: According to the user's input to decide the four points' coordinates.
* @param x1,y1,x2,y2
* @return Rectangle. No possible to be null by default.
*/
public Rectangle produce_a_rectangle(int x1,int y1, int x2, int y2)
{
Rectangle fianl_return_rec = null;
if(x1 <= x2 && y1<= y2)
{
fianl_return_rec = new Rectangle(x1,y1,x2-x1,y2-y1);
}
else if(x1 >= x2 && y2 >= y1)
{
fianl_return_rec = new Rectangle(x2,y1,x1-x2,y2-y1);
}
else if(x1 >= x2 && y1 >= y2)
{
fianl_return_rec = new Rectangle(x2,y2,x1 -x2, y1-y2);
}
else if(x2 >= x1 && y1 >=y2)
{
fianl_return_rec = new Rectangle(x1,y2,x2 - x1, y1-y2);
}
else
{
//nothing.
}
return fianl_return_rec ;
}
public void connection_in_pressed (Connection_line conn_line)
{
press_on_obj = update_objects_state(press_x, press_y);//
Repaint();
//If the user didn't pressed on an object in the first, then break;
if( press_on_obj == false)
{
return ;
}
//else we pressed on an object, and need to find the connection point. ---> WRONG
press_obj = Current_object_status13.get( Select_which_object() );
if(press_obj == null)
{
System.out.println("\n"+"Impossible 001 \n");
}
return;
}
/**
* Change_object_name:
*/
public void Change_object_name()
{
press_obj = Current_Event.Get_Pressed_Obj();
//Guard
if(press_obj == null)
{
System.out.println("�n���I�磌��~���W�I�I");
return;
}
System.out.println("Ready to change an objects' name:\n");
String input_text= JOptionPane.showInputDialog("Please Change Object Name","Change Object Name");//��J��r
if(input_text==null) //�����ɤ~�|��null~
{
Repaint(); //since the pop menu still overlaps the canvas, the Repaint is still required.
return;
}
//Set object's name
press_obj.setObject_name(input_text);
Repaint();
}
Rectangle min_range ;
List<drawing_class> for_find_min_rec = new ArrayList<drawing_class>();
List<Integer> store_all_selected_obj_x = new ArrayList<Integer>();
List<Integer> store_all_selected_obj_y = new ArrayList<Integer>();
public void set_inner_lines_and_record_it()
{
a_inner_line_record.clear();
}//set_inner_lines_and_record_it()
//Group:
public void Group()
{
int selected_itme_count = 0;
update_depth();
System.out.println("Depth in Edit_panel is: " + Depth +"\n");
//To initialize the Composite_Object first.
a_new_composite_obj = new Composite_Object(Depth);
for(int i = 0; i < Current_object_status13.size(); i++)
{
if(Current_object_status13.get(i).is_selected == true)
{
a_new_composite_obj.Add_An_Obj(Current_object_status13.get(i));
selected_itme_count ++;
}
}
//Guard.
if( selected_itme_count < 2)
{
a_new_composite_obj.destroy_self(); //clear components
return;
}
//Composite object survive.
a_new_composite_obj.set_is_selected_true();
//System.out.println("Test: �X�Ӫ���Group�b�@�_�H�G"+ a_new_composite_obj.how_many_items() +"\n");
//System.out.println("The depth of this composite obj is: "+ a_new_composite_obj.get_Depth() +"\n");
Next_object_status13 = new ArrayList<drawing_class >();
for(int i = 0 ; i< Current_object_status13.size() ; i++)
{
if(Current_object_status13.get(i).is_selected == false)
{
Next_object_status13.add(Current_object_status13.get(i));
}
else
{
}
}
Next_object_status13.add(a_new_composite_obj); //Add a new obj.
Current_object_status13 =Next_object_status13;
Group_Obj_History.add(a_new_composite_obj); //Record what composite object is stored.
Group_Degree++;
}//Group
private List<drawing_class> Group_Obj_History = new ArrayList<drawing_class>();
private List<drawing_class> objects_in_group;
public void UnGroup()
{
if(Group_Degree > 0 )
{
System.out.println("�i�H�Ѻc");
Group_Degree--;
}
else
{
return ;
}
a_new_composite_obj = Group_Obj_History.get(Group_Degree);
Remove_Obj_In_Object_Mang(a_new_composite_obj);
System.out.println("Group_degree is :" + Group_Degree );
if(Group_Degree < 0) return;
objects_in_group = a_new_composite_obj.Get_Containing_Obj();
for(int i = 0 ; i< objects_in_group .size() ; i++)
{
Current_object_status13.add(objects_in_group.get(i));
}
Collections.sort(Current_object_status13);
}
boolean k =false;
public void Remove_Obj_In_Object_Mang(drawing_class removed_obj)
{
for(int i = 0; i < Current_object_status13.size() ; i++)
{
if(Current_object_status13.get(i) == removed_obj)
{
k = Current_object_status13.remove(removed_obj);
System.out.println("k is " + k);
}
}
}
}//CLASS BRACKET!