$darkmode
DENOPTIM
Utils.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2020 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.gui;
20
21import javax.swing.JOptionPane;
22
23import denoptim.files.FileUtils;
24
25public class Utils
26{
27
36 public static String getTempFile(String tmpFileName)
37 {
38 String tmpSDFFile = GUIPreferences.tmpSpace
39 + System.getProperty("file.separator")
40 + tmpFileName;
41
42 if (!FileUtils.canWriteAndReadTo(tmpSDFFile))
43 {
44 String tmpFolder = FileUtils.getTempFolder();
45 tmpSDFFile = tmpFolder + System.getProperty("file.separator")
46 + tmpFileName;
47 if (!FileUtils.canWriteAndReadTo(tmpSDFFile))
48 {
49 String preStr = "Could not find a location for temprorary"
50 + " files automatically ";
51 while (!FileUtils.canWriteAndReadTo(tmpSDFFile))
52 {
53 tmpFolder = JOptionPane.showInputDialog("<html>" + preStr
54 + "<br>Please, "
55 + "specify the absolute path of a folder I can use:");
56
57 if (tmpFolder == null)
58 {
59 tmpFolder = "";
60 }
61
62 tmpFolder = tmpFolder.replaceAll("\\\\","/");
63 //NB: '/' is properly interpreted by Jmol even in Windows.
64
65 preStr = "I tried, but I cannot use '" + tmpSDFFile + "'.";
66
67 tmpSDFFile = tmpFolder
68 + System.getProperty("file.separator")
69 + tmpFileName;
70 }
71 }
72 GUIPreferences.tmpSpace = tmpFolder;
73 }
74 return tmpSDFFile;
75 }
76
77//------------------------------------------------------------------------------
78
79
80
81}
static boolean canWriteAndReadTo(String pathName)
Check whether we can write and read to a given pathname.
Definition: FileUtils.java:185
static String getTempFolder()
Looks for a writable location where to put temporary files and returns an absolute pathname to the fo...
Definition: FileUtils.java:204
static String getTempFile(String tmpFileName)
Returns the pathname to a tmp file.
Definition: Utils.java:36