1 package com.nexuiz.demorecorder.application;
\r
4 import java.io.IOException;
\r
6 import org.jdesktop.swingx.JXErrorPane;
\r
7 import org.jdesktop.swingx.error.ErrorInfo;
\r
9 public class DemoRecorderUtils {
\r
11 public static void showNonCriticalErrorDialog(Throwable e) {
\r
12 if (!(e instanceof DemoRecorderException)) {
\r
13 e = new DemoRecorderException("Internal error", e);
\r
15 ErrorInfo info = new ErrorInfo("Error occurred", e.getMessage(), null, null, e, null, null);
\r
16 JXErrorPane.showDialog(null, info);
\r
20 * Shows an error dialog that contains the stack trace, catching the exception so that the program flow
\r
21 * won't be interrupted.
\r
22 * This method will maybe wrap e in a DemoRecorderException with the given message.
\r
23 * @param customMessage
\r
25 * @param wrapException set to true if Exception should be wrapped into a DemoRecorderException
\r
27 public static void showNonCriticalErrorDialog(String customMessage, Throwable e, boolean wrapException) {
\r
29 if (wrapException && !(e instanceof DemoRecorderException)) {
\r
30 ex = new DemoRecorderException(customMessage, e);
\r
33 ErrorInfo info = new ErrorInfo("Error occurred", ex.getMessage(), null, null, ex, null, null);
\r
34 JXErrorPane.showDialog(null, info);
\r
37 public static File computeLocalFile(String subDir, String fileName) {
\r
38 String path = System.getProperty("user.dir");
\r
39 if (subDir != null && !subDir.equals("")) {
\r
40 path += File.separator + subDir;
\r
42 path += File.separator + fileName;
\r
43 return new File(path);
\r
47 * Returns just the name of the file for a given File. E.g. if the File points to
\r
48 * /home/someuser/somedir/somefile.end the function will return "somefile.end"
\r
50 * @return just the name of the file
\r
52 public static String getJustFileNameOfPath(File file) {
\r
53 String fileString = file.getAbsolutePath();
\r
54 int lastIndex = fileString.lastIndexOf(File.separator);
\r
55 String newString = fileString.substring(lastIndex+1, fileString.length());
\r
60 * Attempts to create an empty file (unless it already exists), including the creation
\r
61 * of parent directories. If it succeeds to do so (or if the file already existed), true
\r
62 * will be returned. Otherwise false will be returned
\r
63 * @param file the file to be created
\r
64 * @return true if file already existed or could successfully created, false otherwise
\r
66 public static boolean attemptFileCreation(File file) {
\r
67 if (!file.exists()) {
\r
69 file.createNewFile();
\r
71 } catch (IOException e) {
\r
72 File parentDir = file.getParentFile();
\r
73 if (!parentDir.exists()) {
\r
75 if (parentDir.mkdirs() == true) {
\r
77 file.createNewFile();
\r
79 } catch (Exception ex) {}
\r
81 } catch (Exception ex) {}
\r
90 public static final String getFileExtension(File file) {
\r
91 String fileName = file.getAbsolutePath();
\r
92 String ext = (fileName.lastIndexOf(".") == -1) ? "" : fileName.substring(fileName.lastIndexOf(".") + 1,fileName.length());
\r