| 1 | package event.editor; |
|---|
| 2 | |
|---|
| 3 | import java.awt.BorderLayout; |
|---|
| 4 | import java.awt.Color; |
|---|
| 5 | import java.awt.FlowLayout; |
|---|
| 6 | import javax.swing.*; |
|---|
| 7 | import java.util.*; |
|---|
| 8 | import java.awt.event.*; |
|---|
| 9 | import scriptbuilder.structures.events.*; |
|---|
| 10 | |
|---|
| 11 | enum UpdateType |
|---|
| 12 | { |
|---|
| 13 | |
|---|
| 14 | Add, Remove, TitleChange |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | class PropertyUpdate |
|---|
| 18 | { |
|---|
| 19 | |
|---|
| 20 | private UpdateType type; |
|---|
| 21 | private PropertyPanel panel; |
|---|
| 22 | private int position = -1; |
|---|
| 23 | |
|---|
| 24 | public PropertyUpdate(UpdateType theType, PropertyPanel thePanel) |
|---|
| 25 | { |
|---|
| 26 | type = theType; |
|---|
| 27 | panel = thePanel; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | public PropertyUpdate(UpdateType theType, PropertyPanel thePanel, int thePosition) |
|---|
| 31 | { |
|---|
| 32 | this(theType, thePanel); |
|---|
| 33 | position = thePosition; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | public int getPosition() |
|---|
| 37 | { |
|---|
| 38 | if (position == -1) |
|---|
| 39 | { |
|---|
| 40 | throw new RuntimeException("position unknown"); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | return position; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public UpdateType getType() |
|---|
| 47 | { |
|---|
| 48 | return type; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | public PropertyPanel getPanel() |
|---|
| 52 | { |
|---|
| 53 | return panel; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | enum PropertyTypes |
|---|
| 58 | { |
|---|
| 59 | |
|---|
| 60 | Optional, Multiple; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | class PropertyPanel |
|---|
| 64 | { |
|---|
| 65 | |
|---|
| 66 | private final JPanel panel; |
|---|
| 67 | private final Properties property; |
|---|
| 68 | |
|---|
| 69 | public PropertyPanel(JPanel thePanel, |
|---|
| 70 | Properties theProperty) |
|---|
| 71 | { |
|---|
| 72 | panel = thePanel; |
|---|
| 73 | property = theProperty; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | public JPanel getPanel() |
|---|
| 77 | { |
|---|
| 78 | return panel; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | public Properties getProperty() |
|---|
| 82 | { |
|---|
| 83 | return property; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | public String title() |
|---|
| 87 | { |
|---|
| 88 | return property.getTitle(); |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | class MultPropertyPanel extends PropertyPanel |
|---|
| 93 | { |
|---|
| 94 | |
|---|
| 95 | private int index; |
|---|
| 96 | |
|---|
| 97 | public MultPropertyPanel(JPanel thePanel, |
|---|
| 98 | Properties theProperty, |
|---|
| 99 | int theIndex) |
|---|
| 100 | { |
|---|
| 101 | super(thePanel, theProperty); |
|---|
| 102 | index = theIndex; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | public int getIndex() |
|---|
| 106 | { |
|---|
| 107 | return index; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | public void setIndex(int newIndex) |
|---|
| 111 | { |
|---|
| 112 | index = newIndex; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | @Override |
|---|
| 116 | public String title() |
|---|
| 117 | { |
|---|
| 118 | return super.title() + " " + index; |
|---|
| 119 | } |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | class PropertyPanels extends Observable |
|---|
| 123 | { |
|---|
| 124 | |
|---|
| 125 | private Vector<PropertyPanel> properties = new Vector<PropertyPanel>(); |
|---|
| 126 | |
|---|
| 127 | private EnumMap<Properties, Integer> propertyCounter |
|---|
| 128 | = new EnumMap<Properties, Integer>(Properties.class); |
|---|
| 129 | |
|---|
| 130 | public PropertyPanels() |
|---|
| 131 | { |
|---|
| 132 | for (Properties property : Properties.values()) |
|---|
| 133 | { |
|---|
| 134 | propertyCounter.put(property, 0); |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | private int nextIndex(Properties property) |
|---|
| 139 | { |
|---|
| 140 | propertyCounter.put(property, propertyCounter.get(property) + 1); |
|---|
| 141 | |
|---|
| 142 | return propertyCounter.get(property); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | /** |
|---|
| 146 | * public Vector<PropertyPanel> getProperties() { return |
|---|
| 147 | * (Vector<PropertyPanel>) properties.clone(); } |
|---|
| 148 | */ |
|---|
| 149 | private int add(PropertyPanel panel) |
|---|
| 150 | { |
|---|
| 151 | int position = 0; |
|---|
| 152 | |
|---|
| 153 | for (int i = 0; i < properties.size(); i++) |
|---|
| 154 | { |
|---|
| 155 | if (properties.get(i).title().compareTo(panel.title()) < 0) |
|---|
| 156 | { |
|---|
| 157 | position = i + 1; |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | properties.add(position, panel); |
|---|
| 162 | |
|---|
| 163 | return position; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | public PropertyPanel addPropertyPanel(Properties property, JPanel panel) |
|---|
| 167 | { |
|---|
| 168 | PropertyPanel propertyPanel = null; |
|---|
| 169 | |
|---|
| 170 | if (property.getType() == PropertyTypes.Multiple) |
|---|
| 171 | { |
|---|
| 172 | propertyPanel = new MultPropertyPanel(panel, property, nextIndex(property)); |
|---|
| 173 | //propertyPanel.addObserver(this); |
|---|
| 174 | int position = add(propertyPanel); |
|---|
| 175 | setChanged(); |
|---|
| 176 | notifyObservers(new PropertyUpdate(UpdateType.Add, propertyPanel, position)); |
|---|
| 177 | |
|---|
| 178 | } |
|---|
| 179 | else if (property.getType() == PropertyTypes.Optional) |
|---|
| 180 | { |
|---|
| 181 | if (containsProperty(property)) |
|---|
| 182 | { |
|---|
| 183 | throw new RuntimeException("Property \"" + property + "\" is already added"); |
|---|
| 184 | } |
|---|
| 185 | else |
|---|
| 186 | { |
|---|
| 187 | propertyPanel = new PropertyPanel(panel, property); |
|---|
| 188 | int position = add(propertyPanel); |
|---|
| 189 | //propertyPanel.addObserver(this); |
|---|
| 190 | setChanged(); |
|---|
| 191 | notifyObservers(new PropertyUpdate(UpdateType.Add, propertyPanel, position)); |
|---|
| 192 | } |
|---|
| 193 | } |
|---|
| 194 | else |
|---|
| 195 | { |
|---|
| 196 | throw new RuntimeException("Property \"" + property + "\" not accounted for"); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | return propertyPanel; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | private boolean remove(PropertyPanel panel) |
|---|
| 203 | { |
|---|
| 204 | boolean result = false; |
|---|
| 205 | |
|---|
| 206 | if ((result = properties.remove(panel))) |
|---|
| 207 | { |
|---|
| 208 | setChanged(); |
|---|
| 209 | notifyObservers(new PropertyUpdate(UpdateType.Remove, panel)); |
|---|
| 210 | } |
|---|
| 211 | else |
|---|
| 212 | { |
|---|
| 213 | throw new RuntimeException("Attempted to remove panel that did not exist"); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | if (panel.getProperty().getType() == PropertyTypes.Multiple) |
|---|
| 217 | { |
|---|
| 218 | Vector<MultPropertyPanel> panelsOfSameType = new Vector<MultPropertyPanel>(); |
|---|
| 219 | Vector<MultPropertyPanel> panelsOfGreaterIndex = new Vector<MultPropertyPanel>(); |
|---|
| 220 | |
|---|
| 221 | propertyCounter.put(panel.getProperty(), propertyCounter.get(panel.getProperty()) - 1); |
|---|
| 222 | |
|---|
| 223 | // extract panels of the same property type |
|---|
| 224 | for (PropertyPanel pan : properties) |
|---|
| 225 | { |
|---|
| 226 | if (pan.getProperty() == panel.getProperty()) |
|---|
| 227 | { |
|---|
| 228 | panelsOfSameType.add((MultPropertyPanel) pan); |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | // extract panels whose index is greater than the index of the panel |
|---|
| 233 | // being removed |
|---|
| 234 | for (MultPropertyPanel pan : panelsOfSameType) |
|---|
| 235 | { |
|---|
| 236 | if (pan.getIndex() > ((MultPropertyPanel) panel).getIndex()) |
|---|
| 237 | { |
|---|
| 238 | panelsOfGreaterIndex.add(pan); |
|---|
| 239 | } |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | // decrement the index of each of the remaining panels by one |
|---|
| 243 | for (MultPropertyPanel pan : panelsOfGreaterIndex) |
|---|
| 244 | { |
|---|
| 245 | pan.setIndex(pan.getIndex() - 1); |
|---|
| 246 | setChanged(); |
|---|
| 247 | notifyObservers(new PropertyUpdate(UpdateType.TitleChange, pan)); |
|---|
| 248 | } |
|---|
| 249 | } |
|---|
| 250 | else if (panel.getProperty().getType() == PropertyTypes.Optional) |
|---|
| 251 | { |
|---|
| 252 | // do nothing |
|---|
| 253 | } |
|---|
| 254 | else |
|---|
| 255 | { |
|---|
| 256 | throw new RuntimeException("PropertyTypes not accounted for"); |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | return result; |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | public PropertyPanel removeProperty(Properties property) |
|---|
| 263 | { |
|---|
| 264 | if (property.getType() == PropertyTypes.Multiple) |
|---|
| 265 | { |
|---|
| 266 | throw new RuntimeException("Attemping to remove a property of multiple type"); |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | PropertyPanel removed = null; |
|---|
| 270 | |
|---|
| 271 | for (PropertyPanel panel : properties) |
|---|
| 272 | { |
|---|
| 273 | if (panel.getProperty() == property) |
|---|
| 274 | { |
|---|
| 275 | removed = panel; |
|---|
| 276 | } |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | if (removed == null) |
|---|
| 280 | { |
|---|
| 281 | throw new RuntimeException("Could not find panel with property \"" + property + "\""); |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | remove(removed); |
|---|
| 285 | |
|---|
| 286 | return removed; |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | public PropertyPanel removeProperty(JPanel jPanel) |
|---|
| 290 | { |
|---|
| 291 | PropertyPanel removed = null; |
|---|
| 292 | |
|---|
| 293 | for (PropertyPanel panel : properties) |
|---|
| 294 | { |
|---|
| 295 | if (panel.getPanel() == jPanel) |
|---|
| 296 | { |
|---|
| 297 | removed = panel; |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | if (removed == null) |
|---|
| 302 | { |
|---|
| 303 | throw new RuntimeException("Could not find jPanel"); |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | remove(removed); |
|---|
| 307 | |
|---|
| 308 | return removed; |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | public PropertyPanel removeProperty(String title) |
|---|
| 312 | { |
|---|
| 313 | PropertyPanel removed = null; |
|---|
| 314 | |
|---|
| 315 | for (PropertyPanel panel : properties) |
|---|
| 316 | { |
|---|
| 317 | if (panel.title().equals(title)) |
|---|
| 318 | { |
|---|
| 319 | if (removed == null) |
|---|
| 320 | { |
|---|
| 321 | removed = panel; |
|---|
| 322 | } |
|---|
| 323 | else |
|---|
| 324 | { |
|---|
| 325 | throw new RuntimeException("Attempted to remove a property by title but the title was not unique"); |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | if (removed == null) |
|---|
| 331 | { |
|---|
| 332 | throw new RuntimeException("Did not find titel \"" + title + "\""); |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | remove(removed); |
|---|
| 336 | |
|---|
| 337 | return removed; |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | public boolean removeProperty(PropertyPanel panel) |
|---|
| 341 | { |
|---|
| 342 | return remove(panel); |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | public boolean containsProperty(Properties property) |
|---|
| 346 | { |
|---|
| 347 | boolean contains = false; |
|---|
| 348 | |
|---|
| 349 | for (PropertyPanel panel : properties) |
|---|
| 350 | { |
|---|
| 351 | if (panel.getProperty() == property) |
|---|
| 352 | { |
|---|
| 353 | contains = true; |
|---|
| 354 | } |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | return contains; |
|---|
| 358 | } |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | class PropertyModel extends Observable implements Observer |
|---|
| 362 | { |
|---|
| 363 | |
|---|
| 364 | PropertyPanels properties = new PropertyPanels(); |
|---|
| 365 | |
|---|
| 366 | private EnumMap<Properties, Class> classMap |
|---|
| 367 | = new EnumMap<Properties, Class>(Properties.class); |
|---|
| 368 | |
|---|
| 369 | public PropertyModel() |
|---|
| 370 | { |
|---|
| 371 | classMap.put(Properties.ATMS, GenericEvaluationPanel.class); |
|---|
| 372 | classMap.put(Properties.ActivityLog, GenericEvaluationPanel.class); |
|---|
| 373 | classMap.put(Properties.CAD, GenericEvaluationPanel.class); |
|---|
| 374 | classMap.put(Properties.Facilitator, GenericEvaluationPanel.class); |
|---|
| 375 | classMap.put(Properties.Radio, GenericEvaluationPanel.class); |
|---|
| 376 | |
|---|
| 377 | classMap.put(Properties.MaintenanceRadio, MaintenanceRadioPanel.class); |
|---|
| 378 | classMap.put(Properties.TMTRadio, TMTRadioPanel.class); |
|---|
| 379 | classMap.put(Properties.CHPRadio, CHPRadioPanel.class); |
|---|
| 380 | classMap.put(Properties.Telephone, TelephonePanel.class); |
|---|
| 381 | |
|---|
| 382 | classMap.put(Properties.Audio, AudioPanel.class); |
|---|
| 383 | classMap.put(Properties.CADLog, CADLogPanel.class); |
|---|
| 384 | classMap.put(Properties.CCTV, CCTVPanel.class); |
|---|
| 385 | classMap.put(Properties.CMS, CMSEvaluationPanel.class); |
|---|
| 386 | classMap.put(Properties.Paramics, ParamicsPanel.class); |
|---|
| 387 | classMap.put(Properties.Tow, TowPanel.class); |
|---|
| 388 | classMap.put(Properties.Unit, UnitPanel.class); |
|---|
| 389 | classMap.put(Properties.Witness, WitnessPanel.class); |
|---|
| 390 | |
|---|
| 391 | properties.addObserver(this); |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | public void addProperty(Properties property, ScriptEventInterface se) |
|---|
| 395 | { |
|---|
| 396 | try |
|---|
| 397 | { |
|---|
| 398 | JPanel panel = (JPanel) classMap.get(property).newInstance(); |
|---|
| 399 | |
|---|
| 400 | final PropertyPanel propertyPanel = properties.addPropertyPanel(property, panel); |
|---|
| 401 | if (panel instanceof ScriptEventEditorPanel) |
|---|
| 402 | { |
|---|
| 403 | ((ScriptEventEditorPanel) panel).getEventObject(se); |
|---|
| 404 | } |
|---|
| 405 | if (property.getType() == PropertyTypes.Multiple) |
|---|
| 406 | { |
|---|
| 407 | |
|---|
| 408 | if (panel instanceof RemoveablePanel) |
|---|
| 409 | { |
|---|
| 410 | ((RemoveablePanel) panel).setRemoveListener(new ActionListener() |
|---|
| 411 | { |
|---|
| 412 | public void actionPerformed(ActionEvent evt) |
|---|
| 413 | { |
|---|
| 414 | properties.removeProperty(propertyPanel); |
|---|
| 415 | } |
|---|
| 416 | }); |
|---|
| 417 | } |
|---|
| 418 | else |
|---|
| 419 | { |
|---|
| 420 | throw new RuntimeException("Property was multiple but panel was not removeable"); |
|---|
| 421 | } |
|---|
| 422 | } |
|---|
| 423 | } |
|---|
| 424 | catch (Exception e) |
|---|
| 425 | { |
|---|
| 426 | System.err.println("Could not create panel of type \"" + property + "\""); |
|---|
| 427 | } |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | public void removeProperty(Properties property) |
|---|
| 431 | { |
|---|
| 432 | properties.removeProperty(property); |
|---|
| 433 | } |
|---|
| 434 | |
|---|
| 435 | public void update(Observable o, Object arg) |
|---|
| 436 | { |
|---|
| 437 | setChanged(); |
|---|
| 438 | notifyObservers(arg); |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | /* |
|---|
| 442 | public Vector<PropertyPanel> getPropertyPanels() |
|---|
| 443 | { |
|---|
| 444 | return properties.getProperties(); |
|---|
| 445 | } |
|---|
| 446 | */ |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | public class Editor extends javax.swing.JFrame implements Observer |
|---|
| 450 | { |
|---|
| 451 | |
|---|
| 452 | private PropertyModel model = new PropertyModel(); |
|---|
| 453 | |
|---|
| 454 | public PropertyModel getPropertyModel() |
|---|
| 455 | { |
|---|
| 456 | return model; |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | public void addProperty(Properties property, ScriptEventInterface se) |
|---|
| 460 | { |
|---|
| 461 | model.addProperty(property, se); |
|---|
| 462 | } |
|---|
| 463 | |
|---|
| 464 | private ActionListener optionalChangeListener = new ActionListener() |
|---|
| 465 | { |
|---|
| 466 | public void actionPerformed(ActionEvent evt) |
|---|
| 467 | { |
|---|
| 468 | JCheckBoxMenuItem src = (JCheckBoxMenuItem) evt.getSource(); |
|---|
| 469 | Properties property = Properties.valueOf(src.getText().replaceAll(" ", "")); |
|---|
| 470 | |
|---|
| 471 | if (src.isSelected()) |
|---|
| 472 | { |
|---|
| 473 | model.addProperty(property, new CCTVEvent()); |
|---|
| 474 | } |
|---|
| 475 | else |
|---|
| 476 | { |
|---|
| 477 | model.removeProperty(property); |
|---|
| 478 | } |
|---|
| 479 | } |
|---|
| 480 | }; |
|---|
| 481 | |
|---|
| 482 | private ActionListener multipleChangeListener = new ActionListener() |
|---|
| 483 | { |
|---|
| 484 | public void actionPerformed(ActionEvent evt) |
|---|
| 485 | { |
|---|
| 486 | JMenuItem src = (JMenuItem) evt.getSource(); |
|---|
| 487 | model.addProperty(Properties.valueOf(src.getText().replaceAll(" ", "")), new CCTVEvent()); |
|---|
| 488 | } |
|---|
| 489 | }; |
|---|
| 490 | |
|---|
| 491 | public Editor() |
|---|
| 492 | { |
|---|
| 493 | initComponents(); |
|---|
| 494 | |
|---|
| 495 | model.addObserver(this); |
|---|
| 496 | |
|---|
| 497 | // For each menu |
|---|
| 498 | for (int menuCtr = 0; menuCtr < jMenuBar1.getMenuCount(); menuCtr++) |
|---|
| 499 | { |
|---|
| 500 | // for each menu item |
|---|
| 501 | for (java.awt.Component comp : jMenuBar1.getMenu(menuCtr).getMenuComponents()) |
|---|
| 502 | { |
|---|
| 503 | JMenuItem item = (JMenuItem) comp; |
|---|
| 504 | |
|---|
| 505 | String itemName = item.getText().replaceAll(" ", ""); |
|---|
| 506 | |
|---|
| 507 | Properties property = Properties.valueOf(itemName); |
|---|
| 508 | |
|---|
| 509 | if (property.getType() == PropertyTypes.Multiple) |
|---|
| 510 | { |
|---|
| 511 | item.addActionListener(multipleChangeListener); |
|---|
| 512 | } |
|---|
| 513 | else if (property.getType() == PropertyTypes.Optional) |
|---|
| 514 | { |
|---|
| 515 | item.addActionListener(optionalChangeListener); |
|---|
| 516 | } |
|---|
| 517 | else |
|---|
| 518 | { |
|---|
| 519 | throw new RuntimeException("Property type not accounted for"); |
|---|
| 520 | } |
|---|
| 521 | } |
|---|
| 522 | } |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | /** |
|---|
| 526 | * This method is called from within the constructor to initialize the form. |
|---|
| 527 | * WARNING: Do NOT modify this code. The content of this method is always |
|---|
| 528 | * regenerated by the Form Editor. |
|---|
| 529 | */ |
|---|
| 530 | @SuppressWarnings("unchecked") |
|---|
| 531 | // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
|---|
| 532 | private void initComponents() { |
|---|
| 533 | |
|---|
| 534 | jTabbedPane1 = new javax.swing.JTabbedPane(); |
|---|
| 535 | jMenuBar1 = new javax.swing.JMenuBar(); |
|---|
| 536 | jMenu1 = new javax.swing.JMenu(); |
|---|
| 537 | ATMS = new javax.swing.JCheckBoxMenuItem(); |
|---|
| 538 | ActivityLog = new javax.swing.JCheckBoxMenuItem(); |
|---|
| 539 | CAD = new javax.swing.JCheckBoxMenuItem(); |
|---|
| 540 | CMS = new javax.swing.JMenuItem(); |
|---|
| 541 | Facilitator = new javax.swing.JCheckBoxMenuItem(); |
|---|
| 542 | Radio = new javax.swing.JCheckBoxMenuItem(); |
|---|
| 543 | JMenu2 = new javax.swing.JMenu(); |
|---|
| 544 | MaintenanceRadio = new javax.swing.JCheckBoxMenuItem(); |
|---|
| 545 | TMTRadio = new javax.swing.JCheckBoxMenuItem(); |
|---|
| 546 | Telephone = new javax.swing.JCheckBoxMenuItem(); |
|---|
| 547 | jMenu3 = new javax.swing.JMenu(); |
|---|
| 548 | Audio = new javax.swing.JMenuItem(); |
|---|
| 549 | CADLog = new javax.swing.JMenuItem(); |
|---|
| 550 | CCTV = new javax.swing.JMenuItem(); |
|---|
| 551 | CHPRadio = new javax.swing.JCheckBoxMenuItem(); |
|---|
| 552 | Paramics = new javax.swing.JMenuItem(); |
|---|
| 553 | Tow = new javax.swing.JMenuItem(); |
|---|
| 554 | Unit = new javax.swing.JMenuItem(); |
|---|
| 555 | Witness = new javax.swing.JMenuItem(); |
|---|
| 556 | |
|---|
| 557 | setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); |
|---|
| 558 | setTitle("Event Editor"); |
|---|
| 559 | |
|---|
| 560 | jMenu1.setText("Evaluations"); |
|---|
| 561 | |
|---|
| 562 | ATMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 563 | ATMS.setText("ATMS"); |
|---|
| 564 | ATMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ATMSEval.png"))); // NOI18N |
|---|
| 565 | ATMS.addActionListener(new java.awt.event.ActionListener() { |
|---|
| 566 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
|---|
| 567 | multipleChange(evt); |
|---|
| 568 | } |
|---|
| 569 | }); |
|---|
| 570 | jMenu1.add(ATMS); |
|---|
| 571 | |
|---|
| 572 | ActivityLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK)); |
|---|
| 573 | ActivityLog.setText("Activity Log"); |
|---|
| 574 | ActivityLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ActivityLogEval.png"))); // NOI18N |
|---|
| 575 | ActivityLog.addActionListener(new java.awt.event.ActionListener() { |
|---|
| 576 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
|---|
| 577 | multipleChange(evt); |
|---|
| 578 | } |
|---|
| 579 | }); |
|---|
| 580 | jMenu1.add(ActivityLog); |
|---|
| 581 | |
|---|
| 582 | CAD.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK)); |
|---|
| 583 | CAD.setText("CAD"); |
|---|
| 584 | CAD.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CADEval.png"))); // NOI18N |
|---|
| 585 | CAD.addActionListener(new java.awt.event.ActionListener() { |
|---|
| 586 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
|---|
| 587 | multipleChange(evt); |
|---|
| 588 | } |
|---|
| 589 | }); |
|---|
| 590 | jMenu1.add(CAD); |
|---|
| 591 | |
|---|
| 592 | CMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 593 | CMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CMSEval.png"))); // NOI18N |
|---|
| 594 | CMS.setText("CMS"); |
|---|
| 595 | CMS.addMouseListener(new java.awt.event.MouseAdapter() { |
|---|
| 596 | public void mouseClicked(java.awt.event.MouseEvent evt) { |
|---|
| 597 | multipleChangeListener(evt); |
|---|
| 598 | } |
|---|
| 599 | }); |
|---|
| 600 | CMS.addActionListener(new java.awt.event.ActionListener() { |
|---|
| 601 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
|---|
| 602 | multipleChange(evt); |
|---|
| 603 | } |
|---|
| 604 | }); |
|---|
| 605 | jMenu1.add(CMS); |
|---|
| 606 | |
|---|
| 607 | Facilitator.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 608 | Facilitator.setText("Facilitator"); |
|---|
| 609 | Facilitator.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/FacilitatorEval.png"))); // NOI18N |
|---|
| 610 | Facilitator.addActionListener(new java.awt.event.ActionListener() { |
|---|
| 611 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
|---|
| 612 | optionalChange(evt); |
|---|
| 613 | } |
|---|
| 614 | }); |
|---|
| 615 | jMenu1.add(Facilitator); |
|---|
| 616 | |
|---|
| 617 | Radio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 618 | Radio.setText("Radio"); |
|---|
| 619 | Radio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/RadioEval.png"))); // NOI18N |
|---|
| 620 | Radio.addActionListener(new java.awt.event.ActionListener() { |
|---|
| 621 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
|---|
| 622 | optionalChange(evt); |
|---|
| 623 | } |
|---|
| 624 | }); |
|---|
| 625 | jMenu1.add(Radio); |
|---|
| 626 | |
|---|
| 627 | jMenuBar1.add(jMenu1); |
|---|
| 628 | |
|---|
| 629 | JMenu2.setText("Instructor Actions"); |
|---|
| 630 | |
|---|
| 631 | MaintenanceRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 632 | MaintenanceRadio.setText("Maintenance Radio"); |
|---|
| 633 | MaintenanceRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/MaintenanceRadio.png"))); // NOI18N |
|---|
| 634 | MaintenanceRadio.addActionListener(new java.awt.event.ActionListener() { |
|---|
| 635 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
|---|
| 636 | optionalChange(evt); |
|---|
| 637 | } |
|---|
| 638 | }); |
|---|
| 639 | JMenu2.add(MaintenanceRadio); |
|---|
| 640 | |
|---|
| 641 | TMTRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 642 | TMTRadio.setText("TMT Radio"); |
|---|
| 643 | TMTRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/TMTRadio.png"))); // NOI18N |
|---|
| 644 | TMTRadio.addActionListener(new java.awt.event.ActionListener() { |
|---|
| 645 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
|---|
| 646 | optionalChange(evt); |
|---|
| 647 | } |
|---|
| 648 | }); |
|---|
| 649 | JMenu2.add(TMTRadio); |
|---|
| 650 | |
|---|
| 651 | Telephone.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 652 | Telephone.setText("Telephone"); |
|---|
| 653 | Telephone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Telephone.png"))); // NOI18N |
|---|
| 654 | Telephone.addActionListener(new java.awt.event.ActionListener() { |
|---|
| 655 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
|---|
| 656 | optionalChange(evt); |
|---|
| 657 | } |
|---|
| 658 | }); |
|---|
| 659 | JMenu2.add(Telephone); |
|---|
| 660 | |
|---|
| 661 | jMenuBar1.add(JMenu2); |
|---|
| 662 | |
|---|
| 663 | jMenu3.setText("Automated Data"); |
|---|
| 664 | |
|---|
| 665 | Audio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 666 | Audio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Audio.png"))); // NOI18N |
|---|
| 667 | Audio.setText("Audio"); |
|---|
| 668 | jMenu3.add(Audio); |
|---|
| 669 | |
|---|
| 670 | CADLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 671 | CADLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CAD.png"))); // NOI18N |
|---|
| 672 | CADLog.setText("CAD Log"); |
|---|
| 673 | jMenu3.add(CADLog); |
|---|
| 674 | |
|---|
| 675 | CCTV.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 676 | CCTV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CCTV.png"))); // NOI18N |
|---|
| 677 | CCTV.setText("CCTV"); |
|---|
| 678 | jMenu3.add(CCTV); |
|---|
| 679 | |
|---|
| 680 | CHPRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK)); |
|---|
| 681 | CHPRadio.setText("CHP Radio"); |
|---|
| 682 | CHPRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CHPRadio.png"))); // NOI18N |
|---|
| 683 | CHPRadio.addActionListener(new java.awt.event.ActionListener() { |
|---|
| 684 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
|---|
| 685 | optionalChange(evt); |
|---|
| 686 | } |
|---|
| 687 | }); |
|---|
| 688 | jMenu3.add(CHPRadio); |
|---|
| 689 | |
|---|
| 690 | Paramics.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 691 | Paramics.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Paramics.png"))); // NOI18N |
|---|
| 692 | Paramics.setText("Paramics"); |
|---|
| 693 | jMenu3.add(Paramics); |
|---|
| 694 | |
|---|
| 695 | Tow.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 696 | Tow.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Tow.png"))); // NOI18N |
|---|
| 697 | Tow.setText("Tow"); |
|---|
| 698 | jMenu3.add(Tow); |
|---|
| 699 | |
|---|
| 700 | Unit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 701 | Unit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unit.png"))); // NOI18N |
|---|
| 702 | Unit.setText("Unit"); |
|---|
| 703 | jMenu3.add(Unit); |
|---|
| 704 | |
|---|
| 705 | Witness.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK)); |
|---|
| 706 | Witness.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Witness.png"))); // NOI18N |
|---|
| 707 | Witness.setText("Witness"); |
|---|
| 708 | jMenu3.add(Witness); |
|---|
| 709 | |
|---|
| 710 | jMenuBar1.add(jMenu3); |
|---|
| 711 | |
|---|
| 712 | setJMenuBar(jMenuBar1); |
|---|
| 713 | |
|---|
| 714 | org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); |
|---|
| 715 | getContentPane().setLayout(layout); |
|---|
| 716 | layout.setHorizontalGroup( |
|---|
| 717 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 718 | .add(layout.createSequentialGroup() |
|---|
| 719 | .addContainerGap() |
|---|
| 720 | .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 921, Short.MAX_VALUE) |
|---|
| 721 | .addContainerGap()) |
|---|
| 722 | ); |
|---|
| 723 | layout.setVerticalGroup( |
|---|
| 724 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 725 | .add(layout.createSequentialGroup() |
|---|
| 726 | .addContainerGap() |
|---|
| 727 | .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 580, Short.MAX_VALUE) |
|---|
| 728 | .addContainerGap()) |
|---|
| 729 | ); |
|---|
| 730 | |
|---|
| 731 | pack(); |
|---|
| 732 | }// </editor-fold>//GEN-END:initComponents |
|---|
| 733 | |
|---|
| 734 | private void multipleChangeListener(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_multipleChangeListener |
|---|
| 735 | |
|---|
| 736 | }//GEN-LAST:event_multipleChangeListener |
|---|
| 737 | |
|---|
| 738 | private void multipleChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleChange |
|---|
| 739 | |
|---|
| 740 | }//GEN-LAST:event_multipleChange |
|---|
| 741 | |
|---|
| 742 | private void optionalChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionalChange |
|---|
| 743 | |
|---|
| 744 | }//GEN-LAST:event_optionalChange |
|---|
| 745 | |
|---|
| 746 | /** |
|---|
| 747 | * @param args the command line arguments |
|---|
| 748 | */ |
|---|
| 749 | public static void main(String args[]) |
|---|
| 750 | { |
|---|
| 751 | java.awt.EventQueue.invokeLater(new Runnable() |
|---|
| 752 | { |
|---|
| 753 | public void run() |
|---|
| 754 | { |
|---|
| 755 | new Editor().setVisible(true); |
|---|
| 756 | } |
|---|
| 757 | }); |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | // Variables declaration - do not modify//GEN-BEGIN:variables |
|---|
| 761 | private javax.swing.JCheckBoxMenuItem ATMS; |
|---|
| 762 | private javax.swing.JCheckBoxMenuItem ActivityLog; |
|---|
| 763 | private javax.swing.JMenuItem Audio; |
|---|
| 764 | private javax.swing.JCheckBoxMenuItem CAD; |
|---|
| 765 | private javax.swing.JMenuItem CADLog; |
|---|
| 766 | private javax.swing.JMenuItem CCTV; |
|---|
| 767 | private javax.swing.JCheckBoxMenuItem CHPRadio; |
|---|
| 768 | private javax.swing.JMenuItem CMS; |
|---|
| 769 | private javax.swing.JCheckBoxMenuItem Facilitator; |
|---|
| 770 | private javax.swing.JMenu JMenu2; |
|---|
| 771 | private javax.swing.JCheckBoxMenuItem MaintenanceRadio; |
|---|
| 772 | private javax.swing.JMenuItem Paramics; |
|---|
| 773 | private javax.swing.JCheckBoxMenuItem Radio; |
|---|
| 774 | private javax.swing.JCheckBoxMenuItem TMTRadio; |
|---|
| 775 | private javax.swing.JCheckBoxMenuItem Telephone; |
|---|
| 776 | private javax.swing.JMenuItem Tow; |
|---|
| 777 | private javax.swing.JMenuItem Unit; |
|---|
| 778 | private javax.swing.JMenuItem Witness; |
|---|
| 779 | private javax.swing.JMenu jMenu1; |
|---|
| 780 | private javax.swing.JMenu jMenu3; |
|---|
| 781 | private javax.swing.JMenuBar jMenuBar1; |
|---|
| 782 | private javax.swing.JTabbedPane jTabbedPane1; |
|---|
| 783 | // End of variables declaration//GEN-END:variables |
|---|
| 784 | |
|---|
| 785 | public void update(Observable o, Object arg) |
|---|
| 786 | { |
|---|
| 787 | |
|---|
| 788 | final PropertyUpdate update = (PropertyUpdate) arg; |
|---|
| 789 | final ImageIcon image = update.getPanel().getProperty().getImage(); |
|---|
| 790 | final String caption = update.getPanel().title(); |
|---|
| 791 | |
|---|
| 792 | final JLabel title = new JLabel(caption, image, JLabel.CENTER); |
|---|
| 793 | |
|---|
| 794 | /* |
|---|
| 795 | final BorderLayout layout = new BorderLayout(); |
|---|
| 796 | final JPanel title = new JPanel(layout); |
|---|
| 797 | title.setOpaque(false); |
|---|
| 798 | title.add(new JLabel(image), BorderLayout.WEST); |
|---|
| 799 | title.add(new JLabel(caption), BorderLayout.EAST); |
|---|
| 800 | */ |
|---|
| 801 | if (update.getType() == UpdateType.Add) |
|---|
| 802 | { |
|---|
| 803 | jTabbedPane1.insertTab(null, null, |
|---|
| 804 | update.getPanel().getPanel(), null, update.getPosition()); |
|---|
| 805 | jTabbedPane1.setTabComponentAt(update.getPosition(), title); |
|---|
| 806 | jTabbedPane1.setSelectedIndex(update.getPosition()); |
|---|
| 807 | } |
|---|
| 808 | else if (update.getType() == UpdateType.Remove) |
|---|
| 809 | { |
|---|
| 810 | jTabbedPane1.remove(update.getPanel().getPanel()); |
|---|
| 811 | } |
|---|
| 812 | else if (update.getType() == UpdateType.TitleChange) |
|---|
| 813 | { |
|---|
| 814 | final int index = jTabbedPane1.indexOfComponent( |
|---|
| 815 | update.getPanel().getPanel()); |
|---|
| 816 | |
|---|
| 817 | new Thread(new Runnable() |
|---|
| 818 | { |
|---|
| 819 | public void run() |
|---|
| 820 | { |
|---|
| 821 | Color c = jTabbedPane1.getForegroundAt(index); |
|---|
| 822 | jTabbedPane1.setForegroundAt(index, Color.blue); |
|---|
| 823 | try |
|---|
| 824 | { |
|---|
| 825 | Thread.sleep(350); |
|---|
| 826 | } |
|---|
| 827 | catch (Exception e) |
|---|
| 828 | { |
|---|
| 829 | } |
|---|
| 830 | jTabbedPane1.setTabComponentAt(index, title); |
|---|
| 831 | try |
|---|
| 832 | { |
|---|
| 833 | Thread.sleep(350); |
|---|
| 834 | } |
|---|
| 835 | catch (Exception e) |
|---|
| 836 | { |
|---|
| 837 | } |
|---|
| 838 | jTabbedPane1.setForegroundAt(index, c); |
|---|
| 839 | } |
|---|
| 840 | }).start(); |
|---|
| 841 | } |
|---|
| 842 | else |
|---|
| 843 | { |
|---|
| 844 | throw new RuntimeException("UpdateType not accounted for"); |
|---|
| 845 | } |
|---|
| 846 | } |
|---|
| 847 | |
|---|
| 848 | } |
|---|