1 package eu.svjatoslav.instantlauncher;
4 import java.io.IOException;
5 import java.util.HashMap;
7 import eu.svjatoslav.commons.gui.dialog.ExceptionDialog;
9 public class FileAssociationManager {
11 private static final String TEXT_EDITOR = "scribes";
13 private static final String FILE_INDICATOR = "<FILE>";
15 public static HashMap<String, String[]> extensionToApplication = new HashMap<String, String[]>();
17 public FileAssociationManager() {
19 extensionToApplication.put("txt", new String[] { TEXT_EDITOR, FILE_INDICATOR });
20 extensionToApplication.put("xml", new String[] { TEXT_EDITOR, FILE_INDICATOR });
21 extensionToApplication.put("properties", new String[] { TEXT_EDITOR, FILE_INDICATOR });
22 extensionToApplication.put("ini", new String[] { TEXT_EDITOR, FILE_INDICATOR });
23 extensionToApplication.put("", new String[] { TEXT_EDITOR, FILE_INDICATOR });
25 extensionToApplication.put("jpg", new String[] { "eog", FILE_INDICATOR });
26 extensionToApplication.put("jpeg", new String[] { "eog", FILE_INDICATOR });
27 extensionToApplication.put("png", new String[] { "eog", FILE_INDICATOR });
29 extensionToApplication.put("pdf", new String[] { "evince", FILE_INDICATOR });
31 extensionToApplication.put("mp3", new String[] { "banshee", FILE_INDICATOR });
32 extensionToApplication.put("ogg", new String[] { "banshee", FILE_INDICATOR });
34 extensionToApplication.put("avi", new String[] { "vlc", FILE_INDICATOR });
35 extensionToApplication.put("mkv", new String[] { "vlc", FILE_INDICATOR });
36 extensionToApplication.put("ogv", new String[] { "vlc", FILE_INDICATOR });
37 extensionToApplication.put("mp4", new String[] { "vlc", FILE_INDICATOR });
38 extensionToApplication.put("flv", new String[] { "vlc", FILE_INDICATOR });
39 extensionToApplication.put("wmv", new String[] { "vlc", FILE_INDICATOR });
41 extensionToApplication.put("ods", new String[] { "localc", FILE_INDICATOR });
45 public static boolean openFile(final File file) {
47 final String fileExtension = Utils.getFileExtension(file);
49 System.out.println("About to open file with extension: " + fileExtension);
51 if (extensionToApplication.containsKey(fileExtension)) {
53 System.out.println("Commands found");
55 final String[] commands = extensionToApplication.get(fileExtension);
57 final String[] c = new String[commands.length];
59 for (int i = 0; i < commands.length; i++) {
61 if (commands[i].equals(FILE_INDICATOR)) {
62 c[i] = file.getAbsolutePath();
69 Runtime.getRuntime().exec(c);
70 InstantLauncher.exitProgram();
72 } catch (final IOException e) {
73 new ExceptionDialog(e);