51
52
import dk.aau.cs.model.tapn.TransportArc;
52
53
import dk.aau.cs.util.RequireException;
55
import static net.tapaal.swinghelpers.GridBagHelper.Anchor.*;
56
import static net.tapaal.swinghelpers.GridBagHelper.Fill.HORIZONTAL;
54
58
public class PlaceEditorPanel extends javax.swing.JPanel {
56
60
private final JRootPane rootPane;
58
62
private JCheckBox sharedCheckBox;
59
63
private JCheckBox makeNewSharedCheckBox;
60
private WidthAdjustingComboBox sharedPlacesComboBox;
64
private WidthAdjustingComboBox<TimedPlace> sharedPlacesComboBox;
62
66
private final TimedPlaceComponent place;
63
67
private final Context context;
78
82
setLayout(new java.awt.GridBagLayout());
80
84
initBasicPropertiesPanel();
81
GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
82
gridBagConstraints.gridx = 0;
83
gridBagConstraints.gridy = 0;
84
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
85
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
86
gridBagConstraints.insets = new Insets(5, 8, 0, 8);
85
GridBagConstraints gridBagConstraints = GridBagHelper.as(0,0, WEST, HORIZONTAL, new Insets(5, 8, 0, 8));
87
86
add(basicPropertiesPanel, gridBagConstraints);
89
88
initTimeInvariantPanel();
90
gridBagConstraints = new java.awt.GridBagConstraints();
91
gridBagConstraints.gridx = 0;
92
gridBagConstraints.gridy = 1;
93
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
94
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
95
gridBagConstraints.insets = new Insets(0, 8, 0, 8);
90
gridBagConstraints = GridBagHelper.as(0,1, WEST, HORIZONTAL, new Insets(0, 8, 0, 8));
96
91
add(timeInvariantPanel, gridBagConstraints);
99
gridBagConstraints = new java.awt.GridBagConstraints();
100
gridBagConstraints.gridx = 0;
101
gridBagConstraints.gridy = 2;
95
gridBagConstraints = GridBagHelper.as(0,2, new Insets(0, 8, 5, 8));
102
96
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
103
// gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
104
gridBagConstraints.insets = new Insets(0, 8, 5, 8);
97
//gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
105
98
add(buttonPanel, gridBagConstraints);
130
123
cancelButton.setPreferredSize(new java.awt.Dimension(100, 25));
131
124
cancelButton.addActionListener(evt -> exit());
133
gridBagConstraints = new java.awt.GridBagConstraints();
134
gridBagConstraints.gridx = 0;
135
gridBagConstraints.gridy = 0;
126
gridBagConstraints = GridBagHelper.as(0,0,EAST, new Insets(5, 5, 5, 5));
136
127
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
137
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
138
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
139
129
buttonPanel.add(cancelButton, gridBagConstraints);
143
gridBagConstraints = new java.awt.GridBagConstraints();
144
gridBagConstraints.gridx = 1;
145
gridBagConstraints.gridy = 0;
146
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
147
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
133
gridBagConstraints = GridBagHelper.as(1,0, WEST, new Insets(5, 5, 5, 5));
148
134
buttonPanel.add(okButton, gridBagConstraints);
150
136
setupInitialState();
227
GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
228
gridBagConstraints.gridx = 2;
229
gridBagConstraints.gridy = 1;
230
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
231
gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
213
GridBagConstraints gridBagConstraints = GridBagHelper.as(2,1, WEST, new Insets(0, 3, 3, 3));
232
214
basicPropertiesPanel.add(sharedCheckBox, gridBagConstraints);
234
216
makeSharedButton = new javax.swing.JButton();
250
232
makeNewShared = false;
253
gridBagConstraints = new java.awt.GridBagConstraints();
254
gridBagConstraints.gridx = 3;
255
gridBagConstraints.gridy = 1;
256
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
257
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
235
gridBagConstraints = GridBagHelper.as(3,1, WEST, new Insets(5, 5, 5, 5));
258
236
basicPropertiesPanel.add(makeSharedButton, gridBagConstraints);
260
238
nameLabel = new javax.swing.JLabel("Name:");
261
gridBagConstraints = new java.awt.GridBagConstraints();
262
gridBagConstraints.gridx = 0;
263
gridBagConstraints.gridy = 1;
264
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
265
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
239
gridBagConstraints = GridBagHelper.as(0,1, EAST, new Insets(3, 3, 3, 3));
266
240
basicPropertiesPanel.add(nameLabel, gridBagConstraints);
268
242
nameTextField = new javax.swing.JTextField();
283
257
markingLabel = new javax.swing.JLabel("Marking:");
284
gridBagConstraints = new java.awt.GridBagConstraints();
285
gridBagConstraints.gridx = 0;
286
gridBagConstraints.gridy = 2;
287
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
288
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
258
gridBagConstraints = GridBagHelper.as(0,2, EAST, new Insets(3, 3, 3, 3));
289
259
basicPropertiesPanel.add(markingLabel, gridBagConstraints);
291
// markingSpinner = new javax.swing.JSpinner();
292
// markingSpinner.setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
293
// markingSpinner.setPreferredSize(new Dimension(75,27));
294
261
markingSpinner = new CustomJSpinner(0, okButton);
295
gridBagConstraints = new java.awt.GridBagConstraints();
296
gridBagConstraints.gridx = 1;
297
gridBagConstraints.gridy = 2;
298
gridBagConstraints.anchor = GridBagConstraints.WEST;
299
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
262
gridBagConstraints = GridBagHelper.as(1,2, WEST, new Insets(3, 3, 3, 3));
300
263
basicPropertiesPanel.add(markingSpinner, gridBagConstraints);
302
265
attributesCheckBox = new javax.swing.JCheckBox("Show place name");
303
266
attributesCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
304
attributesCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
305
gridBagConstraints = new java.awt.GridBagConstraints();
306
gridBagConstraints.gridx = 1;
307
gridBagConstraints.gridy = 3;
308
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
309
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
267
attributesCheckBox.setMargin(new Insets(0, 0, 0, 0));
269
gridBagConstraints = GridBagHelper.as(1,3,WEST, new Insets(3, 3, 3, 3));
310
270
basicPropertiesPanel.add(attributesCheckBox, gridBagConstraints);
336
296
timeInvariantPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Age Invariant"));
338
298
invariantGroup = new JPanel(new GridBagLayout());
339
invRelationNormal = new JComboBox(new String[] { "<=", "<" });
340
invRelationConstant = new JComboBox(new String[] { "<=", "<" });
299
invRelationNormal = new JComboBox<>(new String[] { "<=", "<" });
300
invRelationConstant = new JComboBox<>(new String[] { "<=", "<" });
341
301
//invariantSpinner = new JSpinner(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
342
302
invariantSpinner = new CustomJSpinner(0, okButton);
343
303
invariantSpinner.addChangeListener(e -> {
354
GridBagConstraints gbc = new GridBagConstraints();
357
gbc.insets = new Insets(3, 3, 3, 3);
358
gbc.fill = GridBagConstraints.HORIZONTAL;
314
GridBagConstraints gbc = GridBagHelper.as(1,0, HORIZONTAL, new Insets(3, 3, 3, 3));
359
315
invariantGroup.add(invRelationNormal, gbc);
361
gbc = new GridBagConstraints();
364
gbc.insets = new Insets(3, 3, 3, 3);
365
gbc.fill = GridBagConstraints.HORIZONTAL;
366
invariantGroup.add(invRelationConstant, gbc);
368
// invariantSpinner.setMaximumSize(new Dimension(100, 30));
369
// invariantSpinner.setMinimumSize(new Dimension(230, 30));
370
//invariantSpinner.setPreferredSize(new Dimension(230, 30));
372
gbc = new GridBagConstraints();
375
gbc.insets = new Insets(3, 3, 3, 3);
317
gbc = GridBagHelper.as(1,1, HORIZONTAL, new Insets(3, 3, 3, 3));
318
invariantGroup.add(invRelationConstant, gbc);
320
gbc = GridBagHelper.as(2,0, new Insets(3, 3, 3, 3));
376
321
invariantGroup.add(invariantSpinner, gbc);
378
323
invariantInf = new JCheckBox("inf");
386
331
invariantSpinner.setEnabled(true);
387
332
invRelationNormal.setSelectedItem("<=");
388
333
if ((Integer) invariantSpinner.getValue() < 1) {
389
invRelationNormal.setModel(new DefaultComboBoxModel(new String[] { "<=" }));
334
invRelationNormal.setModel(new DefaultComboBoxModel<>(new String[] { "<=" }));
391
invRelationNormal.setModel(new DefaultComboBoxModel(new String[] { "<=", "<" }));
336
invRelationNormal.setModel(new DefaultComboBoxModel<>(new String[] { "<=", "<" }));
394
339
invRelationNormal.setEnabled(false);
395
340
invariantSpinner.setEnabled(false);
396
341
invRelationNormal.setSelectedItem("<");
397
invRelationNormal.setModel(new DefaultComboBoxModel(new String[] { "<" }));
342
invRelationNormal.setModel(new DefaultComboBoxModel<>(new String[] { "<" }));
401
gbc = new GridBagConstraints();
346
gbc = GridBagHelper.as(3,0);
404
347
invariantGroup.add(invariantInf, gbc);
406
349
Set<String> constants = context.network().getConstantNames();
407
350
String[] constantArray = constants.toArray(new String[constants.size()]);
408
351
Arrays.sort(constantArray, String.CASE_INSENSITIVE_ORDER);
410
invConstantsComboBox = new WidthAdjustingComboBox(maxNumberOfPlacesToShowAtOnce);
411
invConstantsComboBox.setModel(new DefaultComboBoxModel(constantArray));
353
invConstantsComboBox = new WidthAdjustingComboBox<>(maxNumberOfPlacesToShowAtOnce);
354
invConstantsComboBox.setModel(new DefaultComboBoxModel<>(constantArray));
412
355
// invConstantsComboBox = new JComboBox(constants.toArray());
413
356
invConstantsComboBox.setMaximumRowCount(20);
414
357
// invConstantsComboBox.setMinimumSize(new Dimension(100, 30));
443
383
btnGroup.add(normalInvRadioButton);
444
384
btnGroup.add(constantInvRadioButton);
446
gbc = new GridBagConstraints();
449
gbc.anchor = GridBagConstraints.WEST;
386
gbc = GridBagHelper.as(0,0, WEST);
450
387
invariantGroup.add(normalInvRadioButton, gbc);
452
gbc = new GridBagConstraints();
455
gbc.anchor = GridBagConstraints.WEST;
389
gbc = GridBagHelper.as(0,1, WEST);
456
390
invariantGroup.add(constantInvRadioButton, gbc);
458
392
TimeInvariant invariantToSet = place.getInvariant();
481
415
normalInvRadioButton.setSelected(true);
482
416
if (invariantToSet.upperBound() instanceof IntBound) {
483
417
if ((Integer) invariantSpinner.getValue() < 1) {
484
invRelationNormal.setModel(new DefaultComboBoxModel(new String[] { "<=" }));
418
invRelationNormal.setModel(new DefaultComboBoxModel<>(new String[] { "<=" }));
486
invRelationNormal.setModel(new DefaultComboBoxModel(new String[] { "<=", "<" }));
420
invRelationNormal.setModel(new DefaultComboBoxModel<>(new String[] { "<=", "<" }));
488
422
invariantSpinner.setValue(invariantToSet.upperBound().value());
489
423
invariantSpinner.setEnabled(true);
495
GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
496
gridBagConstraints.gridx = 1;
497
gridBagConstraints.gridy = 4;
498
gridBagConstraints.gridwidth = 2;
499
gridBagConstraints.anchor = GridBagConstraints.WEST;
500
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
429
GridBagConstraints gridBagConstraints = GridBagHelper.as(1,4,2, WEST, new Insets(3, 3, 3, 3));
501
430
timeInvariantPanel.add(invariantGroup, gridBagConstraints);
507
436
String selected = invRelationConstant.getSelectedItem().toString();
508
437
if (value == 0) {
509
invRelationConstant.setModel(new DefaultComboBoxModel(new String[] { "<=" }));
438
invRelationConstant.setModel(new DefaultComboBoxModel<>(new String[] { "<=" }));
511
invRelationConstant.setModel(new DefaultComboBoxModel(new String[] { "<=", "<" }));
440
invRelationConstant.setModel(new DefaultComboBoxModel<>(new String[] { "<=", "<" }));
513
442
invRelationConstant.setSelectedItem(selected);
535
464
invariantInf.setEnabled(false);
538
ChangeListener changeListener = new javax.swing.event.ChangeListener() {
539
public void stateChanged(javax.swing.event.ChangeEvent evt) {
540
JSpinner spinner = (JSpinner) evt.getSource();
541
JSpinner.NumberEditor numberEditor = ((JSpinner.NumberEditor) spinner.getEditor());
542
numberEditor.getTextField().setBackground(new Color(255, 255, 255));
543
spinner.removeChangeListener(this);
547
467
private void switchToNameTextField() {
548
468
basicPropertiesPanel.remove(sharedPlacesComboBox);
549
GridBagConstraints gbc = new java.awt.GridBagConstraints();
552
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
553
gbc.insets = new java.awt.Insets(3, 3, 3, 3);
554
basicPropertiesPanel.add(nameTextField, gbc);
469
GridBagConstraints gbc = GridBagHelper.as(1,1, HORIZONTAL, new Insets(3, 3, 3, 3));
470
basicPropertiesPanel.add(nameTextField, gbc);
555
472
basicPropertiesPanel.validate();
556
473
basicPropertiesPanel.repaint();
559
476
private void switchToNameDropDown() {
560
477
basicPropertiesPanel.remove(nameTextField);
561
GridBagConstraints gbc = new java.awt.GridBagConstraints();
564
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
565
gbc.insets = new java.awt.Insets(3, 3, 3, 3);
566
basicPropertiesPanel.add(sharedPlacesComboBox, gbc);
478
GridBagConstraints gbc = GridBagHelper.as(1,1, HORIZONTAL, new Insets(3, 3, 3, 3));
479
basicPropertiesPanel.add(sharedPlacesComboBox, gbc);
567
481
basicPropertiesPanel.validate();
568
482
basicPropertiesPanel.repaint();
587
501
private void setInvariantControlsBasedOn(TimeInvariant invariant) {
588
502
if(invariant.upperBound() instanceof ConstantBound){
589
503
constantInvRadioButton.setSelected(true);
590
invRelationConstant.setModel(new DefaultComboBoxModel(invariant.upperBound().value() == 0 ? new String[] { "<=" } : new String[] { "<", "<=" }));
504
invRelationConstant.setModel(new DefaultComboBoxModel<>(invariant.upperBound().value() == 0 ? new String[] { "<=" } : new String[] { "<", "<=" }));
591
505
invRelationConstant.setSelectedItem(invariant.isUpperNonstrict() ? "<=" : "<");
592
506
invRelationConstant.setEnabled(true);
593
507
invConstantsComboBox.setEnabled(true);
596
510
normalInvRadioButton.setSelected(true);
597
511
if(invariant.upperBound() instanceof InfBound){
598
invRelationNormal.setModel(new DefaultComboBoxModel(new String[] { "<" }));
512
invRelationNormal.setModel(new DefaultComboBoxModel<>(new String[] { "<" }));
599
513
invariantSpinner.setValue(0);
600
514
invRelationNormal.setEnabled(false);
601
515
invariantSpinner.setEnabled(false);
602
516
invariantInf.setSelected(true);
604
518
if(invariant.upperBound().value() == 0 && !invariantInf.isSelected()){
605
invRelationNormal.setModel(new DefaultComboBoxModel(new String[] { "<=" }));
519
invRelationNormal.setModel(new DefaultComboBoxModel<>(new String[] { "<=" }));
607
invRelationNormal.setModel(new DefaultComboBoxModel(new String[] { "<", "<=" }));
521
invRelationNormal.setModel(new DefaultComboBoxModel<>(new String[] { "<", "<=" }));
609
523
invRelationNormal.setSelectedItem(invariant.isUpperNonstrict() ? "<=" : "<");
610
524
invariantSpinner.setValue(invariant.upperBound().value());
692
JOptionPane.showMessageDialog(this, "A transition with the specified name already exists in one or more components, or the specified name is invalid.\n\nAcceptable names for places are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nNote that \"true\" and \"false\" are reserved keywords.", "Error", JOptionPane.OK_OPTION);
606
JOptionPane.showMessageDialog(this, "A transition with the specified name already exists in one or more components, or the specified name is invalid.\n\nAcceptable names for places are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nNote that \"true\" and \"false\" are reserved keywords.", "Error", JOptionPane.ERROR_MESSAGE);