From d4a1a55d202de044ab76347802081a4739a1d2c1 Mon Sep 17 00:00:00 2001 From: Mark Kattenbelt Date: Thu, 25 Oct 2007 10:27:45 +0000 Subject: [PATCH] Fixed graph name issue git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@475 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- .../properties/GUIGraphHandler.java | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/prism/src/userinterface/properties/GUIGraphHandler.java b/prism/src/userinterface/properties/GUIGraphHandler.java index 7c92c114..cc7ab42d 100644 --- a/prism/src/userinterface/properties/GUIGraphHandler.java +++ b/prism/src/userinterface/properties/GUIGraphHandler.java @@ -49,14 +49,14 @@ import settings.*; */ public class GUIGraphHandler extends JPanel implements MouseListener { - private int counter = 0; + private boolean canDelete; private JTabbedPane theTabs; private JPopupMenu backMenu, graphMenu; - private ArrayList models; - private ArrayList options; + private java.util.List models; + private java.util.List options; private GUIPlugin plug; @@ -124,9 +124,7 @@ public class GUIGraphHandler extends JPanel implements MouseListener attributes = new HashPrintRequestAttributeSet(); models = new ArrayList(); - options = new ArrayList(); - counter = 0; - + options = new ArrayList(); } private void initComponents() @@ -369,7 +367,7 @@ public class GUIGraphHandler extends JPanel implements MouseListener public void actionPerformed(ActionEvent e) { Graph graph = models.get( - theTabs.getSelectedIndex() + theTabs.getSelectedIndex() ); if (!graph.getDisplaySettings().getBackgroundColor().equals(Color.white)) @@ -399,7 +397,6 @@ public class GUIGraphHandler extends JPanel implements MouseListener models.remove(theTabs.getSelectedIndex()); options.remove(theTabs.getSelectedIndex()); theTabs.remove(graph); - counter--; } }; deleteGraph.putValue(Action.NAME, "Delete graph"); @@ -550,8 +547,27 @@ public class GUIGraphHandler extends JPanel implements MouseListener public int addGraph(Graph m) { - return addGraph(m, "Graph " + (counter + 1)); + String name = ""; + boolean nameNew; + int counter = 1; + + while (true) + { + name = "Graph " + (counter); + nameNew = true; + + for(int i = 0; i < theTabs.getComponentCount(); i++) + { + if(theTabs.getTitleAt(i).equals(name)) + nameNew = false; + } + + if (nameNew) + return addGraph(m, name); + + counter++; + } } public int addGraph(Graph m, String tabName) @@ -575,9 +591,6 @@ public class GUIGraphHandler extends JPanel implements MouseListener // make this new tab the default selection theTabs.setSelectedIndex(theTabs.indexOfComponent(m)); - // increase the graph counter - counter++; - // return the index of the component return index; }