|
35 | 35 |
|
36 | 36 | public final class EERDiagram extends Diagram {
|
37 | 37 |
|
38 |
| - @Override |
39 |
| - protected boolean addingIsValid(@NotNull Component component) { |
40 |
| - |
41 |
| - Set<Class<?>> allowedTypes = Set.of( |
42 |
| - Relationship.class, Cardinality.class, Hierarchy.class, Discriminant.class, |
43 |
| - EntityWrapper.class, Attribute.class, Association.class, Line.class, Note.class |
44 |
| - ); |
45 |
| - |
46 |
| - if (allowedTypes.stream().noneMatch(type -> type.isInstance(component))) { |
47 |
| - throw new IllegalArgumentException( |
48 |
| - "The component must be a type of \n" + allowedTypes |
49 |
| - + "\nProvided: " + component.getClass().getName() |
50 |
| - ); |
51 |
| - } |
52 |
| - |
53 |
| - return true; |
54 |
| - } |
55 |
| - |
56 |
| - @Override |
57 |
| - public JPopupMenu getBackgroundPopupMenu() { |
58 |
| - |
59 |
| - JPopupMenu backgroundPopupMenu = new JPopupMenu(); |
60 |
| - |
61 |
| - JMenuItem addEntity = new JMenuItem(LanguageManager.getMessage("action.addEntity")); |
62 |
| - addEntity.addActionListener(_ -> { |
63 |
| - EntityWrapper.addEntity(this); |
64 |
| - cleanSelectedComponents(); |
65 |
| - }); |
66 |
| - |
67 |
| - JMenuItem addRelationship = new JMenuItem(LanguageManager.getMessage("action.addRelationship")); |
68 |
| - addRelationship.addActionListener(_ -> { |
69 |
| - Relationship.addRelationship(this, this.getSelectedComponents()); |
70 |
| - cleanSelectedComponents(); |
71 |
| - }); |
72 |
| - |
73 |
| - JMenuItem addDependency = new JMenuItem(LanguageManager.getMessage("action.addDependency")); |
74 |
| - addDependency.addActionListener(_ -> { |
75 |
| - Relationship.addDependency(this, this.getSelectedComponents()); |
76 |
| - cleanSelectedComponents(); |
77 |
| - }); |
78 |
| - |
79 |
| - JMenuItem addHierarchy = new JMenuItem(LanguageManager.getMessage("action.addHierarchy")); |
80 |
| - addHierarchy.addActionListener(_ -> { |
81 |
| - Hierarchy.addHierarchy(this, this.getSelectedComponents()); |
82 |
| - cleanSelectedComponents(); |
83 |
| - }); |
84 |
| - |
85 |
| - JMenuItem addNote = new JMenuItem(LanguageManager.getMessage("action.addNote")); |
86 |
| - addNote.addActionListener(_ -> { |
87 |
| - Note.addNote(this); |
88 |
| - cleanSelectedComponents(); |
89 |
| - }); |
90 |
| - |
91 |
| - backgroundPopupMenu.add(addEntity); |
92 |
| - backgroundPopupMenu.add(addRelationship); |
93 |
| - backgroundPopupMenu.add(addDependency); |
94 |
| - backgroundPopupMenu.add(addHierarchy); |
95 |
| - backgroundPopupMenu.add(addNote); |
96 |
| - |
97 |
| - return backgroundPopupMenu; |
98 |
| - } |
99 |
| - |
100 |
| - @Override |
101 |
| - public List<JButton> getMainFrameKeys() { |
102 |
| - |
103 |
| - List<JButton> out = super.getMainFrameKeys(); |
104 |
| - |
105 |
| - JButton addEntityKey = new JButton(); |
106 |
| - addEntityKey.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_DOWN_MASK), "actionE"); |
107 |
| - addEntityKey.getActionMap().put("actionE", new AbstractAction() { |
108 |
| - @Override |
109 |
| - public void actionPerformed(ActionEvent e) { |
110 |
| - EntityWrapper.addEntity(EERDiagram.this); |
111 |
| - EERDiagram.this.cleanSelectedComponents(); |
112 |
| - } |
113 |
| - }); |
114 |
| - out.add(addEntityKey); |
115 |
| - |
116 |
| - JButton addRelationshipKey = new JButton(); |
117 |
| - addRelationshipKey.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK), "actionR"); |
118 |
| - addRelationshipKey.getActionMap().put("actionR", new AbstractAction() { |
119 |
| - @Override |
120 |
| - public void actionPerformed(ActionEvent e) { |
121 |
| - Relationship.addRelationship(EERDiagram.this, EERDiagram.this.getSelectedComponents()); |
122 |
| - EERDiagram.this.cleanSelectedComponents(); |
123 |
| - } |
124 |
| - }); |
125 |
| - out.add(addRelationshipKey); |
126 |
| - |
127 |
| - JButton addDependencyKey= new JButton(); |
128 |
| - addDependencyKey.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK), "actionD"); |
129 |
| - addDependencyKey.getActionMap().put("actionD", new AbstractAction() { |
130 |
| - @Override |
131 |
| - public void actionPerformed(ActionEvent e) { |
132 |
| - Relationship.addDependency(EERDiagram.this, EERDiagram.this.getSelectedComponents()); |
133 |
| - EERDiagram.this.cleanSelectedComponents(); |
134 |
| - } |
135 |
| - }); |
136 |
| - out.add(addDependencyKey); |
137 |
| - |
138 |
| - JButton addHierarchyKey= new JButton(); |
139 |
| - addHierarchyKey.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_DOWN_MASK), "actionH"); |
140 |
| - addHierarchyKey.getActionMap().put("actionH", new AbstractAction() { |
141 |
| - @Override |
142 |
| - public void actionPerformed(ActionEvent e) { |
143 |
| - Hierarchy.addHierarchy(EERDiagram.this, EERDiagram.this.getSelectedComponents()); |
144 |
| - EERDiagram.this.cleanSelectedComponents(); |
145 |
| - } |
146 |
| - }); |
147 |
| - out.add(addHierarchyKey); |
148 |
| - |
149 |
| - JButton addNoteKey= new JButton(); |
150 |
| - addNoteKey.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK), "actionN"); |
151 |
| - addNoteKey.getActionMap().put("actionN", new AbstractAction() { |
152 |
| - @Override |
153 |
| - public void actionPerformed(ActionEvent e) { |
154 |
| - Note.addNote(EERDiagram.this); |
155 |
| - EERDiagram.this.cleanSelectedComponents(); |
156 |
| - } |
157 |
| - }); |
158 |
| - out.add(addNoteKey); |
159 |
| - |
160 |
| - return out; |
161 |
| - } |
162 |
| - |
163 |
| - @Override |
164 |
| - public List<Item> getFileMenuItems() { |
165 |
| - List<Item> out = super.getFileMenuItems(); |
166 |
| - |
167 |
| - Item derivate = new Item("fileMenu.derivate"); |
168 |
| - derivate.addActionListener(_ -> this.derivate()); |
169 |
| - out.add(derivate); |
170 |
| - |
171 |
| - return out; |
172 |
| - } |
173 |
| - |
174 |
| - @Override |
175 |
| - public List<ResourceBundle> getResourceBundles(Locale currentLocale) { |
176 |
| - |
177 |
| - List<ResourceBundle> out = super.getResourceBundles(currentLocale); |
178 |
| - |
179 |
| - out.add(ResourceBundle.getBundle("EERresources/messages", currentLocale)); |
180 |
| - |
181 |
| - return out; |
182 |
| - } |
183 |
| - |
184 | 38 | private void derivate() {
|
185 | 39 | Map<String, Derivation> derivations = new HashMap<>();
|
186 | 40 |
|
@@ -351,17 +205,6 @@ private void extractConstraints(String referencing, String referenced,
|
351 | 205 | addReferencialIntegrityConstraint(constraint, constraints);
|
352 | 206 | }
|
353 | 207 |
|
354 |
| - @Override |
355 |
| - public String getControls() { |
356 |
| - |
357 |
| - return "\nCtrl + E: " + LanguageManager.getMessage("control.addEntity") |
358 |
| - + "\nCtrl + R: " + LanguageManager.getMessage("control.addRelationship") |
359 |
| - + "\nCtrl + D: " + LanguageManager.getMessage("control.addDependency") |
360 |
| - + "\nCtrl + H: " + LanguageManager.getMessage("control.addHierarchy") |
361 |
| - + "\nCtrl + N: " + LanguageManager.getMessage("control.addNote") |
362 |
| - + super.getControls(); |
363 |
| - } |
364 |
| - |
365 | 208 | private void exportDerivationToHTML(Collection<Derivation> derivations, Collection<Constraint> constraints) {
|
366 | 209 |
|
367 | 210 | JFileChooser fileChooser = new JFileChooser();
|
@@ -551,4 +394,175 @@ private static String getHTMLStyles() {
|
551 | 394 | </style>
|
552 | 395 | """;
|
553 | 396 | }
|
| 397 | + |
| 398 | + /* -------------------------------------------------------------------------------------------------------------- */ |
| 399 | + /* Overridden Methods */ |
| 400 | + /* -------------------------------------------------------------------------------------------------------------- */ |
| 401 | + |
| 402 | + @Override |
| 403 | + protected boolean addingIsValid(@NotNull Component component) { |
| 404 | + |
| 405 | + Set<Class<?>> allowedTypes = Set.of( |
| 406 | + Relationship.class, Cardinality.class, Hierarchy.class, Discriminant.class, |
| 407 | + EntityWrapper.class, Attribute.class, Association.class, Line.class, Note.class |
| 408 | + ); |
| 409 | + |
| 410 | + if (allowedTypes.stream().noneMatch(type -> type.isInstance(component))) { |
| 411 | + throw new IllegalArgumentException( |
| 412 | + "The component must be a type of \n" + allowedTypes |
| 413 | + + "\nProvided: " + component.getClass().getName() |
| 414 | + ); |
| 415 | + } |
| 416 | + |
| 417 | + return true; |
| 418 | + } |
| 419 | + |
| 420 | + /* -------------------------------------------------------------------------------------------------------------- */ |
| 421 | + |
| 422 | + @Override |
| 423 | + public JPopupMenu getBackgroundPopupMenu() { |
| 424 | + |
| 425 | + JPopupMenu backgroundPopupMenu = new JPopupMenu(); |
| 426 | + |
| 427 | + JMenuItem addEntity = new JMenuItem(LanguageManager.getMessage("action.addEntity")); |
| 428 | + addEntity.addActionListener(_ -> { |
| 429 | + EntityWrapper.addEntity(this); |
| 430 | + cleanSelectedComponents(); |
| 431 | + }); |
| 432 | + |
| 433 | + JMenuItem addRelationship = new JMenuItem(LanguageManager.getMessage("action.addRelationship")); |
| 434 | + addRelationship.addActionListener(_ -> { |
| 435 | + Relationship.addRelationship(this, this.getSelectedComponents()); |
| 436 | + cleanSelectedComponents(); |
| 437 | + }); |
| 438 | + |
| 439 | + JMenuItem addDependency = new JMenuItem(LanguageManager.getMessage("action.addDependency")); |
| 440 | + addDependency.addActionListener(_ -> { |
| 441 | + Relationship.addDependency(this, this.getSelectedComponents()); |
| 442 | + cleanSelectedComponents(); |
| 443 | + }); |
| 444 | + |
| 445 | + JMenuItem addHierarchy = new JMenuItem(LanguageManager.getMessage("action.addHierarchy")); |
| 446 | + addHierarchy.addActionListener(_ -> { |
| 447 | + Hierarchy.addHierarchy(this, this.getSelectedComponents()); |
| 448 | + cleanSelectedComponents(); |
| 449 | + }); |
| 450 | + |
| 451 | + JMenuItem addNote = new JMenuItem(LanguageManager.getMessage("action.addNote")); |
| 452 | + addNote.addActionListener(_ -> { |
| 453 | + Note.addNote(this); |
| 454 | + cleanSelectedComponents(); |
| 455 | + }); |
| 456 | + |
| 457 | + backgroundPopupMenu.add(addEntity); |
| 458 | + backgroundPopupMenu.add(addRelationship); |
| 459 | + backgroundPopupMenu.add(addDependency); |
| 460 | + backgroundPopupMenu.add(addHierarchy); |
| 461 | + backgroundPopupMenu.add(addNote); |
| 462 | + |
| 463 | + return backgroundPopupMenu; |
| 464 | + } |
| 465 | + |
| 466 | + /* -------------------------------------------------------------------------------------------------------------- */ |
| 467 | + |
| 468 | + @Override |
| 469 | + public List<Item> getFileMenuItems() { |
| 470 | + List<Item> out = super.getFileMenuItems(); |
| 471 | + |
| 472 | + Item derivate = new Item("fileMenu.derivate"); |
| 473 | + derivate.addActionListener(_ -> this.derivate()); |
| 474 | + out.add(derivate); |
| 475 | + |
| 476 | + return out; |
| 477 | + } |
| 478 | + |
| 479 | + /* -------------------------------------------------------------------------------------------------------------- */ |
| 480 | + |
| 481 | + @Override |
| 482 | + public List<ResourceBundle> getResourceBundles(Locale currentLocale) { |
| 483 | + |
| 484 | + List<ResourceBundle> out = super.getResourceBundles(currentLocale); |
| 485 | + |
| 486 | + out.add(ResourceBundle.getBundle("EERresources/messages", currentLocale)); |
| 487 | + |
| 488 | + return out; |
| 489 | + } |
| 490 | + |
| 491 | + /* -------------------------------------------------------------------------------------------------------------- */ |
| 492 | + |
| 493 | + @Override |
| 494 | + public String getControls() { |
| 495 | + |
| 496 | + return "\nCtrl + E: " + LanguageManager.getMessage("control.addEntity") |
| 497 | + + "\nCtrl + R: " + LanguageManager.getMessage("control.addRelationship") |
| 498 | + + "\nCtrl + D: " + LanguageManager.getMessage("control.addDependency") |
| 499 | + + "\nCtrl + H: " + LanguageManager.getMessage("control.addHierarchy") |
| 500 | + + "\nCtrl + N: " + LanguageManager.getMessage("control.addNote") |
| 501 | + + super.getControls(); |
| 502 | + } |
| 503 | + |
| 504 | + /* -------------------------------------------------------------------------------------------------------------- */ |
| 505 | + |
| 506 | + @Override |
| 507 | + public List<JButton> getMainFrameKeys() { |
| 508 | + |
| 509 | + List<JButton> out = super.getMainFrameKeys(); |
| 510 | + |
| 511 | + JButton addEntityKey = new JButton(); |
| 512 | + addEntityKey.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_DOWN_MASK), "actionE"); |
| 513 | + addEntityKey.getActionMap().put("actionE", new AbstractAction() { |
| 514 | + @Override |
| 515 | + public void actionPerformed(ActionEvent e) { |
| 516 | + EntityWrapper.addEntity(EERDiagram.this); |
| 517 | + EERDiagram.this.cleanSelectedComponents(); |
| 518 | + } |
| 519 | + }); |
| 520 | + out.add(addEntityKey); |
| 521 | + |
| 522 | + JButton addRelationshipKey = new JButton(); |
| 523 | + addRelationshipKey.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK), "actionR"); |
| 524 | + addRelationshipKey.getActionMap().put("actionR", new AbstractAction() { |
| 525 | + @Override |
| 526 | + public void actionPerformed(ActionEvent e) { |
| 527 | + Relationship.addRelationship(EERDiagram.this, EERDiagram.this.getSelectedComponents()); |
| 528 | + EERDiagram.this.cleanSelectedComponents(); |
| 529 | + } |
| 530 | + }); |
| 531 | + out.add(addRelationshipKey); |
| 532 | + |
| 533 | + JButton addDependencyKey= new JButton(); |
| 534 | + addDependencyKey.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK), "actionD"); |
| 535 | + addDependencyKey.getActionMap().put("actionD", new AbstractAction() { |
| 536 | + @Override |
| 537 | + public void actionPerformed(ActionEvent e) { |
| 538 | + Relationship.addDependency(EERDiagram.this, EERDiagram.this.getSelectedComponents()); |
| 539 | + EERDiagram.this.cleanSelectedComponents(); |
| 540 | + } |
| 541 | + }); |
| 542 | + out.add(addDependencyKey); |
| 543 | + |
| 544 | + JButton addHierarchyKey= new JButton(); |
| 545 | + addHierarchyKey.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_DOWN_MASK), "actionH"); |
| 546 | + addHierarchyKey.getActionMap().put("actionH", new AbstractAction() { |
| 547 | + @Override |
| 548 | + public void actionPerformed(ActionEvent e) { |
| 549 | + Hierarchy.addHierarchy(EERDiagram.this, EERDiagram.this.getSelectedComponents()); |
| 550 | + EERDiagram.this.cleanSelectedComponents(); |
| 551 | + } |
| 552 | + }); |
| 553 | + out.add(addHierarchyKey); |
| 554 | + |
| 555 | + JButton addNoteKey= new JButton(); |
| 556 | + addNoteKey.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK), "actionN"); |
| 557 | + addNoteKey.getActionMap().put("actionN", new AbstractAction() { |
| 558 | + @Override |
| 559 | + public void actionPerformed(ActionEvent e) { |
| 560 | + Note.addNote(EERDiagram.this); |
| 561 | + EERDiagram.this.cleanSelectedComponents(); |
| 562 | + } |
| 563 | + }); |
| 564 | + out.add(addNoteKey); |
| 565 | + |
| 566 | + return out; |
| 567 | + } |
554 | 568 | }
|
0 commit comments