MATSIM
SaveFileSaver.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * SaveFileSaver.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22  package org.matsim.run.gui;
23 
24 import java.io.File;
25 
26 import javax.swing.JFileChooser;
27 import javax.swing.JOptionPane;
28 
32 /*package*/ class SaveFileSaver extends JFileChooser {
33  private static final long serialVersionUID = 1L;
34 
35  @Override
36  public void approveSelection() {
37  File f = getSelectedFile();
38  if (f.exists() && getDialogType() == SAVE_DIALOG) {
39  String msg = String.format(
40  "<html>ā€œ%sā€ already exists.<br>Do you want to replace it?",
41  f.getName());
42  int option = JOptionPane.showOptionDialog(this, msg, "Save As", JOptionPane.YES_NO_OPTION,
43  JOptionPane.WARNING_MESSAGE, null, new String[] {"Replace", "Cancel"}, "Cancel");
44  if (option != 0) {
45  return;
46  }
47  }
48  super.approveSelection();
49  }
50 }