Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7949/src/net/sourceforge/bprocessor/gl/tool
Modified Files:
CreateSpaceActionListener.java
Log Message:
Space names now how to be unique when created
Index: CreateSpaceActionListener.java
===================================================================
RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/CreateSpaceActionListener.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** CreateSpaceActionListener.java 5 Apr 2006 09:36:16 -0000 1.7
--- CreateSpaceActionListener.java 1 May 2006 10:05:58 -0000 1.8
***************
*** 13,16 ****
--- 13,17 ----
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+ import java.util.Iterator;
***************
*** 37,40 ****
--- 38,44 ----
private boolean functional;
+ /** The current category */
+ private String category;
+
/**
* CreateSpaceActionListener
***************
*** 56,60 ****
public void actionPerformed(ActionEvent e) {
String result;
! String category = null;
if (surface.getOwner() == Project.getInstance().world()) {
category = "Space";
--- 60,64 ----
public void actionPerformed(ActionEvent e) {
String result;
! category = null;
if (surface.getOwner() == Project.getInstance().world()) {
category = "Space";
***************
*** 64,76 ****
if (functional) {
! result = JOptionPane.showInputDialog(GUI.getInstance(),
"Name",
"Create Functional " + category,
! JOptionPane.QUESTION_MESSAGE);
} else {
! result = JOptionPane.showInputDialog(GUI.getInstance(),
"Name",
"Create Construction " + category,
! JOptionPane.QUESTION_MESSAGE);
}
if (log.isDebugEnabled()) {
--- 68,81 ----
if (functional) {
! result = checkName(JOptionPane.showInputDialog(GUI.getInstance(),
"Name",
"Create Functional " + category,
! JOptionPane.QUESTION_MESSAGE));
!
} else {
! result = checkName(JOptionPane.showInputDialog(GUI.getInstance(),
"Name",
"Create Construction " + category,
! JOptionPane.QUESTION_MESSAGE));
}
if (log.isDebugEnabled()) {
***************
*** 98,100 ****
--- 103,134 ----
}
}
+
+ /**
+ * checkName checks if the name entered is not used
+ * @param result the name to check for uniqueness
+ * @return res a unique and verified name
+ */
+ private String checkName(String result) {
+ String res = result;
+ boolean used = false;
+ Iterator it = Project.getInstance().getSpaces().iterator();
+ while (it.hasNext()) {
+ Space current = (Space) it.next();
+ if (current.getName().equals(result)) {
+ res = JOptionPane.showInputDialog(GUI.getInstance(),
+ "Please enter a unique name",
+ "Create Functional " + category,
+ JOptionPane.QUESTION_MESSAGE);
+ used = true;
+ }
+ }
+ if (used) {
+ res = checkName(res);
+ }
+ return res;
+ }
+
+
+
+
}
|