}
}
// Import shapes from another model
private void importSelectedShapes() {
Shape shape;
String name;
Object[] choices = {"Replace", "Rename", I18N.guiJ().get("common.buttons.cancel")};
int[] selected = list.getSelectedIndices();
ArrayList<Shape> shapesToAdd = new ArrayList<Shape>();
// For each selected shape, add it to the current model's file and the turtledrawer,
for (int i = 0; i < selected.length; ++i) {
shape = list.getShape(selected[i]);
// If the shape exists, give the user the chance to overwrite or rename
while (manager.shapesList().exists(shape.getName())) {
int choice = javax.swing.JOptionPane.showOptionDialog
(this,
"A shape with the name \"" + shape.getName() + "\" already exists in this model.\n" +
"Do you want to replace the existing shape or rename the imported one?",
"Import",
javax.swing.JOptionPane.YES_NO_CANCEL_OPTION,
javax.swing.JOptionPane.WARNING_MESSAGE, null,
choices, choices[0]);
if (choice == 0) // overwrite
{
shapesToAdd.add(shape);
break;
} else if (choice == 1) // rename
{
name = javax.swing.JOptionPane.showInputDialog
(this, "Import shape as:", "Import Shapes", javax.swing.JOptionPane.PLAIN_MESSAGE);
// if the user cancels the inputdialog, then name could
// be null causing a nullpointerexception later on
if (name != null) {
shape.setName(name);
}
} else {
return;
}
}