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