JDesktopPane desktop = application.getDesktopPane();
// Work out the next number to use for the default Untitled picture name.
int maximumUntitledFrameNum = 0;
for (JInternalFrame frame : desktop.getAllFrames()) {
PictureFrame pictureFrame = (PictureFrame)frame;
// Untitled picture frames are those without a picture file associated.
if (pictureFrame.getEditStatus().getPictureFile() == null) {
String frameTitle = pictureFrame.getTitle();
if (frameTitle.contains("Untitled")) {
int untitledFrameNum = 1;
if (!frameTitle.endsWith("Untitled")) {
untitledFrameNum = Integer.parseInt(frameTitle.substring(frameTitle.indexOf("Untitled") + 9));
if (untitledFrameNum > maximumUntitledFrameNum) {
maximumUntitledFrameNum = untitledFrameNum;
}
}
if (untitledFrameNum > maximumUntitledFrameNum) {
maximumUntitledFrameNum = untitledFrameNum;
}
}
}
}
StringBuilder defaultPictureName = new StringBuilder("Untitled");
if (maximumUntitledFrameNum > 0) {
defaultPictureName.append(" ");
defaultPictureName.append(maximumUntitledFrameNum + 1);
}
// Now create the new PictureFrame.
PictureFrame newPictureFrame = new PictureFrame(application, application.getEditStatus().getZoomFactor(), defaultPictureName.toString());
int initialFrameIndent = 20 + (desktop.getAllFrames().length * 25);
newPictureFrame.setLocation(initialFrameIndent, initialFrameIndent);
// Add to the desktop, start up the mouse motion timer and then autoselect.
desktop.add(newPictureFrame);
try {
newPictureFrame.setSelected(true);
} catch (PropertyVetoException e) {
}
}