read file associations from configuration
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / Utils.java
1 package eu.svjatoslav.instantlauncher;
2
3 import eu.svjatoslav.commons.gui.dialog.ExceptionDialog;
4
5 import javax.swing.*;
6 import java.awt.*;
7 import java.io.File;
8 import java.io.IOException;
9
10 import static eu.svjatoslav.commons.file.FilePathParser.getFileExtension;
11
12 public class Utils {
13
14     public static void setComponentSize(JComponent component, Dimension size) {
15         component.setMinimumSize(size);
16         component.setMaximumSize(size);
17         component.setSize(size);
18         component.setPreferredSize(size);
19     }
20
21     private static final String FILE_INDICATOR = "{file}";
22
23     public static void runOpeningApplication(final File file, final String[] commands) {
24         for (int i = 0; i < commands.length; i++)
25             if (commands[i].equals(FILE_INDICATOR))
26                 commands[i] = file.getAbsolutePath();
27
28         try {
29             Runtime.getRuntime().exec(commands);
30             InstantLauncher.exitProgram();
31
32         } catch (final IOException e) {
33             new ExceptionDialog(e);
34         }
35     }
36
37 }