1
package pipe.gui.widgets.cpn;
3
import dk.aau.cs.debug.Logger;
4
import dk.aau.cs.gui.Context;
5
import dk.aau.cs.model.tapn.Colored.*;
6
import dk.aau.cs.model.tapn.Colored.ExpressionSupport.ExprStringPosition;
7
import dk.aau.cs.model.tapn.Colored.Expressions.*;
8
import pipe.gui.CreateGui;
9
import pipe.gui.graphicElements.PetriNetObject;
10
import pipe.gui.graphicElements.Place;
11
import pipe.gui.graphicElements.cpn.ColoredInputArcComponent;
12
import pipe.gui.graphicElements.cpn.ColoredOutputArcComponent;
13
import pipe.gui.graphicElements.cpn.ColoredTransportArcComponent;
14
import pipe.gui.widgets.EscapableDialog;
17
import javax.swing.event.DocumentEvent;
18
import javax.swing.event.DocumentListener;
19
import javax.swing.text.MutableAttributeSet;
20
import javax.swing.text.SimpleAttributeSet;
21
import javax.swing.text.StyleConstants;
22
import javax.swing.text.StyledDocument;
24
import java.awt.event.*;
25
import java.util.Vector;
29
public class ArcExpressionPanel extends JPanel {
31
private JPanel exprPanel;
32
private JTextPane exprField;
33
private JScrollPane exprScrollPane;
35
private JPanel numberExprPanel;
36
private JSpinner numberExpressionJSpinner;
37
private JButton numberExpressionButton;
38
private JComboBox<ColorType> allExpressionComboBox;
39
private JSpinner allExpressionJSpinner;
40
private JButton allExpressionButton;
41
private JPanel arithmeticPanel;
42
private JTabbedPane transportArcPane;
44
private JButton additionButton;
45
private JButton addAdditionPlaceHolderButton;
46
private JButton subtractionButton;
47
private JButton scalarButton;
48
private JButton addColorExpressionButton;
49
private JSpinner scalarJSpinner;
51
private JPanel editPanel;
52
private ButtonGroup editButtonsGroup;
53
private JButton resetExprButton;
54
private JButton deleteExprSelectionButton;
55
private JButton editExprButton;
56
private JButton undoButton;
57
private JButton redoButton;
59
private ColoredInputArcComponent objectToBeEditedInput;
60
private ColoredOutputArcComponent objectToBeEditedOutput;
61
private ColoredTransportArcComponent objectToBeEditedTransport;
62
private boolean input;
63
private boolean transportArc;
64
private Context context;
65
private ArcExpression arcExpression;
66
private ExprStringPosition currentSelection = null;
67
private PetriNetObject petriNetObject;
68
private boolean transInput;
70
public ArcExpressionPanel( PetriNetObject objectToBeEdited, Context context, boolean transInput) {
71
this.context = context;
72
this.transInput = transInput;
74
if (objectToBeEdited instanceof ColoredTransportArcComponent) {
75
if (((ColoredTransportArcComponent) objectToBeEdited).getSource() instanceof Place) {
76
this.objectToBeEditedTransport = (ColoredTransportArcComponent)objectToBeEdited;
81
this.objectToBeEditedTransport = (ColoredTransportArcComponent)objectToBeEdited;
86
else if (objectToBeEdited instanceof ColoredInputArcComponent) {
87
this.objectToBeEditedInput = (ColoredInputArcComponent) objectToBeEdited;
90
} else if (objectToBeEdited instanceof ColoredOutputArcComponent) {
91
this.objectToBeEditedOutput = (ColoredOutputArcComponent) objectToBeEdited;
95
petriNetObject = objectToBeEdited;
98
undoButton.setEnabled(false);
99
redoButton.setEnabled(false);
100
editExprButton.setEnabled(false);
103
public ArcExpression getExpression() {return arcExpression;}
105
private void initComponents() {
110
private void initPanels() {
111
exprPanel = new JPanel(new GridBagLayout());
112
exprPanel.setBorder(BorderFactory.createTitledBorder("Arc Expressions"));
114
initNumberExpressionsPanel();
115
initArithmeticPanel();
118
GridBagConstraints gbc = new GridBagConstraints();
121
gbc.insets = new Insets(5, 10, 5, 10);
122
gbc.fill = GridBagConstraints.BOTH;
123
gbc.anchor = GridBagConstraints.WEST;
127
private void initExpr() {
129
if (((ColoredOutputArc) objectToBeEditedOutput.underlyingArc()).getExpression() != null) {
130
PlaceHolderArcExpression placeholderArc = new PlaceHolderArcExpression();
131
arcExpression = placeholderArc;
132
updateSelection(arcExpression);
133
parseExpression(((ColoredOutputArc) objectToBeEditedOutput.underlyingArc()).getExpression());
135
arcExpression = new PlaceHolderArcExpression();
136
exprField.setText(arcExpression.toString());
140
if (transportArc != true) {
141
ColoredInputArc inputArc = (ColoredInputArc) objectToBeEditedInput.underlyingTimedInputArc();
142
if (inputArc.getArcExpression() != null) {
143
PlaceHolderArcExpression placeholderArc = new PlaceHolderArcExpression();
144
arcExpression = placeholderArc;
145
updateSelection(arcExpression);
146
parseExpression(((ColoredInputArc) objectToBeEditedInput.underlyingTimedInputArc()).getArcExpression());
148
arcExpression = new PlaceHolderArcExpression();
149
exprField.setText(arcExpression.toString());
152
ColoredTransportArc transportArc = (ColoredTransportArc) objectToBeEditedTransport.underlyingTransportArc();
154
if (transportArc.getInputExpression() != null) {
155
PlaceHolderArcExpression placeHolderArcExpression = new PlaceHolderArcExpression();
156
arcExpression = placeHolderArcExpression;
157
updateSelection(arcExpression);
158
parseExpression(((ColoredTransportArc) objectToBeEditedTransport.underlyingTransportArc()).getInputExpression());
160
arcExpression = new PlaceHolderArcExpression();
161
exprField.setText(arcExpression.toString());
164
if (transportArc.getOutputExpression() != null) {
165
PlaceHolderArcExpression placeHolderArcExpression = new PlaceHolderArcExpression();
166
arcExpression = placeHolderArcExpression;
167
updateSelection(arcExpression);
168
parseExpression(((ColoredTransportArc) objectToBeEditedTransport.underlyingTransportArc()).getOutputExpression());
170
arcExpression = new PlaceHolderArcExpression();
171
exprField.setText(arcExpression.toString());
179
private void toggleColorExprButton(boolean enable) {
180
addColorExpressionButton.setEnabled(enable);
183
private void toggleArcExpressionButtons(boolean enable) {
184
allExpressionButton.setEnabled(enable);
185
numberExpressionButton.setEnabled(enable);
186
additionButton.setEnabled(enable);
187
subtractionButton.setEnabled(enable);
188
addAdditionPlaceHolderButton.setEnabled(enable);
189
scalarButton.setEnabled(enable);
192
private void toggleaddPlaceHolderButton(boolean enable) {
193
addAdditionPlaceHolderButton.setEnabled(enable);
196
private void toggleEnabledButtons() {
197
if (currentSelection.getObject() instanceof ColorExpression) {
198
toggleaddPlaceHolderButton(false);
199
toggleColorExprButton(true);
201
else if (currentSelection.getObject() instanceof AddExpression) {
202
toggleArcExpressionButtons(false);
203
toggleColorExprButton(false);
204
toggleaddPlaceHolderButton(true);
206
else if (currentSelection.getObject() instanceof ArcExpression) {
207
toggleArcExpressionButtons(true);
208
toggleColorExprButton(false);
209
toggleaddPlaceHolderButton(false);
214
private void updateSelection() {
215
int index = exprField.getCaretPosition();
216
ExprStringPosition position = arcExpression.objectAt(index);
217
Logger.log(position.getObject().toString());
218
if (position == null) {
222
exprField.select(position.getStart(), position.getEnd());
223
currentSelection = position;
225
if (currentSelection != null) {
226
toggleEnabledButtons();
228
//TODO: disable all expr buttons
231
//TODO: updateexprButtonsAccordingToSelection; line 573
234
private void updateSelection(Expression newSelection) {
235
exprField.setText(arcExpression.toString());
237
ExprStringPosition position;
238
if (arcExpression.containsPlaceHolder()) {
239
Expression ae = arcExpression.findFirstPlaceHolder();
240
position = arcExpression.indexOf(ae);
243
position = arcExpression.indexOf(newSelection);
246
exprField.select(position.getStart(), position.getEnd());
247
currentSelection = position;
249
if (currentSelection != null) {
250
toggleEnabledButtons();
257
private void deleteSelection() {
258
if (currentSelection != null) {
259
Expression replacement = null;
260
if (currentSelection.getObject() instanceof ArcExpression) {
261
replacement = getSpecificChildOfProperty(1, currentSelection.getObject());
263
else if (currentSelection.getObject() instanceof ArcExpression) {
264
replacement = new PlaceHolderColorExpression();
266
if (replacement != null) {
267
arcExpression = arcExpression.replace(currentSelection.getObject(), replacement);
268
updateSelection(replacement);
273
private ArcExpression getSpecificChildOfProperty(int number, Expression property) {
274
ExprStringPosition[] children = property.getChildren();
276
for (int i = 0; i < children.length; i++) {
277
Expression child = children[i].getObject();
278
if (child instanceof ArcExpression) {
281
if (count == number) {
282
return (ArcExpression) child;
286
return new PlaceHolderArcExpression();
289
private void addAllExpression() {
290
AllExpression allExpr = new AllExpression(allExpressionComboBox.getItemAt(allExpressionComboBox.getSelectedIndex()));
291
Integer value = (Integer)allExpressionJSpinner.getValue();
292
NumberOfExpression numbExpr = new NumberOfExpression(value, allExpr);
293
if (currentSelection.getObject() instanceof ArcExpression) {
294
arcExpression = arcExpression.replace(currentSelection.getObject(), numbExpr);
295
updateSelection(numbExpr);
299
private void addNumberExpression() {
300
Vector<ColorExpression> colorExprVec = new Vector();
301
colorExprVec.add(new PlaceHolderColorExpression());
302
Integer value = (Integer)numberExpressionJSpinner.getValue();
303
NumberOfExpression numbExpr;
304
if (currentSelection.getObject() instanceof NumberOfExpression) {
305
numbExpr = new NumberOfExpression(value, ((NumberOfExpression)currentSelection.getObject()).getColor());
307
numbExpr = new NumberOfExpression(value, colorExprVec);
309
arcExpression = arcExpression.replace(currentSelection.getObject(), numbExpr);
310
updateSelection(numbExpr);
313
private void parseExpression(ArcExpression expressionToParse) {
314
if (expressionToParse instanceof AddExpression) {
315
AddExpression addExpr = new AddExpression(((AddExpression) expressionToParse).getAddExpression());
316
arcExpression = arcExpression.replace(currentSelection.getObject(), addExpr);
317
updateSelection(addExpr);
319
else if(expressionToParse instanceof SubtractExpression) {
320
SubtractExpression subExpr = new SubtractExpression(((SubtractExpression) expressionToParse).getLeftExpression(), ((SubtractExpression) expressionToParse).getRightExpression());
321
arcExpression = arcExpression.replace(currentSelection.getObject(), subExpr);
322
updateSelection(subExpr);
324
else if (expressionToParse instanceof NumberOfExpression) {
325
NumberOfExpression expessionToParse = (NumberOfExpression) expressionToParse;
326
NumberOfExpression numbExpr = null;
327
if (expessionToParse.getAll() != null) {
328
numbExpr = new NumberOfExpression(((NumberOfExpression) expressionToParse).getNumber(), expessionToParse.getAll());
330
numbExpr = new NumberOfExpression(expessionToParse.getNumber(), expessionToParse.getColor());
332
arcExpression = arcExpression.replace(currentSelection.getObject(), numbExpr);
333
updateSelection(numbExpr);
337
@SuppressWarnings("Duplicates")
338
private void initEditPanel() {
339
editPanel = new JPanel(new GridBagLayout());
340
editPanel.setBorder(BorderFactory.createTitledBorder("Editing"));
341
editPanel.setPreferredSize(new Dimension(260, 190));
343
ButtonGroup editButtonsGroup = new ButtonGroup();
344
deleteExprSelectionButton = new JButton("Delete Selection");
345
resetExprButton = new JButton("Reset Expression");
346
undoButton = new JButton("Undo");
347
redoButton = new JButton("Redo");
348
editExprButton = new JButton("Edit Expression");
349
editExprButton.setEnabled(true);
351
//TODO: add tooltips to buttons
353
editButtonsGroup.add(deleteExprSelectionButton);
354
editButtonsGroup.add(resetExprButton);
355
editButtonsGroup.add(undoButton);
356
editButtonsGroup.add(redoButton);
357
editButtonsGroup.add(editExprButton);
359
deleteExprSelectionButton.addActionListener(new ActionListener() {
361
public void actionPerformed(ActionEvent actionEvent) {
366
resetExprButton.addActionListener(new ActionListener() {
368
public void actionPerformed(ActionEvent actionEvent) {
369
PlaceHolderArcExpression pHExpr = new PlaceHolderArcExpression();
370
arcExpression = arcExpression.replace(arcExpression, pHExpr);
371
updateSelection(pHExpr);
375
GridBagConstraints gbc = new GridBagConstraints();
376
gbc.insets = new Insets(5,5,5,5);
379
gbc.anchor = GridBagConstraints.WEST;
380
editPanel.add(undoButton, gbc);
383
gbc.insets = new Insets(0, 10, 0 , 0);
384
editPanel.add(redoButton, gbc);
386
gbc.insets = new Insets(0, 0, 5 , 0);
390
gbc.fill = GridBagConstraints.HORIZONTAL;
391
editPanel.add(deleteExprSelectionButton, gbc);
394
editPanel.add(resetExprButton, gbc);
397
editPanel.add(editExprButton, gbc);
399
//TODO: Actionlisteners
401
gbc = new GridBagConstraints();
404
gbc.fill = GridBagConstraints.VERTICAL;
406
exprPanel.add(editPanel, gbc);
410
private void initArithmeticPanel() {
411
arithmeticPanel = new JPanel(new GridBagLayout());
412
arithmeticPanel.setBorder(BorderFactory.createTitledBorder("Arithmetic Expressions"));
414
additionButton = new JButton("Addition");
415
addAdditionPlaceHolderButton = new JButton("Add Placeholder");
416
subtractionButton = new JButton("Subtraction");
417
scalarButton = new JButton("Scalar");
419
final Integer current = 1;
423
SpinnerNumberModel numberModelScalar = new SpinnerNumberModel(current, min, max, step);
425
scalarJSpinner = new JSpinner(numberModelScalar);
427
scalarJSpinner.setPreferredSize(new Dimension(50, 27));
428
scalarJSpinner.setPreferredSize(new Dimension(50, 27));
429
scalarJSpinner.setPreferredSize(new Dimension(50, 27));
431
additionButton.setPreferredSize(new Dimension(110, 30));
432
additionButton.setMinimumSize(new Dimension(110, 30));
433
additionButton.setMaximumSize(new Dimension(110, 30));
435
subtractionButton.setPreferredSize(new Dimension(110, 30));
436
subtractionButton.setMinimumSize(new Dimension(110, 30));
437
subtractionButton.setMaximumSize(new Dimension(110, 30));
439
scalarButton.setPreferredSize(new Dimension(110, 30));
440
scalarButton.setMinimumSize(new Dimension(110, 30));
441
scalarButton.setMaximumSize(new Dimension(110, 30));
443
addAdditionPlaceHolderButton.setPreferredSize(new Dimension(150, 30));
445
additionButton.addActionListener(new ActionListener() {
447
public void actionPerformed(ActionEvent actionEvent) {
448
AddExpression addExpr;
449
if (currentSelection.getObject() instanceof ArcExpression) {
450
Vector<ArcExpression> vExpr = new Vector();
451
vExpr.add((ArcExpression) currentSelection.getObject());
452
vExpr.add(new PlaceHolderArcExpression());
453
addExpr = new AddExpression(vExpr);
454
arcExpression = arcExpression.replace(currentSelection.getObject(), addExpr);
455
updateSelection(addExpr);
460
subtractionButton.addActionListener(new ActionListener() {
462
public void actionPerformed(ActionEvent actionEvent) {
463
SubtractExpression subExpr = null;
464
if (currentSelection.getObject() instanceof PlaceHolderArcExpression) {
465
subExpr = new SubtractExpression((PlaceHolderArcExpression)currentSelection.getObject(), new PlaceHolderArcExpression());
466
arcExpression = arcExpression.replace(currentSelection.getObject(), subExpr);
467
updateSelection(subExpr);
469
else if (currentSelection.getObject() instanceof SubtractExpression) {
470
subExpr = new SubtractExpression((SubtractExpression)currentSelection.getObject(), new PlaceHolderArcExpression());
471
arcExpression = arcExpression.replace(currentSelection.getObject(), subExpr);
472
updateSelection(subExpr);
474
else if (currentSelection.getObject() instanceof ScalarProductExpression) {
475
subExpr = new SubtractExpression((ScalarProductExpression)currentSelection.getObject(), new PlaceHolderArcExpression());
476
arcExpression = arcExpression.replace(currentSelection.getObject(), subExpr);
477
updateSelection(subExpr);
478
} else if (currentSelection.getObject() instanceof NumberOfExpression || currentSelection.getObject() instanceof AddExpression) {
479
subExpr = new SubtractExpression((ArcExpression) currentSelection.getObject(), new PlaceHolderArcExpression());
480
arcExpression = arcExpression.replace(currentSelection.getObject(), subExpr);
481
updateSelection(subExpr);
486
scalarButton.addActionListener(new ActionListener() {
488
public void actionPerformed(ActionEvent actionEvent) {
489
ScalarProductExpression scalarExpr = null;
490
Integer value = (Integer)scalarJSpinner.getValue();
491
if (currentSelection.getObject() instanceof ArcExpression) {
492
scalarExpr = new ScalarProductExpression(value, (ArcExpression) currentSelection.getObject());
493
arcExpression = arcExpression.replace(currentSelection.getObject(), scalarExpr);
494
updateSelection(scalarExpr);
499
addAdditionPlaceHolderButton.addActionListener(new ActionListener() {
501
public void actionPerformed(ActionEvent actionEvent) {
502
if (currentSelection.getObject() instanceof AddExpression) {
503
AddExpression addExpr = (AddExpression) currentSelection.getObject();
504
Vector<ArcExpression> vecExpr = addExpr.getAddExpression();
505
vecExpr.add(new PlaceHolderArcExpression());
506
addExpr = new AddExpression(vecExpr);
507
arcExpression = arcExpression.replace(currentSelection.getObject(), addExpr);
508
updateSelection(addExpr);
513
GridBagConstraints gbc = new GridBagConstraints();
516
gbc.insets = new Insets(5, 0,0, 0);
517
gbc.anchor = GridBagConstraints.WEST;
518
arithmeticPanel.add(additionButton, gbc);
521
arithmeticPanel.add(addAdditionPlaceHolderButton, gbc);
523
JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
524
separator.setEnabled(true);
525
gbc = new GridBagConstraints();
529
gbc.insets = new Insets(2, 0, 2, 0);
530
gbc.fill = GridBagConstraints.HORIZONTAL;
531
arithmeticPanel.add(separator,gbc);
535
arithmeticPanel.add(subtractionButton, gbc);
539
arithmeticPanel.add(scalarJSpinner, gbc);
542
arithmeticPanel.add(scalarButton, gbc);
544
gbc = new GridBagConstraints();
547
gbc.fill = GridBagConstraints.VERTICAL;
549
exprPanel.add(arithmeticPanel,gbc);
553
private void initNumberExpressionsPanel() {
554
numberExprPanel = new JPanel(new GridBagLayout());
555
numberExprPanel.setBorder(BorderFactory.createTitledBorder("Numerical Expressions"));
561
SpinnerNumberModel numberModelNumber = new SpinnerNumberModel(current, min, max, step);
562
SpinnerNumberModel numberModelAll = new SpinnerNumberModel(current, min, max, step);
564
numberExpressionJSpinner = new JSpinner(numberModelNumber);
565
numberExpressionButton = new JButton("Number Expression");
569
allExpressionComboBox = new JComboBox();
570
allExpressionJSpinner = new JSpinner(numberModelAll);
571
allExpressionButton = new JButton("All Expression");
573
addColorExpressionButton = new JButton("Edit Color Expression");
575
for (ColorType element : context.activeModel().parentNetwork().colorTypes()) {
576
allExpressionComboBox.addItem(element);
579
numberExpressionJSpinner.setPreferredSize(new Dimension(50, 27));
580
numberExpressionJSpinner.setMinimumSize(new Dimension(50, 27));
581
numberExpressionJSpinner.setMaximumSize(new Dimension(50, 27));
583
allExpressionJSpinner.setPreferredSize(new Dimension(50, 27));
584
allExpressionJSpinner.setMinimumSize(new Dimension(50, 27));
585
allExpressionJSpinner.setMaximumSize(new Dimension(50, 27));
587
allExpressionComboBox.setPreferredSize(new Dimension(150, 27));
588
allExpressionComboBox.setMinimumSize(new Dimension(150, 27));
589
allExpressionComboBox.setMaximumSize(new Dimension(150, 27));
591
numberExpressionButton.setPreferredSize(new Dimension(125, 27));
592
numberExpressionButton.setMinimumSize(new Dimension(125, 27));
593
numberExpressionButton.setMaximumSize(new Dimension(125, 27));
595
allExpressionButton.setPreferredSize(new Dimension(125, 27));
596
allExpressionButton.setMinimumSize(new Dimension(125, 27));
597
allExpressionButton.setMaximumSize(new Dimension(125, 27));
599
addColorExpressionButton.setMaximumSize(new Dimension(125, 27));
600
addColorExpressionButton.setMinimumSize(new Dimension(125, 27));
601
addColorExpressionButton.setPreferredSize(new Dimension(125, 27));
604
allExpressionButton.addActionListener(new ActionListener() {
606
public void actionPerformed(ActionEvent actionEvent) {
611
numberExpressionButton.addActionListener(new ActionListener() {
613
public void actionPerformed(ActionEvent actionEvent) {
614
addNumberExpression();
618
addColorExpressionButton.addActionListener(new ActionListener() {
620
public void actionPerformed(ActionEvent actionEvent) {
621
if (currentSelection.getObject() instanceof ColorExpression) {
622
ColorExpression colorExpr = (ColorExpression)currentSelection.getObject();
624
EscapableDialog guiDialog = new EscapableDialog(CreateGui.getApp(), "Edit Color Expression", true);
625
Container contentPane = guiDialog.getContentPane();
627
ColorExpressionDialogPanel cep = new ColorExpressionDialogPanel(guiDialog.getRootPane(), context, colorExpr);
628
contentPane.add(cep);
630
guiDialog.setResizable(true);
632
guiDialog.setLocationRelativeTo(null);
633
guiDialog.setVisible(true);
635
if (cep.clickedOK == true) {
636
ColorExpression expr = cep.getColorExpression();
637
arcExpression = arcExpression.replace(currentSelection.getObject(), expr);
638
updateSelection(expr);
642
JOptionPane.showMessageDialog(CreateGui.getApp(), "You have to select a colored placeholder location <+> or a color expression already added in the expression to add a color expression.",
643
"Error", JOptionPane.ERROR_MESSAGE);
648
GridBagConstraints gbc = new GridBagConstraints();
651
gbc.anchor = GridBagConstraints.WEST;
652
gbc.insets = new Insets(0, 0,5 ,5 );
653
numberExprPanel.add(allExpressionJSpinner, gbc);
656
gbc.fill = GridBagConstraints.WEST;
657
numberExprPanel.add(allExpressionComboBox, gbc);
660
numberExprPanel.add(allExpressionButton, gbc);
662
gbc = new GridBagConstraints();
665
gbc.anchor = GridBagConstraints.WEST;
666
gbc.insets = new Insets(0, 0,5 ,5 );
667
numberExprPanel.add(numberExpressionJSpinner, gbc);
670
gbc.fill = GridBagConstraints.HORIZONTAL;
671
numberExprPanel.add(numberExpressionButton, gbc);
673
JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
674
separator.setEnabled(true);
675
gbc = new GridBagConstraints();
679
gbc.insets = new Insets(2, 0, 2, 0);
680
gbc.fill = GridBagConstraints.HORIZONTAL;
681
numberExprPanel.add(separator,gbc);
683
gbc = new GridBagConstraints();
686
gbc.fill = GridBagConstraints.HORIZONTAL;
687
numberExprPanel.add(addColorExpressionButton, gbc);
689
gbc = new GridBagConstraints();
692
gbc.anchor = GridBagConstraints.EAST;
693
gbc.fill = GridBagConstraints.VERTICAL;
695
exprPanel.add(numberExprPanel, gbc);
698
private void initExprField () {
699
exprField = new JTextPane();
701
StyledDocument doc = exprField.getStyledDocument();
703
//Set alignment to be centered for all paragraphs
704
MutableAttributeSet standard = new SimpleAttributeSet();
705
StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER);
706
StyleConstants.setFontSize(standard, 14);
707
doc.setParagraphAttributes(0, 0, standard, true);
709
exprField.setBackground(java.awt.Color.white);
711
exprField.setEditable(false);
712
exprField.setToolTipText("Tooltip missing");
714
exprScrollPane = new JScrollPane(exprField);
715
exprScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
716
Dimension d = new Dimension(880, 80);
717
exprScrollPane.setPreferredSize(d);
718
exprScrollPane.setMinimumSize(d);
720
exprField.addMouseListener(new MouseAdapter() {
722
public void mouseReleased(MouseEvent e) {
723
if (!exprField.isEditable()) {
729
exprField.getDocument().addDocumentListener(new DocumentListener() {
731
public void insertUpdate(DocumentEvent documentEvent) {
732
//TODO: setSaveButtonsEnabled()
736
public void removeUpdate(DocumentEvent documentEvent) {
737
//TODO: setSaveButtonsEnabled()
741
public void changedUpdate(DocumentEvent documentEvent) {
742
//TODO: setSaveButtonsEnabled()
746
exprField.addKeyListener(new KeyAdapter() {
748
public void keyPressed(KeyEvent e) {
749
if (!exprField.isEditable()) {
750
//TODO: see line 1232 in CTLQueryDialog for impl example.
755
GridBagConstraints gbc = new GridBagConstraints();
758
gbc.fill = GridBagConstraints.BOTH;
760
exprPanel.add(exprScrollPane, gbc);