-package com.nexuiz.demorecorder.application;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-\r
-import org.jdesktop.swingx.JXErrorPane;\r
-import org.jdesktop.swingx.error.ErrorInfo;\r
-\r
-public class DemoRecorderUtils {\r
- \r
- public static void showNonCriticalErrorDialog(Throwable e) {\r
- if (!(e instanceof DemoRecorderException)) {\r
- e = new DemoRecorderException("Internal error", e);\r
- }\r
- ErrorInfo info = new ErrorInfo("Error occurred", e.getMessage(), null, null, e, null, null);\r
- JXErrorPane.showDialog(null, info);\r
- }\r
- \r
- /**\r
- * Shows an error dialog that contains the stack trace, catching the exception so that the program flow\r
- * won't be interrupted.\r
- * This method will maybe wrap e in a DemoRecorderException with the given message.\r
- * @param customMessage\r
- * @param e\r
- * @param wrapException set to true if Exception should be wrapped into a DemoRecorderException\r
- */\r
- public static void showNonCriticalErrorDialog(String customMessage, Throwable e, boolean wrapException) {\r
- Throwable ex = e;\r
- if (wrapException && !(e instanceof DemoRecorderException)) {\r
- ex = new DemoRecorderException(customMessage, e);\r
- }\r
- \r
- ErrorInfo info = new ErrorInfo("Error occurred", ex.getMessage(), null, null, ex, null, null);\r
- JXErrorPane.showDialog(null, info);\r
- }\r
- \r
- public static File computeLocalFile(String subDir, String fileName) {\r
- String path = System.getProperty("user.dir");\r
- if (subDir != null && !subDir.equals("")) {\r
- path += File.separator + subDir;\r
- }\r
- path += File.separator + fileName;\r
- return new File(path);\r
- }\r
- \r
- /**\r
- * Returns just the name of the file for a given File. E.g. if the File points to\r
- * /home/someuser/somedir/somefile.end the function will return "somefile.end"\r
- * @param file\r
- * @return just the name of the file\r
- */\r
- public static String getJustFileNameOfPath(File file) {\r
- String fileString = file.getAbsolutePath();\r
- int lastIndex = fileString.lastIndexOf(File.separator);\r
- String newString = fileString.substring(lastIndex+1, fileString.length());\r
- return newString;\r
- }\r
- \r
- /**\r
- * Attempts to create an empty file (unless it already exists), including the creation\r
- * of parent directories. If it succeeds to do so (or if the file already existed), true\r
- * will be returned. Otherwise false will be returned\r
- * @param file the file to be created\r
- * @return true if file already existed or could successfully created, false otherwise\r
- */\r
- public static boolean attemptFileCreation(File file) {\r
- if (!file.exists()) {\r
- try {\r
- file.createNewFile();\r
- return true;\r
- } catch (IOException e) {\r
- File parentDir = file.getParentFile();\r
- if (!parentDir.exists()) {\r
- try {\r
- if (parentDir.mkdirs() == true) {\r
- try {\r
- file.createNewFile();\r
- return true;\r
- } catch (Exception ex) {}\r
- }\r
- } catch (Exception ex) {}\r
- }\r
- return false;\r
- }\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- public static final String getFileExtension(File file) {\r
- String fileName = file.getAbsolutePath();\r
- String ext = (fileName.lastIndexOf(".") == -1) ? "" : fileName.substring(fileName.lastIndexOf(".") + 1,fileName.length());\r
- return ext;\r
- }\r
-}\r
+package com.nexuiz.demorecorder.application;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.jdesktop.swingx.JXErrorPane;
+import org.jdesktop.swingx.error.ErrorInfo;
+
+public class DemoRecorderUtils {
+
+ public static void showNonCriticalErrorDialog(Throwable e) {
+ if (!(e instanceof DemoRecorderException)) {
+ e = new DemoRecorderException("Internal error", e);
+ }
+ ErrorInfo info = new ErrorInfo("Error occurred", e.getMessage(), null, null, e, null, null);
+ JXErrorPane.showDialog(null, info);
+ }
+
+ /**
+ * Shows an error dialog that contains the stack trace, catching the exception so that the program flow
+ * won't be interrupted.
+ * This method will maybe wrap e in a DemoRecorderException with the given message.
+ * @param customMessage
+ * @param e
+ * @param wrapException set to true if Exception should be wrapped into a DemoRecorderException
+ */
+ public static void showNonCriticalErrorDialog(String customMessage, Throwable e, boolean wrapException) {
+ Throwable ex = e;
+ if (wrapException && !(e instanceof DemoRecorderException)) {
+ ex = new DemoRecorderException(customMessage, e);
+ }
+
+ ErrorInfo info = new ErrorInfo("Error occurred", ex.getMessage(), null, null, ex, null, null);
+ JXErrorPane.showDialog(null, info);
+ }
+
+ public static File computeLocalFile(String subDir, String fileName) {
+ String path = System.getProperty("user.dir");
+ if (subDir != null && !subDir.equals("")) {
+ path += File.separator + subDir;
+ }
+ path += File.separator + fileName;
+ return new File(path);
+ }
+
+ /**
+ * Returns just the name of the file for a given File. E.g. if the File points to
+ * /home/someuser/somedir/somefile.end the function will return "somefile.end"
+ * @param file
+ * @return just the name of the file
+ */
+ public static String getJustFileNameOfPath(File file) {
+ String fileString = file.getAbsolutePath();
+ int lastIndex = fileString.lastIndexOf(File.separator);
+ String newString = fileString.substring(lastIndex+1, fileString.length());
+ return newString;
+ }
+
+ /**
+ * Attempts to create an empty file (unless it already exists), including the creation
+ * of parent directories. If it succeeds to do so (or if the file already existed), true
+ * will be returned. Otherwise false will be returned
+ * @param file the file to be created
+ * @return true if file already existed or could successfully created, false otherwise
+ */
+ public static boolean attemptFileCreation(File file) {
+ if (!file.exists()) {
+ try {
+ file.createNewFile();
+ return true;
+ } catch (IOException e) {
+ File parentDir = file.getParentFile();
+ if (!parentDir.exists()) {
+ try {
+ if (parentDir.mkdirs() == true) {
+ try {
+ file.createNewFile();
+ return true;
+ } catch (Exception ex) {}
+ }
+ } catch (Exception ex) {}
+ }
+ return false;
+ }
+ } else {
+ return true;
+ }
+ }
+
+ public static final String getFileExtension(File file) {
+ String fileName = file.getAbsolutePath();
+ String ext = (fileName.lastIndexOf(".") == -1) ? "" : fileName.substring(fileName.lastIndexOf(".") + 1,fileName.length());
+ return ext;
+ }
+}