Added fix for new relation creation.
This commit is contained in:
parent
657aece1ac
commit
1cb513cb51
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>nl.andrewlalis</groupId>
|
||||
<artifactId>EntityRelationMappingEditor</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<version>1.3.1</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
|
|
@ -7,7 +7,7 @@ import nl.andrewlalis.erme.view.EditorFrame;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class EntityRelationMappingEditor {
|
||||
public static final String VERSION = "1.3.0";
|
||||
public static final String VERSION = "1.3.1";
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (!FlatLightLaf.install()) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package nl.andrewlalis.erme.control.actions.edits;
|
|||
import lombok.Setter;
|
||||
import nl.andrewlalis.erme.model.MappingModel;
|
||||
import nl.andrewlalis.erme.model.Relation;
|
||||
import nl.andrewlalis.erme.view.DiagramPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
@ -23,6 +24,9 @@ public class AddRelationAction extends AbstractAction {
|
|||
@Setter
|
||||
private MappingModel model;
|
||||
|
||||
@Setter
|
||||
private DiagramPanel diagramPanel;
|
||||
|
||||
public AddRelationAction() {
|
||||
super("Add Relation");
|
||||
this.putValue(SHORT_DESCRIPTION, "Add a new relation to the diagram.");
|
||||
|
@ -39,9 +43,23 @@ public class AddRelationAction extends AbstractAction {
|
|||
JOptionPane.PLAIN_MESSAGE
|
||||
);
|
||||
if (name != null) {
|
||||
Rectangle bounds = this.model.getRelationBounds();
|
||||
Point center = new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
|
||||
this.model.addRelation(new Relation(this.model, center, name));
|
||||
final boolean isFirstRelation = this.model.getRelations().isEmpty();
|
||||
Point p;
|
||||
if (isFirstRelation) {
|
||||
p = new Point(100, 100);
|
||||
} else {
|
||||
Rectangle bounds = this.model.getRelationBounds();
|
||||
p = new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
|
||||
}
|
||||
Relation r = new Relation(this.model, p, name);
|
||||
this.model.getSelectedRelations().forEach(rl -> rl.setSelected(false));
|
||||
r.setSelected(true);
|
||||
this.model.addRelation(r);
|
||||
if (isFirstRelation) {
|
||||
this.model.normalizeRelationPositions();
|
||||
this.diagramPanel.centerModel();
|
||||
this.diagramPanel.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,9 @@ public class MappingModel implements Serializable, Viewable {
|
|||
}
|
||||
|
||||
public Rectangle getRelationBounds() {
|
||||
if (this.getRelations().isEmpty()) {
|
||||
return new Rectangle(0, 0, 0, 0);
|
||||
}
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
|
@ -109,6 +112,10 @@ public class MappingModel implements Serializable, Viewable {
|
|||
minX = Math.min(minX, r.getPosition().x);
|
||||
minY = Math.min(minY, r.getPosition().y);
|
||||
}
|
||||
if (this.getRelations().isEmpty()) {
|
||||
minX = 0;
|
||||
minY = 0;
|
||||
}
|
||||
for (Relation r : this.getRelations()) {
|
||||
final Point current = r.getPosition();
|
||||
r.setPosition(new Point(current.x - minX, current.y - minY));
|
||||
|
|
|
@ -123,6 +123,7 @@ public class DiagramPanel extends JPanel implements ModelChangeListener {
|
|||
LoadAction.getInstance().setDiagramPanel(this);
|
||||
ExportToImageAction.getInstance().setModel(this.model);
|
||||
AddRelationAction.getInstance().setModel(this.model);
|
||||
AddRelationAction.getInstance().setDiagramPanel(this);
|
||||
RemoveRelationAction.getInstance().setModel(this.model);
|
||||
AddAttributeAction.getInstance().setModel(this.model);
|
||||
RemoveAttributeAction.getInstance().setModel(this.model);
|
||||
|
|
Loading…
Reference in New Issue