<orderEntry type="inheritedJdk" />
<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
<version>1.5</version>
</dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.16</version>
- </dependency>
-
<dependency>
<groupId>com.esotericsoftware.yamlbeans</groupId>
<artifactId>yamlbeans</artifactId>
package eu.svjatoslav.instantlauncher;
+import eu.svjatoslav.commons.gui.dialog.ExceptionDialog;
import eu.svjatoslav.instantlauncher.configuration.ConfigurationManager;
import eu.svjatoslav.instantlauncher.configuration.FileAssociation;
-import org.apache.log4j.Logger;
import java.io.File;
import java.io.IOException;
public class InstantLauncher {
- private static final Logger LOGGER = Logger.getLogger(InstantLauncher.class);
+ private final MainFrame mainFrame;
public ConfigurationManager configurationManager;
- final MainFrame mainFrame;
public InstantLauncher() throws IOException {
configurationManager = new ConfigurationManager();
mainFrame = new MainFrame(this);
}
+ public static void exitProgram() {
+ System.exit(0);
+ }
+
/**
* @return <code>true</code> if file was opened. <code>false</code> if
* unknown file type.
FileAssociation fileAssociation = configurationManager.getConfiguration().findFileAssociation(file);
if (fileAssociation == null) return false;
- final String[] commands = fileAssociation.getCommands();
- runOpeningApplication(file, commands);
-
- return false;
+ runOpeningApplication(fileAssociation.command, file);
+ return true;
}
- public static void exitProgram() {
- LOGGER.info("Closing InstantLauncher");
- System.exit(0);
+ public void run() {
+ mainFrame.show();
}
- public void run() throws IOException {
- mainFrame.show();
+ public void openDirectory(File chosenFile) {
+ executeCommand(configurationManager.getConfiguration().directoryOpenCommand, chosenFile.getAbsolutePath());
}
+ public void executeCommand(String... c) {
+ try {
+ Runtime.getRuntime().exec(c);
+ exitProgram();
+
+ } catch (final IOException e) {
+ new ExceptionDialog(e);
+ }
+ }
}
package eu.svjatoslav.instantlauncher;
-import eu.svjatoslav.commons.gui.dialog.ExceptionDialog;
-
import java.io.IOException;
class Main {
public static void main(final String[] args) throws IOException {
- new InstantLauncher().run();
+ new InstantLauncher().run();
}
}
class MainFrame {
- public static final Dimension CONTENT_PANEL_SIZE = new Dimension(1100, 850);
private final InstantLauncher instantLauncher;
private JFrame frame;
private boolean isShowing;
import java.io.File;
import java.io.IOException;
-import static eu.svjatoslav.commons.file.FilePathParser.getFileExtension;
-
public class Utils {
+ private static final String FILE_INDICATOR = "{file}";
+
public static void setComponentSize(JComponent component, Dimension size) {
component.setMinimumSize(size);
component.setMaximumSize(size);
component.setPreferredSize(size);
}
- private static final String FILE_INDICATOR = "{file}";
+ public static void runOpeningApplication(String commands, final File file) {
+ runOpeningApplication(commands.split("\\s+"), file);
+ }
- public static void runOpeningApplication(final File file, final String[] commands) {
+ private static void runOpeningApplication(final String[] commands, final File file) {
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);
}
public class Configuration {
public Set<FileAssociation> fileAssociations;
public String navigationRootPath;
+ public String directoryOpenCommand;
-
- public FileAssociation findFileAssociation(File file){
+ public FileAssociation findFileAssociation(File file) {
for (FileAssociation association : fileAssociations)
if (association.matchesFile(file)) return association;
return null;
}
+ public File getNavigationRootDirectory() {
+ return new File(navigationRootPath);
+ }
+
}
import java.io.*;
import java.util.HashSet;
-import java.util.Map;
public class ConfigurationManager {
private static final String CONFIG_FILE_NAME = ".instantlauncher";
+ private Configuration configuration;
- private boolean propertiesChanged = false;
+ public ConfigurationManager() throws IOException {
+ initConfig();
+ }
public Configuration getConfiguration() {
return configuration;
}
- private 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 {
+ private void initConfig() throws IOException {
final File propertiesFile = getPropertiesFile();
- if (!propertiesFile.exists())
- return;
+ if (!propertiesFile.exists()) {
+ initDefaultConfiguration();
+ saveConfigFile();
+ } else
+ loadConfigFile(propertiesFile);
+ }
+ private void loadConfigFile(File propertiesFile) throws FileNotFoundException, com.esotericsoftware.yamlbeans.YamlException {
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 {
+ private void saveConfigFile() 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){
+ 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}");
+ private void initDefaultConfiguration() {
+ configuration.navigationRootPath = System.getProperty("user.home") + "/";
+ configuration.directoryOpenCommand = "nautilus -w {file}";
+
+ registerFileAssociation(".*\\.jpeg$", "eog {file}");
+ registerFileAssociation(".*\\.jpg$", "eog {file}");
+ registerFileAssociation(".*\\.png$", "eog {file}");
+ registerFileAssociation(".*\\.txt$", "emacs {file}");
+ registerFileAssociation(".*\\.org$", "emacs {file}");
+ registerFileAssociation(".*\\.avi$", "vlc {file}");
+ registerFileAssociation(".*\\.mp4$", "vlc {file}");
+ registerFileAssociation(".*\\.mkv$", "vlc {file}");
}
}
import java.util.regex.Pattern;
public class FileAssociation implements Comparable<FileAssociation> {
- public String fileRegex;
public String command;
+ private String fileRegex;
public FileAssociation() {
}
return matcher.matches();
}
- public String[] getCommands() {
- return command.split("\\s+");
- }
}
private void menuItemSelected(final File chosenFile) {
for (final MenuListener menuListener : menuListeners)
- menuListener.menuItemSelected(this, chosenFile);
+ menuListener.menuItemSelected(chosenFile);
}
private void menuItemSelectedAlternative(final File chosenFile) {
for (final MenuListener menuListener : menuListeners)
- menuListener.menuItemSelectedAlternative(this, chosenFile);
+ menuListener.menuItemSelectedAlternative(chosenFile);
}
private void menuItemSelectedAlternative2(final File chosenFile) {
for (final MenuListener menuListener : menuListeners)
- menuListener.menuItemSelectedAlternative2(this, chosenFile);
+ menuListener.menuItemSelectedAlternative2(chosenFile);
}
private void setSelected(final JButton selectedButton, final File selectedFile) {
package eu.svjatoslav.instantlauncher.menu;
+import java.io.File;
+
interface MenuListener {
/**
/**
* left click
*/
- void menuItemSelected(Menu menu, java.io.File chosenFile);
+ void menuItemSelected(File chosenFile);
/**
* right click
*/
- void menuItemSelectedAlternative(Menu menu, java.io.File chosenFile);
+ void menuItemSelectedAlternative(File chosenFile);
/**
* middle click
*/
- void menuItemSelectedAlternative2(Menu menu, java.io.File chosenFile);
+ void menuItemSelectedAlternative2(File chosenFile);
}
package eu.svjatoslav.instantlauncher.menu;
-import eu.svjatoslav.commons.gui.dialog.ExceptionDialog;
import eu.svjatoslav.instantlauncher.InstantLauncher;
import eu.svjatoslav.instantlauncher.Utils;
contentPane.add(panel);
}
- final File directory = instantLauncher.configurationManager.getNavigationRootDirectory();
+ final File directory = instantLauncher.configurationManager.getConfiguration().getNavigationRootDirectory();
addMenu(directory);
return contentPane;
}
@Override
- public void menuItemSelected(final Menu menu, final File chosenFile) {
+ public void menuItemSelected(final File chosenFile) {
if (chosenFile.isFile()) {
if (chosenFile.canExecute()) {
- executeCommand(chosenFile.getAbsolutePath());
+ instantLauncher.executeCommand(chosenFile.getAbsolutePath());
} else {
boolean fileOpened;
try {
fileOpened = instantLauncher.openFile(chosenFile.getCanonicalFile());
- if (fileOpened) {
+ if (fileOpened)
InstantLauncher.exitProgram();
- }
+
} catch (IOException e) {
e.printStackTrace();
}
if (chosenFile.isDirectory()) {
try {
- executeCommand("nautilus", "-w", chosenFile.getCanonicalFile().getAbsolutePath());
+ instantLauncher.openDirectory(chosenFile.getCanonicalFile());
} catch (IOException e) {
e.printStackTrace();
}
}
}
- private void executeCommand(String... c) {
- try {
- Runtime.getRuntime().exec(c);
- InstantLauncher.exitProgram();
-
- } catch (final IOException e) {
- new ExceptionDialog(e);
- }
- }
-
@Override
- public void menuItemSelectedAlternative(final Menu menu, final File chosenFile) {
- if (chosenFile.isFile()) {
+ public void menuItemSelectedAlternative(final File chosenFile) {
+ if (chosenFile.isFile())
chosenFile.setExecutable(!chosenFile.canExecute());
- } else {
+ else {
try {
- executeCommand("gnome-terminal", "--working-directory="
+ instantLauncher.executeCommand("gnome-terminal", "--working-directory="
+ chosenFile.getCanonicalFile().getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
@Override
- public void menuItemSelectedAlternative2(Menu menu, File chosenFile) {
+ public void menuItemSelectedAlternative2(File chosenFile) {
if (chosenFile.isFile()) {
try {
- executeCommand("emacs", chosenFile.getCanonicalFile().getAbsolutePath());
+ instantLauncher.executeCommand("emacs", chosenFile.getCanonicalFile().getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
-<log4j:configuration>
- <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d{ABSOLUTE}
- %5p %c{1}:%L - %m%n"/>
-
- </layout>
- </appender>
- <root>
- <!-- possible values are: debug, info, error -->
- <priority value="debug"></priority>
- <appender-ref ref="stdout"/>
- </root>
-</log4j:configuration>
\ No newline at end of file