Added license and copyright notice.
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / Utils.java
1 /*
2  * Instantlauncher. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  */
8
9 package eu.svjatoslav.instantlauncher;
10
11 import eu.svjatoslav.commons.gui.dialog.ExceptionDialog;
12
13 import javax.swing.*;
14 import java.awt.*;
15 import java.io.File;
16 import java.io.IOException;
17
18 public class Utils {
19
20     private static final String FILE_INDICATOR = "{file}";
21
22     public static void setComponentSize(JComponent component, Dimension size) {
23         component.setMinimumSize(size);
24         component.setMaximumSize(size);
25         component.setSize(size);
26         component.setPreferredSize(size);
27     }
28
29     public static void runOpeningApplication(String commands, final File file) {
30         try {
31             String[] commandsArray = commands.split("\\s+");
32             for (int i=0; i< commandsArray.length; i++)
33                 commandsArray[i] = commandsArray[i].replaceAll("\\{file\\}", file.getAbsolutePath());
34
35             Runtime.getRuntime().exec(commandsArray);
36         } catch (final IOException e) {
37             new ExceptionDialog(e);
38         }
39     }
40
41     public static void executeCommand(String... c) {
42         try {
43             Runtime.getRuntime().exec(c);
44         } catch (final IOException e) {
45             new ExceptionDialog(e);
46         }
47     }
48
49
50 }