selectedRelations = diagramPanel.getModel().getSelectedRelations();
if (selectedRelations.size() == 0) {
- this.add(AddRelationAction.getInstance());
+ this.add(new AddRelationAction(diagramPanel));
}
if (selectedRelations.size() > 0) {
- this.add(RemoveRelationAction.getInstance());
+ this.add(new RemoveRelationAction(diagramPanel));
}
if (selectedRelations.size() == 1) {
- this.add(AddAttributeAction.getInstance());
- this.add(RemoveAttributeAction.getInstance());
+ Relation relation = selectedRelations.get(0);
+ this.add(new AddAttributeAction(diagramPanel));
+ if (!relation.getAttributes().isEmpty()) {
+ this.add(new RemoveRelationAction(diagramPanel));
+ }
}
}
}
diff --git a/src/main/java/nl/andrewlalis/erme/view/EditorFrame.java b/src/main/java/nl/andrewlalis/erme/view/EditorFrame.java
index 1f8435d..20f9600 100644
--- a/src/main/java/nl/andrewlalis/erme/view/EditorFrame.java
+++ b/src/main/java/nl/andrewlalis/erme/view/EditorFrame.java
@@ -14,8 +14,9 @@ import java.io.InputStream;
public class EditorFrame extends JFrame {
public EditorFrame() {
super("ER-Mapping Editor");
- this.setContentPane(new DiagramPanel(new MappingModel()));
- this.setJMenuBar(new EditorMenuBar());
+ DiagramPanel diagramPanel = new DiagramPanel(new MappingModel());
+ this.setContentPane(diagramPanel);
+ this.setJMenuBar(new EditorMenuBar(diagramPanel));
try {
InputStream is = getClass().getClassLoader().getResourceAsStream("icon.png");
if (is == null) {
@@ -26,7 +27,7 @@ public class EditorFrame extends JFrame {
} catch (IOException e) {
e.printStackTrace();
}
- this.setMinimumSize(new Dimension(400, 400));
+ this.setMinimumSize(new Dimension(300, 300));
this.setPreferredSize(new Dimension(800, 800));
this.pack();
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
diff --git a/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java b/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java
index 96a7604..8be07c0 100644
--- a/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java
+++ b/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java
@@ -3,7 +3,6 @@ package nl.andrewlalis.erme.view;
import nl.andrewlalis.erme.control.actions.*;
import nl.andrewlalis.erme.control.actions.edits.AddAttributeAction;
import nl.andrewlalis.erme.control.actions.edits.AddRelationAction;
-import nl.andrewlalis.erme.control.actions.edits.RemoveAttributeAction;
import nl.andrewlalis.erme.control.actions.edits.RemoveRelationAction;
import javax.swing.*;
@@ -12,51 +11,47 @@ import javax.swing.*;
* The menu bar that's visible atop the application.
*/
public class EditorMenuBar extends JMenuBar {
- public EditorMenuBar() {
- this.add(this.buildFileMenu());
- this.add(this.buildEditMenu());
- this.add(this.buildViewMenu());
- this.add(this.buildHelpMenu());
+ public EditorMenuBar(DiagramPanel diagramPanel) {
+ this.add(this.buildFileMenu(diagramPanel));
+ this.add(this.buildEditMenu(diagramPanel));
+ this.add(this.buildViewMenu(diagramPanel));
+ this.add(this.buildHelpMenu(diagramPanel));
}
- private JMenu buildFileMenu() {
+ private JMenu buildFileMenu(DiagramPanel diagramPanel) {
JMenu menu = new JMenu("File");
- menu.add(NewModelAction.getInstance());
- menu.add(SaveAction.getInstance());
- menu.add(LoadAction.getInstance());
+ menu.add(new NewModelAction(diagramPanel));
+ menu.add(new SaveAction(diagramPanel));
+ menu.add(new LoadAction(diagramPanel));
menu.addSeparator();
- menu.add(ExportToImageAction.getInstance());
+ menu.add(new ExportToImageAction(diagramPanel));
menu.addSeparator();
- menu.add(ExitAction.getInstance());
+ menu.add(new ExitAction(diagramPanel));
return menu;
}
- private JMenu buildEditMenu() {
+ private JMenu buildEditMenu(DiagramPanel diagramPanel) {
JMenu menu = new JMenu("Edit");
- menu.add(AddRelationAction.getInstance());
- menu.add(RemoveRelationAction.getInstance());
- menu.add(AddAttributeAction.getInstance());
- menu.add(RemoveAttributeAction.getInstance());
- menu.add(AutoPositionAction.getInstance());
- menu.addSeparator();
- menu.add(UndoAction.getInstance());
- menu.add(RedoAction.getInstance());
+ menu.add(new AddRelationAction(diagramPanel));
+ menu.add(new RemoveRelationAction(diagramPanel));
+ menu.add(new AddAttributeAction(diagramPanel));
+ menu.add(new RemoveRelationAction(diagramPanel));
+ menu.add(new AutoPositionAction(diagramPanel));
return menu;
}
- private JMenu buildViewMenu() {
+ private JMenu buildViewMenu(DiagramPanel diagramPanel) {
JMenu menu = new JMenu("View");
- menu.add(new JCheckBoxMenuItem(LolcatAction.getInstance()));
- menu.add(new JCheckBoxMenuItem(VisualizeReferencesAction.getInstance()));
+ menu.add(new JCheckBoxMenuItem(new LolcatAction(diagramPanel)));
+ menu.add(new JCheckBoxMenuItem(new VisualizeReferencesAction(diagramPanel)));
return menu;
}
- private JMenu buildHelpMenu() {
+ private JMenu buildHelpMenu(DiagramPanel diagramPanel) {
JMenu menu = new JMenu("Help");
- menu.add(InstructionsAction.getInstance());
- menu.add(MappingAlgorithmHelpAction.getInstance());
- menu.add(LoadSampleModelAction.getInstance());
- menu.add(AboutAction.getInstance());
+ menu.add(new InstructionsAction(diagramPanel));
+ menu.add(new MappingAlgorithmHelpAction(diagramPanel));
+ menu.add(new LoadSampleModelAction(diagramPanel));
return menu;
}
}
diff --git a/src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java b/src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java
index 7731e65..433ec6a 100644
--- a/src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java
+++ b/src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java
@@ -15,6 +15,7 @@ import java.util.Set;
/**
* A panel to be used in a popup that has a OrderableListModel implemented. Implements ModelChangeListener to be able
* to update the list of relations when new ones are added or ones are removed.
+ * TODO: Refactor this to not use static singleton instance.
*/
public class OrderableListPanel extends JPanel implements ModelChangeListener {
private static OrderableListPanel instance;
diff --git a/src/main/java/nl/andrewlalis/erme/view/view_models/AttributeViewModel.java b/src/main/java/nl/andrewlalis/erme/view/view_models/AttributeViewModel.java
index ab104fa..ca45ed2 100644
--- a/src/main/java/nl/andrewlalis/erme/view/view_models/AttributeViewModel.java
+++ b/src/main/java/nl/andrewlalis/erme/view/view_models/AttributeViewModel.java
@@ -1,6 +1,5 @@
package nl.andrewlalis.erme.view.view_models;
-import nl.andrewlalis.erme.control.actions.LolcatAction;
import nl.andrewlalis.erme.model.Attribute;
import nl.andrewlalis.erme.model.AttributeType;
import nl.andrewlalis.erme.model.ForeignKeyAttribute;
@@ -46,7 +45,7 @@ public class AttributeViewModel implements ViewModel {
}
private Color getBackgroundColor(int x, int y, Graphics2D g) {
- if (!LolcatAction.getInstance().isLolcatEnabled()) return BACKGROUND_COLOR;
+ if (!attribute.getRelation().getModel().isLolcatEnabled()) return BACKGROUND_COLOR;
Point offset = g.getClipBounds().getLocation();
g.translate(offset.x, offset.y);
Dimension viewportSize = g.getClipBounds().getSize();
diff --git a/src/main/java/nl/andrewlalis/erme/view/view_models/MappingModelViewModel.java b/src/main/java/nl/andrewlalis/erme/view/view_models/MappingModelViewModel.java
index dff8df8..c54bd7d 100644
--- a/src/main/java/nl/andrewlalis/erme/view/view_models/MappingModelViewModel.java
+++ b/src/main/java/nl/andrewlalis/erme/view/view_models/MappingModelViewModel.java
@@ -1,13 +1,11 @@
package nl.andrewlalis.erme.view.view_models;
-import nl.andrewlalis.erme.control.actions.VisualizeReferencesAction;
import nl.andrewlalis.erme.model.Attribute;
import nl.andrewlalis.erme.model.ForeignKeyAttribute;
import nl.andrewlalis.erme.model.MappingModel;
import nl.andrewlalis.erme.model.Relation;
import java.awt.*;
-import java.awt.color.ColorSpace;
import java.util.Random;
/**
@@ -22,9 +20,7 @@ public class MappingModelViewModel implements ViewModel {
@Override
public void draw(Graphics2D g) {
- if (VisualizeReferencesAction.getInstance().isReferenceVisualizationEnabled()) {
- visualizeReferences(g);
- }
+ if (model.isReferenceVisualizationEnabled()) visualizeReferences(g);
for (Relation r : this.model.getRelations()) {
r.getViewModel().draw(g);
}
diff --git a/src/main/resources/html/instructions.html b/src/main/resources/html/instructions.html
index b5b5bb0..9b04d1c 100644
--- a/src/main/resources/html/instructions.html
+++ b/src/main/resources/html/instructions.html
@@ -7,9 +7,13 @@
Entity-Relation Mapping Editor
-Created by @andrewlalis
A simple UI for editing entity-relation mapping diagrams.
+Created by Andrew Lalis
+And with generous contributions by
+
Have you noticed any unexpected behavior? Is there something you think would make a good addition to this application?
@@ -27,6 +31,9 @@
The Edit menu contains options for making changes to the current model, such as adding or removing relations and attributes, or undoing/redoing actions.
+
+ The View menu contains options for changing how the model is viewed.
+
The Help menu contains some items with additional information about the application, like this help page and a simple About popup with version information. There's also a Load Sample Model option, which will load a very basic sample model into the application that you are free to mess around with.