Newer
Older
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
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package ui.window;
import ui.syscams.*;
import ui.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
* Dialog for managing of SystemC-AMS DE Block
* Creation: 26/04/2018
* @version 1.0 26/04/2018
* @author Irina Kit Yan LEE
public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener, ListSelectionListener {
// private JTextField periodTextField;
// private String listPeriodString[];
// private JComboBox<String> periodComboBoxString;
private JPanel parametersMainPanel;
private JTextField nameStructTextField;
private JTextField valueStructTextField;
private JRadioButton constantStructRadioButton;
private String listTypeStructString[];
private JComboBox<String> typeStructComboBoxString;
private ArrayList<String> listTmpStruct;
private JList<String> structList;
private DefaultListModel<String> structListModel;
private boolean structBool = false;
private JTextField nameTemplateTextField;
private String listTypeTemplateString[];
private JComboBox<String> typeTemplateComboBoxString;
private JTextField nameTypedefTextField;
private String listTypeTypedefString[];
private JComboBox<String> typeTypedefComboBoxString;
private JButton addModifyTypedefButton;
private ArrayList<String> listTmpTypedef;
private JList<String> typedefList;
private DefaultListModel<String> typedefListModel;
private boolean typedefBool = false;
private JButton upButton, downButton, removeButton;
private JTextField nameFnTextField;
private JButton nameFnButton;
private SysCAMSBlockDE block;
public JDialogSysCAMSBlockDE(SysCAMSBlockDE block) {
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setAlwaysOnTop(true);
this.setResizable(false);
this.block = block;
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close");
getRootPane().getActionMap().put("close", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
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
public StringBuffer encode(String data) {
StringBuffer databuf = new StringBuffer(data);
StringBuffer buffer = new StringBuffer("");
int endline = 0;
int nb_arobase = 0;
int condition = 0;
for (int pos = 0; pos != data.length(); pos++) {
char c = databuf.charAt(pos);
switch (c) {
case '\n':
break;
case '\t':
break;
case '{':
buffer.append("{\n");
endline = 1;
nb_arobase++;
break;
case '}':
if (nb_arobase == 1) {
buffer.append("}\n");
endline = 0;
} else {
int i = nb_arobase;
while (i >= 1) {
buffer.append("\t");
i--;
}
buffer.append("}\n");
endline = 1;
}
nb_arobase--;
break;
case ';':
if (condition == 1) {
buffer.append(";");
} else {
buffer.append(";\n");
endline = 1;
}
break;
case ' ':
if (endline == 0) {
buffer.append(databuf.charAt(pos));
}
break;
case '(':
buffer.append("(");
condition = 1;
break;
case ')':
buffer.append(")");
condition = 0;
break;
default:
if (endline == 1) {
endline = 0;
int i = nb_arobase;
while (i >= 1) {
buffer.append("\t");
i--;
}
}
buffer.append(databuf.charAt(pos));
break;
}
}
return buffer;
}
public void dialog() {
JPanel mainPanel = new JPanel(new BorderLayout());
this.add(mainPanel);
JPanel attributesMainPanel = new JPanel();
if (block.getFather() != null) {
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.add("Attributes", attributesMainPanel);
tabbedPane.add("Parameters", parametersMainPanel);
tabbedPane.add("Method Code", codeMainPanel);
mainPanel.add(tabbedPane, BorderLayout.NORTH);
} else {
mainPanel.add(attributesMainPanel, BorderLayout.NORTH);
}
// --- Attributes ---//
attributesMainPanel.setLayout(new BorderLayout());
Box attributesBox = Box.createVerticalBox();
attributesBox.setBorder(BorderFactory.createTitledBorder("Setting DE block attributes"));
GridBagConstraints constraints = new GridBagConstraints();
JPanel attributesBoxPanel = new JPanel();
attributesBoxPanel.setFont(new Font("Helvetica", Font.PLAIN, 14));
constraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(15, 10, 5, 10), 0, 0);
gridBag.setConstraints(labelName, constraints);
attributesBoxPanel.add(labelName);
if (block.getValue().toString().equals("")) {
nameTextField = new JTextField(10);
} else {
nameTextField = new JTextField(block.getValue().toString(), 10);
constraints = new GridBagConstraints(1, 0, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(15, 10, 5, 10), 0, 0);
gridBag.setConstraints(nameTextField, constraints);
attributesBoxPanel.add(nameTextField);
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
// JLabel periodLabel = new JLabel("Period Tm : ");
// constraints = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
// new Insets(5, 10, 15, 10), 0, 0);
// gridBag.setConstraints(periodLabel, constraints);
// attributesBoxPanel.add(periodLabel);
//
// if (block.getPeriod() == -1) {
// periodTextField = new JTextField(10);
// } else {
// periodTextField = new JTextField("" + block.getPeriod(), 10);
// }
// constraints = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
// new Insets(5, 10, 15, 10), 0, 0);
// gridBag.setConstraints(periodTextField, constraints);
// attributesBoxPanel.add(periodTextField);
//
// listPeriodString = new String[3];
// listPeriodString[0] = "us";
// listPeriodString[1] = "ms";
// listPeriodString[2] = "s";
// periodComboBoxString = new JComboBox<String>(listPeriodString);
// if (block.getTime().equals("") || block.getTime().equals("us")) {
// periodComboBoxString.setSelectedIndex(0);
// } else if (block.getTime().equals("ms")) {
// periodComboBoxString.setSelectedIndex(1);
// } else if (block.getTime().equals("s")) {
// periodComboBoxString.setSelectedIndex(2);
// }
// periodComboBoxString.setActionCommand("time");
// periodComboBoxString.addActionListener(this);
// constraints = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
// new Insets(5, 10, 15, 10), 0, 0);
// gridBag.setConstraints(periodComboBoxString, constraints);
// attributesBoxPanel.add(periodComboBoxString);
/*GridBagLayout gridBag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
JPanel attributesBoxPanel = new JPanel();
attributesBoxPanel.setFont(new Font("Helvetica", Font.PLAIN, 14));
attributesBoxPanel.setLayout(gridBag);*/
JLabel labelClock = new JLabel("Clock : ");
constraints = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(15, 10, 5, 10), 0, 0);
gridBag.setConstraints(labelClock, constraints);
attributesBoxPanel.add(labelClock);
if (block.getValue().toString().equals("")) {
clockTextField = new JTextField(10);
} else {
clockTextField = new JTextField(block.getClockName().toString(), 10);
}
constraints = new GridBagConstraints(1, 1, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(15, 10, 5, 10), 0, 0);
gridBag.setConstraints(clockTextField, constraints);
attributesBoxPanel.add(clockTextField);
attributesMainPanel.add(attributesBox, BorderLayout.NORTH);
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
// --- Parameters ---//
parametersMainPanel.setLayout(new BorderLayout());
Box parametersBox = Box.createVerticalBox();
parametersBox.setBorder(BorderFactory.createTitledBorder("Setting TDF block parameters"));
JPanel blockPanel = new JPanel(new GridLayout(3, 1));
// Struct
JPanel structPanel = new JPanel();
structPanel.setFont(new Font("Helvetica", Font.PLAIN, 14));
GridBagLayout gridBagParameter = new GridBagLayout();
GridBagConstraints constraintParameter = new GridBagConstraints();
structPanel.setLayout(gridBagParameter);
TitledBorder border = new TitledBorder("Struct :");
border.setTitleJustification(TitledBorder.CENTER);
border.setTitlePosition(TitledBorder.TOP);
structPanel.setBorder(border);
JLabel nameParameterLabel = new JLabel("identifier");
constraintParameter = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
gridBagParameter.setConstraints(nameParameterLabel, constraintParameter);
structPanel.add(nameParameterLabel);
nameStructTextField = new JTextField();
constraintParameter = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
gridBagParameter.setConstraints(nameStructTextField, constraintParameter);
structPanel.add(nameStructTextField);
JLabel egalLabel = new JLabel("=");
constraintParameter = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
gridBagParameter.setConstraints(egalLabel, constraintParameter);
structPanel.add(egalLabel);
JLabel valueParameterLabel = new JLabel("value");
constraintParameter = new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
gridBagParameter.setConstraints(valueParameterLabel, constraintParameter);
structPanel.add(valueParameterLabel);
valueStructTextField = new JTextField();
constraintParameter = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
gridBagParameter.setConstraints(valueStructTextField, constraintParameter);
structPanel.add(valueStructTextField);
JLabel pointsLabel = new JLabel(":");
constraintParameter = new GridBagConstraints(3, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
gridBagParameter.setConstraints(pointsLabel, constraintParameter);
structPanel.add(pointsLabel);
JLabel constantLabel = new JLabel("const");
constraintParameter = new GridBagConstraints(4, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
gridBagParameter.setConstraints(constantLabel, constraintParameter);
structPanel.add(constantLabel);
constantStructRadioButton = new JRadioButton();
constantStructRadioButton.setActionCommand("Const");
constantStructRadioButton.setSelected(false);
constantStructRadioButton.addActionListener(this);
constraintParameter = new GridBagConstraints(4, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
gridBagParameter.setConstraints(constantStructRadioButton, constraintParameter);
structPanel.add(constantStructRadioButton);
JLabel typeParameterLabel = new JLabel("type");
constraintParameter = new GridBagConstraints(5, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
gridBagParameter.setConstraints(typeParameterLabel, constraintParameter);
structPanel.add(typeParameterLabel);
listTypeStructString = new String[6];
listTypeStructString[0] = "bool";
listTypeStructString[1] = "double";
listTypeStructString[2] = "float";
listTypeStructString[3] = "int";
listTypeStructString[4] = "long";
listTypeStructString[5] = "short";
typeStructComboBoxString = new JComboBox<String>(listTypeStructString);
typeStructComboBoxString.setSelectedIndex(0);
typeStructComboBoxString.addActionListener(this);
constraintParameter = new GridBagConstraints(5, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
gridBagParameter.setConstraints(typeStructComboBoxString, constraintParameter);
structPanel.add(typeStructComboBoxString);
JButton addModifyButton = new JButton("Add / Modify parameter");
addModifyButton.setActionCommand("Add_Modify_Struct");
addModifyButton.addActionListener(this);
constraintParameter = new GridBagConstraints(0, 2, 6, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
gridBagParameter.setConstraints(addModifyButton, constraintParameter);
structPanel.add(addModifyButton);
blockPanel.add(structPanel);
// Template
JPanel templatePanel = new JPanel();
templatePanel.setFont(new Font("Helvetica", Font.PLAIN, 14));
GridBagLayout templateGridBag = new GridBagLayout();
GridBagConstraints templateConstraint = new GridBagConstraints();
templatePanel.setLayout(templateGridBag);
TitledBorder templateBorder = new TitledBorder("Template :");
templateBorder.setTitleJustification(TitledBorder.CENTER);
templateBorder.setTitlePosition(TitledBorder.TOP);
templatePanel.setBorder(templateBorder);
JLabel nameTemplateLabel = new JLabel("identifier");
templateConstraint = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
templateGridBag.setConstraints(nameTemplateLabel, templateConstraint);
templatePanel.add(nameTemplateLabel);
nameTemplateTextField = new JTextField(block.getNameTemplate());
templateConstraint = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
templateGridBag.setConstraints(nameTemplateTextField, templateConstraint);
templatePanel.add(nameTemplateTextField);
//CHANGES
JLabel egalTemplateLabel = new JLabel("=");
templateConstraint = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
templateGridBag.setConstraints(egalTemplateLabel, templateConstraint);
templatePanel.add(egalTemplateLabel);
JLabel valueTemplateLabel = new JLabel("value");
templateConstraint = new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
templateGridBag.setConstraints(valueTemplateLabel, templateConstraint);
templatePanel.add(valueTemplateLabel);
valueTemplateTextField = new JTextField(block.getValueTemplate());
templateConstraint = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
templateGridBag.setConstraints(valueTemplateTextField, templateConstraint);
templatePanel.add(valueTemplateTextField);
//CHANGES
JLabel pointsTemplateLabel = new JLabel(":");
templateConstraint = new GridBagConstraints(3, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
templateGridBag.setConstraints(pointsTemplateLabel, templateConstraint);
templatePanel.add(pointsTemplateLabel);
JLabel typeTemplateLabel = new JLabel("type");
templateConstraint = new GridBagConstraints(4, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
templateGridBag.setConstraints(typeTemplateLabel, templateConstraint);
templatePanel.add(typeTemplateLabel);
listTypeTemplateString = new String[1];
listTypeTemplateString[0] = "int";
typeTemplateComboBoxString = new JComboBox<String>(listTypeTemplateString);
if (block.getTypeTemplate().equals("int") || block.getTypeTemplate().equals("")) {
typeTemplateComboBoxString.setSelectedIndex(0);
}
typeTemplateComboBoxString.addActionListener(this);
templateConstraint = new GridBagConstraints(4, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
new Insets(5, 10, 5, 10), 0, 0);
templateGridBag.setConstraints(typeTemplateComboBoxString, templateConstraint);
templatePanel.add(typeTemplateComboBoxString);
JButton OKButton = new JButton("OK");
OKButton.setActionCommand("OK");
OKButton.addActionListener(this);
templateConstraint = new GridBagConstraints(0, 2, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
templateGridBag.setConstraints(OKButton, templateConstraint);
templatePanel.add(OKButton);
blockPanel.add(templatePanel);
// Typedef
JPanel typedefPanel = new JPanel();
typedefPanel.setFont(new Font("Helvetica", Font.PLAIN, 14));
GridBagLayout typedefGridBag = new GridBagLayout();
GridBagConstraints typedefConstraint = new GridBagConstraints();
typedefPanel.setLayout(typedefGridBag);
TitledBorder typedefBorder = new TitledBorder("Typedef :");
typedefBorder.setTitleJustification(TitledBorder.CENTER);
typedefBorder.setTitlePosition(TitledBorder.TOP);
typedefPanel.setBorder(typedefBorder);
JLabel nameTypedefLabel = new JLabel("identifier");
typedefConstraint = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
typedefGridBag.setConstraints(nameTypedefLabel, typedefConstraint);
typedefPanel.add(nameTypedefLabel);
nameTypedefTextField = new JTextField();
if (block.getListTypedef().isEmpty()) {
nameTypedefTextField.setEditable(false);
} else {
nameTypedefTextField.setEditable(true);
}
typedefConstraint = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
typedefGridBag.setConstraints(nameTypedefTextField, typedefConstraint);
typedefPanel.add(nameTypedefTextField);
JLabel pointsTypedefLabel = new JLabel(":");
typedefConstraint = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
typedefGridBag.setConstraints(pointsTypedefLabel, typedefConstraint);
typedefPanel.add(pointsTypedefLabel);
JLabel typeTypedefLabel = new JLabel("type");
typedefConstraint = new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
typedefGridBag.setConstraints(typeTypedefLabel, typedefConstraint);
typedefPanel.add(typeTypedefLabel);
listTypeTypedefString = new String[1];
listTypeTypedefString[0] = "sc_dt::sc_int";
typeTypedefComboBoxString = new JComboBox<String>(listTypeTypedefString);
typeTypedefComboBoxString.setSelectedIndex(0);
if (block.getListTypedef().isEmpty()) {
typeTypedefComboBoxString.setEnabled(false);
} else {
typeTypedefComboBoxString.setEnabled(true);
}
typeTypedefComboBoxString.addActionListener(this);
typedefConstraint = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
typedefGridBag.setConstraints(typeTypedefComboBoxString, typedefConstraint);
typedefPanel.add(typeTypedefComboBoxString);
addModifyTypedefButton = new JButton("Add / Modify typedef");
addModifyTypedefButton.setActionCommand("Add_Modify_Typedef");
addModifyTypedefButton.addActionListener(this);
if (block.getListTypedef().isEmpty()) {
addModifyTypedefButton.setEnabled(false);
} else {
addModifyTypedefButton.setEnabled(true);
}
typedefConstraint = new GridBagConstraints(0, 2, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
typedefGridBag.setConstraints(addModifyTypedefButton, typedefConstraint);
typedefPanel.add(addModifyTypedefButton);
blockPanel.add(typedefPanel);
parametersBox.add(blockPanel);
parametersMainPanel.add(parametersBox, BorderLayout.WEST);
Box managingParametersBox = Box.createVerticalBox();
JPanel managingParameterBoxPanel = new JPanel(new GridLayout(3, 1));
managingParameterBoxPanel.setFont(new Font("Helvetica", Font.PLAIN, 14));
JPanel listStructPanel = new JPanel();
TitledBorder listStructBorder = new TitledBorder("Managing struct :");
listStructBorder.setTitleJustification(TitledBorder.CENTER);
listStructBorder.setTitlePosition(TitledBorder.TOP);
listStructPanel.setBorder(listStructBorder);
structListModel = block.getListStruct();
structList = new JList<String>(structListModel);
structList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
structList.setLayoutOrientation(JList.VERTICAL);
structList.setSelectedIndex(-1);
structList.setVisibleRowCount(5);
structList.addListSelectionListener(this);
JScrollPane scrollPane = new JScrollPane(structList);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(300, 100));
listStructPanel.add(scrollPane);
managingParameterBoxPanel.add(listStructPanel);
JPanel listTypedefPanel = new JPanel();
TitledBorder listTypedefBorder = new TitledBorder("Managing typedef :");
listTypedefBorder.setTitleJustification(TitledBorder.CENTER);
listTypedefBorder.setTitlePosition(TitledBorder.TOP);
listTypedefPanel.setBorder(listTypedefBorder);
typedefListModel = block.getListTypedef();
typedefList = new JList<String>(typedefListModel);
typedefList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
typedefList.setLayoutOrientation(JList.VERTICAL);
typedefList.setSelectedIndex(-1);
typedefList.setVisibleRowCount(5);
typedefList.addListSelectionListener(this);
JScrollPane typedefScrollPane = new JScrollPane(typedefList);
typedefScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
typedefScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
typedefScrollPane.setPreferredSize(new Dimension(300, 100));
listTypedefPanel.add(typedefScrollPane);
managingParameterBoxPanel.add(listTypedefPanel);
GridBagLayout buttonGridBag = new GridBagLayout();
GridBagConstraints buttonconstraints = new GridBagConstraints();
JPanel buttonPanel = new JPanel();
buttonPanel.setFont(new Font("Helvetica", Font.PLAIN, 14));
buttonPanel.setLayout(buttonGridBag);
upButton = new JButton("Up");
upButton.setActionCommand("Up");
upButton.setEnabled(false);
upButton.addActionListener(this);
buttonconstraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
buttonGridBag.setConstraints(upButton, buttonconstraints);
buttonPanel.add(upButton);
downButton = new JButton("Down");
downButton.setActionCommand("Down");
downButton.setEnabled(false);
downButton.addActionListener(this);
buttonconstraints = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 5, 10), 0, 0);
buttonGridBag.setConstraints(downButton, buttonconstraints);
buttonPanel.add(downButton);
removeButton = new JButton("Remove parameter");
removeButton.setActionCommand("Remove");
removeButton.setEnabled(false);
removeButton.addActionListener(this);
buttonconstraints = new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 15, 10), 0, 0);
buttonGridBag.setConstraints(removeButton, buttonconstraints);
buttonPanel.add(removeButton);
managingParameterBoxPanel.add(buttonPanel);
managingParametersBox.add(managingParameterBoxPanel);
parametersMainPanel.add(managingParametersBox, BorderLayout.EAST);
// --- ProcessCode ---//
codeMainPanel.setLayout(new BorderLayout());
Box codeBox = Box.createVerticalBox();
codeBox.setBorder(BorderFactory.createTitledBorder("Behavior function of DE block"));
JPanel codeBoxPanel = new JPanel(new BorderLayout());
GridBagLayout nameGridBag = new GridBagLayout();
GridBagConstraints nameConstraints = new GridBagConstraints();
JPanel namePanel = new JPanel();
namePanel.setFont(new Font("Helvetica", Font.PLAIN, 14));
namePanel.setLayout(nameGridBag);
JLabel nameFnLabel = new JLabel("Name of the method :");
nameConstraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 10, 5, 10), 0, 0);
nameGridBag.setConstraints(nameFnLabel, nameConstraints);
namePanel.add(nameFnLabel);
nameFnTextField = new JTextField(block.getNameFn(), 20);
nameConstraints = new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 10, 5, 10), 0, 0);
nameGridBag.setConstraints(nameFnTextField, nameConstraints);
namePanel.add(nameFnTextField);
nameFnButton.setActionCommand("Name_OK");
nameConstraints = new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 10, 5, 10), 0, 0);
nameGridBag.setConstraints(nameFnButton, nameConstraints);
namePanel.add(nameFnButton);
StringBuffer stringbuf = encode(block.getCode());
String beginString = stringbuf.toString();
finalString = beginString.replaceAll("\t}", "}");
codeTextArea = new JTextArea(finalString);
codeTextArea.setSize(100, 100);
codeTextArea.setTabSize(2);
codeTextArea.setFont(new Font("Arial", Font.PLAIN, 16));
codeTextArea.setLineWrap(true);
codeTextArea.setWrapStyleWord(true);
JScrollPane codeScrollPane = new JScrollPane(codeTextArea);
codeScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
codeScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
codeScrollPane.setPreferredSize(new Dimension(200, 300));
codeScrollPane.setBorder(new EmptyBorder(15, 10, 15, 10));
codeBoxPanel.add(codeScrollPane, BorderLayout.SOUTH);
codeMainPanel.add(codeBox, BorderLayout.PAGE_START);
JPanel downPanel = new JPanel(new FlowLayout());
JButton saveCloseButton = new JButton("Save and close");
saveCloseButton.setIcon(IconManager.imgic25);
saveCloseButton.setActionCommand("Save_Close");
saveCloseButton.addActionListener(this);
saveCloseButton.setPreferredSize(new Dimension(200, 30));
downPanel.add(saveCloseButton);
JButton cancelButton = new JButton("Cancel");
cancelButton.setIcon(IconManager.imgic27);
cancelButton.setActionCommand("Cancel");
cancelButton.addActionListener(this);
cancelButton.setPreferredSize(new Dimension(200, 30));
mainPanel.add(downPanel, BorderLayout.CENTER);
this.getRootPane().setDefaultButton(saveCloseButton);
}
public void actionPerformed(ActionEvent e) {
if ("Name_OK".equals(e.getActionCommand())) {
if (!nameFnTextField.getText().equals("")) {
codeTextArea.setText("void " + nameFnTextField.getText() + "() {\n\n}");
} else {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "This method has no name. Please add a name for this method.", "Warning !",
JOptionPane.WARNING_MESSAGE);
}
}
if (!(clockTextField.getText().isEmpty())) {
block.setClockName(clockTextField.getText());
}
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if (block.getFather() != null) {
if ("OK".equals(e.getActionCommand())) {
nameTypedefTextField.setEditable(true);
typeTypedefComboBoxString.setEnabled(true);
addModifyTypedefButton.setEnabled(true);
}
if ("Add_Modify_Struct".equals(e.getActionCommand())) {
listTmpStruct = new ArrayList<String>();
Boolean alreadyExist = false;
int alreadyExistId = -1;
String type = (String) typeStructComboBoxString.getSelectedItem();
String s = null;
Boolean valueBoolean = false, valueInteger = false, valueDouble = false, valueLong = false, nameEmpty = false;
if (nameStructTextField.getText().isEmpty()) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The name of struct is empty", "Warning !",
JOptionPane.WARNING_MESSAGE);
nameEmpty = true;
}
for (int i = 0; i < structListModel.getSize(); i++) {
if (nameStructTextField.getText().equals(structListModel.elementAt(i).split("\\s")[0])) {
alreadyExist = true;
alreadyExistId = i;
}
}
if (alreadyExist == false) {
try {
if (type.equals("bool")) {
Boolean.parseBoolean(valueStructTextField.getText());
} else if (type.equals("double")) {
Double.parseDouble(valueStructTextField.getText());
} else if (type.equals("float")) {
Float.parseFloat(valueStructTextField.getText());
} else if (type.equals("int")) {
Integer.parseInt(valueStructTextField.getText());
} else if (type.equals("long")) {
Long.parseLong(valueStructTextField.getText());
} else if (type.equals("short")) {
Short.parseShort(valueStructTextField.getText());
}
} catch (NumberFormatException e1) {
if (type.equals("bool")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Boolean", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueBoolean = true;
} else if (type.equals("double")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Double", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueInteger = true;
} else if (type.equals("float")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Float", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueInteger = true;
} else if (type.equals("int")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Integer", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueDouble = true;
} else if (type.equals("long")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Long", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueLong = true;
} else if (type.equals("short")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Short", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueLong = true;
}
}
if ((valueBoolean == false) && (valueInteger == false) && (valueDouble == false) && (valueLong == false) && (nameEmpty == false)) {
s = nameStructTextField.getText() + " = ";
if (type.equals("bool")) {
s = s + Boolean.parseBoolean(valueStructTextField.getText()) + " : ";
} else if (type.equals("double")) {
s = s + Double.parseDouble(valueStructTextField.getText()) + " : ";
} else if (type.equals("float")) {
s = s + Float.parseFloat(valueStructTextField.getText()) + " : ";
} else if (type.equals("int")) {
s = s + Integer.parseInt(valueStructTextField.getText()) + " : ";
} else if (type.equals("long")) {
s = s + Long.parseLong(valueStructTextField.getText()) + " : ";
} else if (type.equals("short")) {
s = s + Short.parseShort(valueStructTextField.getText()) + " : ";
}
if (constantStructRadioButton.isSelected()) {
s = s + "const " + type;
} else {
s = s + type;
}
structListModel.addElement(s);
listTmpStruct.add(s);
}
} else {
try {
if (type.equals("bool")) {
Boolean.parseBoolean(valueStructTextField.getText());
} else if (type.equals("double")) {
Double.parseDouble(valueStructTextField.getText());
} else if (type.equals("float")) {
Float.parseFloat(valueStructTextField.getText());
} else if (type.equals("int")) {
Integer.parseInt(valueStructTextField.getText());
} else if (type.equals("long")) {
Long.parseLong(valueStructTextField.getText());
} else if (type.equals("short")) {
Short.parseShort(valueStructTextField.getText());
}
} catch (NumberFormatException e1) {
if (type.equals("bool")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Boolean", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueBoolean = true;
} else if (type.equals("double")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Double", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueInteger = true;
} else if (type.equals("float")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Float", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueInteger = true;
} else if (type.equals("int")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Integer", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueDouble = true;
} else if (type.equals("long")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Long", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueLong = true;
} else if (type.equals("short")) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Short", "Warning !",
JOptionPane.WARNING_MESSAGE);
valueLong = true;
}
}
if ((valueBoolean == false) && (valueInteger == false) && (valueDouble == false) && (valueLong == false) && (nameEmpty == false)) {
s = nameStructTextField.getText() + " = ";
if (type.equals("bool")) {
s = s + Boolean.parseBoolean(valueStructTextField.getText()) + " : ";
} else if (type.equals("double")) {
s = s + Double.parseDouble(valueStructTextField.getText()) + " : ";
} else if (type.equals("float")) {
s = s + Float.parseFloat(valueStructTextField.getText()) + " : ";
} else if (type.equals("int")) {
s = s + Integer.parseInt(valueStructTextField.getText()) + " : ";
} else if (type.equals("long")) {
s = s + Long.parseLong(valueStructTextField.getText()) + " : ";
} else if (type.equals("short")) {
s = s + Short.parseShort(valueStructTextField.getText()) + " : ";
}
if (constantStructRadioButton.isSelected()) {
s = s + "const " + type;
} else {
s = s + type;
}
structListModel.setElementAt(s, alreadyExistId);
listTmpStruct.add(s);
}
}
}
if ("Add_Modify_Typedef".equals(e.getActionCommand())) {
listTmpTypedef = new ArrayList<String>();
Boolean alreadyExist = false;
int alreadyExistId = -1;
String type = (String) typeTypedefComboBoxString.getSelectedItem();
String s = null;
Boolean nameEmpty = false;
if (nameTypedefTextField.getText().isEmpty()) {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "The name of typedef is empty", "Warning !",
JOptionPane.WARNING_MESSAGE);
nameEmpty = true;
}
if (nameEmpty == false) {
for (int i = 0; i < typedefListModel.getSize(); i++) {
if (nameTypedefTextField.getText().equals(typedefListModel.elementAt(i).split("\\s")[0])) {
alreadyExist = true;
alreadyExistId = i;
}
}
if (alreadyExist == false) {
s = nameTypedefTextField.getText() + " : " + type;
typedefListModel.addElement(s);
listTmpTypedef.add(s);
} else {
s = nameTypedefTextField.getText() + " : " + type;
typedefListModel.setElementAt(s, alreadyExistId);
listTmpTypedef.add(s);
}
}
}
if ("Remove".equals(e.getActionCommand())) {
if (structBool == true) {
if (structListModel.getSize() >= 1) {
structListModel.remove(structList.getSelectedIndex());
}
}
if (typedefBool == true) {
if (typedefListModel.getSize() >= 1) {
typedefListModel.remove(typedefList.getSelectedIndex());
}
}
}
if ("Up".equals(e.getActionCommand())) {
if (structBool == true) {
if (structList.getSelectedIndex() >= 1) {
String sprev = structListModel.get(structList.getSelectedIndex()-1);
structListModel.remove(structList.getSelectedIndex()-1);
structListModel.add(structList.getSelectedIndex()+1, sprev);
} else {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "Cannot move the parameter up", "Warning !",
JOptionPane.WARNING_MESSAGE);
}
}
if (typedefBool == true) {
if (typedefList.getSelectedIndex() >= 1) {
String sprev = typedefListModel.get(typedefList.getSelectedIndex()-1);
typedefListModel.remove(typedefList.getSelectedIndex()-1);
typedefListModel.add(typedefList.getSelectedIndex()+1, sprev);
} else {
JDialog msg = new JDialog(this);
msg.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(msg, "Cannot move the parameter up", "Warning !",
JOptionPane.WARNING_MESSAGE);
}