-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUse_case.java
139 lines (124 loc) · 4.1 KB
/
Use_case.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
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.ArrayList;
public class Use_case extends Basic_Object
{
private final int draw_obj_name_shift_x = 20;
private final int draw_obj_name_shift_y = 20;
//constructor
public Use_case(int depth,int left_up_x, int left_up_y)
{
super(depth);
this.left_up_x =left_up_x;
this.left_up_y =left_up_y;
Conn_Port = new ArrayList();
Create_Port();
}
public void Create_Port()
{
Conn_Port.add(new Port(left_up_x, left_up_y + UC_height/2)); //Region 1 port
Conn_Port.add(new Port(left_up_x+ UC_width/2, left_up_y + UC_height)); //Region 2 port
Conn_Port.add(new Port(left_up_x+ UC_width, left_up_y + UC_height/2)); //Region 3 port
Conn_Port.add(new Port(left_up_x+ UC_width/2, left_up_y )); //Region 4 port
}
@Override //critical reference01
public boolean update_range_obj_state(Rectangle selection_range)
{
if(selection_range.contains( new Rectangle(this.left_up_x, this.left_up_y,this.UC_width, this.UC_height) ) )
{
is_selected = true;
return true;
}
else
{
is_selected = false;
return false;
}
}
/**
* To check the press or released coordinate is within this object or not.
*/
@Override
public boolean is_selected(int press_coordinate_x,int press_coordinate_y )
{
if( ( (left_up_x <= press_coordinate_x) && (press_coordinate_x <= left_up_x + this.UC_width) ) &&((left_up_y <= press_coordinate_y )&&(press_coordinate_y <= left_up_y + this.UC_height) ) )
{
return true;
}
return false;
}
public static void set_which_Panel_to_be_drawn(Graphics point_to)
{
draw13 = point_to;
}
@Override
public Point get_right_down()
{
return new Point(left_up_x + UC_width, left_up_y + UC_height);
}
@Override
public void draw()
{
draw13.setColor(Color.WHITE);
draw13.fillOval(left_up_x, left_up_y, UC_width, UC_height);
draw13.setColor(Color.BLACK);
draw13.drawOval(left_up_x, left_up_y, UC_width, UC_height);
if(is_selected)
{
for(int i= 0; i< Conn_Port.size(); i++)
{
Conn_Port.get(i).draw_port();
}
}
draw13.drawString(object_name, left_up_x + draw_obj_name_shift_x, left_up_y + draw_obj_name_shift_y);
}
@Override
public Port Get_Connection_Port(int input_x, int input_y )
{
double judge_value1 = 0;
double judge_value2 = 0;
//set line 1
Point line1_start = new Point((double)this.left_up_x,(double)this.left_up_y);
Point line1_end = new Point(this.left_up_x +this.UC_width,this.left_up_y + this.UC_height );
double slope1 = ( line1_end.getY() - line1_start.getY() ) / ( line1_end.getX() - line1_start.getX() ) ;
judge_value1 = input_y - line1_start.getY() - slope1 * (input_x - line1_start.getX() );
//System.out.println("judge_value1 is :" + judge_value1+"\n" );
//set line 2
Point line2_start = new Point((double)this.left_up_x,(double)(this.left_up_y + this.UC_height ));
Point line2_end = new Point((double)(this.left_up_x +this.UC_width),(double)(this.left_up_y ));
double slope2 = ( line2_end.getY() - line2_start.getY() ) / ( line2_end.getX() - line2_start.getX() ) ;
judge_value2 = input_y - line2_start.getY() - slope2 * (input_x - line2_start.getX() );
//System.out.println("judge_value2 is :" + judge_value2+"\n" );
//To get Port
if(judge_value1 >= 0 && judge_value2 <= 0) //region 1 Point
{
return Conn_Port.get(0);
}
else if(judge_value1 > 0 && judge_value2 > 0) //region 2 Point
{
return Conn_Port.get(1);
}
else if(judge_value1 <= 0 && judge_value2 >= 0) //region 3 Point
{
return Conn_Port.get(2);
}
else if(judge_value1 < 0 && judge_value2 < 0) //region 4 Point
{
return Conn_Port.get(3);
}
else
{
// System.out.println("FATAL ERROR in Use_case::Get_Connection_Port ");
return null;
}
}
@Override
public void set_draw_port_false()
{
for(int i= 0; i< Conn_Port.size(); i++)
{
Conn_Port.get(i).set_draw_port_false();
}
}
}