|
| 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.io.*; |
| 10 | + |
| 11 | +/* Package: Class Diagram */ |
| 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 SInvEditDialog extends JDialog |
| 22 | +{ |
| 23 | + JPanel bottom; |
| 24 | + JButton okButton, cancelButton; |
| 25 | + SInvDialogPanel dialogPanel; |
| 26 | + |
| 27 | + String defaultEntity = ""; |
| 28 | + String defaultAssumption = ""; |
| 29 | + String defaultConclusion = ""; |
| 30 | + boolean defaultisSystem = true; |
| 31 | + boolean defaultisCritical = false; |
| 32 | + boolean defaultisBehaviour = true; |
| 33 | + boolean defaultOrdering = false; |
| 34 | + |
| 35 | + String newEntity; |
| 36 | + String newAssumption; |
| 37 | + String newConclusion; |
| 38 | + boolean newisSystem; |
| 39 | + boolean newisCritical; |
| 40 | + boolean newisBehaviour; |
| 41 | + boolean newOrdering; |
| 42 | + |
| 43 | + SInvEditDialog(JFrame owner) |
| 44 | + { super(owner, "Edit/Create Constraint", true); |
| 45 | + |
| 46 | + okButton = new JButton("Ok"); |
| 47 | + cancelButton = new JButton("Cancel"); |
| 48 | + ButtonHandler bHandler = new ButtonHandler(); |
| 49 | + okButton.addActionListener(bHandler); |
| 50 | + cancelButton.addActionListener(bHandler); |
| 51 | + |
| 52 | + bottom = new JPanel(); |
| 53 | + bottom.add(okButton); |
| 54 | + bottom.add(cancelButton); |
| 55 | + bottom.setBorder( |
| 56 | + BorderFactory.createEtchedBorder()); |
| 57 | + dialogPanel = new SInvDialogPanel(); |
| 58 | + getContentPane().setLayout(new BorderLayout()); |
| 59 | + getContentPane().add(bottom, BorderLayout.SOUTH); |
| 60 | + getContentPane().add(dialogPanel, |
| 61 | + BorderLayout.CENTER); |
| 62 | + InvSizeHandler sh = new InvSizeHandler(dialogPanel); |
| 63 | + addComponentListener(sh); |
| 64 | + } |
| 65 | + |
| 66 | + public void setOldFields(String e, String a, String cl, |
| 67 | + boolean isSys, boolean isCrit, boolean isOrd) |
| 68 | + { defaultEntity = e; |
| 69 | + defaultAssumption = a; |
| 70 | + defaultConclusion = cl; |
| 71 | + defaultisSystem = isSys; |
| 72 | + defaultisCritical = isCrit; |
| 73 | + defaultOrdering = isOrd; |
| 74 | + dialogPanel.setOldFields(e,a,cl,isSys,isCrit,isOrd); |
| 75 | + } |
| 76 | + |
| 77 | + public void setFields(String e, String a, String cl, |
| 78 | + boolean isSys, boolean isCrit, |
| 79 | + boolean isBehav, boolean isOrd) |
| 80 | + { newEntity = e; |
| 81 | + newAssumption = a; |
| 82 | + newConclusion = cl; |
| 83 | + newisSystem = isSys; |
| 84 | + newisCritical = isCrit; |
| 85 | + newisBehaviour = isBehav; |
| 86 | + newOrdering = isOrd; |
| 87 | + } |
| 88 | + |
| 89 | + public String getEntity() |
| 90 | + { return newEntity; } |
| 91 | + |
| 92 | + public String getAssumption() |
| 93 | + { return newAssumption; } |
| 94 | + |
| 95 | + public String getConclusion() |
| 96 | + { return newConclusion; } |
| 97 | + |
| 98 | + public boolean isSystem() |
| 99 | + { return newisSystem; } |
| 100 | + |
| 101 | + public boolean isCritical() |
| 102 | + { return newisCritical; } |
| 103 | + |
| 104 | + public boolean isBehaviour() |
| 105 | + { return newisBehaviour; } |
| 106 | + |
| 107 | + public boolean isOrdered() |
| 108 | + { return newOrdering; } |
| 109 | + |
| 110 | + class ButtonHandler implements ActionListener |
| 111 | + { public void actionPerformed(ActionEvent ev) |
| 112 | + { JButton button = (JButton) ev.getSource(); |
| 113 | + String label = button.getText(); |
| 114 | + if ("Ok".equals(label)) |
| 115 | + { setFields(dialogPanel.getEntity(), dialogPanel.getAssump(), |
| 116 | + dialogPanel.getConc(), |
| 117 | + dialogPanel.isSystem(), |
| 118 | + dialogPanel.isCritical(), |
| 119 | + dialogPanel.isBehaviour(), dialogPanel.isOrdered()); } |
| 120 | + else |
| 121 | + { setFields(null,null,null,true,false,true,false); } |
| 122 | + dialogPanel.reset(); |
| 123 | + setVisible(false); |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + class InvSizeHandler implements ComponentListener |
| 128 | + { SInvDialogPanel panel; |
| 129 | + |
| 130 | + InvSizeHandler(SInvDialogPanel p) |
| 131 | + { panel = p; } |
| 132 | + |
| 133 | + public void componentResized(ComponentEvent e) |
| 134 | + { panel.resize(); } |
| 135 | + |
| 136 | + public void componentMoved(ComponentEvent e) { } |
| 137 | + |
| 138 | + public void componentShown(ComponentEvent e) { } |
| 139 | + |
| 140 | + public void componentHidden(ComponentEvent e) { } |
| 141 | + } |
| 142 | + |
| 143 | +} |
| 144 | + |
| 145 | + |
| 146 | +class SInvDialogPanel extends JPanel |
| 147 | +{ JLabel entityLabel; |
| 148 | + JTextField entityField; |
| 149 | + JLabel assumpLabel; |
| 150 | + JTextArea assumpField; |
| 151 | + JLabel concLabel; |
| 152 | + JTextArea concField; |
| 153 | + |
| 154 | + JPanel envPanel; |
| 155 | + ButtonGroup bg1; |
| 156 | + JCheckBox systemInv; |
| 157 | + JCheckBox environmentInv; |
| 158 | + |
| 159 | + JPanel critPanel; |
| 160 | + ButtonGroup bg2; |
| 161 | + JCheckBox noncriticalInv; |
| 162 | + JCheckBox criticalInv; |
| 163 | + |
| 164 | + JPanel behavPanel; |
| 165 | + ButtonGroup bg3; |
| 166 | + JCheckBox behaviourInv; |
| 167 | + JCheckBox preconditionInv; |
| 168 | + |
| 169 | + JPanel orderPanel; |
| 170 | + ButtonGroup bg4; |
| 171 | + JCheckBox orderInv; |
| 172 | + JCheckBox noorderInv; |
| 173 | + |
| 174 | + JScrollPane scroller1, scroller2; |
| 175 | + |
| 176 | + |
| 177 | + SInvDialogPanel() |
| 178 | + { entityLabel = new JLabel("Entity (context):"); |
| 179 | + entityField = new JTextField(30); |
| 180 | + entityField.setToolTipText("The class which the constraint operates on, or leave blank if no class"); |
| 181 | + |
| 182 | + assumpLabel = new JLabel("Assumption:"); |
| 183 | + assumpField = new JTextArea(30,6); |
| 184 | + assumpField.setToolTipText("If assumption is true, the conclusion is (expected to be) true"); |
| 185 | + assumpField.setLineWrap(true); |
| 186 | + concLabel = new JLabel("Conclusion:"); |
| 187 | + concField = new JTextArea(30,10); |
| 188 | + concField.setLineWrap(true); |
| 189 | + |
| 190 | + envPanel = new JPanel(); |
| 191 | + bg1 = new ButtonGroup(); |
| 192 | + systemInv = new JCheckBox("System", true); |
| 193 | + environmentInv = |
| 194 | + new JCheckBox("Environment"); |
| 195 | + bg1.add(systemInv); |
| 196 | + bg1.add(environmentInv); |
| 197 | + envPanel.add(systemInv); |
| 198 | + envPanel.add(environmentInv); |
| 199 | + envPanel.setBorder( |
| 200 | + BorderFactory.createTitledBorder( |
| 201 | + "System Requirement or Environment " + |
| 202 | + "Assumption?")); |
| 203 | + |
| 204 | + critPanel = new JPanel(); |
| 205 | + bg2 = new ButtonGroup(); |
| 206 | + noncriticalInv = |
| 207 | + new JCheckBox("Non-critical", true); |
| 208 | + criticalInv = |
| 209 | + new JCheckBox("Critical"); |
| 210 | + bg2.add(noncriticalInv); |
| 211 | + bg2.add(criticalInv); |
| 212 | + critPanel.add(noncriticalInv); |
| 213 | + critPanel.add(criticalInv); |
| 214 | + critPanel.setBorder( |
| 215 | + BorderFactory.createTitledBorder( |
| 216 | + "Critical (eg: Safety) or " + |
| 217 | + "Non-critical?")); |
| 218 | + |
| 219 | + behavPanel = new JPanel(); |
| 220 | + bg3 = new ButtonGroup(); |
| 221 | + behaviourInv = |
| 222 | + new JCheckBox("Update code", true); |
| 223 | + preconditionInv = |
| 224 | + new JCheckBox("Preconditions"); |
| 225 | + bg3.add(behaviourInv); |
| 226 | + bg3.add(preconditionInv); |
| 227 | + behavPanel.add(behaviourInv); |
| 228 | + behavPanel.add(preconditionInv); |
| 229 | + behavPanel.setBorder( |
| 230 | + BorderFactory.createTitledBorder( |
| 231 | + "Generate update or precondition " + |
| 232 | + "code?")); |
| 233 | + |
| 234 | + orderPanel = new JPanel(); |
| 235 | + bg4 = new ButtonGroup(); |
| 236 | + orderInv = |
| 237 | + new JCheckBox("Ordered (ascending)"); |
| 238 | + noorderInv = |
| 239 | + new JCheckBox("Unordered", true); |
| 240 | + bg4.add(orderInv); |
| 241 | + bg4.add(noorderInv); |
| 242 | + orderPanel.add(orderInv); |
| 243 | + orderPanel.add(noorderInv); |
| 244 | + orderPanel.setBorder( |
| 245 | + BorderFactory.createTitledBorder( |
| 246 | + "Ordered iteration over entity?")); |
| 247 | + |
| 248 | + setBorder( |
| 249 | + BorderFactory.createTitledBorder( |
| 250 | + "Constraint on Entity: " + |
| 251 | + "Assumption => Conclusion")); |
| 252 | + |
| 253 | + add(entityLabel); |
| 254 | + add(entityField); |
| 255 | + |
| 256 | + add(assumpLabel); |
| 257 | + scroller1 = new JScrollPane(assumpField, |
| 258 | + JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, |
| 259 | + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
| 260 | + scroller1.setPreferredSize(new Dimension(300,65)); |
| 261 | + add(scroller1); |
| 262 | + // add(assumpField); |
| 263 | + add(concLabel); |
| 264 | + |
| 265 | + scroller2 = new JScrollPane(concField, |
| 266 | + JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, |
| 267 | + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
| 268 | + scroller2.setPreferredSize(new Dimension(300,65)); |
| 269 | + add(scroller2); |
| 270 | + |
| 271 | + add(envPanel); |
| 272 | + add(critPanel); |
| 273 | + add(behavPanel); |
| 274 | + add(orderPanel); |
| 275 | + } |
| 276 | + |
| 277 | + public void setOldFields(String e, String a, String cl, |
| 278 | + boolean isSys, boolean isCrit, boolean isOrd) |
| 279 | + { entityField.setText(e); |
| 280 | + assumpField.setText(a); |
| 281 | + concField.setText(cl); |
| 282 | + systemInv.setSelected(isSys); |
| 283 | + criticalInv.setSelected(isCrit); |
| 284 | + orderInv.setSelected(isOrd); |
| 285 | + } |
| 286 | + |
| 287 | + public Dimension getPreferredSize() |
| 288 | + { return new Dimension(390,500); } |
| 289 | + |
| 290 | + public Dimension getMinimumSize() |
| 291 | + { return new Dimension(390,500); } |
| 292 | + |
| 293 | + public Dimension getMaximumSize() |
| 294 | + { return new Dimension(390,500); } |
| 295 | + |
| 296 | + public void doLayout() |
| 297 | + { int labelwidth = 80; |
| 298 | + int fieldwidth = 270; |
| 299 | + |
| 300 | + entityLabel.setBounds(10,30,90,30); |
| 301 | + entityField.setBounds(100,35,270,30); |
| 302 | + |
| 303 | + assumpLabel.setBounds(10,70,90,30); |
| 304 | + scroller1.setBounds(100,75,270,80); |
| 305 | + concLabel.setBounds(10,160,90,30); |
| 306 | + scroller2.setBounds(100,165,270,80); |
| 307 | + envPanel.setBounds(10,260,360,50); |
| 308 | + critPanel.setBounds(10,320,360,50); |
| 309 | + behavPanel.setBounds(10,380,360,50); |
| 310 | + orderPanel.setBounds(10,440,360,50); |
| 311 | + } |
| 312 | + |
| 313 | + public void resize() |
| 314 | + { int newwidth = getWidth(); |
| 315 | + |
| 316 | + // entityLabel.setBounds(10,30,90,30); |
| 317 | + // entityField.setBounds(100,35,270,30); |
| 318 | + |
| 319 | + // assumpLabel.setBounds(10,70,90,30); |
| 320 | + assumpField.setSize(newwidth - 150, 6); |
| 321 | + scroller1.setBounds(100,75,newwidth - 150,80); |
| 322 | + // concLabel.setBounds(10,160,90,30); |
| 323 | + concField.setSize(newwidth - 150, 10); |
| 324 | + scroller2.setBounds(100,165,newwidth - 150,80); |
| 325 | + // envPanel.setBounds(10,260,360,50); |
| 326 | + // critPanel.setBounds(10,320,360,50); |
| 327 | + // behavPanel.setBounds(10,380,360,50); |
| 328 | + // orderPanel.setBounds(10,440,360,50); |
| 329 | + } |
| 330 | + |
| 331 | + |
| 332 | + public void reset() |
| 333 | + { assumpField.setText(""); |
| 334 | + concField.setText(""); |
| 335 | + systemInv.setSelected(true); |
| 336 | + noncriticalInv.setSelected(true); |
| 337 | + behaviourInv.setSelected(true); |
| 338 | + orderInv.setSelected(false); |
| 339 | + } |
| 340 | + |
| 341 | + public String getEntity() |
| 342 | + { return entityField.getText(); } |
| 343 | + |
| 344 | + public String getAssump() |
| 345 | + { return assumpField.getText(); } |
| 346 | + |
| 347 | + public String getConc() |
| 348 | + { return concField.getText(); } |
| 349 | + |
| 350 | + public boolean isSystem() |
| 351 | + { return systemInv.isSelected(); } |
| 352 | + |
| 353 | + public boolean isCritical() |
| 354 | + { return criticalInv.isSelected(); } |
| 355 | + |
| 356 | + public boolean isBehaviour() |
| 357 | + { return behaviourInv.isSelected(); } |
| 358 | + |
| 359 | + public boolean isOrdered() |
| 360 | + { return orderInv.isSelected(); } |
| 361 | +} |
| 362 | + |
| 363 | + |
| 364 | + |
| 365 | + |
| 366 | + |
| 367 | + |
| 368 | + |
| 369 | + |
| 370 | + |
| 371 | + |
| 372 | + |
| 373 | + |
| 374 | + |
| 375 | + |
| 376 | + |
| 377 | + |
| 378 | + |
| 379 | + |
| 380 | + |
| 381 | + |
| 382 | + |
0 commit comments