diff --git a/pom.xml b/pom.xml
index 2506475..029aacf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
nl.andrewlalis
EntityRelationMappingEditor
- 1.4.0
+ 1.5.0
diff --git a/src/main/java/nl/andrewlalis/erme/EntityRelationMappingEditor.java b/src/main/java/nl/andrewlalis/erme/EntityRelationMappingEditor.java
index 9341024..75fcb5f 100644
--- a/src/main/java/nl/andrewlalis/erme/EntityRelationMappingEditor.java
+++ b/src/main/java/nl/andrewlalis/erme/EntityRelationMappingEditor.java
@@ -7,7 +7,7 @@ import nl.andrewlalis.erme.view.EditorFrame;
import java.nio.charset.StandardCharsets;
public class EntityRelationMappingEditor {
- public static final String VERSION = "1.4.0";
+ public static final String VERSION = "1.5.0";
public static void main(String[] args) {
if (!FlatLightLaf.install()) {
diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/LocalAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/LocalAction.java
new file mode 100644
index 0000000..2b490f8
--- /dev/null
+++ b/src/main/java/nl/andrewlalis/erme/control/actions/LocalAction.java
@@ -0,0 +1,26 @@
+package nl.andrewlalis.erme.control.actions;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.swing.*;
+import java.awt.*;
+
+public abstract class LocalAction extends AbstractAction {
+ @Setter
+ @Getter
+ private Point location;
+
+ public LocalAction(String name, Point location) {
+ super(name);
+ this.location = location;
+ }
+
+ public LocalAction(String name) {
+ this(name, null);
+ }
+
+ public boolean hasLocation() {
+ return this.location != null;
+ }
+}
diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddRelationAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddRelationAction.java
index 36563a5..1f882ab 100644
--- a/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddRelationAction.java
+++ b/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddRelationAction.java
@@ -1,6 +1,7 @@
package nl.andrewlalis.erme.control.actions.edits;
import lombok.Setter;
+import nl.andrewlalis.erme.control.actions.LocalAction;
import nl.andrewlalis.erme.model.MappingModel;
import nl.andrewlalis.erme.model.Relation;
import nl.andrewlalis.erme.view.DiagramPanel;
@@ -11,9 +12,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
-public class AddRelationAction extends AbstractAction {
+public class AddRelationAction extends LocalAction {
private static AddRelationAction instance;
-
public static AddRelationAction getInstance() {
if (instance == null) {
instance = new AddRelationAction();
@@ -44,7 +44,12 @@ public class AddRelationAction extends AbstractAction {
if (name != null) {
final boolean isFirstRelation = this.model.getRelations().isEmpty();
Point p;
- if (isFirstRelation) {
+ if (this.hasLocation()) {
+ p = new Point(
+ this.getLocation().x - this.diagramPanel.getPanningTranslation().x,
+ this.getLocation().y - this.diagramPanel.getPanningTranslation().y
+ );
+ } else if (isFirstRelation) {
p = new Point(100, 100);
} else {
Rectangle bounds = this.model.getRelationBounds();
diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/edits/RemoveAttributeAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/edits/RemoveAttributeAction.java
index d1fbb4b..6f74d6a 100644
--- a/src/main/java/nl/andrewlalis/erme/control/actions/edits/RemoveAttributeAction.java
+++ b/src/main/java/nl/andrewlalis/erme/control/actions/edits/RemoveAttributeAction.java
@@ -7,12 +7,10 @@ import nl.andrewlalis.erme.model.Relation;
import nl.andrewlalis.erme.view.DiagramPanel;
import javax.swing.*;
-import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.List;
-import java.util.stream.Stream;
public class RemoveAttributeAction extends AbstractAction {
private static RemoveAttributeAction instance;
diff --git a/src/main/java/nl/andrewlalis/erme/control/diagram/DiagramMouseListener.java b/src/main/java/nl/andrewlalis/erme/control/diagram/DiagramMouseListener.java
index 5beaadb..cc20d24 100644
--- a/src/main/java/nl/andrewlalis/erme/control/diagram/DiagramMouseListener.java
+++ b/src/main/java/nl/andrewlalis/erme/control/diagram/DiagramMouseListener.java
@@ -54,7 +54,7 @@ public class DiagramMouseListener extends MouseAdapter {
// If the user right-clicked, show a popup menu.
if (e.getButton() == MouseEvent.BUTTON3) {
- DiagramPopupMenu popupMenu = new DiagramPopupMenu(this.model);
+ DiagramPopupMenu popupMenu = new DiagramPopupMenu(this.model, e);
popupMenu.show(panel, e.getX(), e.getY());
}
diff --git a/src/main/java/nl/andrewlalis/erme/view/DiagramPopupMenu.java b/src/main/java/nl/andrewlalis/erme/view/DiagramPopupMenu.java
index 4a797f0..c6bd5e9 100644
--- a/src/main/java/nl/andrewlalis/erme/view/DiagramPopupMenu.java
+++ b/src/main/java/nl/andrewlalis/erme/view/DiagramPopupMenu.java
@@ -1,6 +1,5 @@
package nl.andrewlalis.erme.view;
-import nl.andrewlalis.erme.control.actions.ExportToImageAction;
import nl.andrewlalis.erme.control.actions.edits.AddAttributeAction;
import nl.andrewlalis.erme.control.actions.edits.AddRelationAction;
import nl.andrewlalis.erme.control.actions.edits.RemoveAttributeAction;
@@ -9,11 +8,13 @@ import nl.andrewlalis.erme.model.MappingModel;
import nl.andrewlalis.erme.model.Relation;
import javax.swing.*;
+import java.awt.event.MouseEvent;
import java.util.List;
public class DiagramPopupMenu extends JPopupMenu {
- public DiagramPopupMenu(MappingModel model) {
+ public DiagramPopupMenu(MappingModel model, MouseEvent e) {
List selectedRelations = model.getSelectedRelations();
+ AddRelationAction.getInstance().setLocation(e.getPoint());
if (selectedRelations.size() == 0) {
this.add(AddRelationAction.getInstance());
}