From af00918502c1f4d3df270a243fe136bea30c4c33 Mon Sep 17 00:00:00 2001 From: Bjorn Pijnacker Date: Fri, 26 Feb 2021 20:23:42 +0100 Subject: [PATCH 1/8] Implemented rudimentary auto-positioning feature using alphabetic sorting of relations Now going to be working on custom sorting --- .../control/actions/AutoPositionAction.java | 56 +++++++++++++++++++ .../nl/andrewlalis/erme/model/Relation.java | 7 ++- .../andrewlalis/erme/view/DiagramPanel.java | 2 + .../andrewlalis/erme/view/EditorMenuBar.java | 1 + .../erme/view/OrderableListModel.java | 16 ++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java create mode 100644 src/main/java/nl/andrewlalis/erme/view/OrderableListModel.java diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java new file mode 100644 index 0000000..3b46629 --- /dev/null +++ b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java @@ -0,0 +1,56 @@ +package nl.andrewlalis.erme.control.actions; + +import lombok.Getter; +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.*; +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.Collections; +import java.util.concurrent.atomic.AtomicInteger; + +public class AutoPositionAction extends AbstractAction { + private static AutoPositionAction instance; + private final static int MARGIN = 10; + private final static int PADDING = 10; + + public static AutoPositionAction getInstance() { + if (instance == null) { + instance = new AutoPositionAction(); + } + return instance; + } + + @Setter + private DiagramPanel diagramPanel; + @Setter + private MappingModel model; + + public AutoPositionAction() { + super("Position Relations"); + this.putValue(SHORT_DESCRIPTION, "Automatically Position Relations"); + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + this.positionRelations(); + diagramPanel.repaint(); + } + + private void positionRelations() { + diagramPanel.resetTranslation(); + ArrayList relationList = new ArrayList<>(model.getRelations()); + Collections.sort(relationList); + if (relationList.isEmpty()) return; + + int vertSpace = (int) relationList.get(0).getViewModel().getBounds(diagramPanel.getGraphics2D()).getHeight() + PADDING; + AtomicInteger vertPos = new AtomicInteger(MARGIN); + relationList.forEach(r -> { + r.setPosition(new Point(MARGIN, vertPos.getAndAdd(vertSpace))); + }); + } +} diff --git a/src/main/java/nl/andrewlalis/erme/model/Relation.java b/src/main/java/nl/andrewlalis/erme/model/Relation.java index 05c0e66..8393002 100644 --- a/src/main/java/nl/andrewlalis/erme/model/Relation.java +++ b/src/main/java/nl/andrewlalis/erme/model/Relation.java @@ -15,7 +15,7 @@ import java.util.stream.Collectors; * Represents a single "relation" or table in the diagram. */ @Getter -public class Relation implements Serializable, Viewable { +public class Relation implements Serializable, Viewable, Comparable { private final MappingModel model; private Point position; private String name; @@ -97,4 +97,9 @@ public class Relation implements Serializable, Viewable { this.getAttributes().forEach(a -> c.addAttribute(a.copy(c))); return c; } + + @Override + public int compareTo(Relation relation) { + return this.name.compareTo(relation.name); + } } diff --git a/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java b/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java index 54bc65e..ba57981 100644 --- a/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java +++ b/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java @@ -129,6 +129,8 @@ public class DiagramPanel extends JPanel implements ModelChangeListener { RemoveAttributeAction.getInstance().setModel(this.model); LoadSampleModelAction.getInstance().setDiagramPanel(this); LolcatAction.getInstance().setDiagramPanel(this); + AutoPositionAction.getInstance().setDiagramPanel(this); + AutoPositionAction.getInstance().setModel(this.model); } public static void prepareGraphics(Graphics2D g) { diff --git a/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java b/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java index 8710c3d..afd76fa 100644 --- a/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java +++ b/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java @@ -40,6 +40,7 @@ public class EditorMenuBar extends JMenuBar { menu.add(AddAttributeAction.getInstance()); menu.add(RemoveAttributeAction.getInstance()); menu.add(new JCheckBoxMenuItem(LolcatAction.getInstance())); + menu.add(AutoPositionAction.getInstance()); menu.addSeparator(); menu.add(UndoAction.getInstance()); menu.add(RedoAction.getInstance()); diff --git a/src/main/java/nl/andrewlalis/erme/view/OrderableListModel.java b/src/main/java/nl/andrewlalis/erme/view/OrderableListModel.java new file mode 100644 index 0000000..c3d29c9 --- /dev/null +++ b/src/main/java/nl/andrewlalis/erme/view/OrderableListModel.java @@ -0,0 +1,16 @@ +package nl.andrewlalis.erme.view; + +import nl.andrewlalis.erme.model.Relation; + +import java.util.ArrayList; +import java.util.Collections; + +public class OrderableListModel { + private ArrayList list; + + public void moveUp(int index) { + if (index > 0) { + Collections.swap(list, index, index - 1); + } + } +} From faadc40d265f964c3463e29aecd6b9cdd92e4475 Mon Sep 17 00:00:00 2001 From: Bjorn Pijnacker Date: Fri, 26 Feb 2021 21:36:18 +0100 Subject: [PATCH 2/8] Implemented custom order alignment - Implemented a custom model for a JList that allows for reordering elements using JButtons - Ask the user whether to sort alphabetically or using an order they decide - Ensured that the list in the OrderableListPanel keeps its order between multiple sorting times (this saves the user the work of re-sorting every time) --- .../control/actions/AutoPositionAction.java | 83 ++++++++++++++----- .../andrewlalis/erme/model/MappingModel.java | 2 + .../andrewlalis/erme/view/DiagramPanel.java | 1 + .../erme/view/OrderableListModel.java | 59 +++++++++++-- .../erme/view/OrderableListPanel.java | 82 ++++++++++++++++++ 5 files changed, 201 insertions(+), 26 deletions(-) create mode 100644 src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java index 3b46629..04ff7ef 100644 --- a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java +++ b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java @@ -1,10 +1,10 @@ package nl.andrewlalis.erme.control.actions; -import lombok.Getter; import lombok.Setter; import nl.andrewlalis.erme.model.MappingModel; import nl.andrewlalis.erme.model.Relation; import nl.andrewlalis.erme.view.DiagramPanel; +import nl.andrewlalis.erme.view.OrderableListPanel; import javax.swing.*; import java.awt.*; @@ -13,10 +13,22 @@ import java.util.ArrayList; import java.util.Collections; import java.util.concurrent.atomic.AtomicInteger; +/** + * A class that implements an AutoPositionAction. This automatically (vertically) positions all relations in the model + * based either on alphabetic ordering (by name) or an order that's set by the user + */ public class AutoPositionAction extends AbstractAction { - private static AutoPositionAction instance; private final static int MARGIN = 10; private final static int PADDING = 10; + private static AutoPositionAction instance; + @Setter + private DiagramPanel diagramPanel; + @Setter + private MappingModel model; + public AutoPositionAction() { + super("Position Relations"); + this.putValue(SHORT_DESCRIPTION, "Automatically Position Relations"); + } public static AutoPositionAction getInstance() { if (instance == null) { @@ -25,32 +37,63 @@ public class AutoPositionAction extends AbstractAction { return instance; } - @Setter - private DiagramPanel diagramPanel; - @Setter - private MappingModel model; - - public AutoPositionAction() { - super("Position Relations"); - this.putValue(SHORT_DESCRIPTION, "Automatically Position Relations"); - } - @Override public void actionPerformed(ActionEvent actionEvent) { - this.positionRelations(); + if (model.getRelations().size() == 0) { + JOptionPane.showMessageDialog( + null, + "Cannot position all relations when there are no relations present", + "Relations Required", + JOptionPane.WARNING_MESSAGE + ); + return; + } + String[] choices = new String[]{"Alphabeticaly", "Custom Order"}; + String choice = (String) JOptionPane.showInputDialog( + null, + "Select how to sort the relations", + "Position Relations", + JOptionPane.PLAIN_MESSAGE, + null, + choices, + 0); + if (choice == null) return; + if (choice.equals(choices[0])) { + positionRelation(); + } else if (choice.equals(choices[1])) { + JOptionPane.showConfirmDialog( + null, + OrderableListPanel.getInstance(), + "teststring", + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.PLAIN_MESSAGE); + this.positionRelations(OrderableListPanel.getInstance().getOrderList()); + } diagramPanel.repaint(); } - private void positionRelations() { - diagramPanel.resetTranslation(); - ArrayList relationList = new ArrayList<>(model.getRelations()); - Collections.sort(relationList); - if (relationList.isEmpty()) return; + /** + * Sets the location on all relations in the orderList to be vertically aligned + * @param orderList The ordered list of relations to be aligned + */ + private void positionRelations(ArrayList orderList) { + if (orderList.isEmpty()) return; - int vertSpace = (int) relationList.get(0).getViewModel().getBounds(diagramPanel.getGraphics2D()).getHeight() + PADDING; + int vertSpace = (int) orderList.get(0).getViewModel().getBounds(diagramPanel.getGraphics2D()).getHeight() + PADDING; AtomicInteger vertPos = new AtomicInteger(MARGIN); - relationList.forEach(r -> { + orderList.forEach(r -> { r.setPosition(new Point(MARGIN, vertPos.getAndAdd(vertSpace))); }); + + diagramPanel.centerModel(); + } + + /** + * Creates an orderList by grabbing all relations and sorting them + */ + private void positionRelation() { + ArrayList relationList = new ArrayList<>(model.getRelations()); + Collections.sort(relationList); + positionRelations(relationList); } } diff --git a/src/main/java/nl/andrewlalis/erme/model/MappingModel.java b/src/main/java/nl/andrewlalis/erme/model/MappingModel.java index b7ed500..9fc16da 100644 --- a/src/main/java/nl/andrewlalis/erme/model/MappingModel.java +++ b/src/main/java/nl/andrewlalis/erme/model/MappingModel.java @@ -1,6 +1,7 @@ package nl.andrewlalis.erme.model; import lombok.Getter; +import nl.andrewlalis.erme.view.OrderableListPanel; import nl.andrewlalis.erme.view.view_models.MappingModelViewModel; import nl.andrewlalis.erme.view.view_models.ViewModel; @@ -27,6 +28,7 @@ public class MappingModel implements Serializable, Viewable { public MappingModel() { this.relations = new HashSet<>(); this.changeListeners = new HashSet<>(); + this.addChangeListener(OrderableListPanel.getInstance()); } public void addRelation(Relation r) { diff --git a/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java b/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java index ba57981..d2ebd37 100644 --- a/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java +++ b/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java @@ -131,6 +131,7 @@ public class DiagramPanel extends JPanel implements ModelChangeListener { LolcatAction.getInstance().setDiagramPanel(this); AutoPositionAction.getInstance().setDiagramPanel(this); AutoPositionAction.getInstance().setModel(this.model); + OrderableListPanel.getInstance().setModel(this.model); } public static void prepareGraphics(Graphics2D g) { diff --git a/src/main/java/nl/andrewlalis/erme/view/OrderableListModel.java b/src/main/java/nl/andrewlalis/erme/view/OrderableListModel.java index c3d29c9..dab45b2 100644 --- a/src/main/java/nl/andrewlalis/erme/view/OrderableListModel.java +++ b/src/main/java/nl/andrewlalis/erme/view/OrderableListModel.java @@ -1,16 +1,63 @@ package nl.andrewlalis.erme.view; +import lombok.Getter; import nl.andrewlalis.erme.model.Relation; +import javax.swing.*; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; -public class OrderableListModel { - private ArrayList list; +/** + * A custom model for a ListModel that supports ordering by publically accessable methods + */ +public class OrderableListModel extends AbstractListModel { + @Getter + private final ArrayList list = new ArrayList<>(); - public void moveUp(int index) { - if (index > 0) { - Collections.swap(list, index, index - 1); + public OrderableListModel() { + super(); + } + + public void addAll(Collection relations) { + list.addAll(relations); + } + + public void removeAll(Collection relations) { + list.removeAll(relations); + } + + public void add(Relation relation) { + list.add(relation); + } + + public void remove(Relation relation) { + list.remove(relation); + } + + public void moveUp(int index) { + if (index > 0) { + Collections.swap(list, index, index - 1); + } + + this.fireContentsChanged(this, index, index - 1); + } + + public void moveDown(int index) { + if (index < this.getSize() - 1) { + Collections.swap(list, index, index + 1); } - } + + this.fireContentsChanged(this, index, index + 1); + } + + @Override + public int getSize() { + return list.size(); + } + + @Override + public Relation getElementAt(int i) { + return list.get(i); + } } diff --git a/src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java b/src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java new file mode 100644 index 0000000..427bdca --- /dev/null +++ b/src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java @@ -0,0 +1,82 @@ +package nl.andrewlalis.erme.view; + +import lombok.Setter; +import nl.andrewlalis.erme.model.MappingModel; +import nl.andrewlalis.erme.model.ModelChangeListener; +import nl.andrewlalis.erme.model.Relation; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +/** + * A panel to be used in a popup that has a OrderableListModel implemented. Implements ModelChangeListener to be able + * to update the list of relations when new ones are added or ones are removed. + */ +public class OrderableListPanel extends JPanel implements ModelChangeListener { + private static OrderableListPanel instance; + private final JList list; + private final OrderableListModel listModel; + @Setter + private MappingModel model; + + private OrderableListPanel() { + list = new JList<>(); + listModel = new OrderableListModel(); + list.setModel(listModel); + + JButton up = new JButton(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (list.isSelectionEmpty()) return; + listModel.moveUp(list.getSelectedIndex()); + list.setSelectedIndex(list.getSelectedIndex() - 1); + } + }); + up.setText("\u2227"); + JButton down = new JButton(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (list.isSelectionEmpty()) return; + listModel.moveDown(list.getSelectedIndex()); + list.setSelectedIndex(list.getSelectedIndex() + 1); + } + }); + down.setText("\u2228"); + + this.add(list); + this.add(up); + this.add(down); + } + + public static OrderableListPanel getInstance() { + if (instance == null) { + instance = new OrderableListPanel(); + } + return instance; + } + + /** + * Updates removed and new relations in the listModel. Does it in a special way to preserve existing ordering in the + * list, so user has to do minimal re-sorting. + */ + @Override + public void onModelChanged() { + if (this.model == null) return; + Set newRelations = new HashSet<>(model.getRelations()); + newRelations.removeAll(listModel.getList()); + + Set removedRelations = new HashSet<>(listModel.getList()); + removedRelations.removeAll(model.getRelations()); + + listModel.removeAll(removedRelations); + listModel.addAll(newRelations); + } + + public ArrayList getOrderList() { + return new ArrayList<>(listModel.getList()); + } +} From 8da7e5cfce7995ed19bfbfd809015e89ee1d4c99 Mon Sep 17 00:00:00 2001 From: Bjorn Pijnacker Date: Fri, 26 Feb 2021 21:37:34 +0100 Subject: [PATCH 3/8] Small naming change --- .../andrewlalis/erme/control/actions/AutoPositionAction.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java index 04ff7ef..ec3d2fe 100644 --- a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java +++ b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java @@ -26,8 +26,8 @@ public class AutoPositionAction extends AbstractAction { @Setter private MappingModel model; public AutoPositionAction() { - super("Position Relations"); - this.putValue(SHORT_DESCRIPTION, "Automatically Position Relations"); + super("Align Relations"); + this.putValue(SHORT_DESCRIPTION, "Automatically Align Relations"); } public static AutoPositionAction getInstance() { From 521ee92c0ac798d2a0d358a5ff645f7e1f048037 Mon Sep 17 00:00:00 2001 From: Bjorn Pijnacker Date: Fri, 26 Feb 2021 21:49:30 +0100 Subject: [PATCH 4/8] Implemented a fix for the custom sort not seeing relations after loading a model --- src/main/java/nl/andrewlalis/erme/model/MappingModel.java | 1 - src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/nl/andrewlalis/erme/model/MappingModel.java b/src/main/java/nl/andrewlalis/erme/model/MappingModel.java index 9fc16da..b7763d0 100644 --- a/src/main/java/nl/andrewlalis/erme/model/MappingModel.java +++ b/src/main/java/nl/andrewlalis/erme/model/MappingModel.java @@ -28,7 +28,6 @@ public class MappingModel implements Serializable, Viewable { public MappingModel() { this.relations = new HashSet<>(); this.changeListeners = new HashSet<>(); - this.addChangeListener(OrderableListPanel.getInstance()); } public void addRelation(Relation r) { diff --git a/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java b/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java index d2ebd37..49406d6 100644 --- a/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java +++ b/src/main/java/nl/andrewlalis/erme/view/DiagramPanel.java @@ -64,6 +64,7 @@ public class DiagramPanel extends JPanel implements ModelChangeListener { this.addMouseListener(listener); this.addMouseMotionListener(listener); this.updateActionModels(); + newModel.addChangeListener(OrderableListPanel.getInstance()); this.centerModel(); this.repaint(); } From d238c521ea42a333b23e7a223abbf500311704cb Mon Sep 17 00:00:00 2001 From: Bjorn Pijnacker Date: Sat, 27 Feb 2021 09:30:21 +0100 Subject: [PATCH 5/8] fixed an issue where the spacing was decided by the first element and not the (vertically) largest --- .../erme/control/actions/AutoPositionAction.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java index ec3d2fe..ae1e378 100644 --- a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java +++ b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java @@ -78,11 +78,15 @@ public class AutoPositionAction extends AbstractAction { */ private void positionRelations(ArrayList orderList) { if (orderList.isEmpty()) return; - - int vertSpace = (int) orderList.get(0).getViewModel().getBounds(diagramPanel.getGraphics2D()).getHeight() + PADDING; + AtomicInteger vertSpace = new AtomicInteger(0); + orderList.forEach(r -> { + int height = (int) r.getViewModel().getBounds(diagramPanel.getGraphics2D()).getHeight(); + vertSpace.set(Math.max(vertSpace.get(), height)); + }); + vertSpace.addAndGet(PADDING); AtomicInteger vertPos = new AtomicInteger(MARGIN); orderList.forEach(r -> { - r.setPosition(new Point(MARGIN, vertPos.getAndAdd(vertSpace))); + r.setPosition(new Point(MARGIN, vertPos.getAndAdd(vertSpace.get()))); }); diagramPanel.centerModel(); From ecd5a0b8fc8d5918d3fcec1abb5df9bcc1159069 Mon Sep 17 00:00:00 2001 From: Bjorn Pijnacker Date: Sat, 27 Feb 2021 19:54:12 +0100 Subject: [PATCH 6/8] fixed ambiguous naming of positionRelation() method the bottom method now just returns the alpabetically sorted one and passes that as an argument to the other method which expects a sorted list of relations --- .../erme/control/actions/AutoPositionAction.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java index ae1e378..37165a6 100644 --- a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java +++ b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java @@ -59,7 +59,7 @@ public class AutoPositionAction extends AbstractAction { 0); if (choice == null) return; if (choice.equals(choices[0])) { - positionRelation(); + positionRelations(getAlphabeticRelationList()); } else if (choice.equals(choices[1])) { JOptionPane.showConfirmDialog( null, @@ -95,9 +95,9 @@ public class AutoPositionAction extends AbstractAction { /** * Creates an orderList by grabbing all relations and sorting them */ - private void positionRelation() { + private ArrayList getAlphabeticRelationList() { ArrayList relationList = new ArrayList<>(model.getRelations()); Collections.sort(relationList); - positionRelations(relationList); + return relationList; } } From 560f72110d9709c01652e917fdeb0bed7a8d8786 Mon Sep 17 00:00:00 2001 From: Bjorn Pijnacker Date: Sat, 27 Feb 2021 20:02:38 +0100 Subject: [PATCH 7/8] parented dialogs in AutoPositionAction to the DiagramPanel This ensures they spawn at the center of the panel and not centered on the computer's primary display --- .../erme/control/actions/AutoPositionAction.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java index 37165a6..cfe5d56 100644 --- a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java +++ b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java @@ -41,7 +41,7 @@ public class AutoPositionAction extends AbstractAction { public void actionPerformed(ActionEvent actionEvent) { if (model.getRelations().size() == 0) { JOptionPane.showMessageDialog( - null, + this.diagramPanel, "Cannot position all relations when there are no relations present", "Relations Required", JOptionPane.WARNING_MESSAGE @@ -50,7 +50,7 @@ public class AutoPositionAction extends AbstractAction { } String[] choices = new String[]{"Alphabeticaly", "Custom Order"}; String choice = (String) JOptionPane.showInputDialog( - null, + this.diagramPanel, "Select how to sort the relations", "Position Relations", JOptionPane.PLAIN_MESSAGE, @@ -62,7 +62,7 @@ public class AutoPositionAction extends AbstractAction { positionRelations(getAlphabeticRelationList()); } else if (choice.equals(choices[1])) { JOptionPane.showConfirmDialog( - null, + this.diagramPanel, OrderableListPanel.getInstance(), "teststring", JOptionPane.OK_CANCEL_OPTION, From 9256eaa10ddcc44dd6c7c107db0a5020c0e06024 Mon Sep 17 00:00:00 2001 From: Bjorn Pijnacker Date: Sat, 27 Feb 2021 20:04:05 +0100 Subject: [PATCH 8/8] switched some spaces to tabs (again) --- .../erme/view/OrderableListPanel.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java b/src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java index 427bdca..7731e65 100644 --- a/src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java +++ b/src/main/java/nl/andrewlalis/erme/view/OrderableListPanel.java @@ -63,20 +63,20 @@ public class OrderableListPanel extends JPanel implements ModelChangeListener { * Updates removed and new relations in the listModel. Does it in a special way to preserve existing ordering in the * list, so user has to do minimal re-sorting. */ - @Override - public void onModelChanged() { - if (this.model == null) return; + @Override + public void onModelChanged() { + if (this.model == null) return; Set newRelations = new HashSet<>(model.getRelations()); newRelations.removeAll(listModel.getList()); - Set removedRelations = new HashSet<>(listModel.getList()); - removedRelations.removeAll(model.getRelations()); + Set removedRelations = new HashSet<>(listModel.getList()); + removedRelations.removeAll(model.getRelations()); - listModel.removeAll(removedRelations); - listModel.addAll(newRelations); - } + listModel.removeAll(removedRelations); + listModel.addAll(newRelations); + } - public ArrayList getOrderList() { - return new ArrayList<>(listModel.getList()); + public ArrayList getOrderList() { + return new ArrayList<>(listModel.getList()); } }