Bumped version, slight cleanup of AddRelationAction.
This commit is contained in:
		
							parent
							
								
									a8966d6051
								
							
						
					
					
						commit
						d63eb3345f
					
				
							
								
								
									
										2
									
								
								pom.xml
								
								
								
								
							
							
						
						
									
										2
									
								
								pom.xml
								
								
								
								
							| 
						 | 
				
			
			@ -6,7 +6,7 @@
 | 
			
		|||
 | 
			
		||||
    <groupId>nl.andrewlalis</groupId>
 | 
			
		||||
    <artifactId>EntityRelationMappingEditor</artifactId>
 | 
			
		||||
    <version>1.4.0</version>
 | 
			
		||||
    <version>1.5.0</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.4.0";
 | 
			
		||||
	public static final String VERSION = "1.5.0";
 | 
			
		||||
 | 
			
		||||
	public static void main(String[] args) {
 | 
			
		||||
		if (!FlatLightLaf.install()) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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());
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<Relation> selectedRelations = model.getSelectedRelations();
 | 
			
		||||
		AddRelationAction.getInstance().setLocation(e.getPoint());
 | 
			
		||||
		if (selectedRelations.size() == 0) {
 | 
			
		||||
			this.add(AddRelationAction.getInstance());
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue