3
3
import dk.aau.cs.debug.Logger;
4
4
import dk.aau.cs.gui.Context;
5
import dk.aau.cs.model.tapn.Colored.ColorType;
6
import dk.aau.cs.model.tapn.Colored.ColoredInputArc;
7
import dk.aau.cs.model.tapn.Colored.ColoredOutputArc;
5
import dk.aau.cs.model.tapn.Bound;
6
import dk.aau.cs.model.tapn.Colored.*;
7
import dk.aau.cs.model.tapn.Colored.Color;
8
8
import dk.aau.cs.model.tapn.Colored.ExpressionSupport.ExprStringPosition;
9
9
import dk.aau.cs.model.tapn.Colored.Expressions.*;
10
import dk.aau.cs.model.tapn.TimedPlace;
10
import dk.aau.cs.model.tapn.RatBound;
11
import dk.aau.cs.model.tapn.TimeInterval;
11
12
import pipe.gui.CreateGui;
12
13
import pipe.gui.graphicElements.PetriNetObject;
13
14
import pipe.gui.graphicElements.cpn.ColoredInputArcComponent;
14
15
import pipe.gui.graphicElements.cpn.ColoredOutputArcComponent;
15
import pipe.gui.graphicElements.tapn.TimedInputArcComponent;
17
17
import javax.swing.*;
18
18
import javax.swing.event.DocumentEvent;
47
49
private JButton addColorExpressionButton;
48
50
private JSpinner scalarJSpinner;
52
private JPanel timedGuardColorPanel;
53
private JComboBox<ColoredTimeInterval> activeTimeGuardColorsComboBox;
54
private JLabel activeTimeGuardsLabel;
55
private JButton removeActiveColorButton;
56
private JComboBox<ColoredTimeInterval> inactiveTimedGuardColorsCombobox;
57
private JButton addInactiveColorButton;
58
private JLabel inactiveTimeGuardsLabel;
50
60
private JPanel editPanel;
51
61
private ButtonGroup editButtonsGroup;
52
62
private JButton resetExprButton;
58
68
private ColoredInputArcComponent objectToBeEditedInput;
59
69
private ColoredOutputArcComponent objectToBeEditedOutput;
60
70
private boolean input;
61
private TimedInputArcComponent test;
62
71
private Context context;
63
private ArrayList<TimedPlace> places;
64
72
private ArcExpression arcExpression;
65
73
private ExprStringPosition currentSelection = null;
67
74
private PetriNetObject petriNetObject;
75
private ColoredTimeInterval activeTimeGuard;
69
77
public ColoredArcDialogPanel(JRootPane rootPane, PetriNetObject objectToBeEdited, Context context) {
70
78
super(rootPane, objectToBeEdited);
100
initializeColoredTimedGuard();
103
private void initializeColoredTimedGuard() { // we get all available colors from the color type of the connecting place and add them to inactive colors
104
// Only if there are no prior invariants set for this arc
106
List<ColoredTimeInterval> coloredTimeIntervalList;
107
coloredTimeIntervalList = ((ColoredInputArc)objectToBeEditedInput.underlyingTimedInputArc()).getColorTimeIntervals();
109
for (ColoredTimeInterval timeInterval : coloredTimeIntervalList) {
110
if (timeInterval.isActive()) {
111
activeTimeGuardColorsComboBox.addItem(timeInterval);
114
inactiveTimedGuardColorsCombobox.addItem(timeInterval);
118
activeTimeGuard = (ColoredTimeInterval) activeTimeGuardColorsComboBox.getSelectedItem();
93
121
private void initExpr() {
300
private void updateOldTimeInterval() { // we save the changes made in the gui to the time interval object associated with the color
301
boolean isLowerIncluded;
302
boolean isUpperIncluded;
303
int firstValue = Integer.parseInt(firstIntervalNumber.getValue().toString());
304
int secondValue = Integer.parseInt(secondIntervalNumber.getValue().toString());
305
Bound lower = new RatBound(BigDecimal.valueOf(firstValue));
308
if (inf.isSelected()) {
309
upper = Bound.Infinity;
311
upper = new RatBound(BigDecimal.valueOf(secondValue));
313
if (leftDelimiter.getSelectedItem().equals("["))
314
isLowerIncluded = true;
316
isLowerIncluded = false;
318
if (rightDelimiter.getSelectedItem().equals("]"))
319
isUpperIncluded = true;
321
isUpperIncluded = false;
323
for (int i = 0; i < activeTimeGuardColorsComboBox.getItemCount(); i++) {
324
if (activeTimeGuardColorsComboBox.getItemAt(i).equals(activeTimeGuard)) {
325
activeTimeGuardColorsComboBox.getItemAt(i).setLowerBound(lower);
326
activeTimeGuardColorsComboBox.getItemAt(i).setUpperBound(upper);
327
activeTimeGuardColorsComboBox.getItemAt(i).setIsLowerIncluded(isLowerIncluded);
328
activeTimeGuardColorsComboBox.getItemAt(i).setIsUpperIncluded(isUpperIncluded);
334
private void setNewTimeInterval() { // we update the gui for time intervals to reflect the time interval object assoicated with the new color selected
335
ColoredTimeInterval activeInterval = activeTimeGuardColorsComboBox.getItemAt(activeTimeGuardColorsComboBox.getSelectedIndex());
336
activeTimeGuard = activeInterval;
338
if (activeInterval != null) {
339
int lower = activeInterval.lowerBound().value();
340
int upper = activeInterval.upperBound().value();
341
boolean isUpperIncl = activeInterval.isUpperIncluded();
342
boolean isLowerIncl = activeInterval.isLowerIncluded();
344
SpinnerNumberModel firstNumberModel = new SpinnerNumberModel(lower, 0, Integer.MAX_VALUE, 1);
345
SpinnerNumberModel secondNumberModel = null;
346
if (upper == -1) { // -1 is equal to infinity bound
347
inf.setSelected(true);
348
secondIntervalNumber.setEnabled(false);
349
rightDelimiter.setEnabled(false);
350
secondNumberModel = new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1);
352
inf.setSelected(false);
353
secondIntervalNumber.setEnabled(true);
354
rightDelimiter.setEnabled(true);
355
secondNumberModel = new SpinnerNumberModel(upper, 0, Integer.MAX_VALUE, 1);
358
firstIntervalNumber.setModel(firstNumberModel);
359
secondIntervalNumber.setModel(secondNumberModel);
361
//TODO: Might be missing case where upper and lower are not numbers, but constants instead. see setNonColoredInitialState in GuardDialogue
364
leftDelimiter.setSelectedItem("[");
366
leftDelimiter.setSelectedItem("(");
369
rightDelimiter.setSelectedItem("]");
371
rightDelimiter.setSelectedItem(")");
272
377
private void initonOK() {
273
378
okButton.addActionListener(new ActionListener() {
275
380
public void actionPerformed(ActionEvent actionEvent) {
278
onOK(objectToBeEditedInput);
383
// onOK(objectToBeEditedInput);
281
onOK(objectToBeEditedOutput);
386
// onOK(objectToBeEditedOutput);
392
private List<ColoredTimeInterval> getCTIList() {
393
List<ColoredTimeInterval> ctiList = new ArrayList<ColoredTimeInterval>();
395
for (int i = 0; i < activeTimeGuardColorsComboBox.getItemCount(); i++) {
396
ctiList.add(activeTimeGuardColorsComboBox.getItemAt(i));
398
for (int i = 0; i < inactiveTimedGuardColorsCombobox.getItemCount(); i++) {
399
ctiList.add(inactiveTimedGuardColorsCombobox.getItemAt(i));
287
405
private void onOkColored() {
407
updateOldTimeInterval();
289
409
ColoredInputArc inputArc = (ColoredInputArc)objectToBeEditedInput.underlyingTimedInputArc();
290
410
inputArc.setExpression(arcExpression);
291
411
objectToBeEditedInput.setUnderlyingArc(inputArc);
292
412
((ColoredInputArc)((ColoredInputArcComponent)petriNetObject).underlyingTimedInputArc()).setExpression(arcExpression);
413
((ColoredInputArc)((ColoredInputArcComponent)petriNetObject).underlyingTimedInputArc()).setColorTimeIntervals(getCTIList());
295
416
ColoredOutputArc outputArc = (ColoredOutputArc)objectToBeEditedOutput.underlyingArc();
296
417
objectToBeEditedOutput.setUnderlyingArc(outputArc);
297
418
((ColoredOutputArc)((ColoredOutputArcComponent)petriNetObject).underlyingArc()).setExpression(arcExpression);
302
422
private void initPanels() {
303
423
exprPanel = new JPanel(new GridBagLayout());
304
424
exprPanel.setBorder(BorderFactory.createTitledBorder("Arc Expressions"));
426
initColoredTimedGuard();
307
429
initNumberExpressionsPanel();
673
795
exprPanel.add(numberExprPanel, gbc);
798
private void initColoredTimedGuard() {
799
timedGuardColorPanel = new JPanel(new GridBagLayout());
800
timedGuardColorPanel.setBorder(BorderFactory.createTitledBorder("Colors for Timed Guard"));
802
activeTimeGuardColorsComboBox = new JComboBox<ColoredTimeInterval>();
803
activeTimeGuardsLabel = new JLabel("Active time guards:");
804
removeActiveColorButton = new JButton("Remove time guard");
806
inactiveTimedGuardColorsCombobox = new JComboBox<ColoredTimeInterval>();
807
inactiveTimeGuardsLabel = new JLabel("Inactive time guards:");
808
addInactiveColorButton = new JButton("Add time guard");
811
Dimension dimComboBox = new Dimension(175, 25);
812
Dimension dimButton = new Dimension(125, 25);
814
activeTimeGuardColorsComboBox.setPreferredSize(dimComboBox);
815
inactiveTimedGuardColorsCombobox.setPreferredSize(dimComboBox);
816
addInactiveColorButton.setPreferredSize(dimButton);
817
removeActiveColorButton.setPreferredSize(dimButton);
819
addInactiveColorButton.addActionListener(new ActionListener() {
821
public void actionPerformed(ActionEvent actionEvent) {
822
ColoredTimeInterval selectedTimeInterval = inactiveTimedGuardColorsCombobox.getItemAt(inactiveTimedGuardColorsCombobox.getSelectedIndex());
823
selectedTimeInterval.setActive(true);
824
activeTimeGuardColorsComboBox.addItem(selectedTimeInterval);
825
inactiveTimedGuardColorsCombobox.removeItemAt(inactiveTimedGuardColorsCombobox.getSelectedIndex());
826
if (inactiveTimedGuardColorsCombobox.getItemCount() < 0) {
827
inactiveTimedGuardColorsCombobox.setSelectedIndex(0);
832
removeActiveColorButton.addActionListener(new ActionListener() {
834
public void actionPerformed(ActionEvent actionEvent) {
835
ColoredTimeInterval selectedTimeInterval = activeTimeGuardColorsComboBox.getItemAt(activeTimeGuardColorsComboBox.getSelectedIndex());
836
selectedTimeInterval.setActive(false);
837
activeTimeGuardColorsComboBox.removeItemAt(activeTimeGuardColorsComboBox.getSelectedIndex());
838
inactiveTimedGuardColorsCombobox.addItem(selectedTimeInterval);
842
activeTimeGuardColorsComboBox.addActionListener(new ActionListener() {
844
public void actionPerformed(ActionEvent actionEvent) {
845
// activeTimeGuardColorsComboBox.setSelectedIndex(activeTimeGuardColorsComboBox.getItemCount()-1);
847
Logger.log(activeTimeGuardColorsComboBox.getItemAt(activeTimeGuardColorsComboBox.getSelectedIndex()).getColor().getColorName());
848
ColoredTimeInterval selectedTimeInterval = activeTimeGuardColorsComboBox.getItemAt(activeTimeGuardColorsComboBox.getSelectedIndex());
849
if (selectedTimeInterval.getColor().getColorName().equals("*")) {
850
removeActiveColorButton.setEnabled(false);
852
removeActiveColorButton.setEnabled(true);
854
updateOldTimeInterval();
855
setNewTimeInterval();
861
GridBagConstraints gbc = new GridBagConstraints();
864
gbc.anchor = GridBagConstraints.WEST;
865
timedGuardColorPanel.add(inactiveTimeGuardsLabel, gbc);
868
timedGuardColorPanel.add(inactiveTimedGuardColorsCombobox, gbc);
871
gbc.anchor = GridBagConstraints.EAST;
872
gbc.insets = new Insets(5, 0, 5, 0);
873
timedGuardColorPanel.add(addInactiveColorButton, gbc);
876
gbc = new GridBagConstraints();
879
gbc.anchor = GridBagConstraints.WEST;
880
timedGuardColorPanel.add(activeTimeGuardsLabel, gbc);
883
timedGuardColorPanel.add(activeTimeGuardColorsComboBox, gbc);
886
gbc.insets = new Insets(5, 0, 5, 0);
887
gbc.anchor = GridBagConstraints.EAST;
888
timedGuardColorPanel.add(removeActiveColorButton, gbc);
892
gbc.insets = new Insets(5, 10, 5, 10);
893
gbc.fill = GridBagConstraints.BOTH;
894
gbc.anchor = GridBagConstraints.WEST;
895
add(timedGuardColorPanel, gbc);
676
898
private void initExprField () {
677
899
exprField = new JTextPane();