* Save a maze.
* @return The saved maze or null. Can return itself or a new instance.
*/
public MazeInfo saveMaze()
{
final PrimaryFrame frame = Main.getPrimaryFrameInstance();
DefaultComboBoxModel cbm = frame.getMazeInfoModel().getMazeInfoComboBoxModel();
TreeSet<String> paths = new TreeSet<String>();
for (int i = 0; i < cbm.getSize(); i++)
{
String path = ((MazeInfo) cbm.getElementAt(i)).getPath();
if (path.isEmpty() == false)
paths.add(path.toLowerCase());
}
if (this.isDirty())
{
MazeInfo toSave = this;
if (!this.isMutable())
{
toSave = this.getMutableClone();
Box box = new Box(BoxLayout.Y_AXIS);
JLabel label = new JLabel("What would you like to call the" + " maze?");
JTextField field = new JTextField();
box.add(label);
box.add(field);
String newName = null;
while (true)
{
int result = JOptionPane.showConfirmDialog(frame,
box,
"Maze Name",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.OK_OPTION)
{
if (field.getText().length() > 0)
{
newName = field.getText();
break;
}
}
else
break;
}
if (newName == null)
return null;
this.clearDirty();
toSave.setName(newName);
toSave.setPath("");
frame.getMazeInfoModel().addMaze(toSave);
toSave.saveMaze();
return toSave;
}
else if (this.getPath() == null || this.getPath().isEmpty())
{