read file associations from configuration
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / Utils.java
index f382e7c..1884fec 100755 (executable)
@@ -1,33 +1,37 @@
 package eu.svjatoslav.instantlauncher;
 
+import eu.svjatoslav.commons.gui.dialog.ExceptionDialog;
+
 import javax.swing.*;
 import java.awt.*;
 import java.io.File;
+import java.io.IOException;
 
-public class Utils {
-
-    public static String getFileExtension(File file) {
-        // extract file name without file name extension
-        String fullFileName = file.getName();
-
-        int dot = fullFileName.lastIndexOf('.');
-        String fileExtension;
-        if (dot == -1) {
-            fileExtension = "";
-        } else {
-            fileExtension = fullFileName.substring(dot + 1);
-            fileExtension = fileExtension.toLowerCase();
-        }
+import static eu.svjatoslav.commons.file.FilePathParser.getFileExtension;
 
-        return fileExtension;
-    }
+public class Utils {
 
     public static void setComponentSize(JComponent component, Dimension size) {
         component.setMinimumSize(size);
         component.setMaximumSize(size);
         component.setSize(size);
         component.setPreferredSize(size);
+    }
+
+    private static final String FILE_INDICATOR = "{file}";
+
+    public static void runOpeningApplication(final File file, final String[] commands) {
+        for (int i = 0; i < commands.length; i++)
+            if (commands[i].equals(FILE_INDICATOR))
+                commands[i] = file.getAbsolutePath();
 
+        try {
+            Runtime.getRuntime().exec(commands);
+            InstantLauncher.exitProgram();
+
+        } catch (final IOException e) {
+            new ExceptionDialog(e);
+        }
     }
 
 }