~cpn-gui/tapaal/typeChecker

« back to all changes in this revision

Viewing changes to src/pipe/gui/widgets/ColoredArcDialogPanel.java

  • Committer: Mark Glavind
  • Date: 2018-12-17 19:55:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1001.
  • Revision ID: mglavi14@student.aau.dk-20181217195519-5jidq02dtjknclth
WIP on colored arc editor panel

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import dk.aau.cs.gui.Context;
4
4
import dk.aau.cs.model.tapn.Colored.ColorType;
5
 
import dk.aau.cs.model.tapn.Colored.Expressions.ArcExpression;
 
5
import dk.aau.cs.model.tapn.Colored.ExpressionSupport.ExprStringPosition;
 
6
import dk.aau.cs.model.tapn.Colored.Expressions.*;
6
7
import dk.aau.cs.model.tapn.TimedPlace;
7
8
import pipe.gui.graphicElements.PetriNetObject;
8
9
import pipe.gui.graphicElements.cpn.ColoredInputArcComponent;
16
17
import javax.swing.text.StyleConstants;
17
18
import javax.swing.text.StyledDocument;
18
19
import java.awt.*;
19
 
import java.awt.event.KeyAdapter;
20
 
import java.awt.event.KeyEvent;
21
 
import java.awt.event.MouseAdapter;
22
 
import java.awt.event.MouseEvent;
 
20
import java.awt.event.*;
23
21
import java.util.ArrayList;
 
22
import java.util.Vector;
24
23
 
25
24
public class ColoredArcDialogPanel extends GuardDialogue {
26
25
 
34
33
    private JButton numberExpressionButton;
35
34
    private JLabel allExpressionLabel;
36
35
    private JComboBox<ColorType> allExpressionComboBox;
 
36
    private JSpinner allExpressionJSpinner;
37
37
    private JButton allExpressionButton;
38
38
    private JButton addColorExpressionButton;
39
39
 
55
55
    private Context context;
56
56
    private ArrayList<TimedPlace> places;
57
57
    private ArcExpression arcExpression;
 
58
    private ExprStringPosition currentSelection = null;
58
59
 
59
60
    public ColoredArcDialogPanel(JRootPane rootPane, PetriNetObject objectToBeEdited, Context context) {
60
61
        super(rootPane, objectToBeEdited);
61
62
        this.context = context;
62
 
        initComponents();
63
63
        if (objectToBeEdited instanceof ColoredInputArcComponent) {
64
64
            this.objectToBeEdited = (ColoredInputArcComponent) objectToBeEdited;
65
65
        }
 
66
        initComponents();
66
67
    }
67
68
 
68
69
    private void initComponents() {
70
71
    }
71
72
 
72
73
    private void updateSelection() {
73
 
 
 
74
        int index = exprField.getCaretPosition();
 
75
        ExprStringPosition position = arcExpression.objectAt(index);
 
76
 
 
77
        if (position == null) {
 
78
            return;
 
79
        }
 
80
 
 
81
        exprField.select(position.getStart(), position.getEnd());
 
82
        currentSelection = position;
 
83
 
 
84
        if (currentSelection != null) {
 
85
            //TODO: set enabled options according to reduction
 
86
        } {
 
87
            //TODO: disable all expr buttons
 
88
        }
 
89
 
 
90
        //TODO: updateexprButtonsAccordingToSelection; line 573
74
91
    }
75
92
 
76
93
    private void updateSelection(ArcExpression newSelection) {
 
94
        exprField.setText(arcExpression.toString());
 
95
 
 
96
        ExprStringPosition position;
 
97
        if (arcExpression.containsPlaceHolder()) {
 
98
            Expression ae = arcExpression.findFirstPlaceHolder();
 
99
            position = arcExpression.indexOf(ae);
 
100
        }
 
101
         else {
 
102
             position = arcExpression.indexOf(newSelection);
 
103
        }
 
104
 
 
105
        exprField.select(position.getStart(), position.getEnd());
 
106
         currentSelection = position;
 
107
 
 
108
         if (currentSelection != null) {
 
109
             //TODO: 595
 
110
         }
 
111
         else {
 
112
             //TODO::
 
113
         }
 
114
 
77
115
 
78
116
    }
79
117
 
99
137
 
100
138
    }
101
139
 
 
140
    private void addAllExpression() {
 
141
        AllExpression allExpr = new AllExpression(allExpressionComboBox.getItemAt(allExpressionComboBox.getSelectedIndex()));
 
142
        Integer value = (Integer)numberExpressionJSpinner.getValue();
 
143
        NumberOfExpression numbExpr = new NumberOfExpression(value, allExpr);
 
144
        arcExpression = arcExpression.replace(currentSelection.getObject(), numbExpr);
 
145
        updateSelection(numbExpr);
 
146
    }
 
147
 
 
148
    private void addNumberExpression() {
 
149
        Vector<ColorExpression> colorExprVec = new Vector();
 
150
        colorExprVec.add(new PlaceHolderColorExpression());
 
151
        Integer value = (Integer)allExpressionJSpinner.getValue();
 
152
        NumberOfExpression numbExpr = new NumberOfExpression(value, colorExprVec);
 
153
        arcExpression = arcExpression.replace(currentSelection.getObject(), numbExpr);
 
154
        updateSelection(numbExpr);
 
155
    }
 
