<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: eu.svjatoslav:svjatoslavcommons:1.5" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.16" level="project" />
+ <orderEntry type="library" name="Maven: com.esotericsoftware.yamlbeans:yamlbeans:1.09" level="project" />
</component>
</module>
\ No newline at end of file
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
+
+ <dependency>
+ <groupId>com.esotericsoftware.yamlbeans</groupId>
+ <artifactId>yamlbeans</artifactId>
+ <version>1.09</version>
+ </dependency>
+
</dependencies>
<build>
+++ /dev/null
-package eu.svjatoslav.instantlauncher;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Properties;
-
-public class Configuration {
-
- private static final String KEY_ROOT_DIRECTORY = "KEY_ROOT_DIRECTORY";
- private static final String CONFIG_FILE_NAME = ".instantlauncher";
- private final Properties properties = new Properties();
-
- private boolean propertiesChanged = false;
-
- public Configuration() throws IOException {
- initialize();
- }
-
- private File getPropertiesFile() {
- return new File(System.getProperty("user.home") + "/" + CONFIG_FILE_NAME);
- }
-
- public File getRootDirectory() {
-
- if (properties.containsKey(KEY_ROOT_DIRECTORY)) {
- return new File(properties.getProperty(KEY_ROOT_DIRECTORY));
- } else {
- properties.put(KEY_ROOT_DIRECTORY, System.getProperty("user.home") + "/");
- propertiesChanged = true;
- return getRootDirectory();
- }
-
- }
-
- private void initialize() throws IOException {
-
- loadIfFileExists();
-
- validatePropertiesFile();
-
- if (propertiesChanged) {
- saveFile();
- }
- }
-
- private void loadIfFileExists() throws IOException {
- final File propertiesFile = getPropertiesFile();
-
- if (propertiesFile.exists()) {
- final FileInputStream inStream = new FileInputStream(propertiesFile);
- properties.load(inStream);
- inStream.close();
- }
- }
-
- private void saveFile() throws IOException {
- properties.store(new FileOutputStream(getPropertiesFile()), "Instantlauncher configuration file.");
- }
-
- private void validatePropertiesFile() {
- getRootDirectory();
- }
-
-}
import java.io.IOException;
import java.util.HashMap;
+import static eu.svjatoslav.commons.file.FilePathParser.getFileExtension;
+
public class FileAssociationManager {
private static final String FILE_INDICATOR = "<FILE>";
return true;
}
- final String fileExtension = Utils.getFileExtension(file);
+ final String fileExtension = getFileExtension(file);
if (extensionToApplication.containsKey(fileExtension)) {
final String[] commands = extensionToApplication.get(fileExtension);
package eu.svjatoslav.instantlauncher;
+import eu.svjatoslav.instantlauncher.configuration.ConfigurationManager;
import org.apache.log4j.Logger;
import java.io.IOException;
public class InstantLauncher {
private static final Logger LOGGER = Logger.getLogger(InstantLauncher.class);
- public Configuration configuration;
+ public ConfigurationManager configuration;
FileAssociationManager associationManager = new FileAssociationManager();
public static void exitProgram() {
}
public void run() throws IOException {
- configuration = new Configuration();
+ configuration = new ConfigurationManager();
final MainFrame mainFrame = new MainFrame(this);
mainFrame.show();
import eu.svjatoslav.commons.gui.dialog.ExceptionDialog;
-class Main {
+import java.io.IOException;
- public static void main(final String[] args) {
+class Main {
- try {
- new InstantLauncher().run();
- } catch (final Exception e) {
- new ExceptionDialog(e);
- }
+ public static void main(final String[] args) throws IOException {
+ new InstantLauncher().run();
}
}
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();
- }
-
- return fileExtension;
- }
-
public static void setComponentSize(JComponent component, Dimension size) {
component.setMinimumSize(size);
component.setMaximumSize(size);
--- /dev/null
+package eu.svjatoslav.instantlauncher.configuration;
+
+import java.util.Set;
+
+public class Configuration {
+ public Set<FileAssociation> fileAssociations;
+ public String navigationRootPath;
+}
--- /dev/null
+package eu.svjatoslav.instantlauncher.configuration;
+
+import com.esotericsoftware.yamlbeans.YamlReader;
+import com.esotericsoftware.yamlbeans.YamlWriter;
+
+import java.io.*;
+import java.util.HashSet;
+import java.util.Map;
+
+public class ConfigurationManager {
+
+ private static final String CONFIG_FILE_NAME = ".instantlauncher";
+
+ private boolean propertiesChanged = false;
+
+ Configuration configuration;
+
+ public ConfigurationManager() throws IOException {
+ initialize();
+ }
+
+ private File getPropertiesFile() {
+ return new File(System.getProperty("user.home") + "/" + CONFIG_FILE_NAME);
+ }
+
+ public File getNavigationRootDirectory() {
+ if (configuration.navigationRootPath == null){
+ configuration.navigationRootPath = System.getProperty("user.home") + "/";
+ propertiesChanged = true;
+ registerDefaultAssociations();
+ }
+
+ return new File(configuration.navigationRootPath);
+ }
+
+ private void initialize() throws IOException {
+
+ loadIfFileExists();
+
+ validatePropertiesFile();
+
+ if (propertiesChanged) {
+ saveFile();
+ }
+ }
+
+ private void loadIfFileExists() throws IOException {
+ final File propertiesFile = getPropertiesFile();
+ if (!propertiesFile.exists())
+ return;
+
+ YamlReader reader = new YamlReader(new FileReader(propertiesFile));
+ configuration = reader.read(Configuration.class);
+ if (configuration == null) {
+ configuration = new Configuration();
+ configuration.fileAssociations = new HashSet<>();
+ };
+ }
+
+ private void saveFile() throws IOException {
+ YamlWriter writer = new YamlWriter(new FileWriter(getPropertiesFile()));
+ writer.write(configuration);
+ writer.close();
+ }
+
+ private void validatePropertiesFile() {
+ getNavigationRootDirectory();
+ }
+
+ private void registerFileAssociation(String fileRegex, String command){
+ FileAssociation association = new FileAssociation(fileRegex, command);
+ configuration.fileAssociations.add(association);
+ propertiesChanged = true;
+ }
+
+ private void registerDefaultAssociations(){
+ registerFileAssociation(".jpeg$", "eog {file}");
+ }
+}
--- /dev/null
+package eu.svjatoslav.instantlauncher.configuration;
+
+public class FileAssociation implements Comparable<FileAssociation> {
+ public String fileRegex;
+ public String command;
+
+ public FileAssociation() {
+ }
+
+ public FileAssociation(String fileRegex, String command) {
+ this.fileRegex = fileRegex;
+ this.command = command;
+ }
+
+ @Override
+ public int compareTo(FileAssociation o) {
+ return fileRegex.compareTo(o.fileRegex);
+ }
+}
contentPane.add(panel);
}
- final File directory = instantLauncher.configuration.getRootDirectory();
+ final File directory = instantLauncher.configuration.getNavigationRootDirectory();
addMenu(directory);
return contentPane;