|
| 1 | +import java.awt.*; |
| 2 | +import java.awt.event.*; |
| 3 | +import javax.swing.*; |
| 4 | +import javax.swing.event.*; |
| 5 | + |
| 6 | +import javax.swing.border.*; |
| 7 | +import java.util.EventObject; |
| 8 | +import java.util.Vector; |
| 9 | +import java.util.StringTokenizer; |
| 10 | +import java.io.*; |
| 11 | + |
| 12 | +/****************************** |
| 13 | +* Copyright (c) 2003,2019 Kevin Lano |
| 14 | +* This program and the accompanying materials are made available under the |
| 15 | +* terms of the Eclipse Public License 2.0 which is available at |
| 16 | +* http://www.eclipse.org/legal/epl-2.0 |
| 17 | +* |
| 18 | +* SPDX-License-Identifier: EPL-2.0 |
| 19 | +* *****************************/ |
| 20 | + |
| 21 | +class TempInvEditDialog extends JDialog |
| 22 | +{ |
| 23 | + JPanel bottom; |
| 24 | + JButton okButton, cancelButton; |
| 25 | + TempInvDialogPanel dialogPanel; |
| 26 | + String defaultOp = ""; |
| 27 | + String defaultCond = ""; |
| 28 | + String defaultEffect = ""; |
| 29 | + boolean defaultisSys = true; |
| 30 | + boolean defaultisCrit = false; |
| 31 | + |
| 32 | + Vector newOp = new Vector(); |
| 33 | + String newCond; |
| 34 | + String newEffect; |
| 35 | + boolean newisSys; |
| 36 | + boolean newisCrit; |
| 37 | + |
| 38 | + TempInvEditDialog(JFrame owner) |
| 39 | + { super(owner, |
| 40 | + "Edit/Create Temporal Invariant", true); |
| 41 | + okButton = new JButton("Ok"); |
| 42 | + cancelButton = new JButton("Cancel"); |
| 43 | + ButtonHandler bHandler = new ButtonHandler(); |
| 44 | + okButton.addActionListener(bHandler); |
| 45 | + cancelButton.addActionListener(bHandler); |
| 46 | + |
| 47 | + bottom = new JPanel(); |
| 48 | + bottom.add(okButton); |
| 49 | + bottom.add(cancelButton); |
| 50 | + bottom.setBorder( |
| 51 | + BorderFactory.createEtchedBorder()); |
| 52 | + dialogPanel = new TempInvDialogPanel(); |
| 53 | + getContentPane().setLayout(new BorderLayout()); |
| 54 | + getContentPane().add(bottom, BorderLayout.SOUTH); |
| 55 | + getContentPane().add(dialogPanel, |
| 56 | + BorderLayout.CENTER); } |
| 57 | + |
| 58 | + public void setOldFields(Vector op, String c, |
| 59 | + String e, boolean isSys, |
| 60 | + boolean isCrit) |
| 61 | + { defaultOp = ""; |
| 62 | + for (int i = 0; i < op.size(); i++) |
| 63 | + { defaultOp = |
| 64 | + defaultOp + (String) op.get(i) + " "; } |
| 65 | + defaultCond = c; |
| 66 | + defaultEffect = e; |
| 67 | + defaultisSys = isSys; |
| 68 | + defaultisCrit = isCrit; |
| 69 | + dialogPanel.setOldFields(defaultOp, c,e,isSys,isCrit); } |
| 70 | + |
| 71 | + public void setFields(String op, String c, String e, |
| 72 | + boolean isSys, boolean isCrit) |
| 73 | + { StringTokenizer st = new StringTokenizer(op); |
| 74 | + newOp = new Vector(); |
| 75 | + |
| 76 | + if (op == null) |
| 77 | + { newOp = null; } |
| 78 | + else |
| 79 | + { while (st.hasMoreTokens()) |
| 80 | + { newOp.add((String) st.nextToken()); } |
| 81 | + } |
| 82 | + |
| 83 | + newCond = c; |
| 84 | + newEffect = e; |
| 85 | + newisSys = isSys; |
| 86 | + newisCrit = isCrit; } |
| 87 | + |
| 88 | + public Vector getOp() { return newOp; } |
| 89 | + |
| 90 | + public String getCond() { return newCond; } |
| 91 | + |
| 92 | + public String getEffect() { return newEffect; } |
| 93 | + |
| 94 | + public boolean isSystem() { return newisSys; } |
| 95 | + |
| 96 | + public boolean isCritical() { return newisCrit; } |
| 97 | + |
| 98 | + class ButtonHandler implements ActionListener |
| 99 | + { public void actionPerformed(ActionEvent ev) |
| 100 | + { JButton button = (JButton) ev.getSource(); |
| 101 | + String label = button.getText(); |
| 102 | + if ("Ok".equals(label)) |
| 103 | + { setFields(dialogPanel.getOp(), |
| 104 | + dialogPanel.getCond(), |
| 105 | + dialogPanel.getEffect(), |
| 106 | + dialogPanel.isSystem(), |
| 107 | + dialogPanel.isCritical()); } |
| 108 | + else |
| 109 | + { setFields(null, null, null, true, false); } |
| 110 | + dialogPanel.reset(); |
| 111 | + setVisible(false); |
| 112 | + } |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +class TempInvDialogPanel extends JPanel |
| 117 | +{ JLabel opLabel; |
| 118 | + JTextField opField; /* Modal ops */ |
| 119 | + JLabel condLabel; |
| 120 | + JTextField condField; |
| 121 | + JLabel effectLabel; |
| 122 | + JTextField effectField; |
| 123 | + |
| 124 | + JPanel envPanel; |
| 125 | + ButtonGroup bg1; |
| 126 | + JCheckBox systemInv; |
| 127 | + JCheckBox environmentInv; |
| 128 | + |
| 129 | + JPanel critPanel; |
| 130 | + ButtonGroup bg2; |
| 131 | + JCheckBox noncriticalInv; |
| 132 | + JCheckBox criticalInv; |
| 133 | + |
| 134 | + TempInvDialogPanel() |
| 135 | + { envPanel = new JPanel(); |
| 136 | + bg1 = new ButtonGroup(); |
| 137 | + systemInv = new JCheckBox("System", true); |
| 138 | + environmentInv = |
| 139 | + new JCheckBox("Environment"); |
| 140 | + bg1.add(systemInv); |
| 141 | + bg1.add(environmentInv); |
| 142 | + envPanel.add(systemInv); |
| 143 | + envPanel.add(environmentInv); |
| 144 | + envPanel.setBorder( |
| 145 | + BorderFactory.createTitledBorder( |
| 146 | + "System Requirement or Environment " + |
| 147 | + "Assumption?")); |
| 148 | + |
| 149 | + critPanel = new JPanel(); |
| 150 | + bg2 = new ButtonGroup(); |
| 151 | + noncriticalInv = |
| 152 | + new JCheckBox("Non-critical", true); |
| 153 | + criticalInv = |
| 154 | + new JCheckBox("Critical"); |
| 155 | + bg2.add(noncriticalInv); |
| 156 | + bg2.add(criticalInv); |
| 157 | + critPanel.add(noncriticalInv); |
| 158 | + critPanel.add(criticalInv); |
| 159 | + critPanel.setBorder( |
| 160 | + BorderFactory.createTitledBorder( |
| 161 | + "Critical (eg: Safety) or " + |
| 162 | + "Non-critical?")); |
| 163 | + |
| 164 | + opLabel = new JLabel("Modalities:"); |
| 165 | + opField = new JTextField(); |
| 166 | + condLabel = new JLabel("Assumption:"); |
| 167 | + condField = new JTextField(); |
| 168 | + effectLabel = new JLabel("Conclusion:"); |
| 169 | + effectField = new JTextField(); |
| 170 | + setBorder( |
| 171 | + BorderFactory.createTitledBorder( |
| 172 | + "Temporal invariant: " + |
| 173 | + "Assumption => Modalities(Conclusion)")); |
| 174 | + add(condLabel); |
| 175 | + add(condField); |
| 176 | + add(opLabel); |
| 177 | + add(opField); |
| 178 | + add(effectLabel); |
| 179 | + add(effectField); |
| 180 | + add(envPanel); |
| 181 | + add(critPanel); } |
| 182 | + |
| 183 | + public void setOldFields(String op, String c, |
| 184 | + String e, boolean isSys, |
| 185 | + boolean isCrit) |
| 186 | + { opField.setText(op); |
| 187 | + condField.setText(c); |
| 188 | + effectField.setText(e); |
| 189 | + systemInv.setSelected(isSys); |
| 190 | + criticalInv.setSelected(isCrit); } |
| 191 | + |
| 192 | + public Dimension getPreferredSize() |
| 193 | + { return new Dimension(410,250); } |
| 194 | + |
| 195 | + public Dimension getMinimumSize() |
| 196 | + { return new Dimension(410,250); } |
| 197 | + |
| 198 | + public void doLayout() |
| 199 | + { condLabel.setBounds(10,10,90,30); |
| 200 | + condField.setBounds(100,15,300,20); |
| 201 | + opLabel.setBounds(10,40,90,30); |
| 202 | + opField.setBounds(100,45,300,20); |
| 203 | + effectLabel.setBounds(10,70,90,30); |
| 204 | + effectField.setBounds(100,75,300,20); |
| 205 | + envPanel.setBounds(10,110,390,50); |
| 206 | + critPanel.setBounds(10,170,390,50); } |
| 207 | + |
| 208 | + |
| 209 | + public void reset() |
| 210 | + { opField.setText(""); |
| 211 | + condField.setText(""); |
| 212 | + effectField.setText(""); |
| 213 | + systemInv.setSelected(true); |
| 214 | + criticalInv.setSelected(false); } |
| 215 | + |
| 216 | + public String getOp() |
| 217 | + { return opField.getText(); } |
| 218 | + |
| 219 | + public String getCond() |
| 220 | + { return condField.getText(); } |
| 221 | + |
| 222 | + public String getEffect() |
| 223 | + { return effectField.getText(); } |
| 224 | + |
| 225 | + public boolean isSystem() |
| 226 | + { return systemInv.isSelected(); } |
| 227 | + |
| 228 | + public boolean isCritical() |
| 229 | + { return criticalInv.isSelected(); } |
| 230 | +} |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | + |
| 235 | + |
| 236 | + |
| 237 | + |
| 238 | + |
| 239 | + |
0 commit comments