156
 
102
157
    private void initEditPanel() {
103
158
        editPanel = new JPanel(new GridBagLayout());
104
159
        editPanel.setBorder(BorderFactory.createTitledBorder("Editing"));
167
222
        arithmeticButtonGroup.add(subtractionButton);
168
223
        arithmeticButtonGroup.add(scalarButton);
169
224
 
 
225
        additionButton.setPreferredSize(new Dimension(110, 30));
 
226
        subtractionButton.setPreferredSize(new Dimension(110, 30));
 
227
        scalarButton.setPreferredSize(new Dimension(110, 30));
 
228
 
 
229
        additionButton.addActionListener(new ActionListener() {
 
230
            @Override
 
231
            public void actionPerformed(ActionEvent actionEvent) {
 
232
                AddExpression addExpr = null;
 
233
                if (currentSelection.getObject() instanceof PlaceHolderArcExpression) {
 
234
                    addExpr = new AddExpression()
 
235
 
 
236
                }
 
237
            }
 
238
        });
 
239
 
170
240
        GridBagConstraints gbc = new GridBagConstraints();
171
241
        gbc.gridx = 0;
172
242
        gbc.gridy = 0;
195
265
        numberExpressionJSpinner = new JSpinner();
196
266
        numberExpressionButton = new JButton("Number Expression");
197
267
 
 
268
 
198
269
        allExpressionLabel = new JLabel("All Expression:");
199
270
        allExpressionComboBox = new JComboBox();
 
271
        allExpressionJSpinner = new JSpinner();
200
272
        allExpressionButton = new JButton("All Expression");
201
273
 
202
274
        addColorExpressionButton = new JButton("Add Color Expression");
209
281
        numberExpressionJSpinner.setMinimumSize(new Dimension(50, 27));
210
282
        numberExpressionJSpinner.setMaximumSize(new Dimension(50, 27));
211
283
 
 
284
        allExpressionJSpinner.setPreferredSize(new Dimension(50, 27));
 
285
        allExpressionJSpinner.setMinimumSize(new Dimension(50, 27));
 
286
        allExpressionJSpinner.setMaximumSize(new Dimension(50, 27));
 
287
 
212
288
        allExpressionComboBox.setPreferredSize(new Dimension(150, 27));
213
289
        allExpressionComboBox.setMinimumSize(new Dimension(150, 27));
214
290
        allExpressionComboBox.setMaximumSize(new Dimension(150, 27));
225
301
        addColorExpressionButton.setMaximumSize(new Dimension(125, 27));
226
302
        addColorExpressionButton.setMaximumSize(new Dimension(125, 27));
227
303
 
 
304
        allExpressionButton.addActionListener(new ActionListener() {
 
305
            @Override
 
306
            public void actionPerformed(ActionEvent actionEvent) {
 
307
                addAllExpression();
 
308
            }
 
309
        });
 
310
 
 
311
        numberExpressionButton.addActionListener(new ActionListener() {
 
312
            @Override
 
313
            public void actionPerformed(ActionEvent actionEvent) {
 
314
                addNumberExpression();
 
315
            }
 
316
        });
 
317
 
228
318
        GridBagConstraints gbc = new GridBagConstraints();
229
319
        gbc.gridx = 0;
230
320
        gbc.gridy = 0;
233
323
        numberExprPanel.add(allExpressionLabel, gbc);
234
324
 
235
325
        gbc.gridx = 1;
 
326
        numberExprPanel.add(allExpressionJSpinner, gbc);
 
327
 
 
328
        gbc.gridx = 2;
 
329
        gbc.fill = GridBagConstraints.HORIZONTAL;
236
330
        numberExprPanel.add(allExpressionComboBox, gbc);
237
331
 
238
 
        gbc.gridx = 2;
239
 
        gbc.fill = GridBagConstraints.HORIZONTAL;
 
332
        gbc.gridx = 3;
240
333
        numberExprPanel.add(allExpressionButton, gbc);
241
334
 
242
335
        gbc = new GridBagConstraints();
267
360
        exprPanel.add(numberExprPanel, gbc);
268
361
    }
269
362
 
270
 
    private void initExprField() {
 
363
    private void initExprField () {
271
364
        exprField = new JTextPane();
272
365
 
273
366
        StyledDocument doc = exprField.getStyledDocument();
279
372
        doc.setParagraphAttributes(0,0, standard,true);
280
373
 
281
374
        exprField.setBackground(java.awt.Color.white);
282
 
/*
 
375
 
283
376
        if (objectToBeEdited.getArcExpression() != null) {
284
377
            PlaceHolderArcExpression placeholderArc = new PlaceHolderArcExpression();
285
378
            arcExpression = placeholderArc;
289
382
            arcExpression = new PlaceHolderArcExpression();
290
383
            exprField.setText(arcExpression.toString());
291
384
        }
292
 
        */
 
385
 
293
386
        /*
294
387
        ArrayList<TimedPlace> places = new ArrayList(context.activeModel().places());
295
388
        ArrayList<TimedTransition> transitions = new ArrayList(context.activeModel().transitions());