Bumped version, slight cleanup of AddRelationAction.

This commit is contained in:
Andrew Lalis 2021-02-27 21:01:21 +01:00
parent a8966d6051
commit d63eb3345f
7 changed files with 40 additions and 10 deletions

View File

@ -6,7 +6,7 @@
<groupId>nl.andrewlalis</groupId> <groupId>nl.andrewlalis</groupId>
<artifactId>EntityRelationMappingEditor</artifactId> <artifactId>EntityRelationMappingEditor</artifactId>
<version>1.4.0</version> <version>1.5.0</version>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

View File

@ -7,7 +7,7 @@ import nl.andrewlalis.erme.view.EditorFrame;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
public class EntityRelationMappingEditor { 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) { public static void main(String[] args) {
if (!FlatLightLaf.install()) { if (!FlatLightLaf.install()) {

View File

@ -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;
}
}

View File

@ -1,6 +1,7 @@
package nl.andrewlalis.erme.control.actions.edits; package nl.andrewlalis.erme.control.actions.edits;
import lombok.Setter; import lombok.Setter;
import nl.andrewlalis.erme.control.actions.LocalAction;
import nl.andrewlalis.erme.model.MappingModel; import nl.andrewlalis.erme.model.MappingModel;
import nl.andrewlalis.erme.model.Relation; import nl.andrewlalis.erme.model.Relation;
import nl.andrewlalis.erme.view.DiagramPanel; import nl.andrewlalis.erme.view.DiagramPanel;
@ -11,9 +12,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.InputEvent; import java.awt.event.InputEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
public class AddRelationAction extends AbstractAction { public class AddRelationAction extends LocalAction {
private static AddRelationAction instance; private static AddRelationAction instance;
public static AddRelationAction getInstance() { public static AddRelationAction getInstance() {
if (instance == null) { if (instance == null) {
instance = new AddRelationAction(); instance = new AddRelationAction();
@ -44,7 +44,12 @@ public class AddRelationAction extends AbstractAction {
if (name != null) { if (name != null) {
final boolean isFirstRelation = this.model.getRelations().isEmpty(); final boolean isFirstRelation = this.model.getRelations().isEmpty();
Point p; 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); p = new Point(100, 100);
} else { } else {
Rectangle bounds = this.model.getRelationBounds(); Rectangle bounds = this.model.getRelationBounds();

View File

@ -7,12 +7,10 @@ import nl.andrewlalis.erme.model.Relation;
import nl.andrewlalis.erme.view.DiagramPanel; import nl.andrewlalis.erme.view.DiagramPanel;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.InputEvent; import java.awt.event.InputEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
public class RemoveAttributeAction extends AbstractAction { public class RemoveAttributeAction extends AbstractAction {
private static RemoveAttributeAction instance; private static RemoveAttributeAction instance;

View File

@ -54,7 +54,7 @@ public class DiagramMouseListener extends MouseAdapter {
// If the user right-clicked, show a popup menu. // If the user right-clicked, show a popup menu.
if (e.getButton() == MouseEvent.BUTTON3) { 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()); popupMenu.show(panel, e.getX(), e.getY());
} }

View File

@ -1,6 +1,5 @@
package nl.andrewlalis.erme.view; 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.AddAttributeAction;
import nl.andrewlalis.erme.control.actions.edits.AddRelationAction; import nl.andrewlalis.erme.control.actions.edits.AddRelationAction;
import nl.andrewlalis.erme.control.actions.edits.RemoveAttributeAction; 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 nl.andrewlalis.erme.model.Relation;
import javax.swing.*; import javax.swing.*;
import java.awt.event.MouseEvent;
import java.util.List; import java.util.List;
public class DiagramPopupMenu extends JPopupMenu { public class DiagramPopupMenu extends JPopupMenu {
public DiagramPopupMenu(MappingModel model) { public DiagramPopupMenu(MappingModel model, MouseEvent e) {
List<Relation> selectedRelations = model.getSelectedRelations(); List<Relation> selectedRelations = model.getSelectedRelations();
AddRelationAction.getInstance().setLocation(e.getPoint());
if (selectedRelations.size() == 0) { if (selectedRelations.size() == 0) {
this.add(AddRelationAction.getInstance()); this.add(AddRelationAction.getInstance());
} }