X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Finstantlauncher%2Fmenu%2FMultiLevelMenu.java;h=bc370466dfd9a8dc3d55b22af57854764f7a917e;hb=ea9f229a2b0d0be0e765bdd508948b28cd2d490e;hp=fa200da68174aa2891d7fce1d73c4f3530696b33;hpb=b72db77c2582c6eb3042dc2df08b995ef38a6a45;p=instantlauncher.git diff --git a/src/main/java/eu/svjatoslav/instantlauncher/menu/MultiLevelMenu.java b/src/main/java/eu/svjatoslav/instantlauncher/menu/MultiLevelMenu.java index fa200da..bc37046 100755 --- a/src/main/java/eu/svjatoslav/instantlauncher/menu/MultiLevelMenu.java +++ b/src/main/java/eu/svjatoslav/instantlauncher/menu/MultiLevelMenu.java @@ -1,33 +1,24 @@ package eu.svjatoslav.instantlauncher.menu; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; - -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JPanel; - import eu.svjatoslav.commons.gui.dialog.ExceptionDialog; -import eu.svjatoslav.instantlauncher.FileAssociationManager; import eu.svjatoslav.instantlauncher.InstantLauncher; import eu.svjatoslav.instantlauncher.Utils; +import javax.swing.*; +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + public class MultiLevelMenu implements MenuListener { + private static final int VERTICAL_MENUS_COUNT = 7; + private static final Dimension CONTENT_PANEL_SIZE = new Dimension(1024, 900); private final InstantLauncher instantLauncher; + private final ArrayList menus = new ArrayList<>(); - private static final int VERTICAL_MENUS_COUNT = 5; - - public static final Dimension CONTENT_PANEL_SIZE = new Dimension(1024, 900); - - ArrayList menus = new ArrayList(); - - ArrayList panels = new ArrayList(); - JPanel contentPane; + private final ArrayList panels = new ArrayList<>(); + private JPanel contentPane; public MultiLevelMenu(final InstantLauncher instantLauncher) { this.instantLauncher = instantLauncher; @@ -35,15 +26,16 @@ public class MultiLevelMenu implements MenuListener { /** * Adds new vertical menu. - * + * * @return true if operation succeeded, or false - * if there was not enough space left for a new menu. + * if there was not enough space left for a new menu. */ - public boolean addMenu(final File directory) { + private boolean addMenu(final File directory) { final int newMenuHorizontalIndex = menus.size(); - if (newMenuHorizontalIndex >= VERTICAL_MENUS_COUNT) + if (newMenuHorizontalIndex >= VERTICAL_MENUS_COUNT) { return false; + } final Menu menu = new Menu(directory); menu.addMenuListener(this); @@ -76,24 +68,25 @@ public class MultiLevelMenu implements MenuListener { contentPane.add(panel); } - final File directory = instantLauncher.configuration.getRootDirectory(); + final File directory = instantLauncher.configurationManager.getNavigationRootDirectory(); addMenu(directory); return contentPane; } - public int getMenuIndex(final Menu menu) { + private int getMenuIndex(final Menu menu) { int i = 0; for (final Menu m : menus) { - if (m == menu) + if (m == menu) { return i; + } i++; } return -1; } @Override - public void menuItemSelected(final Menu menu, final File chosenFile) { + public void menuItemHighlighted(final Menu menu, final File chosenFile) { if (chosenFile.isDirectory()) { final int menuIndex = getMenuIndex(menu); @@ -107,54 +100,60 @@ public class MultiLevelMenu implements MenuListener { } } - if (chosenFile.isFile()) { + } + @Override + public void menuItemSelected(final Menu menu, final File chosenFile) { + if (chosenFile.isFile()) { if (chosenFile.canExecute()) { + executeCommand(chosenFile.getAbsolutePath()); + } else { + boolean fileOpened; try { - // Execute a command without arguments - final String command = chosenFile.getAbsolutePath(); - - final String[] c = new String[1]; - c[0] = command; - - Runtime.getRuntime().exec(c); - InstantLauncher.exitProgram(); - } catch (final IOException e) { - ExceptionDialog.showException(e); + fileOpened = instantLauncher.openFile(chosenFile.getCanonicalFile()); + if (fileOpened) { + InstantLauncher.exitProgram(); + } + } catch (IOException e) { + e.printStackTrace(); } + } + } - } else { - final boolean fileOpened = FileAssociationManager.openFile(chosenFile); - if (fileOpened) { - InstantLauncher.exitProgram(); - } + if (chosenFile.isDirectory()) { + try { + executeCommand("nautilus", "-w", chosenFile.getCanonicalFile().getAbsolutePath()); + } catch (IOException e) { + e.printStackTrace(); } } } - @Override - public void menuItemSelectedAlternative(final Menu menu, final File chosenFile) { - if (chosenFile.isDirectory()) { - // Execute a command without arguments - final String directoryPath = chosenFile.getAbsolutePath(); + private void executeCommand(String... c) { + try { + Runtime.getRuntime().exec(c); + InstantLauncher.exitProgram(); - final String[] c = new String[2]; - c[0] = "nautilus"; - c[1] = directoryPath; + } catch (final IOException e) { + new ExceptionDialog(e); + } + } + @Override + public void menuItemSelectedAlternative(final Menu menu, final File chosenFile) { + if (chosenFile.isFile()) { + chosenFile.setExecutable(!chosenFile.canExecute()); + } else { try { - Runtime.getRuntime().exec(c); - InstantLauncher.exitProgram(); - - } catch (final IOException e) { - ExceptionDialog.showException(e); + executeCommand("gnome-terminal", "--working-directory=" + + chosenFile.getCanonicalFile().getAbsolutePath()); + } catch (IOException e) { + e.printStackTrace(); } - } else { - chosenFile.setExecutable(!chosenFile.canExecute()); } } - public void removeMenus(final int fromIndex) { + private void removeMenus(final int fromIndex) { for (int i = fromIndex; i < menus.size(); i++) { final JPanel jPanel = panels.get(i); @@ -166,4 +165,16 @@ public class MultiLevelMenu implements MenuListener { } } + @Override + public void menuItemSelectedAlternative2(Menu menu, File chosenFile) { + if (chosenFile.isFile()) { + try { + executeCommand("emacs", chosenFile.getCanonicalFile().getAbsolutePath()); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + }