Merge branch 'main' into auto-position

This commit is contained in:
Bjorn Pijnacker 2021-02-27 20:38:41 +01:00 committed by GitHub
commit e623bddcf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 65 additions and 26 deletions

View File

@ -1,6 +1,8 @@
package nl.andrewlalis.erme.control.actions;
import lombok.Setter;
import nl.andrewlalis.erme.EntityRelationMappingEditor;
import nl.andrewlalis.erme.view.DiagramPanel;
import javax.swing.*;
import java.awt.*;
@ -14,6 +16,9 @@ public class AboutAction extends AbstractAction {
return instance;
}
@Setter
private DiagramPanel diagramPanel;
public AboutAction() {
super("About");
this.putValue(SHORT_DESCRIPTION, "Show some information about this program.");
@ -22,7 +27,7 @@ public class AboutAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(
(Component) e.getSource(),
this.diagramPanel,
"Entity-Relation Mapping Editor\n" +
"by Andrew Lalis\n" +
"Version " + EntityRelationMappingEditor.VERSION + "\n" +

View File

@ -1,5 +1,8 @@
package nl.andrewlalis.erme.control.actions;
import lombok.Setter;
import nl.andrewlalis.erme.view.DiagramPanel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
@ -16,6 +19,9 @@ public class ExitAction extends AbstractAction {
return instance;
}
@Setter
private DiagramPanel diagramPanel;
public ExitAction() {
super("Exit");
this.putValue(Action.SHORT_DESCRIPTION, "Exit the program.");
@ -25,7 +31,7 @@ public class ExitAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
int choice = JOptionPane.showConfirmDialog(
(Component) e.getSource(),
this.diagramPanel,
"Are you sure you want to quit?\nAll unsaved data will be lost.",
"Confirm Exit",
JOptionPane.OK_CANCEL_OPTION,

View File

@ -34,6 +34,8 @@ public class ExportToImageAction extends AbstractAction {
@Setter
private MappingModel model;
@Setter
private DiagramPanel diagramPanel;
public ExportToImageAction() {
super("Export to Image");
@ -45,7 +47,7 @@ public class ExportToImageAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (this.model.getRelations().isEmpty()) {
JOptionPane.showMessageDialog(
(Component) e.getSource(),
this.diagramPanel,
"Model is empty. Add some relations before exporting to an image.",
"Model Empty",
JOptionPane.WARNING_MESSAGE
@ -61,7 +63,7 @@ public class ExportToImageAction extends AbstractAction {
if (path != null) {
fileChooser.setSelectedFile(new File(path));
}
int choice = fileChooser.showSaveDialog((Component) e.getSource());
int choice = fileChooser.showSaveDialog(this.diagramPanel);
if (choice == JFileChooser.APPROVE_OPTION) {
File chosenFile = fileChooser.getSelectedFile();
if (chosenFile == null || chosenFile.isDirectory()) {
@ -82,7 +84,7 @@ public class ExportToImageAction extends AbstractAction {
ImageIO.write(render, extension, chosenFile);
prefs.put(LAST_EXPORT_LOCATION_KEY, chosenFile.getAbsolutePath());
JOptionPane.showMessageDialog(
fileChooser,
this.diagramPanel,
"Image export completed in " + String.format("%.4f", durationSeconds) + " seconds.\n" +
"Resolution: " + render.getWidth() + "x" + render.getHeight(),
"Image Export Complete",

View File

@ -1,5 +1,8 @@
package nl.andrewlalis.erme.control.actions;
import lombok.Setter;
import nl.andrewlalis.erme.view.DiagramPanel;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.awt.*;
@ -24,10 +27,13 @@ public abstract class HtmlDocumentViewerAction extends AbstractAction {
this.modalityType = modalityType;
}
@Setter
private DiagramPanel diagramPanel;
@Override
public void actionPerformed(ActionEvent e) {
JDialog dialog = new JDialog(
SwingUtilities.getWindowAncestor((Component) e.getSource()),
SwingUtilities.getWindowAncestor(this.diagramPanel),
(String) this.getValue(NAME),
this.modalityType
);
@ -54,7 +60,7 @@ public abstract class HtmlDocumentViewerAction extends AbstractAction {
} catch (IOException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(
(Component) e.getSource(),
this.diagramPanel,
"An error occured:\n" + ex.getMessage(),
"Error",
JOptionPane.ERROR_MESSAGE
@ -68,7 +74,7 @@ public abstract class HtmlDocumentViewerAction extends AbstractAction {
dialog.setMaximumSize(new Dimension(600, 800));
dialog.setPreferredSize(new Dimension(600, 800));
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setLocationRelativeTo(this.diagramPanel);
dialog.setVisible(true);
}

View File

@ -49,7 +49,7 @@ public class LoadAction extends AbstractAction {
if (path != null) {
fileChooser.setSelectedFile(new File(path));
}
int choice = fileChooser.showOpenDialog((Component) e.getSource());
int choice = fileChooser.showOpenDialog(this.diagramPanel);
if (choice == JFileChooser.APPROVE_OPTION) {
File chosenFile = fileChooser.getSelectedFile();
if (chosenFile == null || chosenFile.isDirectory() || !chosenFile.exists() || !chosenFile.canRead()) {

View File

@ -2,6 +2,7 @@ package nl.andrewlalis.erme.control.actions;
import lombok.Setter;
import nl.andrewlalis.erme.model.MappingModel;
import nl.andrewlalis.erme.view.DiagramPanel;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
@ -28,6 +29,8 @@ public class SaveAction extends AbstractAction {
@Setter
private MappingModel model;
@Setter
private DiagramPanel diagramPanel;
public SaveAction() {
super("Save");
@ -48,7 +51,7 @@ public class SaveAction extends AbstractAction {
if (path != null) {
fileChooser.setSelectedFile(new File(path));
}
int choice = fileChooser.showSaveDialog((Component) e.getSource());
int choice = fileChooser.showSaveDialog(this.diagramPanel);
if (choice == JFileChooser.APPROVE_OPTION) {
File chosenFile = fileChooser.getSelectedFile();
if (chosenFile == null || chosenFile.isDirectory()) {

View File

@ -2,6 +2,7 @@ package nl.andrewlalis.erme.control.actions.edits;
import lombok.Setter;
import nl.andrewlalis.erme.model.*;
import nl.andrewlalis.erme.view.DiagramPanel;
import javax.swing.*;
import java.awt.*;
@ -24,6 +25,8 @@ public class AddAttributeAction extends AbstractAction {
@Setter
private MappingModel model;
@Setter
private DiagramPanel diagramPanel;
public AddAttributeAction() {
super("Add Attribute");
@ -36,7 +39,7 @@ public class AddAttributeAction extends AbstractAction {
List<Relation> selectedRelations = this.model.getSelectedRelations();
if (selectedRelations.size() != 1) {
JOptionPane.showMessageDialog(
(Component) e.getSource(),
this.diagramPanel,
"A single relation must be selected to add an attribute.",
"Single Relation Required",
JOptionPane.WARNING_MESSAGE
@ -45,11 +48,11 @@ public class AddAttributeAction extends AbstractAction {
}
Relation r = selectedRelations.get(0);
Attribute createdAttribute;
Component c = (Component) e.getSource();
String name = JOptionPane.showInputDialog(c, "Enter the name of the attribute.", "Attribute Name", JOptionPane.PLAIN_MESSAGE);
Component source = this.diagramPanel;
String name = JOptionPane.showInputDialog(source, "Enter the name of the attribute.", "Attribute Name", JOptionPane.PLAIN_MESSAGE);
if (name == null) return;
Integer index = (Integer) JOptionPane.showInputDialog(
c,
source,
"Select the index to insert this attribute at.",
"Attribute Index",
JOptionPane.PLAIN_MESSAGE,
@ -59,7 +62,7 @@ public class AddAttributeAction extends AbstractAction {
);
if (index == null) return;
AttributeType type = (AttributeType) JOptionPane.showInputDialog(
c,
source,
"Select the type this attribute is.",
"Attribute Type",
JOptionPane.PLAIN_MESSAGE,
@ -69,7 +72,7 @@ public class AddAttributeAction extends AbstractAction {
);
if (type == null) return;
boolean shouldUseForeignKey = ((String) JOptionPane.showInputDialog(
c,
source,
"Is this attribute a foreign key?",
"Foreign Key",
JOptionPane.PLAIN_MESSAGE,
@ -79,11 +82,11 @@ public class AddAttributeAction extends AbstractAction {
)).equalsIgnoreCase("yes");
if (shouldUseForeignKey) {
if (this.model.getRelations().size() < 2) {
JOptionPane.showMessageDialog(c, "There should be at least 2 relations present in the model.", "Not Enough Relations", JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(source, "There should be at least 2 relations present in the model.", "Not Enough Relations", JOptionPane.WARNING_MESSAGE);
return;
}
Relation fkRelation = (Relation) JOptionPane.showInputDialog(
c,
source,
"Select the relation that this foreign key references.",
"Foreign Key Relation Reference",
JOptionPane.PLAIN_MESSAGE,
@ -94,11 +97,11 @@ public class AddAttributeAction extends AbstractAction {
if (fkRelation == null) return;
List<Attribute> eligibleAttributes = fkRelation.getAttributes();
if (eligibleAttributes.isEmpty()) {
JOptionPane.showMessageDialog(c, "There are no referencable attributes in the selected relation.", "No Referencable Attributes", JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(source, "There are no referencable attributes in the selected relation.", "No Referencable Attributes", JOptionPane.WARNING_MESSAGE);
return;
}
Attribute fkAttribute = (Attribute) JOptionPane.showInputDialog(
c,
source,
"Select the attribute that this foreign key references.",
"Foreign Key Attribute Reference",
JOptionPane.PLAIN_MESSAGE,

View File

@ -35,9 +35,8 @@ public class AddRelationAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
Component c = (Component) e.getSource();
String name = JOptionPane.showInputDialog(
c,
this.diagramPanel,
"Enter the name of the relation.",
"Add Relation",
JOptionPane.PLAIN_MESSAGE

View File

@ -4,6 +4,7 @@ import lombok.Setter;
import nl.andrewlalis.erme.model.Attribute;
import nl.andrewlalis.erme.model.MappingModel;
import nl.andrewlalis.erme.model.Relation;
import nl.andrewlalis.erme.view.DiagramPanel;
import javax.swing.*;
import java.awt.*;
@ -25,6 +26,8 @@ public class RemoveAttributeAction extends AbstractAction {
@Setter
private MappingModel model;
@Setter
private DiagramPanel diagramPanel;
public RemoveAttributeAction() {
super("Remove Attribute");
@ -37,7 +40,7 @@ public class RemoveAttributeAction extends AbstractAction {
List<Relation> selectedRelations = this.model.getSelectedRelations();
if (selectedRelations.size() != 1 || selectedRelations.get(0).getAttributes().isEmpty()) {
JOptionPane.showMessageDialog(
(Component) e.getSource(),
this.diagramPanel,
"A single relation with at least one attribute must be selected to remove an attribute.",
"Single Relation With Attribute Required",
JOptionPane.WARNING_MESSAGE
@ -46,7 +49,7 @@ public class RemoveAttributeAction extends AbstractAction {
}
Relation r = selectedRelations.get(0);
Attribute attribute = (Attribute) JOptionPane.showInputDialog(
(Component) e.getSource(),
this.diagramPanel,
"Select the attribute to remove.",
"Select Attribute",
JOptionPane.PLAIN_MESSAGE,

View File

@ -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.*;
@ -22,6 +23,8 @@ public class RemoveRelationAction extends AbstractAction {
@Setter
private MappingModel model;
@Setter
private DiagramPanel diagramPanel;
public RemoveRelationAction() {
super("Remove Relation");
@ -33,7 +36,7 @@ public class RemoveRelationAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (this.model.getSelectedRelations().isEmpty()) {
JOptionPane.showMessageDialog(
(Component) e.getSource(),
this.diagramPanel,
"No relations selected. Select at least one relation to remove.",
"No Relations Selected",
JOptionPane.WARNING_MESSAGE

View File

@ -123,16 +123,25 @@ public class DiagramPanel extends JPanel implements ModelChangeListener {
SaveAction.getInstance().setModel(this.model);
LoadAction.getInstance().setDiagramPanel(this);
ExportToImageAction.getInstance().setModel(this.model);
ExportToImageAction.getInstance().setDiagramPanel(this);
AddRelationAction.getInstance().setModel(this.model);
AddRelationAction.getInstance().setDiagramPanel(this);
RemoveRelationAction.getInstance().setModel(this.model);
RemoveRelationAction.getInstance().setDiagramPanel(this);
AddAttributeAction.getInstance().setModel(this.model);
AddAttributeAction.getInstance().setDiagramPanel(this);
RemoveAttributeAction.getInstance().setModel(this.model);
RemoveAttributeAction.getInstance().setDiagramPanel(this);
LoadSampleModelAction.getInstance().setDiagramPanel(this);
LolcatAction.getInstance().setDiagramPanel(this);
AutoPositionAction.getInstance().setDiagramPanel(this);
AutoPositionAction.getInstance().setModel(this.model);
OrderableListPanel.getInstance().setModel(this.model);
AboutAction.getInstance().setDiagramPanel(this);
ExitAction.getInstance().setDiagramPanel(this);
InstructionsAction.getInstance().setDiagramPanel(this);
MappingAlgorithmHelpAction.getInstance().setDiagramPanel(this);
SaveAction.getInstance().setDiagramPanel(this);
}
public static void prepareGraphics(Graphics2D g) {