-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUML_Editor_13.java
358 lines (297 loc) · 11.6 KB
/
UML_Editor_13.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
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import java.awt.Color;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JButton;
import javax.swing.JLayeredPane;
import javax.swing.SpringLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.Icon;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JToolBar;
import javax.swing.JTabbedPane;
import javax.swing.JInternalFrame;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;
import javax.swing.JLabel;
import java.awt.SystemColor;
import javax.swing.UIManager;
public class UML_Editor_13 extends JFrame {
private int button_width = 68;
private int button_height = 49;
protected JButton Select_button;
protected JButton Association_button;
protected JButton Generalization_button;
protected JButton Composition_button;
protected JButton Class_button ;
protected JButton Use_case_button;
private JTextField txtSelect;
private JTextField txtAssociationLine;
private JTextField txtGeneralizationLine;
private JTextField txtCompositionLine;
private JTextField txtCreateAClass;
private JTextField txtCreateUseCase;
private static int panel_start_x = 200; //����JPanel���_�l��m�C
private static int panel_start_y = 20;
private static int panel_width = 513;
private static int panel_height = 531;
private JMenuBar menuBar;
private JMenu File ;
private JMenuItem Save;
private JMenu Open;
private JMenu Edit;
private JMenuItem ChangeObjName;
private JMenuItem Group;
private JMenuItem Ungroup ;
//Operation instance variable.
//private Edit_panel just_use = new Edit_panel();
public static int getPanel_start_x() {
return panel_start_x;
}
public static int getPanel_start_y() {
return panel_start_y;
}
public static int getPanel_width() {
return panel_width;
}
public static int getPanel_height() {
return panel_height;
}
//black the button
private int pressed_button = 0;
public static Edit_panel canvas = new Edit_panel();
//private int JFrame_width =
/**
* Launch the application.
*/
public static void main(String[] args)
{
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run()
{
UML_Editor_13 frame = new UML_Editor_13();
frame.setVisible(true);
frame.setResizable(false); //The frame size is fixed.
Port.Set_Port_Graphics(canvas.getGraphics());
}
} );
}
/**
* Create the frame.
*/
public UML_Editor_13() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 728, 687);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu Edit = new JMenu("EDIT");
menuBar.add(Edit);
JMenuItem ChangeObjName = new JMenuItem("Change Object Name");
ChangeObjName.setSelected(true);
Edit.add(ChangeObjName);
JMenuItem Group = new JMenuItem("Group");
Edit.add(Group);
JMenuItem Ungroup = new JMenuItem("UnGroup");
Edit.add(Ungroup);
//SET layout.
getContentPane().setLayout(null);
//1. Select BUTTON.
Icon select_img = new ImageIcon(this.getClass().getResource("selection.jpg"));
Select_button = new JButton( select_img );
Select_button.setBackground(Color.WHITE);
Select_button.setBounds(68, 59, 68 , 43);
getContentPane().add(Select_button);
Select_button.setToolTipText("SELECT"); //tooltip
//2. Association button
Icon association_img = new ImageIcon(this.getClass().getResource("association.jpg"));//create image ICON
Association_button = new JButton(association_img); // new JButton object.
Association_button.setBackground(Color.WHITE);
Association_button.setBounds(68, 146, 68 , 36 ); //set the location.
getContentPane().add(Association_button); //add to JFrame
Association_button.setToolTipText("Association Line");//tooltip
//3. Generalization button.
Icon generalization_img = new ImageIcon(this.getClass().getResource("generalization.jpg"));
Generalization_button = new JButton(generalization_img);
Generalization_button.setBackground(Color.WHITE);
Generalization_button.setBounds(68, 222, 68 , 36 );
getContentPane().add(Generalization_button);
Generalization_button.setToolTipText("Generalization Line");
//4. Composition button
Icon composition_img = new ImageIcon(this.getClass().getResource("composition.jpg"));
Composition_button = new JButton(composition_img );
Composition_button.setBackground(Color.WHITE);
Composition_button.setToolTipText("Composition line");
Composition_button.setBounds(68, 304, 68 , 43 );
getContentPane().add(Composition_button);
//5. Class button
Icon class_img = new ImageIcon(this.getClass().getResource("class.jpg"));
Class_button = new JButton(class_img);
Class_button.setBackground(Color.WHITE);
Class_button.setToolTipText("Create a class");
Class_button.setBounds(68, 384, 68 , 49 );
getContentPane().add(Class_button);
//6. Use Class button
Icon use_case_img = new ImageIcon(this.getClass().getResource("use_case.jpg"));
Use_case_button = new JButton(use_case_img );
Use_case_button.setBackground(Color.WHITE);
Use_case_button.setToolTipText("Create an 'Use Case' ");
Use_case_button.setBounds(68, 476, 68 , 49 );
getContentPane().add(Use_case_button);
txtSelect = new JTextField();
txtSelect.setHorizontalAlignment(SwingConstants.CENTER);
txtSelect.setText("Select");
txtSelect.setBounds(33, 107, 144, 22);
getContentPane().add(txtSelect);
txtSelect.setColumns(10);
txtAssociationLine = new JTextField();
txtAssociationLine.setHorizontalAlignment(SwingConstants.CENTER);
txtAssociationLine.setText("Association Line");
txtAssociationLine.setBounds(33, 188, 144, 22);
getContentPane().add(txtAssociationLine);
txtAssociationLine.setColumns(10);
txtGeneralizationLine = new JTextField();
txtGeneralizationLine.setHorizontalAlignment(SwingConstants.CENTER);
txtGeneralizationLine.setText("Generalization Line");
txtGeneralizationLine.setBounds(33, 269, 144, 22);
getContentPane().add(txtGeneralizationLine);
txtGeneralizationLine.setColumns(10);
txtCompositionLine = new JTextField();
txtCompositionLine.setHorizontalAlignment(SwingConstants.CENTER);
txtCompositionLine.setText("Composition Line");
txtCompositionLine.setBounds(32, 350, 145, 22);
getContentPane().add(txtCompositionLine);
txtCompositionLine.setColumns(10);
txtCreateAClass = new JTextField();
txtCreateAClass.setHorizontalAlignment(SwingConstants.CENTER);
txtCreateAClass.setText("Create a class");
txtCreateAClass.setBounds(33, 442, 144, 22);
getContentPane().add(txtCreateAClass);
txtCreateAClass.setColumns(10);
txtCreateUseCase = new JTextField();
txtCreateUseCase.setHorizontalAlignment(SwingConstants.CENTER);
txtCreateUseCase.setText("Create an Use Case");
txtCreateUseCase.setBounds(33, 528, 144, 22);
getContentPane().add(txtCreateUseCase);
txtCreateUseCase.setColumns(10);
canvas.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
canvas.setBackground(Color.WHITE);
canvas.setBounds(panel_start_x, panel_start_y, panel_width , panel_height);
getContentPane().add(canvas);
Mouse_Mode.set_canvas(canvas);
Select_button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
canvas.Remove_Mouse_Event(); //Remove the last mouse event:
canvas.Set_Mouse_Event(new Selection_Mode()); //Exchange switch to Command Line method
canvas.set_MODE(1);
reset_back_color();
Select_button.setBackground(Color.black);
}
});
Association_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
canvas.Remove_Mouse_Event(); //Remove the last mouse event
canvas.Set_Mouse_Event(new AssociationLineMode()); //Exchange switch to Command Line method
canvas.set_MODE(2);
Association_line.set_Draw(canvas.getGraphics());
reset_back_color();
Association_button.setBackground(Color.black);
}
});
Generalization_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
canvas.Remove_Mouse_Event(); //Remove the last mouse event:
canvas.Set_Mouse_Event(new Gen_Line_Mode()); //Exchange switch to Command Line method
canvas.set_MODE(3);
//Set graphics.
Generalization_line.set_Draw(canvas.getGraphics());
reset_back_color();
Generalization_button.setBackground(Color.black);
}
});
Composition_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//Remove the last mouse event:
canvas.Remove_Mouse_Event();
//Exchange switch to Command Line method
canvas.Set_Mouse_Event(new Cmp_Line_Mode());
canvas.set_MODE(4);
Composition_line.set_Draw(canvas.getGraphics());
reset_back_color();
Composition_button.setBackground(Color.black);
}
});
Class_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
canvas.Remove_Mouse_Event();
//Exchange switch to Command Line method
canvas.Set_Mouse_Event(new Draw_CD_Mode());
canvas.set_MODE(5);
reset_back_color();
Shape.set_which_Panel_to_be_drawn(canvas.getGraphics());
Class_button.setBackground(Color.black);
}
});
Use_case_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
canvas.Remove_Mouse_Event();
canvas.Set_Mouse_Event(new Draw_UC_Mode());
canvas.set_MODE(6);
reset_back_color();
Use_case.set_which_Panel_to_be_drawn(canvas.getGraphics());
Use_case_button.setBackground(Color.black);
}
});
ChangeObjName.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
canvas.Change_object_name();
}//end method actionPerformed.
}//end anonymous inner class
);//end call to addActionListener
//Group action:
Group.addActionListener(
new ActionListener()//anonymous inner class
{
public void actionPerformed(ActionEvent e)
{
canvas.Group();
}//end method actionPerformed.
}//end anonymous inner class
);//end call to addActionListener
//Ungroup action:
Ungroup.addActionListener(
new ActionListener()//anonymous inner class
{
public void actionPerformed(ActionEvent e)
{
canvas.UnGroup();
}//end method actionPerformed.
}//end anonymous inner class
);//end call to addActionListener
}
public void reset_back_color()
{
Select_button.setBackground(Color.WHITE);
Association_button.setBackground(Color.WHITE);
Generalization_button.setBackground(Color.WHITE);
Composition_button.setBackground(Color.WHITE);
Class_button.setBackground(Color.WHITE);
Use_case_button.setBackground(Color.WHITE);
}
}