-
Notifications
You must be signed in to change notification settings - Fork 9
/
ArchitectureApp.java
342 lines (275 loc) · 11.1 KB
/
ArchitectureApp.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
/*
* Classname : ArchitectureApp
*
* Version information : 1
*
* Date :
*
* Description : This class describes the (JFrame) window for producing
* UML Component diagrams. It has its
* own menu and tool bar.
package: Architecture
*/
/******************************
* Copyright (c) 2003--2023 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
* *****************************/
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.print.*;
import java.util.Vector;
import javax.swing.JApplet;
import javax.swing.text.*;
public class ArchitectureApp extends JApplet implements ActionListener
{ private JLabel messageLabel;
private ArchitectureArea drawArea;
private ListShowDialog listShowDialog;
private Vector entities = new Vector();
private UCDArea parent = null;
private TempInvEditDialog tinvDialog;
public void init()
{ JMenuBar menuBar;
JMenu fileMenu, createMenu;
JMenuItem saveMenu;
JMenuItem stateMenu;
JMenuItem transMenu;
JMenuItem state2Menu;
JMenuItem eventMenu;
// setDefaultCloseOperation(HIDE_ON_CLOSE);
// setTitle("Architecture Editor");
//Add regular components to the window, using the default BorderLayout.
Container contentPane = getContentPane();
drawArea = new ArchitectureArea(this,parent,"Architecture Editor",entities);
//Put the drawing area in a scroll pane.
JScrollPane state_scroll = new JScrollPane(drawArea,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
state_scroll.setPreferredSize(new Dimension(500,400));
contentPane.add(state_scroll, BorderLayout.CENTER);
messageLabel = new JLabel("Click within the framed area.");
contentPane.add(messageLabel, BorderLayout.SOUTH);
//Create the menu bar.
menuBar = new JMenuBar();
setJMenuBar(menuBar);
// FILE menu heading
//---------------------
fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
fileMenu.getAccessibleContext().setAccessibleDescription(
"Allows user to save/file work");
menuBar.add(fileMenu);
//a group of JMenuItems under the "File" option
// saveMenu.setMnemonic(KeyEvent.VK_S);
JMenuItem saveDataMI = new JMenuItem("Save data");
saveDataMI.addActionListener(this);
fileMenu.add(saveDataMI);
JMenuItem loadMenu = new JMenuItem("Load data");
loadMenu.addActionListener(this);
fileMenu.add(loadMenu);
fileMenu.addSeparator();
JMenuItem saveModelMI = new JMenuItem("Save as model");
saveModelMI.addActionListener(this);
fileMenu.add(saveModelMI);
/* fileMenu.addSeparator();
JMenuItem loadDataRequirementsMI = new JMenuItem("Formalise data reqs");
loadDataRequirementsMI.addActionListener(this);
fileMenu.add(loadDataRequirementsMI); */
fileMenu.addSeparator();
JMenuItem printMI = new JMenuItem("Print");
printMI.addActionListener(this);
fileMenu.add(printMI);
// VIEW menu heading
//--------------------
JMenu viewMenu = new JMenu("View");
viewMenu.setMnemonic(KeyEvent.VK_V);
// menuBar.add(viewMenu);
JMenuItem stateList = new JMenuItem("Components");
stateList.addActionListener(this);
viewMenu.add(stateList);
JMenuItem transList = new JMenuItem("Interfaces");
transList.addActionListener(this);
viewMenu.add(transList);
//CREATE menu heading
//--------------------
createMenu = new JMenu("Create");
createMenu.setMnemonic(KeyEvent.VK_C);
createMenu.getAccessibleContext().setAccessibleDescription(
"To create components, interfaces and connectors");
menuBar.add(createMenu);
//a group of JMenuItems for Create
stateMenu = new JMenuItem("Component");
stateMenu.getAccessibleContext().setAccessibleDescription(
"Draws a component");
stateMenu.addActionListener(this);
createMenu.add(stateMenu);
transMenu = new JMenuItem("Provided interface");
createMenu.add(transMenu);
transMenu.addActionListener(this);
JMenuItem scenarioMenu = new JMenuItem("Required interface");
createMenu.add(scenarioMenu);
scenarioMenu.addActionListener(this);
// state2Menu = new JMenuItem("Lifeline state");
// state2Menu.getAccessibleContext().setAccessibleDescription(
// "Draws state as a rounded rectangle");
// state2Menu.addActionListener(this);
// createMenu.add(state2Menu);
// JMenuItem state3Menu = new JMenuItem("Execution instance");
// state3Menu.getAccessibleContext().setAccessibleDescription(
// "Draws execution instance as a rectangle");
// state3Menu.addActionListener(this);
// createMenu.add(state3Menu);
// JMenuItem taMenu = new JMenuItem("Time annotation");
// taMenu.getAccessibleContext().setAccessibleDescription(
// "Draws time annotation at point");
// taMenu.addActionListener(this);
// createMenu.add(taMenu);
// JMenuItem daMenu = new JMenuItem("Duration annotation");
// daMenu.getAccessibleContext().setAccessibleDescription(
// "Draws duration annotation");
// daMenu.addActionListener(this);
// createMenu.add(daMenu);
//EDIT menu heading
//--------------------
JMenu editMenu = new JMenu("Edit");
editMenu.getAccessibleContext().setAccessibleDescription(
"To edit elements");
menuBar.add(editMenu);
menuBar.add(viewMenu);
JMenuItem editState = new JMenuItem("Edit component");
JMenuItem editScenario = new JMenuItem("Edit interface");
JMenuItem moveElement = new JMenuItem("Move");
// JMenuItem gluemoveMI = new JMenuItem("Glue move");
// JMenuItem resizeMI = new JMenuItem("Resize");
JMenuItem deleteElement = new JMenuItem("Delete");
JMenuItem shrinkMI = new JMenuItem("Shrink");
editState.addActionListener(this);
editScenario.addActionListener(this);
moveElement.addActionListener(this);
// gluemoveMI.addActionListener(this);
// resizeMI.addActionListener(this);
deleteElement.addActionListener(this);
shrinkMI.addActionListener(this);
editMenu.add(editState);
editMenu.add(editScenario);
editMenu.add(moveElement);
// editMenu.add(gluemoveMI);
// editMenu.add(resizeMI);
editMenu.add(deleteElement);
editMenu.add(shrinkMI);
editMenu.addSeparator();
// Synthesis MENU
JMenu synthMenu = new JMenu("Synthesis");
menuBar.add(synthMenu);
JMenuItem ralSynthesis = new JMenuItem("Derive Java");
ralSynthesis.addActionListener(this);
synthMenu.add(ralSynthesis);
// JMenuItem rtlSynthesis = new JMenuItem("RTL");
// rtlSynthesis.addActionListener(this);
// synthMenu.add(rtlSynthesis);
setVisible(true);
}
public ArchitectureArea getDrawArea()
{ return drawArea; }
public void paint(Graphics g)
{ setVisible(true); }
public void actionPerformed(ActionEvent e)
{
Object eventSource = e.getSource();
if (eventSource instanceof JMenuItem)
{
String label = (String) e.getActionCommand();
if (label.equals("Save data"))
{ drawArea.saveDataToFile("architecture.txt");
messageLabel.setText("Saved data to architecture.txt");
}
else if (label.equals("Load data"))
{ drawArea.loadDataFromFile("out.dat");
messageLabel.setText("Loaded data from architecture.txt");
}
if (label.equals("Save as model"))
{ drawArea.saveModelDataToFile("archmodel.txt");
messageLabel.setText("Saved data to archmodel.txt");
}
else if (label.equals("Components"))
{ System.out.println(">>> List of components");
System.out.println(">>> ------------------");
drawArea.updateModel();
drawArea.disp_States();
}
else if (label.equals("Interfaces"))
{ System.out.println(">>> List of interfaces");
System.out.println(">>> ------------------");
drawArea.disp_Trans();
}
else if (label.equals("Print"))
{ printData(); }
else if (label.equals("Derive Java"))
{
drawArea.synthesiseJava();
}
else if (label.equals("Component"))
{ System.out.println("Creating a component: click on location");
drawArea.setDrawMode(RequirementsArea.POINTS);
messageLabel.setText("Click on location");
}
else if (label.equals("Required interface"))
{ System.out.println("Click and drag from a component to create a required interface");
drawArea.setDrawMode(InteractionArea.DLINES);
messageLabel.setText("Click and drag from a component to create a required interface");
}
else if (label.equals("Provided interface"))
{ System.out.println("Creating a provided interface of a component:\n" +
"Click and drag from component to interface location");
drawArea.setDrawMode(RequirementsArea.SLINES);
messageLabel.setText("Click and drag from component to interface location");
}
else if (label.equals("Edit component"))
{ System.out.println("Select component to edit");
drawArea.setDrawMode(InteractionArea.EDIT);
drawArea.setEditMode(InteractionArea.EDITING);
messageLabel.setText("Click within the component");
}
else if (label.equals("Edit interface"))
{ System.out.println("Select interface to edit");
drawArea.setDrawMode(InteractionArea.EDIT);
drawArea.setEditMode(InteractionArea.EDITING);
messageLabel.setText("Click near centre of line");
// editScenario();
}
else if (label.equals("Move"))
{ System.out.println("Select component or interface to move");
drawArea.setDrawMode(InteractionArea.EDIT);
drawArea.setEditMode(InteractionArea.MOVING);
messageLabel.setText("Click on component or interface");
}
else if (label.equals("Delete"))
{ System.out.println("Select component/interface or connection to delete");
drawArea.setDrawMode(InteractionArea.EDIT);
drawArea.setEditMode(InteractionArea.DELETING);
}
else if (label.equals("Shrink"))
{ drawArea.shrink(1.2);
repaint();
}
}
}
private void printData()
{ PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(drawArea);
if (pj.printDialog())
{ try { pj.print(); }
catch (Exception ex) { ex.printStackTrace(); }
}
}
public void updateLabel(Point point) {
messageLabel.setText("Click occurred at coordinate ("
+ point.x + ","+point.y+").");
}
}