// Attempts to save the current shape being drawn, prompting the
// user if any issues come up
private void saveShape() {
String name;
int overwrite;
VectorShape newShape;
// Make sure the shape has a name
if (nameText.getText().equals("")) {
name =
javax.swing.JOptionPane.showInputDialog
(this, "Name:", "Name Shape", javax.swing.JOptionPane.PLAIN_MESSAGE);
if (name == null) {
return;
}
} else {
name = nameText.getText();
}
name = name.toLowerCase();
// If the user chose to quit, don't save
if (name == null || name.equals("")) {
return;
}
String originalName = originalShape.getName();
// If this is an attempt to overwrite a shape, prompt for
// permission to do it
if (container.exists(name) && !name.equals(originalName)) {
overwrite = javax.swing.JOptionPane.showConfirmDialog
(this, "A shape with this name already exists. Do you want to replace it?",
"Confirm Overwrite", javax.swing.JOptionPane.YES_NO_OPTION);
if (overwrite != javax.swing.JOptionPane.YES_OPTION) {
return;
}
}
newShape = shape;
newShape.setName(name);
newShape.setRotatable(shapeRotatable);
newShape.markRecolorableElements(getColor(shape.getEditableColorIndex()),
shape.getEditableColorIndex());
container.update(originalShape, newShape);
dispose();
}