public void saveAndClose(final Window win) {
		final File file = new File(pageAddress);
		if (!pageAddress.equals("Untitled.cml")) {
			if (!validateFileName(file))
				return;
			if (!isWriting()) {
				new SwingWorker("Page-saving thread") {
					public Object construct() {
						synchronized (lock) {
							SaveComponentStateReminder.setEnabled(false);
							saveTo(file);
						}
						return file;
					}

					public void finished() {
						isWriting = false;
						System.out.println(file + " written");
						win.dispatchEvent(new WindowEvent(win, WindowEvent.WINDOW_CLOSING));
					}
				}.start();
			}
		} else {
			fileChooser.setAcceptAllFileFilterUsed(false);
			fileChooser.addChoosableFileFilter(FileFilterFactory.getFilter("cml"));
			fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
			String s = Modeler.getInternationalText("SavePage");
			fileChooser.setDialogTitle(s != null ? s : "Save page");
			fileChooser.setApproveButtonMnemonic('S');
			fileChooser.resetTextField();
			String latestPath = fileChooser.getLastVisitedPath();
			if (latestPath != null)
				fileChooser.setCurrentDirectory(new File(latestPath));
			if (fileChooser.showSaveDialog(win) == JFileChooser.APPROVE_OPTION) {
				final String filename = FileUtilities.fileNameAutoExtend(FileFilterFactory.getFilter("cml"), fileChooser.getSelectedFile());
				final File file2 = new File(filename);
				boolean b = true;
				if (file2.exists()) {
					s = Modeler.getInternationalText("FileExists");
					String s1 = Modeler.getInternationalText("File");
					String s2 = Modeler.getInternationalText("Overwrite");
					String s3 = Modeler.getInternationalText("Exists");
					if (JOptionPane.showConfirmDialog(win, (s1 != null ? s1 : "File") + " " + file2.getName() + " " + (s3 != null ? s3 : "exists") + ", " + (s2 != null ? s2 : "overwrite") + "?", s != null ? s : "File exists", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION || isWriting()) {
						b = false;
					}
				}
				if (b) {
					new SwingWorker("Page:saveAndClose()") {
						public Object construct() {
							synchronized (lock) {
								SaveComponentStateReminder.setEnabled(false);
								saveTo(file2);
							}
							return file2;
						}

						public void finished() {
							isWriting = false;
							fileChooser.rememberPath(fileChooser.getCurrentDirectory().toString());
							fileChooser.rememberFile(filename, null);
							System.out.println(filename + " written");
							win.dispatchEvent(new WindowEvent(win, WindowEvent.WINDOW_CLOSING));
						}
					}.start();
				}
			}
		}
	}