From 7b19618501851d1cf78bfb2ee5f2f8443f8e0f24 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 11 Nov 2017 05:14:38 -0600 Subject: [PATCH 1/2] Code upgraded to Java 7 --- QuickOpener/pom.xml | 396 ++++---- .../oscommands/commands/Commands.java | 280 +++--- .../oscommands/detector/OSDetector.java | 4 +- .../java/me/dsnet/quickopener/PathFinder.java | 439 +++++---- .../me/dsnet/quickopener/actions/Path.java | 155 +-- .../dsnet/quickopener/actions/RunCommand.java | 344 +++---- .../popup/CustomCommandPopupAction.java | 99 +- .../popup/CustomFileSystemPopupAction.java | 4 - .../actions/popup/DialogCustomCommandRun.java | 634 ++++++------ .../actions/popup/DialogCustomFileSystem.java | 931 +++++++++--------- .../actions/popup/DialogCustomTerminal.java | 867 ++++++++-------- .../actions/popup/DialogueFileSelector.java | 920 +++++++++-------- .../actions/popup/PropertyTableModel.java | 143 ++- .../quickopener/prefs/CommandsPanel.java | 544 +++++----- .../dsnet/quickopener/prefs/GeneralPanel.java | 644 ++++++------ .../dsnet/quickopener/prefs/PlacesPanel.java | 500 +++++----- .../me/dsnet/quickopener/prefs/PrefsUtil.java | 2 +- .../QuickOpenerOptionsPanelController.java | 165 ++-- .../quickopener/prefs/QuickOpenerPanel.java | 293 +++--- 19 files changed, 3694 insertions(+), 3670 deletions(-) diff --git a/QuickOpener/pom.xml b/QuickOpener/pom.xml index 4110877..a950686 100644 --- a/QuickOpener/pom.xml +++ b/QuickOpener/pom.xml @@ -1,199 +1,199 @@ - - - 4.0.0 - me.dsnet - me.dsnet.quickopener - 1.1.0.3 - nbm - - Diego Zambelli Sessona (diego.sessona@gmail.com) - - http://github.com/kinkadzs/QuickOpener-NetBeans - - - - org.codehaus.mojo - nbm-maven-plugin - 3.13 - true - - - me.dsnet.quickopener - nbproject/private/keystore - myself - license.txt - GPL - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.5.1 - - 1.6 - 1.6 - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - true - - - - - - - netbeans - Repository hosting NetBeans modules - http://bits.netbeans.org/nexus/content/groups/netbeans - - false - - - - - - org.netbeans.api - org-netbeans-api-annotations-common - ${version.netbeans} - - - org.netbeans.api - org-openide-awt - ${version.netbeans} - jar - - - org.netbeans.api - org-openide-dialogs - ${version.netbeans} - jar - - - org.netbeans.api - org-openide-loaders - ${version.netbeans} - jar - - - org.netbeans.api - org-netbeans-modules-projectapi - ${version.netbeans} - jar - - - org.netbeans.api - org-netbeans-modules-projectuiapi - ${version.netbeans} - jar - - - org.netbeans.api - org-netbeans-modules-options-api - ${version.netbeans} - jar - - - org.netbeans.api - org-openide-util - ${version.netbeans} - - - org.jdesktop - beansbinding - 1.2.1 - - - org.netbeans.api - org-openide-filesystems - ${version.netbeans} - - - org.netbeans.api - org-openide-util-lookup - ${version.netbeans} - - - org.netbeans.api - org-openide-nodes - ${version.netbeans} - - - org.netbeans.api - org-openide-windows - ${version.netbeans} - - - org.netbeans.api - org-netbeans-modules-editor-lib - ${version.netbeans} - - - org.netbeans.api - org-netbeans-modules-editor-lib2 - ${version.netbeans} - - - org.netbeans.api - org-openide-text - ${version.netbeans} - - - org.netbeans.api - org-netbeans-modules-javahelp - ${version.netbeans} - - - - UTF-8 - RELEASE802 - - QuickOpener - - <p>Sometimes while programming in NetBeans you want to explore a particular file that you are editing on the file system browser, or maybe launch a command in a terminal to do something with it. - </p><p>This plugins brings to your NetBeans six action, three of them always available and three of them available when the selected node has a file assiociated with it. - In particular:</p><p><em>When the selection has a valid file:</em></p><ul><li><strong>Open the default OS shell</strong> on the location of the file (or its folder) selected. - </li><li><strong>Open the file system browser</strong> on the location of the file (or its folder) selected. - </li><li><strong>Copy to the clipboard</strong> the path of the file selected. - </li></ul><p><em>Always enabled:</em></p><ul><li><strong>Launch a shell command</strong> (with parameters, customizable on preferences)</li><li><strong>FileSystem browser on any location</strong> (favorites, customizable on preferences)</li><li><strong>Open a shell on any location</strong> (favorites, customizable on preferences)</li></ul> - - -<h2>Updates</h2> - -<h3>1.1.0:</h3> -<ul> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/66">Feature 66</a>]: Refactor run custom dialog: simplify, add keyboard-only support</li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/33">Feature 33</a>]: Support for project folder replacement variable ${projectFolder}/${mainProjectFolder}</li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/67">Feature 67</a>]: More patterns - see <a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/67">details</a></li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/30">Feature 30</a>]: Support favorites nodes</li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/64">Feature 64</a>]: Support lookups with java.io.File</li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/65">Bugfix 65</a>]: Missing mnemonics in dialogs and options</li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/69">Bugfix 69</a>]: "Launch custom command..." should be available if there is no selected file</li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/77">Bugfix 77</a>]: Fix GUI detection for Ubuntu 16.04</li> -</ul> - -<h3>1.0.4:</h3> -<ul> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/63">Bugfix 63</a>]: File manager opens twice (KDE)</li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/62">Bugfix 62</a>]: java.lang.NoSuchMethodError: java.lang.Process.waitFor running NB @ JDK7</li> - </ul> - -<h3>1.0.3:</h3> -<ul> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/56">Task 56</a>]: Provide a 8.1 version for the plugin center</li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/60">Task 60</a>]: Include new version of oscommands</li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/61">Task 61</a>]: Convert to maven-project for better maintainence</li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/51">Bugfix 51</a>]: [Windows] Open in FileManager should select the file/dir</li> -<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/49">Bugfix 49</a>]: [Linux] Crash in options when running "LinuxUnknown" and KDE not detected</li> - - </ul> - -<p><a href="https://github.com/kinkadzs/QuickOpener-NetBeans/wiki/Home">The project is hosted on github, click here to report a bug or make a suggestion... - </a>Enjoy, Diego+Benno. - </p> + + + 4.0.0 + me.dsnet + me.dsnet.quickopener + 1.1.0.3 + nbm + + Diego Zambelli Sessona (diego.sessona@gmail.com) + + http://github.com/kinkadzs/QuickOpener-NetBeans + + + + org.codehaus.mojo + nbm-maven-plugin + 3.13 + true + + + me.dsnet.quickopener + nbproject/private/keystore + myself + license.txt + GPL + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + true + + + + + + + netbeans + Repository hosting NetBeans modules + http://bits.netbeans.org/nexus/content/groups/netbeans + + false + + + + + + org.netbeans.api + org-netbeans-api-annotations-common + ${version.netbeans} + + + org.netbeans.api + org-openide-awt + ${version.netbeans} + jar + + + org.netbeans.api + org-openide-dialogs + ${version.netbeans} + jar + + + org.netbeans.api + org-openide-loaders + ${version.netbeans} + jar + + + org.netbeans.api + org-netbeans-modules-projectapi + ${version.netbeans} + jar + + + org.netbeans.api + org-netbeans-modules-projectuiapi + ${version.netbeans} + jar + + + org.netbeans.api + org-netbeans-modules-options-api + ${version.netbeans} + jar + + + org.netbeans.api + org-openide-util + ${version.netbeans} + + + org.jdesktop + beansbinding + 1.2.1 + + + org.netbeans.api + org-openide-filesystems + ${version.netbeans} + + + org.netbeans.api + org-openide-util-lookup + ${version.netbeans} + + + org.netbeans.api + org-openide-nodes + ${version.netbeans} + + + org.netbeans.api + org-openide-windows + ${version.netbeans} + + + org.netbeans.api + org-netbeans-modules-editor-lib + ${version.netbeans} + + + org.netbeans.api + org-netbeans-modules-editor-lib2 + ${version.netbeans} + + + org.netbeans.api + org-openide-text + ${version.netbeans} + + + org.netbeans.api + org-netbeans-modules-javahelp + ${version.netbeans} + + + + UTF-8 + RELEASE802 + + QuickOpener + + <p>Sometimes while programming in NetBeans you want to explore a particular file that you are editing on the file system browser, or maybe launch a command in a terminal to do something with it. + </p><p>This plugins brings to your NetBeans six action, three of them always available and three of them available when the selected node has a file assiociated with it. + In particular:</p><p><em>When the selection has a valid file:</em></p><ul><li><strong>Open the default OS shell</strong> on the location of the file (or its folder) selected. + </li><li><strong>Open the file system browser</strong> on the location of the file (or its folder) selected. + </li><li><strong>Copy to the clipboard</strong> the path of the file selected. + </li></ul><p><em>Always enabled:</em></p><ul><li><strong>Launch a shell command</strong> (with parameters, customizable on preferences)</li><li><strong>FileSystem browser on any location</strong> (favorites, customizable on preferences)</li><li><strong>Open a shell on any location</strong> (favorites, customizable on preferences)</li></ul> + + +<h2>Updates</h2> + +<h3>1.1.0:</h3> +<ul> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/66">Feature 66</a>]: Refactor run custom dialog: simplify, add keyboard-only support</li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/33">Feature 33</a>]: Support for project folder replacement variable ${projectFolder}/${mainProjectFolder}</li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/67">Feature 67</a>]: More patterns - see <a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/67">details</a></li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/30">Feature 30</a>]: Support favorites nodes</li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/64">Feature 64</a>]: Support lookups with java.io.File</li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/65">Bugfix 65</a>]: Missing mnemonics in dialogs and options</li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/69">Bugfix 69</a>]: "Launch custom command..." should be available if there is no selected file</li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/77">Bugfix 77</a>]: Fix GUI detection for Ubuntu 16.04</li> +</ul> + +<h3>1.0.4:</h3> +<ul> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/63">Bugfix 63</a>]: File manager opens twice (KDE)</li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/62">Bugfix 62</a>]: java.lang.NoSuchMethodError: java.lang.Process.waitFor running NB @ JDK7</li> + </ul> + +<h3>1.0.3:</h3> +<ul> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/56">Task 56</a>]: Provide a 8.1 version for the plugin center</li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/60">Task 60</a>]: Include new version of oscommands</li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/61">Task 61</a>]: Convert to maven-project for better maintainence</li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/51">Bugfix 51</a>]: [Windows] Open in FileManager should select the file/dir</li> +<li>[<a href="https://github.com/dzsessona/QuickOpener-NetBeans/issues/49">Bugfix 49</a>]: [Linux] Crash in options when running "LinuxUnknown" and KDE not detected</li> + + </ul> + +<p><a href="https://github.com/kinkadzs/QuickOpener-NetBeans/wiki/Home">The project is hosted on github, click here to report a bug or make a suggestion... + </a>Enjoy, Diego+Benno. + </p> \ No newline at end of file diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/Commands.java b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/Commands.java index 1cc3f05..adc1631 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/Commands.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/Commands.java @@ -1,130 +1,150 @@ -package com.sessonad.oscommands.commands; - - -import com.sessonad.oscommands.detector.OSDetector; -import com.sessonad.oscommands.detector.OperatingSystem; -import java.awt.Desktop; -import java.io.File; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - - -/** - * - * @author SessonaD - * @author markiewb - */ -public abstract class Commands { - - private static final Logger LOG = Logger.getLogger(Commands.class.getName()); - - static Commands platform; - - @SuppressWarnings("unchecked") - public static T getPlatform(){ - if (platform == null)initializePlatform(); - return (T)platform; - } - - static void initializePlatform(){ - OperatingSystem os = OSDetector.detectOS(); - if (os.equals(OperatingSystem.WINDOWS)) platform = new WindowsCommands(); - else if (os.equals(OperatingSystem.MAC_OS)) platform = new MacOSCommands(); - else if (os.equals(OperatingSystem.LINUX_GNOME))platform = new LinuxGnomeCommands(); - else if (os.equals(OperatingSystem.LINUX_KDE)) platform = new LinuxKdeCommands(); - else if (os.equals(OperatingSystem.LINUX_LXDE)) platform = new LinuxLxdeCommands(); - else if (os.equals(OperatingSystem.LINUX_XFCE)) platform = new LinuxXfceCommands(); - else if (os.equals(OperatingSystem.LINUX_UNKNOWN)) platform = new LinuxUnknownCommands(); - else if (os.equals(OperatingSystem.UNKNOWN)) platform = new UnknownOSCommands(); - } - - public abstract OperatingSystem getOperatingSystem(); - - public void openInShell(String currentPath) throws Exception { - String fullCommand = ""; - if(getOperatingSystem().equals(OperatingSystem.WINDOWS)){ - fullCommand = getOperatingSystem().getShellCommand()+"\""+currentPath+"\""; - }else{ - fullCommand = getOperatingSystem().getShellCommand() + currentPath; - } - Runtime.getRuntime().exec(fullCommand); - } - - /** - * Old function. Only left for backward compatibility. - * - * @param current - * @throws Exception - */ - @Deprecated - public void browseInFileSystem(File current) throws Exception { - if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { - try { - Desktop.getDesktop().open(current); - } catch (IOException e) { - executeFileSystemBrowserCommand(current); - } - } else { - executeFileSystemBrowserCommand(current); - } - } - /** - * Browses to the file or directory (depending on the features of the - * OS/file-browser). If it does work, then - * {@link Desktop#open(java.io.File)} is used. - * - * @param fileOrDir - * @throws Exception - */ - public void browseInFileSystemToFileOrDir(File fileOrDir) throws Exception { - if (null == fileOrDir) { - return; - } - - try { - executeFileSystemBrowserCommand(fileOrDir); - } catch (Exception e) { - LOG.log(Level.WARNING, String.format("Could not browse to file %s. Try to fallback to Desktop.getDesktop().open()", fileOrDir), e); - - //execution via executeFileSystemBrowserCommand did not work, so fallback to Desktop.open() - if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { - try { - File directory = fileOrDir.isDirectory() ? fileOrDir : fileOrDir.getParentFile(); - Desktop.getDesktop().open(directory); - } catch (IOException ioe) { - //NOP, no fallback anymore - } - } - } - - } - - /** - * - * @param fileOrDir - * @return exit-code from the process (!=0 means error) - * @throws IOException - */ - protected Process executeFileSystemBrowserCommand(File fileOrDir) throws IOException { - final boolean isFile = fileOrDir.isFile(); - File directory = isFile ? fileOrDir.getParentFile() : fileOrDir; - String fullCommand = null; - if (isFile) { - if (getOperatingSystem().isFeatured(SupportedFeatures.BROWSE_TO_FILE)) { - fullCommand = getOperatingSystem().getFileSystemBrowserCommandForFile() + fileOrDir.getAbsolutePath(); - } - if (getOperatingSystem().isFeatured(SupportedFeatures.BROWSE_TO_DIR)) { - fullCommand = getOperatingSystem().getFileSystemBrowserCommand() + directory.getAbsolutePath(); - } - } else { - //exp - fullCommand = getOperatingSystem().getFileSystemBrowserCommand() + directory.getAbsolutePath(); - } - if (null == fullCommand) { - return null; - } - - return Runtime.getRuntime().exec(fullCommand); - } -} +package com.sessonad.oscommands.commands; + + +import com.sessonad.oscommands.detector.OSDetector; +import com.sessonad.oscommands.detector.OperatingSystem; +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + + +/** + * + * @author SessonaD + * @author markiewb + */ +public abstract class Commands { + + private static final Logger LOG = Logger.getLogger(Commands.class.getName()); + + static Commands platform; + + @SuppressWarnings("unchecked") + public static T getPlatform(){ + if (platform == null)initializePlatform(); + return (T)platform; + } + + static void initializePlatform(){ + OperatingSystem os = OSDetector.detectOS(); + switch (os) { + case WINDOWS: + platform = new WindowsCommands(); + break; + case MAC_OS: + platform = new MacOSCommands(); + break; + case LINUX_GNOME: + platform = new LinuxGnomeCommands(); + break; + case LINUX_KDE: + platform = new LinuxKdeCommands(); + break; + case LINUX_LXDE: + platform = new LinuxLxdeCommands(); + break; + case LINUX_XFCE: + platform = new LinuxXfceCommands(); + break; + case LINUX_UNKNOWN: + platform = new LinuxUnknownCommands(); + break; + case UNKNOWN: + platform = new UnknownOSCommands(); + break; + default: + break; + } + } + + public abstract OperatingSystem getOperatingSystem(); + + public void openInShell(String currentPath) throws Exception { + String fullCommand; + if(getOperatingSystem().equals(OperatingSystem.WINDOWS)){ + fullCommand = getOperatingSystem().getShellCommand()+"\""+currentPath+"\""; + }else{ + fullCommand = getOperatingSystem().getShellCommand() + currentPath; + } + Runtime.getRuntime().exec(fullCommand); + } + + /** + * Old function. Only left for backward compatibility. + * + * @param current + * @throws Exception + */ + @Deprecated + public void browseInFileSystem(File current) throws Exception { + if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { + try { + Desktop.getDesktop().open(current); + } catch (IOException e) { + executeFileSystemBrowserCommand(current); + } + } else { + executeFileSystemBrowserCommand(current); + } + } + /** + * Browses to the file or directory (depending on the features of the + * OS/file-browser). If it does work, then + * {@link Desktop#open(java.io.File)} is used. + * + * @param fileOrDir + * @throws Exception + */ + public void browseInFileSystemToFileOrDir(File fileOrDir) throws Exception { + if (null == fileOrDir) { + return; + } + + try { + executeFileSystemBrowserCommand(fileOrDir); + } catch (IOException e) { + LOG.log(Level.WARNING, String.format("Could not browse to file %s. Try to fallback to Desktop.getDesktop().open()", fileOrDir), e); + + //execution via executeFileSystemBrowserCommand did not work, so fallback to Desktop.open() + if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { + try { + File directory = fileOrDir.isDirectory() ? fileOrDir : fileOrDir.getParentFile(); + Desktop.getDesktop().open(directory); + } catch (IOException ioe) { + //NOP, no fallback anymore + } + } + } + + } + + /** + * + * @param fileOrDir + * @return exit-code from the process (!=0 means error) + * @throws IOException + */ + protected Process executeFileSystemBrowserCommand(File fileOrDir) throws IOException { + final boolean isFile = fileOrDir.isFile(); + File directory = isFile ? fileOrDir.getParentFile() : fileOrDir; + String fullCommand = null; + if (isFile) { + if (getOperatingSystem().isFeatured(SupportedFeatures.BROWSE_TO_FILE)) { + fullCommand = getOperatingSystem().getFileSystemBrowserCommandForFile() + fileOrDir.getAbsolutePath(); + } + if (getOperatingSystem().isFeatured(SupportedFeatures.BROWSE_TO_DIR)) { + fullCommand = getOperatingSystem().getFileSystemBrowserCommand() + directory.getAbsolutePath(); + } + } else { + //exp + fullCommand = getOperatingSystem().getFileSystemBrowserCommand() + directory.getAbsolutePath(); + } + if (null == fullCommand) { + return null; + } + + return Runtime.getRuntime().exec(fullCommand); + } +} diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OSDetector.java b/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OSDetector.java index d8a323c..a8ad633 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OSDetector.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OSDetector.java @@ -39,7 +39,9 @@ private static OperatingSystem detectLinuxGUI() { private static boolean checkProcessNames(String... processNames) throws Exception { for (String processName : processNames) { - if (executePidOfCommand(processName)) return true; + if (executePidOfCommand(processName)) { + return true; + } } return false; } diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/PathFinder.java b/QuickOpener/src/main/java/me/dsnet/quickopener/PathFinder.java index c924b6c..75bee48 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/PathFinder.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/PathFinder.java @@ -1,219 +1,220 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener; - -import java.io.File; -import org.netbeans.api.project.FileOwnerQuery; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ui.OpenProjects; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileSystem; -import org.openide.filesystems.FileUtil; -import org.openide.loaders.DataFolder; -import org.openide.loaders.DataObject; -import org.openide.loaders.DataShadow; -import org.openide.loaders.MultiDataObject; -import org.openide.nodes.Node; -import org.openide.windows.TopComponent; - - - -/** - * - * @author SessonaD - */ -public class PathFinder { - - public static File getMainProjectRoot(){ - try { - Project project = OpenProjects.getDefault().getMainProject(); - FileObject root = project.getProjectDirectory(); - return FileUtil.toFile(root); - } catch (Exception e) { - return null; - } - } - - public static String getMainProjectRootPath(){ - try { - return getMainProjectRoot().getAbsolutePath(); - } catch (Exception e) { - return null; - } - } - - public static String getMyNetbeansConfPath(){ - try { - FileObject root = FileUtil.getConfigRoot(); - return FileUtil.toFile(root).getAbsolutePath(); - } catch (Exception e) { - return null; - } - } - - public static File getActiveFile(DataObject dataObj,boolean isFolder){ - try{ - if(dataObj == null){ - return getActiveFileFromSelectedNode(isFolder); - }else{ - try{ - return getActiveFileFromDataObject(dataObj,isFolder); - }catch(NullPointerException npex){ - return getActiveFileFromSelectedNode(isFolder); - } - } - } catch (Exception e) { - return null; - } - } - - public static String getActivePath(DataObject dataObj, boolean isFolder) { - File found = getActiveFile(dataObj, isFolder); - return getActivePath(found); - } - - public static String getActiveProject() { - File found = getActiveFile(null, false); - if (null != found && found.exists()) { - FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(found)); - - Project owner = FileOwnerQuery.getOwner(fo); - if (null != owner) { - File toFile = FileUtil.toFile(owner.getProjectDirectory()); - return toFile.getAbsolutePath(); - } - } - return null; - } - - public static String getRelativeActivePath(DataObject dataObj,boolean isFolder){ - try{ - String filePath = getActivePath(dataObj,isFolder); - String rootPath = getMainProjectRootPath(); - if((filePath != null && !filePath.isEmpty())&&(rootPath != null && !rootPath.isEmpty())&&(filePath.contains(rootPath))){ - return (filePath.substring(rootPath.length() + 1)); - }else{ - return null; - } - }catch(Exception e){ - return null; - } - } - - private static File getActiveFileFromDataObject(DataObject dataObj,boolean isFolder){ - if(dataObj == null){ return null;} - else{ - try{ - dataObj = getDataObjectAndResolveShadows(dataObj); - File toReturn = getFileFromDataObject(dataObj,isFolder); - if (toReturn != null && toReturn.exists()) { - return toReturn; - } else { - if ((dataObj instanceof DataFolder)) { - DataFolder df = (DataFolder) dataObj; - FileObject fobj = df.getPrimaryFile(); - File found = getFileFromFileObject(fobj); - if (found == null) { - return null; - } else { - return isFolder ? found.getParentFile() : found; - } - } else if (dataObj instanceof MultiDataObject) { - MultiDataObject mdo = (MultiDataObject) dataObj; - FileObject fobj = mdo.getPrimaryFile(); - File found = getFileFromFileObject(fobj); - if (found == null) { - return null; - } else { - return isFolder ? found.getParentFile() : found; - } - } - } - }catch(Exception e){ - return null; - } - return null; - } - } - - public static String getActivePath(File file) { - return ((file != null) && (file.exists())) ? file.getAbsolutePath() : null; - } - - //TODO check deprecated api - private static File getFileFromFileObject(FileObject fobj){ - try{ - if(fobj == null){ - return null; - }else if(fobj.isRoot()){ - FileSystem fs =fobj.getFileSystem(); - String path = fs.getSystemName(); - File f = new File(path); - return f; - }else{ - return getFileFromFileObject(fobj.getParent()); - } - }catch(Exception e){ - //e.printStackTrace(); - return null; - } - - } - - private static File getFileFromDataObject(DataObject dataObj, boolean isFolder) { - try { - File current = FileUtil.toFile(dataObj.getPrimaryFile()); - if (!isFolder) { - return current; - } else { - return (current.isDirectory()) ? current : current.getParentFile(); - } - } catch (Exception e) { - // e.printStackTrace(); - return null; - } - } - - private static File getActiveFileFromSelectedNode(boolean isFolder) { - try { - TopComponent topActive = TopComponent.getRegistry().getActivated(); - Node[] nodes = topActive.getActivatedNodes(); - if (nodes.length == 1) { - final Node node = nodes[0]; - final DataObject dataObject = node.getLookup().lookup(DataObject.class); - - File result; - // a) try to get File - result = node.getLookup().lookup(File.class); - // b) old fallback - if (null == result) { - result = getActiveFileFromDataObject(dataObject, isFolder); - } - return result; - - } else { - return null; - } - } catch (Exception e) { - return null; - } - } - - /** - * Support favorite nodes too - * https://github.com/dzsessona/QuickOpener-NetBeans/issues/30 - * - * @param dataObject - * @return - */ - private static DataObject getDataObjectAndResolveShadows(DataObject dataObject) { - if (dataObject instanceof DataShadow) { - DataShadow dataShadow = (DataShadow) dataObject; - return dataShadow.getOriginal(); - } - return dataObject; - } - -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener; + +import java.io.File; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ui.OpenProjects; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileStateInvalidException; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataFolder; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataShadow; +import org.openide.loaders.MultiDataObject; +import org.openide.nodes.Node; +import org.openide.windows.TopComponent; + + + +/** + * + * @author SessonaD + */ +public class PathFinder { + + public static File getMainProjectRoot(){ + try { + Project project = OpenProjects.getDefault().getMainProject(); + FileObject root = project.getProjectDirectory(); + return FileUtil.toFile(root); + } catch (Exception e) { + return null; + } + } + + public static String getMainProjectRootPath(){ + try { + return getMainProjectRoot().getAbsolutePath(); + } catch (Exception e) { + return null; + } + } + + public static String getMyNetbeansConfPath(){ + try { + FileObject root = FileUtil.getConfigRoot(); + return FileUtil.toFile(root).getAbsolutePath(); + } catch (Exception e) { + return null; + } + } + + public static File getActiveFile(DataObject dataObj,boolean isFolder){ + try{ + if(dataObj == null){ + return getActiveFileFromSelectedNode(isFolder); + }else{ + try{ + return getActiveFileFromDataObject(dataObj,isFolder); + }catch(NullPointerException npex){ + return getActiveFileFromSelectedNode(isFolder); + } + } + } catch (Exception e) { + return null; + } + } + + public static String getActivePath(DataObject dataObj, boolean isFolder) { + File found = getActiveFile(dataObj, isFolder); + return getActivePath(found); + } + + public static String getActiveProject() { + File found = getActiveFile(null, false); + if (null != found && found.exists()) { + FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(found)); + + Project owner = FileOwnerQuery.getOwner(fo); + if (null != owner) { + File toFile = FileUtil.toFile(owner.getProjectDirectory()); + return toFile.getAbsolutePath(); + } + } + return null; + } + + public static String getRelativeActivePath(DataObject dataObj,boolean isFolder){ + try{ + String filePath = getActivePath(dataObj,isFolder); + String rootPath = getMainProjectRootPath(); + if((filePath != null && !filePath.isEmpty())&&(rootPath != null && !rootPath.isEmpty())&&(filePath.contains(rootPath))){ + return (filePath.substring(rootPath.length() + 1)); + }else{ + return null; + } + }catch(Exception e){ + return null; + } + } + + private static File getActiveFileFromDataObject(DataObject dataObj,boolean isFolder){ + if(dataObj == null){ return null;} + else{ + try{ + dataObj = getDataObjectAndResolveShadows(dataObj); + File toReturn = getFileFromDataObject(dataObj,isFolder); + if (toReturn != null && toReturn.exists()) { + return toReturn; + } else { + if ((dataObj instanceof DataFolder)) { + DataFolder df = (DataFolder) dataObj; + FileObject fobj = df.getPrimaryFile(); + File found = getFileFromFileObject(fobj); + if (found == null) { + return null; + } else { + return isFolder ? found.getParentFile() : found; + } + } else if (dataObj instanceof MultiDataObject) { + MultiDataObject mdo = (MultiDataObject) dataObj; + FileObject fobj = mdo.getPrimaryFile(); + File found = getFileFromFileObject(fobj); + if (found == null) { + return null; + } else { + return isFolder ? found.getParentFile() : found; + } + } + } + }catch(Exception e){ + return null; + } + return null; + } + } + + public static String getActivePath(File file) { + return ((file != null) && (file.exists())) ? file.getAbsolutePath() : null; + } + + //TODO check deprecated api + private static File getFileFromFileObject(FileObject fobj){ + try{ + if(fobj == null){ + return null; + }else if(fobj.isRoot()){ + FileSystem fs =fobj.getFileSystem(); + String path = fs.getSystemName(); + File f = new File(path); + return f; + }else{ + return getFileFromFileObject(fobj.getParent()); + } + }catch(FileStateInvalidException e){ + //e.printStackTrace(); + return null; + } + + } + + private static File getFileFromDataObject(DataObject dataObj, boolean isFolder) { + try { + File current = FileUtil.toFile(dataObj.getPrimaryFile()); + if (!isFolder) { + return current; + } else { + return (current.isDirectory()) ? current : current.getParentFile(); + } + } catch (Exception e) { + // e.printStackTrace(); + return null; + } + } + + private static File getActiveFileFromSelectedNode(boolean isFolder) { + try { + TopComponent topActive = TopComponent.getRegistry().getActivated(); + Node[] nodes = topActive.getActivatedNodes(); + if (nodes.length == 1) { + final Node node = nodes[0]; + final DataObject dataObject = node.getLookup().lookup(DataObject.class); + + File result; + // a) try to get File + result = node.getLookup().lookup(File.class); + // b) old fallback + if (null == result) { + result = getActiveFileFromDataObject(dataObject, isFolder); + } + return result; + + } else { + return null; + } + } catch (Exception e) { + return null; + } + } + + /** + * Support favorite nodes too + * https://github.com/dzsessona/QuickOpener-NetBeans/issues/30 + * + * @param dataObject + * @return + */ + private static DataObject getDataObjectAndResolveShadows(DataObject dataObject) { + if (dataObject instanceof DataShadow) { + DataShadow dataShadow = (DataShadow) dataObject; + return dataShadow.getOriginal(); + } + return dataObject; + } + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Path.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Path.java index 31fb509..210297f 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Path.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Path.java @@ -1,77 +1,78 @@ -package me.dsnet.quickopener.actions; - -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.StringSelection; -import java.io.File; -import me.dsnet.quickopener.PathFinder; -import me.dsnet.quickopener.QuickMessages; -import me.dsnet.quickopener.prefs.PrefsUtil; -import me.dsnet.quickopener.prefs.QuickOpenerProperty; -import org.netbeans.api.annotations.common.StaticResource; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.awt.ActionID; -import org.openide.awt.ActionRegistration; -import org.openide.nodes.Node; -import org.openide.util.NbBundle.Messages; - -/** - * - * @author SessonaD - * @author markiewb (contributor) - */ -@ActionID( - category = "Tools", - id = "me.dsnet.quickopener.actions.Path") -@ActionRegistration( - lazy = false, - displayName = "#CTL_Path" -) -@Messages("CTL_Path=Copy Path") -public final class Path extends AbstractFileContextAwareAction { - - @StaticResource - private static final String icon = "me/dsnet/quickopener/icons/path.png"; - - @Override - public String getName() { - return Bundle.CTL_Path(); - } - - @Override - protected String iconResource() { - return icon; - } - - @Override - protected void performAction(Node[] activatedNodes) { - File file = getFile(); - - String path = PathFinder.getActivePath(file); - if (path == null) { - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_FILE_IN_SELECTION, NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - return; - } - String ossep = getOSSeparator(); - QuickOpenerProperty prop = PrefsUtil.load(null, "generalseparator", ossep); - if (!prop.getValue().equals(ossep)) { - String torep = (ossep.equals("\\")) ? "\\\\" : ossep; - String repl = (prop.getValue().equals("\\")) ? "\\\\" : prop.getValue(); - path = path.replaceAll(torep, repl); - } - try { - Toolkit toolkit = Toolkit.getDefaultToolkit(); - Clipboard clipboard = toolkit.getSystemClipboard(); - StringSelection strSel = new StringSelection(path); - clipboard.setContents(strSel, null); - } catch (Exception ex) { - } - } - - private String getOSSeparator() { - return System.getProperty("file.separator"); - } - -} +package me.dsnet.quickopener.actions; + +import java.awt.HeadlessException; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.io.File; +import me.dsnet.quickopener.PathFinder; +import me.dsnet.quickopener.QuickMessages; +import me.dsnet.quickopener.prefs.PrefsUtil; +import me.dsnet.quickopener.prefs.QuickOpenerProperty; +import org.netbeans.api.annotations.common.StaticResource; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; +import org.openide.nodes.Node; +import org.openide.util.NbBundle.Messages; + +/** + * + * @author SessonaD + * @author markiewb (contributor) + */ +@ActionID( + category = "Tools", + id = "me.dsnet.quickopener.actions.Path") +@ActionRegistration( + lazy = false, + displayName = "#CTL_Path" +) +@Messages("CTL_Path=Copy Path") +public final class Path extends AbstractFileContextAwareAction { + + @StaticResource + private static final String icon = "me/dsnet/quickopener/icons/path.png"; + + @Override + public String getName() { + return Bundle.CTL_Path(); + } + + @Override + protected String iconResource() { + return icon; + } + + @Override + protected void performAction(Node[] activatedNodes) { + File file = getFile(); + + String path = PathFinder.getActivePath(file); + if (path == null) { + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_FILE_IN_SELECTION, NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + return; + } + String ossep = getOSSeparator(); + QuickOpenerProperty prop = PrefsUtil.load(null, "generalseparator", ossep); + if (!prop.getValue().equals(ossep)) { + String torep = (ossep.equals("\\")) ? "\\\\" : ossep; + String repl = (prop.getValue().equals("\\")) ? "\\\\" : prop.getValue(); + path = path.replaceAll(torep, repl); + } + try { + Toolkit toolkit = Toolkit.getDefaultToolkit(); + Clipboard clipboard = toolkit.getSystemClipboard(); + StringSelection strSel = new StringSelection(path); + clipboard.setContents(strSel, null); + } catch (HeadlessException ex) { + } + } + + private String getOSSeparator() { + return System.getProperty("file.separator"); + } + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/RunCommand.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/RunCommand.java index 3614cb5..0a30fb6 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/RunCommand.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/RunCommand.java @@ -1,171 +1,173 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.actions; - -import java.io.File; -import me.dsnet.quickopener.PathFinder; -import me.dsnet.quickopener.QuickMessages; -import me.dsnet.quickopener.prefs.PrefsUtil; -import java.util.LinkedHashMap; -import java.util.Map; -import javax.swing.JEditorPane; -import javax.swing.text.JTextComponent; -import javax.swing.text.StyledDocument; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.cookies.EditorCookie; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.nodes.Node; -import org.openide.text.NbDocument; -import org.openide.windows.TopComponent; - -/** - * - * @author SessonaD - */ -public class RunCommand { - - private static boolean isNotBlank(String f) { - return f != null && !f.isEmpty(); - } - private final String _command; - - public RunCommand(String command) { - this._command = command; - } - - public boolean actionPerformed() { - if (_command == null) { - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_COMMAND, NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - return false; - } else { - final Map createPlaceholders = createPlaceholders(); - String command = fillPlaceholders(_command, createPlaceholders); - //Are all placeholders replaced? -> if not then show a message! - boolean foundUnreplacedPlaceholder = false; - for (String placeholder : createPlaceholders.keySet()) { - if (command.contains(placeholder)) { - foundUnreplacedPlaceholder = true; - break; - } - } - - if (foundUnreplacedPlaceholder) { - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_DEFAULT_PARAMETERS + " \nCommand was: " + command, NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - return false; - } - try { - String msg = QuickMessages.CONFIRM_COMMAND_PREFIX + command + QuickMessages.CONFIRM_COMMAND_SUFFIX; - boolean nedToConfirm = Boolean.parseBoolean((PrefsUtil.load(null, "confirmationDialogue", "true")).getValue()); - NotifyDescriptor d = new NotifyDescriptor.Confirmation(msg, "Confirm", NotifyDescriptor.OK_CANCEL_OPTION); - if (!nedToConfirm || (nedToConfirm && NotifyDescriptor.OK_OPTION == DialogDisplayer.getDefault().notify(d))) { - Runtime.getRuntime().exec(command); - return true; - } else { - return false; - } - } catch (Exception ex) { - return false; - } - } - } - - private Map createPlaceholders() { - String currentFile = PathFinder.getActivePath(null, false); - String currentFolder = PathFinder.getActivePath(null, true); - String relativeFile = PathFinder.getRelativeActivePath(null, false); - String relativeFolder = PathFinder.getRelativeActivePath(null, true); - String currentProjectFolder = PathFinder.getActiveProject(); - String mainProjectFolder = PathFinder.getMainProjectRootPath(); - Map placeholders = new LinkedHashMap(); - - if (null != currentFile && new File(currentFile).exists()) { - File file = new File(currentFile); - FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(file)); - placeholders.put("${fileNameExt}", fo.getNameExt()); - placeholders.put("${fileName}", fo.getName()); - placeholders.put("${fileExt}", fo.getExt()); - } else { - placeholders.put("${fileNameExt}", ""); - placeholders.put("${fileName}", ""); - placeholders.put("${fileExt}", ""); - } - //${line}:${column} ${line0}:${column0} '${selectedText}' ${fileNameExt} ${fileName} ${fileExt} ${file} ${folder} ${relativeFile} ${relativeFolder} ${projectFolder} ${mainProjectFolder} - placeholders.put("${file}", currentFile); - placeholders.put("${folder}", currentFolder); - placeholders.put("${relativeFile}", relativeFile); - placeholders.put("${relativeFolder}", relativeFolder); - placeholders.put("${projectFolder}", currentProjectFolder); - placeholders.put("${mainProjectFolder}", mainProjectFolder); - - JTextComponent editor = getCurrentEditor(); - int caret = (null != editor) ? editor.getCaretPosition() : -1; - StyledDocument sdocument = (null != editor && (editor.getDocument() instanceof StyledDocument)) ? (StyledDocument) editor.getDocument() - : null; - if (null != sdocument) { - - int line0 = NbDocument.findLineNumber(sdocument, caret); - int column0 = NbDocument.findLineColumn(sdocument, caret); - String selectedText = editor.getSelectedText(); - placeholders.put("${line0}", "" + line0); - placeholders.put("${line}", "" + (line0 + 1)); - placeholders.put("${column0}", "" + column0); - placeholders.put("${column}", "" + (column0 + 1)); - placeholders.put("${selectedText}", null != selectedText ? selectedText : ""); - } else { - // add defaults for editor related placeholders - placeholders.put("${line0}", ""); - placeholders.put("${line}", ""); - placeholders.put("${column0}", ""); - placeholders.put("${column}", ""); - placeholders.put("${selectedText}", ""); - } - - return placeholders; - } - - private String fillPlaceholders(String command, Map placeholders) { - //Replace all placeholders - for (Map.Entry entry : placeholders.entrySet()) { - String pattern = entry.getKey(); - String fileName = entry.getValue(); - /** - * Replacement for - *
if(command.contains("${currentFile}") && isNotBlank(currentFile)) {command=command.replace("${currentFile}", currentFile);}
-             * 
- */ - if (command.contains(pattern) && isNotBlank(fileName)) { - command = command.replace(pattern, fileName); - } - } - return command; - } - - public String getCommandWithReplacedPlaceholders() { - final Map placeholders = createPlaceholders(); - return fillPlaceholders(_command, placeholders); - } - - private JTextComponent getCurrentEditor() { - Node[] arr = TopComponent.getRegistry().getCurrentNodes(); - if (null == arr) { - return null; - } - for (int i = 0; i < arr.length; i++) { - EditorCookie ec = (EditorCookie) arr[i].getCookie(EditorCookie.class); - if (ec != null) { - JEditorPane[] panes = ec.getOpenedPanes(); - if (panes != null && panes.length > 0) { - return panes[0]; - } - } - } - return null; - } - -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener.actions; + +import java.io.File; +import java.io.IOException; +import me.dsnet.quickopener.PathFinder; +import me.dsnet.quickopener.QuickMessages; +import me.dsnet.quickopener.prefs.PrefsUtil; +import java.util.LinkedHashMap; +import java.util.Map; +import javax.swing.JEditorPane; +import javax.swing.text.JTextComponent; +import javax.swing.text.StyledDocument; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.cookies.EditorCookie; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.nodes.Node; +import org.openide.text.NbDocument; +import org.openide.windows.TopComponent; + +/** + * + * @author SessonaD + */ +public class RunCommand { + + private static boolean isNotBlank(String f) { + return f != null && !f.isEmpty(); + } + private final String _command; + + public RunCommand(String command) { + this._command = command; + } + + public boolean actionPerformed() { + if (_command == null) { + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_COMMAND, NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + return false; + } else { + final Map createPlaceholders = createPlaceholders(); + String command = fillPlaceholders(_command, createPlaceholders); + //Are all placeholders replaced? -> if not then show a message! + boolean foundUnreplacedPlaceholder = false; + for (String placeholder : createPlaceholders.keySet()) { + if (command.contains(placeholder)) { + foundUnreplacedPlaceholder = true; + break; + } + } + + if (foundUnreplacedPlaceholder) { + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_DEFAULT_PARAMETERS + " \nCommand was: " + command, NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + return false; + } + try { + String msg = QuickMessages.CONFIRM_COMMAND_PREFIX + command + QuickMessages.CONFIRM_COMMAND_SUFFIX; + boolean nedToConfirm = Boolean.parseBoolean((PrefsUtil.load(null, "confirmationDialogue", "true")).getValue()); + NotifyDescriptor d = new NotifyDescriptor.Confirmation(msg, "Confirm", NotifyDescriptor.OK_CANCEL_OPTION); + if (!nedToConfirm || (nedToConfirm && NotifyDescriptor.OK_OPTION == DialogDisplayer.getDefault().notify(d))) { + Runtime.getRuntime().exec(command); + return true; + } else { + return false; + } + } catch (IOException ex) { + return false; + } + } + } + + private Map createPlaceholders() { + String currentFile = PathFinder.getActivePath(null, false); + String currentFolder = PathFinder.getActivePath(null, true); + String relativeFile = PathFinder.getRelativeActivePath(null, false); + String relativeFolder = PathFinder.getRelativeActivePath(null, true); + String currentProjectFolder = PathFinder.getActiveProject(); + String mainProjectFolder = PathFinder.getMainProjectRootPath(); + Map placeholders = new LinkedHashMap<>(); + + if (null != currentFile && new File(currentFile).exists()) { + File file = new File(currentFile); + FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(file)); + placeholders.put("${fileNameExt}", fo.getNameExt()); + placeholders.put("${fileName}", fo.getName()); + placeholders.put("${fileExt}", fo.getExt()); + } else { + placeholders.put("${fileNameExt}", ""); + placeholders.put("${fileName}", ""); + placeholders.put("${fileExt}", ""); + } + //${line}:${column} ${line0}:${column0} '${selectedText}' ${fileNameExt} ${fileName} ${fileExt} ${file} ${folder} ${relativeFile} ${relativeFolder} ${projectFolder} ${mainProjectFolder} + placeholders.put("${file}", currentFile); + placeholders.put("${folder}", currentFolder); + placeholders.put("${relativeFile}", relativeFile); + placeholders.put("${relativeFolder}", relativeFolder); + placeholders.put("${projectFolder}", currentProjectFolder); + placeholders.put("${mainProjectFolder}", mainProjectFolder); + + JTextComponent editor = getCurrentEditor(); + int caret = (null != editor) ? editor.getCaretPosition() : -1; + StyledDocument sdocument = (null != editor && (editor.getDocument() instanceof StyledDocument)) ? (StyledDocument) editor.getDocument() + : null; + if (null != sdocument) { + + int line0 = NbDocument.findLineNumber(sdocument, caret); + int column0 = NbDocument.findLineColumn(sdocument, caret); + String selectedText = (null != editor) ? editor.getSelectedText(): ""; + placeholders.put("${line0}", "" + line0); + placeholders.put("${line}", "" + (line0 + 1)); + placeholders.put("${column0}", "" + column0); + placeholders.put("${column}", "" + (column0 + 1)); + placeholders.put("${selectedText}", null != selectedText ? selectedText : ""); + } else { + // add defaults for editor related placeholders + placeholders.put("${line0}", ""); + placeholders.put("${line}", ""); + placeholders.put("${column0}", ""); + placeholders.put("${column}", ""); + placeholders.put("${selectedText}", ""); + } + + return placeholders; + } + + private String fillPlaceholders(String command, Map placeholders) { + //Replace all placeholders + for (Map.Entry entry : placeholders.entrySet()) { + String pattern = entry.getKey(); + String fileName = entry.getValue(); + /** + * Replacement for + *
if(command.contains("${currentFile}") && isNotBlank(currentFile)) {command=command.replace("${currentFile}", currentFile);}
+             * 
+ */ + if (command.contains(pattern) && isNotBlank(fileName)) { + command = command.replace(pattern, fileName); + } + } + return command; + } + + public String getCommandWithReplacedPlaceholders() { + final Map placeholders = createPlaceholders(); + return fillPlaceholders(_command, placeholders); + } + + private JTextComponent getCurrentEditor() { + Node[] arr = TopComponent.getRegistry().getCurrentNodes(); + if (null == arr) { + return null; + } + for (Node arr1 : arr) { +// EditorCookie ec = (EditorCookie) arr1.getCookie(EditorCookie.class); + EditorCookie ec = (EditorCookie) arr1.getLookup().lookup(EditorCookie.class); + if (ec != null) { + JEditorPane[] panes = ec.getOpenedPanes(); + if (panes != null && panes.length > 0) { + return panes[0]; + } + } + } + return null; + } + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomCommandPopupAction.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomCommandPopupAction.java index 901d983..defb6db 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomCommandPopupAction.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomCommandPopupAction.java @@ -1,49 +1,50 @@ -package me.dsnet.quickopener.actions.popup; - -import java.awt.Dimension; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import javax.swing.AbstractAction; -import javax.swing.Icon; -import org.openide.util.NbBundle; - -/** - * - * @author SessonaD - */ -@NbBundle.Messages("CTL_CustomCommandPopupAction=Launch custom command...") -public class CustomCommandPopupAction extends AbstractAction implements ActionListener { - - public CustomCommandPopupAction() { - } - - public CustomCommandPopupAction(String name) { - super(name); - } - - public CustomCommandPopupAction(String name, Icon icon) { - super(name, icon); - } - - @Override - public void actionPerformed(ActionEvent e) { - - java.awt.EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - try { - DialogCustomCommandRun dialogue = new DialogCustomCommandRun(null, true); - final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - final int x = (screenSize.width - dialogue.getWidth()) / 2; - final int y = (screenSize.height - dialogue.getHeight()) / 2; - dialogue.setLocation(x, y); - dialogue.setVisible(true); - - } catch (Exception ex) { - } - } - }); - } - -} +package me.dsnet.quickopener.actions.popup; + +import java.awt.Dimension; +import java.awt.HeadlessException; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.AbstractAction; +import javax.swing.Icon; +import org.openide.util.NbBundle; + +/** + * + * @author SessonaD + */ +@NbBundle.Messages("CTL_CustomCommandPopupAction=Launch custom command...") +public class CustomCommandPopupAction extends AbstractAction implements ActionListener { + + public CustomCommandPopupAction() { + } + + public CustomCommandPopupAction(String name) { + super(name); + } + + public CustomCommandPopupAction(String name, Icon icon) { + super(name, icon); + } + + @Override + public void actionPerformed(ActionEvent e) { + + java.awt.EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + try { + DialogCustomCommandRun dialogue = new DialogCustomCommandRun(null, true); + final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + final int x = (screenSize.width - dialogue.getWidth()) / 2; + final int y = (screenSize.height - dialogue.getHeight()) / 2; + dialogue.setLocation(x, y); + dialogue.setVisible(true); + + } catch (HeadlessException ex) { + } + } + }); + } + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomFileSystemPopupAction.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomFileSystemPopupAction.java index 64d9c2c..373c687 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomFileSystemPopupAction.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomFileSystemPopupAction.java @@ -8,10 +8,6 @@ import java.io.File; import javax.swing.AbstractAction; import javax.swing.Icon; -import org.openide.awt.ActionID; -import org.openide.awt.ActionReference; -import org.openide.awt.ActionReferences; -import org.openide.awt.ActionRegistration; import org.openide.util.NbBundle; /** diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomCommandRun.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomCommandRun.java index 1de9355..ca21223 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomCommandRun.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomCommandRun.java @@ -1,318 +1,316 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.actions.popup; - -import java.awt.event.ActionEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import javax.swing.*; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import me.dsnet.quickopener.actions.RunCommand; -import org.netbeans.api.options.OptionsDisplayer; -import org.openide.util.ImageUtilities; -import org.openide.util.NbBundle; - -/** - * - * @author SessonaD - */ -@NbBundle.Messages("CTL_DialogCustomCommandRunPreview=") -public class DialogCustomCommandRun extends javax.swing.JDialog { - - public static final int CHARSNUMBER = 80; - - /** - * Creates new form DialogCustomCommand - */ - public DialogCustomCommandRun(java.awt.Frame parent, boolean modal) { - super(parent, modal); - initComponents(); - reinitModel(); - jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); - jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); - jTable2.getColumnModel().getColumn(0).setMaxWidth(400); - jTable2.getColumnModel().getColumn(0).setMinWidth(100); - jTable2.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - updatePreview(); - } - - }); - jTable2.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - e.consume(); - executeSelectedCommand(); - } - } - }); - //select first command if available - updatePreview(); - - // Close the dialog when Esc is pressed - String cancelName = "cancel"; - InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); - ActionMap actionMap = getRootPane().getActionMap(); - actionMap.put(cancelName, new AbstractAction() { - - public void actionPerformed(ActionEvent e) { - doClose(); - } - }); - } - - private void executeSelectedCommand() { - String selectedCommand = getSelectedCommand(); - if (null != selectedCommand) { - boolean ok = new RunCommand(selectedCommand).actionPerformed(); - if (ok) { - doClose(); - } - } - } - - private void updatePreview() { - String command = getSelectedCommand(); - if (null != command) { - lblPreviewCommand.setText(Bundle.CTL_DialogCustomCommandRunPreview() + new RunCommand(command).getCommandWithReplacedPlaceholders()); - } else { - lblPreviewCommand.setText(Bundle.CTL_DialogCustomCommandRunPreview()); - } - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - cancelButton = new javax.swing.JButton(); - jScrollPane1 = new javax.swing.JScrollPane(); - jTable2 = new javax.swing.JTable(); - jLabel3 = new javax.swing.JLabel(); - jButton1 = new javax.swing.JButton(); - jScrollPane2 = new javax.swing.JScrollPane(); - lblPreviewCommand = new javax.swing.JTextPane(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - setTitle(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.title")); // NOI18N - setIconImage(ImageUtilities.loadImage("me/dsnet/quickopener/icons/run.png")); - addWindowListener(new java.awt.event.WindowAdapter() { - public void windowClosing(java.awt.event.WindowEvent evt) { - closeDialog(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.cancelButton.text")); // NOI18N - cancelButton.setFocusPainted(false); - cancelButton.setRequestFocusEnabled(false); - cancelButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cancelButtonActionPerformed(evt); - } - }); - - jTable2.setAutoCreateRowSorter(true); - jTable2.setModel(new javax.swing.table.DefaultTableModel( - new Object [][] { - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null} - }, - new String [] { - "Title 1", "Title 2", "Title 3", "Title 4" - } - ) { - boolean[] canEdit = new boolean [] { - false, false, false, false - }; - - public boolean isCellEditable(int rowIndex, int columnIndex) { - return canEdit [columnIndex]; - } - }); - jTable2.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jTable2MouseClicked(evt); - } - }); - jScrollPane1.setViewportView(jTable2); - if (jTable2.getColumnModel().getColumnCount() > 0) { - jTable2.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jTable2.columnModel.title0")); // NOI18N - jTable2.getColumnModel().getColumn(1).setHeaderValue(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jTable2.columnModel.title1")); // NOI18N - jTable2.getColumnModel().getColumn(2).setHeaderValue(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jTable2.columnModel.title2")); // NOI18N - jTable2.getColumnModel().getColumn(3).setHeaderValue(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jTable2.columnModel.title3")); // NOI18N - } - - jLabel3.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel3.setLabelFor(jTable2); - org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jLabel3.text")); // NOI18N - jLabel3.setToolTipText(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jLabel3.toolTipText")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jButton1.text")); // NOI18N - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - lblPreviewCommand.setEditable(false); - lblPreviewCommand.setBorder(null); - jScrollPane2.setViewportView(lblPreviewCommand); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane2) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, Short.MAX_VALUE)) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 667, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addComponent(jButton1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel3) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton1) - .addComponent(cancelButton)) - .addContainerGap()) - ); - - layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cancelButton, jButton1}); - - pack(); - }// //GEN-END:initComponents - - private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed - doClose(); - }//GEN-LAST:event_cancelButtonActionPerformed - - /** - * Closes the dialog - */ - private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog - doClose(); - }//GEN-LAST:event_closeDialog - - public String getSelectedCommand() { - final int thisrow = jTable2.getSelectedRow(); - if (-1 != thisrow) { - final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); - String command = (String) jTable2.getModel().getValueAt(row, 1); - return command; - } - return null; - - } - - private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked - if (evt.getClickCount() == 2) { - executeSelectedCommand(); - } - }//GEN-LAST:event_jTable2MouseClicked - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - OptionsDisplayer.getDefault().open("Advanced" + "/QuickOpener", true); - reinitModel(); - jTable2.requestFocusInWindow(); - }//GEN-LAST:event_jButton1ActionPerformed - - private void doClose() { - setVisible(false); - dispose(); - } - - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - /* - * Set the Nimbus look and feel - */ - // - /* - * If Nimbus (introduced in Java SE 6) is not available, stay with the - * default look and feel. For details see - * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html - */ - try { - for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { - if ("Nimbus".equals(info.getName())) { - javax.swing.UIManager.setLookAndFeel(info.getClassName()); - break; - } - } - } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(DialogCustomCommandRun.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(DialogCustomCommandRun.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(DialogCustomCommandRun.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(DialogCustomCommandRun.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - // - - /* - * Create and display the dialog - */ - java.awt.EventQueue.invokeLater(new Runnable() { - - public void run() { - DialogCustomCommandRun dialog = new DialogCustomCommandRun(new javax.swing.JFrame(), true); - dialog.addWindowListener(new java.awt.event.WindowAdapter() { - - @Override - public void windowClosing(java.awt.event.WindowEvent e) { - System.exit(0); - } - }); - dialog.setVisible(true); - } - }); - } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton cancelButton; - private javax.swing.JButton jButton1; - private javax.swing.JLabel jLabel3; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JScrollPane jScrollPane2; - private javax.swing.JTable jTable2; - private javax.swing.JTextPane lblPreviewCommand; - // End of variables declaration//GEN-END:variables - - private void reinitModel() { - jTable2.setModel(new PropertyTableModel("command")); - - //select first command if available - if (jTable2.getModel().getRowCount() >= 1) { - jTable2.changeSelection(0, 0, false, false); - } - } -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener.actions.popup; + +import java.awt.event.ActionEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import me.dsnet.quickopener.actions.RunCommand; +import org.netbeans.api.options.OptionsDisplayer; +import org.openide.util.ImageUtilities; +import org.openide.util.NbBundle; + +/** + * + * @author SessonaD + */ +@NbBundle.Messages("CTL_DialogCustomCommandRunPreview=") +public class DialogCustomCommandRun extends javax.swing.JDialog { + + public static final int CHARSNUMBER = 80; + + /** + * Creates new form DialogCustomCommand + */ + public DialogCustomCommandRun(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + reinitModel(); + jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); + jTable2.getColumnModel().getColumn(0).setMaxWidth(400); + jTable2.getColumnModel().getColumn(0).setMinWidth(100); + jTable2.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + updatePreview(); + } + + }); + jTable2.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + e.consume(); + executeSelectedCommand(); + } + } + }); + //select first command if available + updatePreview(); + + // Close the dialog when Esc is pressed + String cancelName = "cancel"; + InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); + ActionMap actionMap = getRootPane().getActionMap(); + actionMap.put(cancelName, new AbstractAction() { + + @Override + public void actionPerformed(ActionEvent e) { + doClose(); + } + }); + } + + private void executeSelectedCommand() { + String selectedCommand = getSelectedCommand(); + if (null != selectedCommand) { + boolean ok = new RunCommand(selectedCommand).actionPerformed(); + if (ok) { + doClose(); + } + } + } + + private void updatePreview() { + String command = getSelectedCommand(); + if (null != command) { + lblPreviewCommand.setText(Bundle.CTL_DialogCustomCommandRunPreview() + new RunCommand(command).getCommandWithReplacedPlaceholders()); + } else { + lblPreviewCommand.setText(Bundle.CTL_DialogCustomCommandRunPreview()); + } + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + cancelButton = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTable2 = new javax.swing.JTable(); + jLabel3 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + jScrollPane2 = new javax.swing.JScrollPane(); + lblPreviewCommand = new javax.swing.JTextPane(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.title")); // NOI18N + setIconImage(ImageUtilities.loadImage("me/dsnet/quickopener/icons/run.png")); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + closeDialog(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.cancelButton.text")); // NOI18N + cancelButton.setFocusPainted(false); + cancelButton.setRequestFocusEnabled(false); + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + + jTable2.setAutoCreateRowSorter(true); + jTable2.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null} + }, + new String [] { + "Title 1", "Title 2", "Title 3", "Title 4" + } + ) { + boolean[] canEdit = new boolean [] { + false, false, false, false + }; + + public boolean isCellEditable(int rowIndex, int columnIndex) { + return canEdit [columnIndex]; + } + }); + jTable2.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jTable2MouseClicked(evt); + } + }); + jScrollPane1.setViewportView(jTable2); + if (jTable2.getColumnModel().getColumnCount() > 0) { + jTable2.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jTable2.columnModel.title0")); // NOI18N + jTable2.getColumnModel().getColumn(1).setHeaderValue(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jTable2.columnModel.title1")); // NOI18N + jTable2.getColumnModel().getColumn(2).setHeaderValue(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jTable2.columnModel.title2")); // NOI18N + jTable2.getColumnModel().getColumn(3).setHeaderValue(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jTable2.columnModel.title3")); // NOI18N + } + + jLabel3.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel3.setLabelFor(jTable2); + org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jLabel3.text")); // NOI18N + jLabel3.setToolTipText(org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jLabel3.toolTipText")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(DialogCustomCommandRun.class, "DialogCustomCommandRun.jButton1.text")); // NOI18N + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + lblPreviewCommand.setEditable(false); + lblPreviewCommand.setBorder(null); + jScrollPane2.setViewportView(lblPreviewCommand); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane2) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE)) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 667, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(jButton1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(cancelButton)) + .addContainerGap()) + ); + + layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cancelButton, jButton1}); + + pack(); + }// //GEN-END:initComponents + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + doClose(); + }//GEN-LAST:event_cancelButtonActionPerformed + + /** + * Closes the dialog + */ + private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog + doClose(); + }//GEN-LAST:event_closeDialog + + public String getSelectedCommand() { + final int thisrow = jTable2.getSelectedRow(); + if (-1 != thisrow) { + final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); + String command = (String) jTable2.getModel().getValueAt(row, 1); + return command; + } + return null; + + } + + private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked + if (evt.getClickCount() == 2) { + executeSelectedCommand(); + } + }//GEN-LAST:event_jTable2MouseClicked + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + OptionsDisplayer.getDefault().open("Advanced" + "/QuickOpener", true); + reinitModel(); + jTable2.requestFocusInWindow(); + }//GEN-LAST:event_jButton1ActionPerformed + + private void doClose() { + setVisible(false); + dispose(); + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* + * Set the Nimbus look and feel + */ + // + /* + * If Nimbus (introduced in Java SE 6) is not available, stay with the + * default look and feel. For details see + * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(DialogCustomCommandRun.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + // + + /* + * Create and display the dialog + */ + java.awt.EventQueue.invokeLater(new Runnable() { + + @Override + public void run() { + DialogCustomCommandRun dialog = new DialogCustomCommandRun(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton cancelButton; + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel3; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTable jTable2; + private javax.swing.JTextPane lblPreviewCommand; + // End of variables declaration//GEN-END:variables + + private void reinitModel() { + jTable2.setModel(new PropertyTableModel("command")); + + //select first command if available + if (jTable2.getModel().getRowCount() >= 1) { + jTable2.changeSelection(0, 0, false, false); + } + } +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomFileSystem.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomFileSystem.java index 1b12c80..0a50d14 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomFileSystem.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomFileSystem.java @@ -1,465 +1,466 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.actions.popup; - -import me.dsnet.quickopener.PathFinder; -import me.dsnet.quickopener.QuickMessages; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.io.File; -import java.text.MessageFormat; -import javax.swing.*; -import static me.dsnet.quickopener.LAFUtils.convertToLink; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.ImageUtilities; - -/** - * - * @author SessonaD - */ -public class DialogCustomFileSystem extends javax.swing.JDialog { - - public static final int RET_CANCEL = 0; - public static final int RET_OK = 1; - public static final int CHARSNUMBER = 80; - private String selectioPath; - private String mynetbeansPath; - private String mainProjectPath; - - /** - * Creates new form DialogCustomCommand - */ - public DialogCustomFileSystem(java.awt.Frame parent, boolean modal) { - super(parent, modal); - initComponents(); - jTable2.setModel(new PropertyTableModel("folder")); - jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); - jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); - jTable2.getColumnModel().getColumn(0).setMaxWidth(400); - jTable2.getColumnModel().getColumn(0).setMinWidth(100); - - mainProjectPath=PathFinder.getMainProjectRootPath(); - if(mainProjectPath!=null){ - jLabel8.setEnabled(true); - jLabel8.setText(convertToLink(getPathLongerThan(mainProjectPath))); - } - selectioPath=PathFinder.getActivePath(null,true); - if(selectioPath!=null){ - jLabel9.setEnabled(true); - jLabel9.setText(convertToLink(getPathLongerThan(selectioPath))); - } - mynetbeansPath=PathFinder.getMyNetbeansConfPath(); - if(mynetbeansPath!=null){ - jLabel7.setEnabled(true); - jLabel7.setText(convertToLink(getPathLongerThan(mynetbeansPath))); - } - // Close the dialog when Esc is pressed - String cancelName = "cancel"; - InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); - ActionMap actionMap = getRootPane().getActionMap(); - actionMap.put(cancelName, new AbstractAction() { - - public void actionPerformed(ActionEvent e) { - doClose(RET_CANCEL); - } - }); - } - - private String getPathLongerThan(String path){ - if(path.length()>=CHARSNUMBER){ - String intpath = path.substring(path.length()-CHARSNUMBER); - int idx = intpath.indexOf("\\"); - if(idx!=-1){ - return "..." + intpath.substring(idx); - } - int adx = intpath.indexOf("/"); - if(adx!=-1){ - return "..." + intpath.substring(adx); - } - return "..." + intpath; - }else{ - return path; - } - } - - public String getCommand(){ - return cmdTextField.getText(); - } - - /** - * @return the return status of this dialog - one of RET_OK or RET_CANCEL - */ - public int getReturnStatus() { - return returnStatus; - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - bindingGroup = new org.jdesktop.beansbinding.BindingGroup(); - - fileChooser = new javax.swing.JFileChooser(); - okButton = new javax.swing.JButton(); - cancelButton = new javax.swing.JButton(); - cmdTextField = new javax.swing.JTextField(); - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - jScrollPane1 = new javax.swing.JScrollPane(); - jTable2 = new javax.swing.JTable(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - jLabel5 = new javax.swing.JLabel(); - jLabel6 = new javax.swing.JLabel(); - jLabel7 = new javax.swing.JLabel(); - jLabel8 = new javax.swing.JLabel(); - jLabel9 = new javax.swing.JLabel(); - jLabel10 = new javax.swing.JLabel(); - browseButton = new javax.swing.JButton(); - - setTitle(org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.title")); // NOI18N - setIconImage(ImageUtilities.loadImage("me/dsnet/quickopener/icons/folder-documents-icon-cu.png")); - addWindowListener(new java.awt.event.WindowAdapter() { - public void windowClosing(java.awt.event.WindowEvent evt) { - closeDialog(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.okButton.text")); // NOI18N - - org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cmdTextField, org.jdesktop.beansbinding.ELProperty.create("${not empty text}"), okButton, org.jdesktop.beansbinding.BeanProperty.create("enabled")); - bindingGroup.addBinding(binding); - - okButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - okButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.cancelButton.text")); // NOI18N - cancelButton.setRequestFocusEnabled(false); - cancelButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cancelButtonActionPerformed(evt); - } - }); - - cmdTextField.setText(org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.cmdTextField.text")); // NOI18N - - jLabel1.setLabelFor(cmdTextField); - org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel1.text")); // NOI18N - jLabel1.setRequestFocusEnabled(false); - - jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/folder-documents-icon48-cu.png"))); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel2.text")); // NOI18N - - jTable2.setAutoCreateRowSorter(true); - jTable2.setModel(new javax.swing.table.DefaultTableModel( - new Object [][] { - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null} - }, - new String [] { - "Title 1", "Title 2", "Title 3", "Title 4" - } - )); - jTable2.setFillsViewportHeight(true); - jTable2.setFocusable(false); - jTable2.setRequestFocusEnabled(false); - jTable2.setShowVerticalLines(false); - jTable2.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jTable2MouseClicked(evt); - } - }); - jScrollPane1.setViewportView(jTable2); - - jLabel3.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel3.setLabelFor(jTable2); - org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel3.text")); // NOI18N - - jLabel4.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel4.setLabelFor(jLabel9); - org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel4.text")); // NOI18N - - jLabel5.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel5.setLabelFor(jLabel8); - org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel5.text")); // NOI18N - - jLabel6.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel6.setLabelFor(jLabel7); - org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel6.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel7.text")); // NOI18N - jLabel7.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jLabel7MouseClicked(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(jLabel8, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel8.text")); // NOI18N - jLabel8.setEnabled(false); - jLabel8.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jLabel8MouseClicked(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(jLabel9, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel9.text")); // NOI18N - jLabel9.setEnabled(false); - jLabel9.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jLabel9MouseClicked(evt); - } - }); - - jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/help.png"))); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(jLabel10, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel10.text")); // NOI18N - jLabel10.setToolTipText(org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel10.toolTipText")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.browseButton.text")); // NOI18N - browseButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - browseButtonActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel5) - .addComponent(jLabel4) - .addComponent(jLabel6)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGroup(layout.createSequentialGroup() - .addGap(37, 37, 37) - .addComponent(jLabel2) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(cmdTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(browseButton)) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, Short.MAX_VALUE)))) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(okButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel10))))) - .addContainerGap()) - ); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton}); - - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(cmdTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(browseButton))) - .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(jLabel4) - .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(jLabel5) - .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(jLabel6) - .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(23, 23, 23) - .addComponent(jLabel3) - .addGap(7, 7, 7) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE) - .addGap(8, 8, 8) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(okButton) - .addComponent(cancelButton) - .addComponent(jLabel10)) - .addContainerGap()) - ); - - getRootPane().setDefaultButton(okButton); - jLabel10.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel10.AccessibleContext.accessibleDescription")); // NOI18N - - bindingGroup.bind(); - - pack(); - }// //GEN-END:initComponents - - private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed - File file= new File(cmdTextField.getText()); - if(file.exists()&& file.isDirectory()){ - doClose(RET_OK); - }else{ - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NOT_IN_FILE_SYSTEM,NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - } - - }//GEN-LAST:event_okButtonActionPerformed - - private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed - doClose(RET_CANCEL); - }//GEN-LAST:event_cancelButtonActionPerformed - - /** - * Closes the dialog - */ - private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog - doClose(RET_CANCEL); - }//GEN-LAST:event_closeDialog - - private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked - if (evt.getClickCount() == 1) { - final int thisrow = jTable2.getSelectedRow(); - if (-1 != thisrow) { - final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); - String path = (String) jTable2.getModel().getValueAt(row, 1); - cmdTextField.setText(path); - } - } - }//GEN-LAST:event_jTable2MouseClicked - - private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked - if(jLabel7.isEnabled()){ - cmdTextField.setText(mynetbeansPath); - } - }//GEN-LAST:event_jLabel7MouseClicked - - private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel8MouseClicked - if(jLabel8.isEnabled()){ - cmdTextField.setText(mainProjectPath); - } - }//GEN-LAST:event_jLabel8MouseClicked - - private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked - if(jLabel9.isEnabled()){ - cmdTextField.setText(selectioPath); - } - }//GEN-LAST:event_jLabel9MouseClicked - - private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed - fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - int returnVal = fileChooser.showOpenDialog(this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fileChooser.getSelectedFile(); - if(file!=null){ - cmdTextField.setText(file.getAbsolutePath()); - } - } - }//GEN-LAST:event_browseButtonActionPerformed - - private void doClose(int retStatus) { - returnStatus = retStatus; - setVisible(false); - dispose(); - } - - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - /* - * Set the Nimbus look and feel - */ - // - /* - * If Nimbus (introduced in Java SE 6) is not available, stay with the - * default look and feel. For details see - * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html - */ - try { - for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { - if ("Nimbus".equals(info.getName())) { - javax.swing.UIManager.setLookAndFeel(info.getClassName()); - break; - } - } - } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(DialogCustomFileSystem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(DialogCustomFileSystem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(DialogCustomFileSystem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(DialogCustomFileSystem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - // - - /* - * Create and display the dialog - */ - java.awt.EventQueue.invokeLater(new Runnable() { - - public void run() { - DialogCustomFileSystem dialog = new DialogCustomFileSystem(new javax.swing.JFrame(), true); - dialog.addWindowListener(new java.awt.event.WindowAdapter() { - - @Override - public void windowClosing(java.awt.event.WindowEvent e) { - System.exit(0); - } - }); - dialog.setVisible(true); - } - }); - } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton browseButton; - private javax.swing.JButton cancelButton; - private javax.swing.JTextField cmdTextField; - private javax.swing.JFileChooser fileChooser; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel10; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JLabel jLabel6; - private javax.swing.JLabel jLabel7; - private javax.swing.JLabel jLabel8; - private javax.swing.JLabel jLabel9; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTable jTable2; - private javax.swing.JButton okButton; - private org.jdesktop.beansbinding.BindingGroup bindingGroup; - // End of variables declaration//GEN-END:variables - private int returnStatus = RET_CANCEL; -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener.actions.popup; + +import me.dsnet.quickopener.PathFinder; +import me.dsnet.quickopener.QuickMessages; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.io.File; +import java.text.MessageFormat; +import javax.swing.*; +import static me.dsnet.quickopener.LAFUtils.convertToLink; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.ImageUtilities; + +/** + * + * @author SessonaD + */ +public class DialogCustomFileSystem extends javax.swing.JDialog { + + public static final int RET_CANCEL = 0; + public static final int RET_OK = 1; + public static final int CHARSNUMBER = 80; + private String selectioPath; + private String mynetbeansPath; + private String mainProjectPath; + + /** + * Creates new form DialogCustomCommand + */ + public DialogCustomFileSystem(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + jTable2.setModel(new PropertyTableModel("folder")); + jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); + jTable2.getColumnModel().getColumn(0).setMaxWidth(400); + jTable2.getColumnModel().getColumn(0).setMinWidth(100); + + mainProjectPath=PathFinder.getMainProjectRootPath(); + if(mainProjectPath!=null){ + jLabel8.setEnabled(true); + jLabel8.setText(convertToLink(getPathLongerThan(mainProjectPath))); + } + selectioPath=PathFinder.getActivePath(null,true); + if(selectioPath!=null){ + jLabel9.setEnabled(true); + jLabel9.setText(convertToLink(getPathLongerThan(selectioPath))); + } + mynetbeansPath=PathFinder.getMyNetbeansConfPath(); + if(mynetbeansPath!=null){ + jLabel7.setEnabled(true); + jLabel7.setText(convertToLink(getPathLongerThan(mynetbeansPath))); + } + // Close the dialog when Esc is pressed + String cancelName = "cancel"; + InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); + ActionMap actionMap = getRootPane().getActionMap(); + actionMap.put(cancelName, new AbstractAction() { + + @Override + public void actionPerformed(ActionEvent e) { + doClose(RET_CANCEL); + } + }); + } + + private String getPathLongerThan(String path){ + if(path.length()>=CHARSNUMBER){ + String intpath = path.substring(path.length()-CHARSNUMBER); + int idx = intpath.indexOf("\\"); + if(idx!=-1){ + return "..." + intpath.substring(idx); + } + int adx = intpath.indexOf("/"); + if(adx!=-1){ + return "..." + intpath.substring(adx); + } + return "..." + intpath; + }else{ + return path; + } + } + + public String getCommand(){ + return cmdTextField.getText(); + } + + /** + * @return the return status of this dialog - one of RET_OK or RET_CANCEL + */ + public int getReturnStatus() { + return returnStatus; + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + bindingGroup = new org.jdesktop.beansbinding.BindingGroup(); + + fileChooser = new javax.swing.JFileChooser(); + okButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + cmdTextField = new javax.swing.JTextField(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTable2 = new javax.swing.JTable(); + jLabel3 = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); + jLabel5 = new javax.swing.JLabel(); + jLabel6 = new javax.swing.JLabel(); + jLabel7 = new javax.swing.JLabel(); + jLabel8 = new javax.swing.JLabel(); + jLabel9 = new javax.swing.JLabel(); + jLabel10 = new javax.swing.JLabel(); + browseButton = new javax.swing.JButton(); + + setTitle(org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.title")); // NOI18N + setIconImage(ImageUtilities.loadImage("me/dsnet/quickopener/icons/folder-documents-icon-cu.png")); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + closeDialog(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.okButton.text")); // NOI18N + + org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cmdTextField, org.jdesktop.beansbinding.ELProperty.create("${not empty text}"), okButton, org.jdesktop.beansbinding.BeanProperty.create("enabled")); + bindingGroup.addBinding(binding); + + okButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + okButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.cancelButton.text")); // NOI18N + cancelButton.setRequestFocusEnabled(false); + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + + cmdTextField.setText(org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.cmdTextField.text")); // NOI18N + + jLabel1.setLabelFor(cmdTextField); + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel1.text")); // NOI18N + jLabel1.setRequestFocusEnabled(false); + + jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/folder-documents-icon48-cu.png"))); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel2.text")); // NOI18N + + jTable2.setAutoCreateRowSorter(true); + jTable2.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null} + }, + new String [] { + "Title 1", "Title 2", "Title 3", "Title 4" + } + )); + jTable2.setFillsViewportHeight(true); + jTable2.setFocusable(false); + jTable2.setRequestFocusEnabled(false); + jTable2.setShowVerticalLines(false); + jTable2.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jTable2MouseClicked(evt); + } + }); + jScrollPane1.setViewportView(jTable2); + + jLabel3.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel3.setLabelFor(jTable2); + org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel3.text")); // NOI18N + + jLabel4.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel4.setLabelFor(jLabel9); + org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel4.text")); // NOI18N + + jLabel5.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel5.setLabelFor(jLabel8); + org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel5.text")); // NOI18N + + jLabel6.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel6.setLabelFor(jLabel7); + org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel6.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel7.text")); // NOI18N + jLabel7.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jLabel7MouseClicked(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel8, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel8.text")); // NOI18N + jLabel8.setEnabled(false); + jLabel8.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jLabel8MouseClicked(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel9, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel9.text")); // NOI18N + jLabel9.setEnabled(false); + jLabel9.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jLabel9MouseClicked(evt); + } + }); + + jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/help.png"))); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(jLabel10, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel10.text")); // NOI18N + jLabel10.setToolTipText(org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel10.toolTipText")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.browseButton.text")); // NOI18N + browseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + browseButtonActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel3) + .addComponent(jLabel5) + .addComponent(jLabel4) + .addComponent(jLabel6)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(layout.createSequentialGroup() + .addGap(37, 37, 37) + .addComponent(jLabel2) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(cmdTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(browseButton)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE)))) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(okButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel10))))) + .addContainerGap()) + ); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton}); + + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(cmdTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(browseButton))) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel4) + .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel5) + .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel6) + .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(23, 23, 23) + .addComponent(jLabel3) + .addGap(7, 7, 7) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE) + .addGap(8, 8, 8) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(okButton) + .addComponent(cancelButton) + .addComponent(jLabel10)) + .addContainerGap()) + ); + + getRootPane().setDefaultButton(okButton); + jLabel10.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(DialogCustomFileSystem.class, "DialogCustomFileSystem.jLabel10.AccessibleContext.accessibleDescription")); // NOI18N + + bindingGroup.bind(); + + pack(); + }// //GEN-END:initComponents + + private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed + File file= new File(cmdTextField.getText()); + if(file.exists()&& file.isDirectory()){ + doClose(RET_OK); + }else{ + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NOT_IN_FILE_SYSTEM,NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + } + + }//GEN-LAST:event_okButtonActionPerformed + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + doClose(RET_CANCEL); + }//GEN-LAST:event_cancelButtonActionPerformed + + /** + * Closes the dialog + */ + private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog + doClose(RET_CANCEL); + }//GEN-LAST:event_closeDialog + + private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked + if (evt.getClickCount() == 1) { + final int thisrow = jTable2.getSelectedRow(); + if (-1 != thisrow) { + final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); + String path = (String) jTable2.getModel().getValueAt(row, 1); + cmdTextField.setText(path); + } + } + }//GEN-LAST:event_jTable2MouseClicked + + private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked + if(jLabel7.isEnabled()){ + cmdTextField.setText(mynetbeansPath); + } + }//GEN-LAST:event_jLabel7MouseClicked + + private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel8MouseClicked + if(jLabel8.isEnabled()){ + cmdTextField.setText(mainProjectPath); + } + }//GEN-LAST:event_jLabel8MouseClicked + + private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked + if(jLabel9.isEnabled()){ + cmdTextField.setText(selectioPath); + } + }//GEN-LAST:event_jLabel9MouseClicked + + private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int returnVal = fileChooser.showOpenDialog(this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fileChooser.getSelectedFile(); + if(file!=null){ + cmdTextField.setText(file.getAbsolutePath()); + } + } + }//GEN-LAST:event_browseButtonActionPerformed + + private void doClose(int retStatus) { + returnStatus = retStatus; + setVisible(false); + dispose(); + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* + * Set the Nimbus look and feel + */ + // + /* + * If Nimbus (introduced in Java SE 6) is not available, stay with the + * default look and feel. For details see + * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(DialogCustomFileSystem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(DialogCustomFileSystem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(DialogCustomFileSystem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(DialogCustomFileSystem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* + * Create and display the dialog + */ + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + DialogCustomFileSystem dialog = new DialogCustomFileSystem(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton browseButton; + private javax.swing.JButton cancelButton; + private javax.swing.JTextField cmdTextField; + private javax.swing.JFileChooser fileChooser; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel10; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; + private javax.swing.JLabel jLabel7; + private javax.swing.JLabel jLabel8; + private javax.swing.JLabel jLabel9; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTable jTable2; + private javax.swing.JButton okButton; + private org.jdesktop.beansbinding.BindingGroup bindingGroup; + // End of variables declaration//GEN-END:variables + private int returnStatus = RET_CANCEL; +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomTerminal.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomTerminal.java index b559c99..dc04a82 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomTerminal.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomTerminal.java @@ -1,435 +1,432 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.actions.popup; - -import me.dsnet.quickopener.PathFinder; -import me.dsnet.quickopener.QuickMessages; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.io.File; -import javax.swing.*; -import me.dsnet.quickopener.LAFUtils; -import static me.dsnet.quickopener.LAFUtils.convertToLink; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.ImageUtilities; - -/** - * - * @author SessonaD - */ -public class DialogCustomTerminal extends javax.swing.JDialog { - - public static final int RET_CANCEL = 0; - public static final int RET_OK = 1; - public static final int CHARSNUMBER = 80; - private String selectioPath; - private String mynetbeansPath; - private String mainProjectPath; - - /** - * Creates new form DialogCustomCommand - */ - public DialogCustomTerminal(java.awt.Frame parent, boolean modal) { - super(parent, modal); - initComponents(); - jTable2.setModel(new PropertyTableModel("folder")); - jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); - jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); - jTable2.getColumnModel().getColumn(0).setMaxWidth(400); - jTable2.getColumnModel().getColumn(0).setMinWidth(100); - mainProjectPath=PathFinder.getMainProjectRootPath(); - if(mainProjectPath!=null){ - jLabel8.setEnabled(true); - jLabel8.setText(convertToLink(getPathLongerThan(mainProjectPath))); - } - selectioPath=PathFinder.getActivePath(null,true); - if(selectioPath!=null){ - jLabel9.setEnabled(true); - jLabel9.setText(convertToLink(getPathLongerThan(selectioPath))); - } - mynetbeansPath=PathFinder.getMyNetbeansConfPath(); - if(mynetbeansPath!=null){ - jLabel7.setEnabled(true); - jLabel7.setText(convertToLink(getPathLongerThan(mynetbeansPath))); - } - // Close the dialog when Esc is pressed - String cancelName = "cancel"; - InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); - ActionMap actionMap = getRootPane().getActionMap(); - actionMap.put(cancelName, new AbstractAction() { - - public void actionPerformed(ActionEvent e) { - doClose(RET_CANCEL); - } - }); - } - - private String getPathLongerThan(String path){ - if(path.length()>=CHARSNUMBER){ - String intpath = path.substring(path.length()-CHARSNUMBER); - int idx = intpath.indexOf("\\"); - if(idx!=-1){ - return "..." + intpath.substring(idx); - } - int adx = intpath.indexOf("/"); - if(adx!=-1){ - return "..." + intpath.substring(adx); - } - return "..." + intpath; - }else{ - return path; - } - } - - public String getCommand(){ - return cmdTextField.getText(); - } - - /** - * @return the return status of this dialog - one of RET_OK or RET_CANCEL - */ - public int getReturnStatus() { - return returnStatus; - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - bindingGroup = new org.jdesktop.beansbinding.BindingGroup(); - - okButton = new javax.swing.JButton(); - cancelButton = new javax.swing.JButton(); - cmdTextField = new javax.swing.JTextField(); - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - jScrollPane1 = new javax.swing.JScrollPane(); - jTable2 = new javax.swing.JTable(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - jLabel5 = new javax.swing.JLabel(); - jLabel6 = new javax.swing.JLabel(); - jLabel7 = new javax.swing.JLabel(); - jLabel8 = new javax.swing.JLabel(); - jLabel9 = new javax.swing.JLabel(); - jLabel10 = new javax.swing.JLabel(); - - setTitle(org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.title")); // NOI18N - setIconImage(ImageUtilities.loadImage("me/dsnet/quickopener/icons/terminal-cu.png")); - addWindowListener(new java.awt.event.WindowAdapter() { - public void windowClosing(java.awt.event.WindowEvent evt) { - closeDialog(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.okButton.text")); // NOI18N - - org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cmdTextField, org.jdesktop.beansbinding.ELProperty.create("${not empty text}"), okButton, org.jdesktop.beansbinding.BeanProperty.create("enabled")); - bindingGroup.addBinding(binding); - - okButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - okButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.cancelButton.text")); // NOI18N - cancelButton.setRequestFocusEnabled(false); - cancelButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cancelButtonActionPerformed(evt); - } - }); - - cmdTextField.setText(org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.cmdTextField.text")); // NOI18N - - jLabel1.setLabelFor(cmdTextField); - org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel1.text")); // NOI18N - jLabel1.setRequestFocusEnabled(false); - - jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/terminal48-cu2.png"))); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel2.text")); // NOI18N - - jTable2.setAutoCreateRowSorter(true); - jTable2.setModel(new javax.swing.table.DefaultTableModel( - new Object [][] { - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null} - }, - new String [] { - "Title 1", "Title 2", "Title 3", "Title 4" - } - )); - jTable2.setFillsViewportHeight(true); - jTable2.setFocusable(false); - jTable2.setRequestFocusEnabled(false); - jTable2.setShowVerticalLines(false); - jTable2.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jTable2MouseClicked(evt); - } - }); - jScrollPane1.setViewportView(jTable2); - - jLabel3.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel3.setLabelFor(jTable2); - org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel3.text")); // NOI18N - - jLabel4.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel4.setLabelFor(jLabel9); - org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel4.text")); // NOI18N - - jLabel5.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel5.setLabelFor(jLabel8); - org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel5.text")); // NOI18N - - jLabel6.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel6.setLabelFor(jLabel7); - org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel6.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel7.text")); // NOI18N - jLabel7.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jLabel7MouseClicked(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(jLabel8, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel8.text")); // NOI18N - jLabel8.setEnabled(false); - jLabel8.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jLabel8MouseClicked(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(jLabel9, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel9.text")); // NOI18N - jLabel9.setEnabled(false); - jLabel9.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jLabel9MouseClicked(evt); - } - }); - - jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/help.png"))); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(jLabel10, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel10.text")); // NOI18N - jLabel10.setToolTipText("Click on any path to set the input box.
\n
\nYou can customize the your preferred places in:
\nTools > Options > Miscellaneous > QuickOpener\n"); // NOI18N - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel5) - .addComponent(jLabel4) - .addComponent(jLabel6)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGroup(layout.createSequentialGroup() - .addGap(27, 27, 27) - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1) - .addComponent(cmdTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE))) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(okButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel10))))) - .addContainerGap()) - ); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton}); - - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cmdTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(jLabel4) - .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(jLabel5) - .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(jLabel6) - .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(23, 23, 23) - .addComponent(jLabel3) - .addGap(8, 8, 8) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE) - .addGap(8, 8, 8) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(okButton) - .addComponent(cancelButton) - .addComponent(jLabel10)) - .addContainerGap()) - ); - - layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cancelButton, jLabel10, okButton}); - - getRootPane().setDefaultButton(okButton); - - bindingGroup.bind(); - - pack(); - }//
//GEN-END:initComponents - - private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed - File file= new File(cmdTextField.getText()); - if(file.exists()&& file.isDirectory()){ - doClose(RET_OK); - }else{ - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NOT_IN_FILE_SYSTEM,NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - } - }//GEN-LAST:event_okButtonActionPerformed - - private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed - doClose(RET_CANCEL); - }//GEN-LAST:event_cancelButtonActionPerformed - - /** - * Closes the dialog - */ - private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog - doClose(RET_CANCEL); - }//GEN-LAST:event_closeDialog - - private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked - if (evt.getClickCount() == 1) { - final int thisrow = jTable2.getSelectedRow(); - if (-1 != thisrow) { - final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); - String path = (String) jTable2.getModel().getValueAt(row, 1); - cmdTextField.setText(path); - } - } - }//GEN-LAST:event_jTable2MouseClicked - - private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked - if(jLabel7.isEnabled()){ - cmdTextField.setText(mynetbeansPath); - } - }//GEN-LAST:event_jLabel7MouseClicked - - private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel8MouseClicked - if(jLabel8.isEnabled()){ - cmdTextField.setText(mainProjectPath); - } - }//GEN-LAST:event_jLabel8MouseClicked - - private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked - if(jLabel9.isEnabled()){ - cmdTextField.setText(selectioPath); - } - }//GEN-LAST:event_jLabel9MouseClicked - - private void doClose(int retStatus) { - returnStatus = retStatus; - setVisible(false); - dispose(); - } - - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - /* - * Set the Nimbus look and feel - */ - // - /* - * If Nimbus (introduced in Java SE 6) is not available, stay with the - * default look and feel. For details see - * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html - */ - try { - for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { - if ("Nimbus".equals(info.getName())) { - javax.swing.UIManager.setLookAndFeel(info.getClassName()); - break; - } - } - } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(DialogCustomTerminal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(DialogCustomTerminal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(DialogCustomTerminal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(DialogCustomTerminal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - // - - /* - * Create and display the dialog - */ - java.awt.EventQueue.invokeLater(new Runnable() { - - public void run() { - DialogCustomTerminal dialog = new DialogCustomTerminal(new javax.swing.JFrame(), true); - dialog.addWindowListener(new java.awt.event.WindowAdapter() { - - @Override - public void windowClosing(java.awt.event.WindowEvent e) { - System.exit(0); - } - }); - dialog.setVisible(true); - } - }); - } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton cancelButton; - private javax.swing.JTextField cmdTextField; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel10; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JLabel jLabel6; - private javax.swing.JLabel jLabel7; - private javax.swing.JLabel jLabel8; - private javax.swing.JLabel jLabel9; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTable jTable2; - private javax.swing.JButton okButton; - private org.jdesktop.beansbinding.BindingGroup bindingGroup; - // End of variables declaration//GEN-END:variables - private int returnStatus = RET_CANCEL; -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener.actions.popup; + +import me.dsnet.quickopener.PathFinder; +import me.dsnet.quickopener.QuickMessages; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.io.File; +import javax.swing.*; +import static me.dsnet.quickopener.LAFUtils.convertToLink; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.ImageUtilities; + +/** + * + * @author SessonaD + */ +public class DialogCustomTerminal extends javax.swing.JDialog { + + public static final int RET_CANCEL = 0; + public static final int RET_OK = 1; + public static final int CHARSNUMBER = 80; + private String selectioPath; + private String mynetbeansPath; + private String mainProjectPath; + + /** + * Creates new form DialogCustomCommand + */ + public DialogCustomTerminal(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + jTable2.setModel(new PropertyTableModel("folder")); + jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); + jTable2.getColumnModel().getColumn(0).setMaxWidth(400); + jTable2.getColumnModel().getColumn(0).setMinWidth(100); + mainProjectPath=PathFinder.getMainProjectRootPath(); + if(mainProjectPath!=null){ + jLabel8.setEnabled(true); + jLabel8.setText(convertToLink(getPathLongerThan(mainProjectPath))); + } + selectioPath=PathFinder.getActivePath(null,true); + if(selectioPath!=null){ + jLabel9.setEnabled(true); + jLabel9.setText(convertToLink(getPathLongerThan(selectioPath))); + } + mynetbeansPath=PathFinder.getMyNetbeansConfPath(); + if(mynetbeansPath!=null){ + jLabel7.setEnabled(true); + jLabel7.setText(convertToLink(getPathLongerThan(mynetbeansPath))); + } + // Close the dialog when Esc is pressed + String cancelName = "cancel"; + InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); + ActionMap actionMap = getRootPane().getActionMap(); + actionMap.put(cancelName, new AbstractAction() { + + @Override + public void actionPerformed(ActionEvent e) { + doClose(RET_CANCEL); + } + }); + } + + private String getPathLongerThan(String path){ + if(path.length()>=CHARSNUMBER){ + String intpath = path.substring(path.length()-CHARSNUMBER); + int idx = intpath.indexOf("\\"); + if(idx!=-1){ + return "..." + intpath.substring(idx); + } + int adx = intpath.indexOf("/"); + if(adx!=-1){ + return "..." + intpath.substring(adx); + } + return "..." + intpath; + }else{ + return path; + } + } + + public String getCommand(){ + return cmdTextField.getText(); + } + + /** + * @return the return status of this dialog - one of RET_OK or RET_CANCEL + */ + public int getReturnStatus() { + return returnStatus; + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + bindingGroup = new org.jdesktop.beansbinding.BindingGroup(); + + okButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + cmdTextField = new javax.swing.JTextField(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTable2 = new javax.swing.JTable(); + jLabel3 = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); + jLabel5 = new javax.swing.JLabel(); + jLabel6 = new javax.swing.JLabel(); + jLabel7 = new javax.swing.JLabel(); + jLabel8 = new javax.swing.JLabel(); + jLabel9 = new javax.swing.JLabel(); + jLabel10 = new javax.swing.JLabel(); + + setTitle(org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.title")); // NOI18N + setIconImage(ImageUtilities.loadImage("me/dsnet/quickopener/icons/terminal-cu.png")); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + closeDialog(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.okButton.text")); // NOI18N + + org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cmdTextField, org.jdesktop.beansbinding.ELProperty.create("${not empty text}"), okButton, org.jdesktop.beansbinding.BeanProperty.create("enabled")); + bindingGroup.addBinding(binding); + + okButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + okButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.cancelButton.text")); // NOI18N + cancelButton.setRequestFocusEnabled(false); + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + + cmdTextField.setText(org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.cmdTextField.text")); // NOI18N + + jLabel1.setLabelFor(cmdTextField); + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel1.text")); // NOI18N + jLabel1.setRequestFocusEnabled(false); + + jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/terminal48-cu2.png"))); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel2.text")); // NOI18N + + jTable2.setAutoCreateRowSorter(true); + jTable2.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null} + }, + new String [] { + "Title 1", "Title 2", "Title 3", "Title 4" + } + )); + jTable2.setFillsViewportHeight(true); + jTable2.setFocusable(false); + jTable2.setRequestFocusEnabled(false); + jTable2.setShowVerticalLines(false); + jTable2.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jTable2MouseClicked(evt); + } + }); + jScrollPane1.setViewportView(jTable2); + + jLabel3.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel3.setLabelFor(jTable2); + org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel3.text")); // NOI18N + + jLabel4.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel4.setLabelFor(jLabel9); + org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel4.text")); // NOI18N + + jLabel5.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel5.setLabelFor(jLabel8); + org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel5.text")); // NOI18N + + jLabel6.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel6.setLabelFor(jLabel7); + org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel6.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel7.text")); // NOI18N + jLabel7.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jLabel7MouseClicked(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel8, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel8.text")); // NOI18N + jLabel8.setEnabled(false); + jLabel8.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jLabel8MouseClicked(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel9, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel9.text")); // NOI18N + jLabel9.setEnabled(false); + jLabel9.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jLabel9MouseClicked(evt); + } + }); + + jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/help.png"))); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(jLabel10, org.openide.util.NbBundle.getMessage(DialogCustomTerminal.class, "DialogCustomTerminal.jLabel10.text")); // NOI18N + jLabel10.setToolTipText("Click on any path to set the input box.
\n
\nYou can customize the your preferred places in:
\nTools > Options > Miscellaneous > QuickOpener\n"); // NOI18N + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel3) + .addComponent(jLabel5) + .addComponent(jLabel4) + .addComponent(jLabel6)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(layout.createSequentialGroup() + .addGap(27, 27, 27) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1) + .addComponent(cmdTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE))) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(okButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel10))))) + .addContainerGap()) + ); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton}); + + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cmdTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel4) + .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel5) + .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel6) + .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(23, 23, 23) + .addComponent(jLabel3) + .addGap(8, 8, 8) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE) + .addGap(8, 8, 8) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(okButton) + .addComponent(cancelButton) + .addComponent(jLabel10)) + .addContainerGap()) + ); + + layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cancelButton, jLabel10, okButton}); + + getRootPane().setDefaultButton(okButton); + + bindingGroup.bind(); + + pack(); + }//
//GEN-END:initComponents + + private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed + File file= new File(cmdTextField.getText()); + if(file.exists()&& file.isDirectory()){ + doClose(RET_OK); + }else{ + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NOT_IN_FILE_SYSTEM,NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + } + }//GEN-LAST:event_okButtonActionPerformed + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + doClose(RET_CANCEL); + }//GEN-LAST:event_cancelButtonActionPerformed + + /** + * Closes the dialog + */ + private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog + doClose(RET_CANCEL); + }//GEN-LAST:event_closeDialog + + private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked + if (evt.getClickCount() == 1) { + final int thisrow = jTable2.getSelectedRow(); + if (-1 != thisrow) { + final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); + String path = (String) jTable2.getModel().getValueAt(row, 1); + cmdTextField.setText(path); + } + } + }//GEN-LAST:event_jTable2MouseClicked + + private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked + if(jLabel7.isEnabled()){ + cmdTextField.setText(mynetbeansPath); + } + }//GEN-LAST:event_jLabel7MouseClicked + + private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel8MouseClicked + if(jLabel8.isEnabled()){ + cmdTextField.setText(mainProjectPath); + } + }//GEN-LAST:event_jLabel8MouseClicked + + private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked + if(jLabel9.isEnabled()){ + cmdTextField.setText(selectioPath); + } + }//GEN-LAST:event_jLabel9MouseClicked + + private void doClose(int retStatus) { + returnStatus = retStatus; + setVisible(false); + dispose(); + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* + * Set the Nimbus look and feel + */ + // + /* + * If Nimbus (introduced in Java SE 6) is not available, stay with the + * default look and feel. For details see + * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(DialogCustomTerminal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + // + + /* + * Create and display the dialog + */ + java.awt.EventQueue.invokeLater(new Runnable() { + + @Override + public void run() { + DialogCustomTerminal dialog = new DialogCustomTerminal(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton cancelButton; + private javax.swing.JTextField cmdTextField; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel10; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; + private javax.swing.JLabel jLabel7; + private javax.swing.JLabel jLabel8; + private javax.swing.JLabel jLabel9; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTable jTable2; + private javax.swing.JButton okButton; + private org.jdesktop.beansbinding.BindingGroup bindingGroup; + // End of variables declaration//GEN-END:variables + private int returnStatus = RET_CANCEL; +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogueFileSelector.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogueFileSelector.java index 4a5b401..f7e760d 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogueFileSelector.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogueFileSelector.java @@ -1,461 +1,459 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.actions.popup; - -import me.dsnet.quickopener.PathFinder; -import me.dsnet.quickopener.QuickMessages; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.io.File; -import javax.swing.*; -import static me.dsnet.quickopener.LAFUtils.convertToLink; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.ImageUtilities; - -/** - * - * @author SessonaD - */ -public class DialogueFileSelector extends javax.swing.JDialog { - - public static final int RET_CANCEL = 0; - public static final int RET_OK = 1; - public static final int CHARSNUMBER = 80; - private String selectioPath; - private String mynetbeansPath; - private String mainProjectPath; - - /** - * Creates new form DialogCustomCommand - */ - public DialogueFileSelector(java.awt.Frame parent, boolean modal) { - super(parent, modal); - initComponents(); - jTable2.setModel(new PropertyTableModel("folder")); - jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); - jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); - jTable2.getColumnModel().getColumn(0).setMaxWidth(400); - jTable2.getColumnModel().getColumn(0).setMinWidth(100); - mainProjectPath=PathFinder.getMainProjectRootPath(); - if(mainProjectPath!=null){ - jLabel8.setEnabled(true); - jLabel8.setText(convertToLink(getPathLongerThan(mainProjectPath))); - } - selectioPath=PathFinder.getActivePath(null,false); - if(selectioPath!=null){ - jLabel9.setEnabled(true); - jLabel9.setText(convertToLink(getPathLongerThan(selectioPath))); - } - mynetbeansPath=PathFinder.getMyNetbeansConfPath(); - if(mynetbeansPath!=null){ - jLabel7.setEnabled(true); - jLabel7.setText(convertToLink(getPathLongerThan(mynetbeansPath))); - } - // Close the dialog when Esc is pressed - String cancelName = "cancel"; - InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); - ActionMap actionMap = getRootPane().getActionMap(); - actionMap.put(cancelName, new AbstractAction() { - - public void actionPerformed(ActionEvent e) { - doClose(RET_CANCEL); - } - }); - } - - private String getPathLongerThan(String path){ - if(path.length()>=CHARSNUMBER){ - String intpath = path.substring(path.length()-CHARSNUMBER); - int idx = intpath.indexOf("\\"); - if(idx!=-1){ - return "..." + intpath.substring(idx); - } - int adx = intpath.indexOf("/"); - if(adx!=-1){ - return "..." + intpath.substring(adx); - } - return "..." + intpath; - }else{ - return path; - } - } - - public String getCommand(){ - return cmdTextField.getText(); - } - - /** - * @return the return status of this dialog - one of RET_OK or RET_CANCEL - */ - public int getReturnStatus() { - return returnStatus; - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - bindingGroup = new org.jdesktop.beansbinding.BindingGroup(); - - fileChooser = new javax.swing.JFileChooser(); - okButton = new javax.swing.JButton(); - cancelButton = new javax.swing.JButton(); - cmdTextField = new javax.swing.JTextField(); - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - jScrollPane1 = new javax.swing.JScrollPane(); - jTable2 = new javax.swing.JTable(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - jLabel5 = new javax.swing.JLabel(); - jLabel6 = new javax.swing.JLabel(); - jLabel7 = new javax.swing.JLabel(); - jLabel8 = new javax.swing.JLabel(); - jLabel9 = new javax.swing.JLabel(); - jLabel10 = new javax.swing.JLabel(); - browseButton = new javax.swing.JButton(); - - setTitle(org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.title")); // NOI18N - setIconImage(ImageUtilities.loadImage("me/dsnet/quickopener/icons/folder-documents-icon.png")); - addWindowListener(new java.awt.event.WindowAdapter() { - public void windowClosing(java.awt.event.WindowEvent evt) { - closeDialog(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.okButton.text")); // NOI18N - - org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cmdTextField, org.jdesktop.beansbinding.ELProperty.create("${not empty text}"), okButton, org.jdesktop.beansbinding.BeanProperty.create("enabled")); - bindingGroup.addBinding(binding); - - okButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - okButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.cancelButton.text")); // NOI18N - cancelButton.setRequestFocusEnabled(false); - cancelButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cancelButtonActionPerformed(evt); - } - }); - - cmdTextField.setText(org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.cmdTextField.text")); // NOI18N - cmdTextField.setEnabled(false); - - jLabel1.setLabelFor(cmdTextField); - org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel1.text")); // NOI18N - jLabel1.setRequestFocusEnabled(false); - - jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/folder-documents-icon48.png"))); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel2.text")); // NOI18N - - jTable2.setAutoCreateRowSorter(true); - jTable2.setModel(new javax.swing.table.DefaultTableModel( - new Object [][] { - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null} - }, - new String [] { - "Title 1", "Title 2", "Title 3", "Title 4" - } - )); - jTable2.setFillsViewportHeight(true); - jTable2.setFocusable(false); - jTable2.setRequestFocusEnabled(false); - jTable2.setShowVerticalLines(false); - jTable2.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jTable2MouseClicked(evt); - } - }); - jScrollPane1.setViewportView(jTable2); - - jLabel3.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel3.setLabelFor(jTable2); - org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel3.text")); // NOI18N - - jLabel4.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel4.setLabelFor(jLabel9); - org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel4.text")); // NOI18N - - jLabel5.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel5.setLabelFor(jLabel8); - org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel5.text")); // NOI18N - - jLabel6.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N - jLabel6.setLabelFor(jLabel7); - org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel6.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel7.text")); // NOI18N - jLabel7.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jLabel7MouseClicked(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(jLabel8, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel8.text")); // NOI18N - jLabel8.setEnabled(false); - jLabel8.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jLabel8MouseClicked(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(jLabel9, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel9.text")); // NOI18N - jLabel9.setEnabled(false); - jLabel9.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jLabel9MouseClicked(evt); - } - }); - - jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/help.png"))); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(jLabel10, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel10.text")); // NOI18N - jLabel10.setToolTipText("Click on any path to set the input box.
\n
\nYou can customize the your preferred places in:
\nTools > Options > Miscellaneous > QuickOpener\n"); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.browseButton.text")); // NOI18N - browseButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - browseButtonActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel5) - .addComponent(jLabel4) - .addComponent(jLabel6)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGroup(layout.createSequentialGroup() - .addGap(37, 37, 37) - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGroup(layout.createSequentialGroup() - .addComponent(cmdTextField) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(browseButton)))) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(okButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel10))))) - .addContainerGap()) - ); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton}); - - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(cmdTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(browseButton))) - .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(jLabel4) - .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(jLabel5) - .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(jLabel6) - .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(23, 23, 23) - .addComponent(jLabel3) - .addGap(8, 8, 8) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE) - .addGap(8, 8, 8) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(okButton) - .addComponent(cancelButton) - .addComponent(jLabel10)) - .addContainerGap()) - ); - - getRootPane().setDefaultButton(okButton); - - bindingGroup.bind(); - - pack(); - }//
//GEN-END:initComponents - - private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed - File file= new File(cmdTextField.getText()); - if(file.exists()){ - doClose(RET_OK); - }else{ - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NOT_IN_FILE_SYSTEM,NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - } - - }//GEN-LAST:event_okButtonActionPerformed - - private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed - doClose(RET_CANCEL); - }//GEN-LAST:event_cancelButtonActionPerformed - - /** - * Closes the dialog - */ - private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog - doClose(RET_CANCEL); - }//GEN-LAST:event_closeDialog - - private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked - if (evt.getClickCount() == 1) { - final int thisrow = jTable2.getSelectedRow(); - if (-1 != thisrow) { - final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); - String path = (String) jTable2.getModel().getValueAt(row, 1); - cmdTextField.setText(path); - } - } - }//GEN-LAST:event_jTable2MouseClicked - - private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked - if(jLabel7.isEnabled()){ - cmdTextField.setText(mynetbeansPath); - } - }//GEN-LAST:event_jLabel7MouseClicked - - private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel8MouseClicked - if(jLabel8.isEnabled()){ - cmdTextField.setText(mainProjectPath); - } - }//GEN-LAST:event_jLabel8MouseClicked - - private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked - if(jLabel9.isEnabled()){ - cmdTextField.setText(selectioPath); - } - }//GEN-LAST:event_jLabel9MouseClicked - - private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed - fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - int returnVal = fileChooser.showOpenDialog(this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fileChooser.getSelectedFile(); - if(file!=null){ - cmdTextField.setText(file.getAbsolutePath()); - } - } - }//GEN-LAST:event_browseButtonActionPerformed - - private void doClose(int retStatus) { - returnStatus = retStatus; - setVisible(false); - dispose(); - } - - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - /* - * Set the Nimbus look and feel - */ - // - /* - * If Nimbus (introduced in Java SE 6) is not available, stay with the - * default look and feel. For details see - * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html - */ - try { - for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { - if ("Nimbus".equals(info.getName())) { - javax.swing.UIManager.setLookAndFeel(info.getClassName()); - break; - } - } - } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(DialogueFileSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(DialogueFileSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(DialogueFileSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(DialogueFileSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - // - - /* - * Create and display the dialog - */ - java.awt.EventQueue.invokeLater(new Runnable() { - - public void run() { - DialogueFileSelector dialog = new DialogueFileSelector(new javax.swing.JFrame(), true); - dialog.addWindowListener(new java.awt.event.WindowAdapter() { - - @Override - public void windowClosing(java.awt.event.WindowEvent e) { - System.exit(0); - } - }); - dialog.setVisible(true); - } - }); - } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton browseButton; - private javax.swing.JButton cancelButton; - private javax.swing.JTextField cmdTextField; - private javax.swing.JFileChooser fileChooser; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel10; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JLabel jLabel6; - private javax.swing.JLabel jLabel7; - private javax.swing.JLabel jLabel8; - private javax.swing.JLabel jLabel9; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTable jTable2; - private javax.swing.JButton okButton; - private org.jdesktop.beansbinding.BindingGroup bindingGroup; - // End of variables declaration//GEN-END:variables - private int returnStatus = RET_CANCEL; -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener.actions.popup; + +import me.dsnet.quickopener.PathFinder; +import me.dsnet.quickopener.QuickMessages; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.io.File; +import javax.swing.*; +import static me.dsnet.quickopener.LAFUtils.convertToLink; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.ImageUtilities; + +/** + * + * @author SessonaD + */ +public class DialogueFileSelector extends javax.swing.JDialog { + + public static final int RET_CANCEL = 0; + public static final int RET_OK = 1; + public static final int CHARSNUMBER = 80; + private String selectioPath; + private String mynetbeansPath; + private String mainProjectPath; + + /** + * Creates new form DialogCustomCommand + */ + public DialogueFileSelector(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + jTable2.setModel(new PropertyTableModel("folder")); + jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); + jTable2.getColumnModel().getColumn(0).setMaxWidth(400); + jTable2.getColumnModel().getColumn(0).setMinWidth(100); + mainProjectPath=PathFinder.getMainProjectRootPath(); + if(mainProjectPath!=null){ + jLabel8.setEnabled(true); + jLabel8.setText(convertToLink(getPathLongerThan(mainProjectPath))); + } + selectioPath=PathFinder.getActivePath(null,false); + if(selectioPath!=null){ + jLabel9.setEnabled(true); + jLabel9.setText(convertToLink(getPathLongerThan(selectioPath))); + } + mynetbeansPath=PathFinder.getMyNetbeansConfPath(); + if(mynetbeansPath!=null){ + jLabel7.setEnabled(true); + jLabel7.setText(convertToLink(getPathLongerThan(mynetbeansPath))); + } + // Close the dialog when Esc is pressed + String cancelName = "cancel"; + InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); + ActionMap actionMap = getRootPane().getActionMap(); + actionMap.put(cancelName, new AbstractAction() { + + @Override + public void actionPerformed(ActionEvent e) { + doClose(RET_CANCEL); + } + }); + } + + private String getPathLongerThan(String path){ + if(path.length()>=CHARSNUMBER){ + String intpath = path.substring(path.length()-CHARSNUMBER); + int idx = intpath.indexOf("\\"); + if(idx!=-1){ + return "..." + intpath.substring(idx); + } + int adx = intpath.indexOf("/"); + if(adx!=-1){ + return "..." + intpath.substring(adx); + } + return "..." + intpath; + }else{ + return path; + } + } + + public String getCommand(){ + return cmdTextField.getText(); + } + + /** + * @return the return status of this dialog - one of RET_OK or RET_CANCEL + */ + public int getReturnStatus() { + return returnStatus; + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + bindingGroup = new org.jdesktop.beansbinding.BindingGroup(); + + fileChooser = new javax.swing.JFileChooser(); + okButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + cmdTextField = new javax.swing.JTextField(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTable2 = new javax.swing.JTable(); + jLabel3 = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); + jLabel5 = new javax.swing.JLabel(); + jLabel6 = new javax.swing.JLabel(); + jLabel7 = new javax.swing.JLabel(); + jLabel8 = new javax.swing.JLabel(); + jLabel9 = new javax.swing.JLabel(); + jLabel10 = new javax.swing.JLabel(); + browseButton = new javax.swing.JButton(); + + setTitle(org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.title")); // NOI18N + setIconImage(ImageUtilities.loadImage("me/dsnet/quickopener/icons/folder-documents-icon.png")); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + closeDialog(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.okButton.text")); // NOI18N + + org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cmdTextField, org.jdesktop.beansbinding.ELProperty.create("${not empty text}"), okButton, org.jdesktop.beansbinding.BeanProperty.create("enabled")); + bindingGroup.addBinding(binding); + + okButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + okButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.cancelButton.text")); // NOI18N + cancelButton.setRequestFocusEnabled(false); + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + + cmdTextField.setText(org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.cmdTextField.text")); // NOI18N + cmdTextField.setEnabled(false); + + jLabel1.setLabelFor(cmdTextField); + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel1.text")); // NOI18N + jLabel1.setRequestFocusEnabled(false); + + jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/folder-documents-icon48.png"))); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel2.text")); // NOI18N + + jTable2.setAutoCreateRowSorter(true); + jTable2.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null} + }, + new String [] { + "Title 1", "Title 2", "Title 3", "Title 4" + } + )); + jTable2.setFillsViewportHeight(true); + jTable2.setFocusable(false); + jTable2.setRequestFocusEnabled(false); + jTable2.setShowVerticalLines(false); + jTable2.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jTable2MouseClicked(evt); + } + }); + jScrollPane1.setViewportView(jTable2); + + jLabel3.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel3.setLabelFor(jTable2); + org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel3.text")); // NOI18N + + jLabel4.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel4.setLabelFor(jLabel9); + org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel4.text")); // NOI18N + + jLabel5.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel5.setLabelFor(jLabel8); + org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel5.text")); // NOI18N + + jLabel6.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N + jLabel6.setLabelFor(jLabel7); + org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel6.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel7.text")); // NOI18N + jLabel7.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jLabel7MouseClicked(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel8, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel8.text")); // NOI18N + jLabel8.setEnabled(false); + jLabel8.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jLabel8MouseClicked(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel9, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel9.text")); // NOI18N + jLabel9.setEnabled(false); + jLabel9.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jLabel9MouseClicked(evt); + } + }); + + jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/me/dsnet/quickopener/icons/help.png"))); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(jLabel10, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.jLabel10.text")); // NOI18N + jLabel10.setToolTipText("Click on any path to set the input box.
\n
\nYou can customize the your preferred places in:
\nTools > Options > Miscellaneous > QuickOpener\n"); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(DialogueFileSelector.class, "DialogueFileSelector.browseButton.text")); // NOI18N + browseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + browseButtonActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel3) + .addComponent(jLabel5) + .addComponent(jLabel4) + .addComponent(jLabel6)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(layout.createSequentialGroup() + .addGap(37, 37, 37) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createSequentialGroup() + .addComponent(cmdTextField) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(browseButton)))) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(okButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel10))))) + .addContainerGap()) + ); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton}); + + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(cmdTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(browseButton))) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel4) + .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel5) + .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel6) + .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(23, 23, 23) + .addComponent(jLabel3) + .addGap(8, 8, 8) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE) + .addGap(8, 8, 8) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(okButton) + .addComponent(cancelButton) + .addComponent(jLabel10)) + .addContainerGap()) + ); + + getRootPane().setDefaultButton(okButton); + + bindingGroup.bind(); + + pack(); + }//
//GEN-END:initComponents + + private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed + File file= new File(cmdTextField.getText()); + if(file.exists()){ + doClose(RET_OK); + }else{ + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NOT_IN_FILE_SYSTEM,NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + } + + }//GEN-LAST:event_okButtonActionPerformed + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + doClose(RET_CANCEL); + }//GEN-LAST:event_cancelButtonActionPerformed + + /** + * Closes the dialog + */ + private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog + doClose(RET_CANCEL); + }//GEN-LAST:event_closeDialog + + private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked + if (evt.getClickCount() == 1) { + final int thisrow = jTable2.getSelectedRow(); + if (-1 != thisrow) { + final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); + String path = (String) jTable2.getModel().getValueAt(row, 1); + cmdTextField.setText(path); + } + } + }//GEN-LAST:event_jTable2MouseClicked + + private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked + if(jLabel7.isEnabled()){ + cmdTextField.setText(mynetbeansPath); + } + }//GEN-LAST:event_jLabel7MouseClicked + + private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel8MouseClicked + if(jLabel8.isEnabled()){ + cmdTextField.setText(mainProjectPath); + } + }//GEN-LAST:event_jLabel8MouseClicked + + private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked + if(jLabel9.isEnabled()){ + cmdTextField.setText(selectioPath); + } + }//GEN-LAST:event_jLabel9MouseClicked + + private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int returnVal = fileChooser.showOpenDialog(this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fileChooser.getSelectedFile(); + if(file!=null){ + cmdTextField.setText(file.getAbsolutePath()); + } + } + }//GEN-LAST:event_browseButtonActionPerformed + + private void doClose(int retStatus) { + returnStatus = retStatus; + setVisible(false); + dispose(); + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* + * Set the Nimbus look and feel + */ + // + /* + * If Nimbus (introduced in Java SE 6) is not available, stay with the + * default look and feel. For details see + * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(DialogueFileSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + // + + /* + * Create and display the dialog + */ + java.awt.EventQueue.invokeLater(new Runnable() { + + @Override + public void run() { + DialogueFileSelector dialog = new DialogueFileSelector(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton browseButton; + private javax.swing.JButton cancelButton; + private javax.swing.JTextField cmdTextField; + private javax.swing.JFileChooser fileChooser; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel10; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; + private javax.swing.JLabel jLabel7; + private javax.swing.JLabel jLabel8; + private javax.swing.JLabel jLabel9; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTable jTable2; + private javax.swing.JButton okButton; + private org.jdesktop.beansbinding.BindingGroup bindingGroup; + // End of variables declaration//GEN-END:variables + private int returnStatus = RET_CANCEL; +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/PropertyTableModel.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/PropertyTableModel.java index 6b0b394..75f045e 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/PropertyTableModel.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/PropertyTableModel.java @@ -1,72 +1,71 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.actions.popup; - -import me.dsnet.quickopener.prefs.PrefsUtil; -import me.dsnet.quickopener.prefs.QuickOpenerProperty; -import java.util.List; -import java.util.prefs.BackingStoreException; -import javax.swing.table.AbstractTableModel; -import org.openide.util.Exceptions; - -/** - * - * @author SessonaD - */ -public class PropertyTableModel extends AbstractTableModel { - - String[] columnNames = {"Name", "Path"}; - Object[][] data = null; - - public PropertyTableModel(String prefix) { - setColumnNames(prefix); - try { - List prefs = PrefsUtil.getAllMatching(prefix); - this.data = new Object[prefs.size()][2]; - for (int i = 0; i < prefs.size(); i++) { - QuickOpenerProperty pref = prefs.get(i); - String desc = pref.getDescription(); - String val = pref.getValue(); - this.data[i] = new String[]{desc, val}; - } - } catch (BackingStoreException ex) { - //Exceptions.printStackTrace(ex); - } - } - - private void setColumnNames(String prefix) { - if (prefix.equals("command")) { - columnNames = new String[]{"Name", "Command"}; - } else { - columnNames = new String[]{"Name", "Path"}; - } - } - - @Override - public int getColumnCount() { - return columnNames.length; - } - - @Override - public int getRowCount() { - return data.length; - } - - @Override - public String getColumnName(int col) { - return columnNames[col]; - } - - @Override - public Object getValueAt(int row, int col) { - return data[row][col]; - } - - @Override - public Class getColumnClass(int c) { - return String.class; - } - -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener.actions.popup; + +import me.dsnet.quickopener.prefs.PrefsUtil; +import me.dsnet.quickopener.prefs.QuickOpenerProperty; +import java.util.List; +import java.util.prefs.BackingStoreException; +import javax.swing.table.AbstractTableModel; + +/** + * + * @author SessonaD + */ +public class PropertyTableModel extends AbstractTableModel { + + String[] columnNames = {"Name", "Path"}; + Object[][] data = null; + + public PropertyTableModel(String prefix) { + setColumnNames(prefix); + try { + List prefs = PrefsUtil.getAllMatching(prefix); + this.data = new Object[prefs.size()][2]; + for (int i = 0; i < prefs.size(); i++) { + QuickOpenerProperty pref = prefs.get(i); + String desc = pref.getDescription(); + String val = pref.getValue(); + this.data[i] = new String[]{desc, val}; + } + } catch (BackingStoreException ex) { + //Exceptions.printStackTrace(ex); + } + } + + private void setColumnNames(String prefix) { + if (prefix.equals("command")) { + columnNames = new String[]{"Name", "Command"}; + } else { + columnNames = new String[]{"Name", "Path"}; + } + } + + @Override + public int getColumnCount() { + return columnNames.length; + } + + @Override + public int getRowCount() { + return data.length; + } + + @Override + public String getColumnName(int col) { + return columnNames[col]; + } + + @Override + public Object getValueAt(int row, int col) { + return data[row][col]; + } + + @Override + public Class getColumnClass(int c) { + return String.class; + } + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/CommandsPanel.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/CommandsPanel.java index 2cf8010..917ee67 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/CommandsPanel.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/CommandsPanel.java @@ -1,273 +1,271 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.prefs; - -import com.sessonad.oscommands.commands.Commands; -import me.dsnet.quickopener.QuickMessages; -import me.dsnet.quickopener.actions.popup.PropertyTableModel; -import java.util.List; -import java.util.prefs.BackingStoreException; -import javax.swing.JTable; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.Exceptions; -import org.openide.util.HelpCtx; - -/** - * - * @author SessonaD - */ -public class CommandsPanel extends javax.swing.JPanel { - - private final String cmdos = Commands.getPlatform().getOperatingSystem().getShellPrefix(); - - /** - * Creates new form CommandsPanel - */ - public CommandsPanel() { - super(); - initComponents(); - jTable2.setModel(new PropertyTableModel("command")); - jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); - jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); - jTable2.getColumnModel().getColumn(0).setMaxWidth(400); - jTable2.getColumnModel().getColumn(0).setMinWidth(100); - jLabel5.setText("(for your OS is: \'" + cmdos + "\')"); - - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jPanel1 = new javax.swing.JPanel(); - jLabel1 = new javax.swing.JLabel(); - cmdvalue = new javax.swing.JTextField(); - cmddescription = new javax.swing.JTextField(); - jButton1 = new javax.swing.JButton(); - jLabel4 = new javax.swing.JLabel(); - jButton2 = new javax.swing.JButton(); - jCheckBox1 = new javax.swing.JCheckBox(); - jLabel5 = new javax.swing.JLabel(); - jScrollPane1 = new javax.swing.JScrollPane(); - jTable2 = new javax.swing.JTable(); - btnPlaceholders = new javax.swing.JButton(); - - jLabel1.setLabelFor(cmddescription); - org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jLabel1.text")); // NOI18N - - cmdvalue.setText(org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.cmdvalue.text")); // NOI18N - - cmddescription.setText(org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.cmddescription.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jButton1.text")); // NOI18N - jButton1.setToolTipText(org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jButton1.toolTipText")); // NOI18N - jButton1.setRequestFocusEnabled(false); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jLabel4.setLabelFor(cmdvalue); - org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jLabel4.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(jButton2, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jButton2.text")); // NOI18N - jButton2.setRequestFocusEnabled(false); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jCheckBox1.text")); // NOI18N - jCheckBox1.setFocusPainted(false); - jCheckBox1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jCheckBox1ActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jLabel5.text")); // NOI18N - - jTable2.setAutoCreateRowSorter(true); - jTable2.setModel(new javax.swing.table.DefaultTableModel( - new Object [][] { - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null} - }, - new String [] { - "Title 1", "Title 2", "Title 3", "Title 4" - } - )); - jTable2.setFillsViewportHeight(true); - jTable2.setFocusable(false); - jTable2.setRequestFocusEnabled(false); - jTable2.setShowVerticalLines(false); - jTable2.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jTable2MouseClicked(evt); - } - }); - jScrollPane1.setViewportView(jTable2); - - org.openide.awt.Mnemonics.setLocalizedText(btnPlaceholders, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.btnPlaceholders.text")); // NOI18N - btnPlaceholders.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnPlaceholdersActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGap(74, 74, 74) - .addComponent(jCheckBox1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cmdvalue, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btnPlaceholders, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cmddescription))) - .addContainerGap()) - ); - - jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnPlaceholders, jButton1, jButton2}); - - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(cmddescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel4) - .addComponent(cmdvalue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(btnPlaceholders)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jCheckBox1) - .addComponent(jLabel5)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(jButton1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jButton2) - .addContainerGap(78, Short.MAX_VALUE)))) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 304, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 252, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - String description = cmddescription.getText(); - description = description.replaceAll(" ", "_"); - String value = cmdvalue.getText(); - if (description.isEmpty()) { - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.DESCRIPTION_MANDATORY, NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - return; - } - PrefsUtil.store("command" + description, value); - jTable2.setModel(new PropertyTableModel("command")); - }//GEN-LAST:event_jButton1ActionPerformed - - private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - try { - PrefsUtil.remove("command" + cmddescription.getText().replaceAll(" ", "_")); - jTable2.setModel(new PropertyTableModel("command")); - } catch (BackingStoreException ex) { - // Exceptions.printStackTrace(ex); - } - - }//GEN-LAST:event_jButton2ActionPerformed - - private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed - if (cmdos == null) { - return; - } - boolean value = jCheckBox1.isSelected(); - String text = cmdvalue.getText(); - if (value && text != null && !text.startsWith(cmdos)) { - text = cmdos + text; - } else if (!value && text != null && text.startsWith(cmdos)) { - text = text.replaceAll(cmdos, ""); - } - cmdvalue.setText(text); - }//GEN-LAST:event_jCheckBox1ActionPerformed - - private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked - if (evt.getClickCount() == 1) { - final int thisrow = jTable2.getSelectedRow(); - if (-1 != thisrow) { - final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); - String description = (String) jTable2.getModel().getValueAt(row, 0); - String command = (String) jTable2.getModel().getValueAt(row, 1); - cmddescription.setText(description); - cmdvalue.setText(command); - } - } - }//GEN-LAST:event_jTable2MouseClicked - - private void btnPlaceholdersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPlaceholdersActionPerformed - new HelpCtx("me.dsnet.quickopener.placeholders").display(); - }//GEN-LAST:event_btnPlaceholdersActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btnPlaceholders; - private javax.swing.JTextField cmddescription; - private javax.swing.JTextField cmdvalue; - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JCheckBox jCheckBox1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JPanel jPanel1; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTable jTable2; - // End of variables declaration//GEN-END:variables -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener.prefs; + +import com.sessonad.oscommands.commands.Commands; +import me.dsnet.quickopener.QuickMessages; +import me.dsnet.quickopener.actions.popup.PropertyTableModel; +import java.util.prefs.BackingStoreException; +import javax.swing.JTable; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.HelpCtx; + +/** + * + * @author SessonaD + */ +public class CommandsPanel extends javax.swing.JPanel { + + private final String cmdos = Commands.getPlatform().getOperatingSystem().getShellPrefix(); + + /** + * Creates new form CommandsPanel + */ + public CommandsPanel() { + super(); + initComponents(); + jTable2.setModel(new PropertyTableModel("command")); + jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); + jTable2.getColumnModel().getColumn(0).setMaxWidth(400); + jTable2.getColumnModel().getColumn(0).setMinWidth(100); + jLabel5.setText("(for your OS is: \'" + cmdos + "\')"); + + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jPanel1 = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + cmdvalue = new javax.swing.JTextField(); + cmddescription = new javax.swing.JTextField(); + jButton1 = new javax.swing.JButton(); + jLabel4 = new javax.swing.JLabel(); + jButton2 = new javax.swing.JButton(); + jCheckBox1 = new javax.swing.JCheckBox(); + jLabel5 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTable2 = new javax.swing.JTable(); + btnPlaceholders = new javax.swing.JButton(); + + jLabel1.setLabelFor(cmddescription); + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jLabel1.text")); // NOI18N + + cmdvalue.setText(org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.cmdvalue.text")); // NOI18N + + cmddescription.setText(org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.cmddescription.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jButton1.text")); // NOI18N + jButton1.setToolTipText(org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jButton1.toolTipText")); // NOI18N + jButton1.setRequestFocusEnabled(false); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jLabel4.setLabelFor(cmdvalue); + org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jLabel4.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jButton2, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jButton2.text")); // NOI18N + jButton2.setRequestFocusEnabled(false); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jCheckBox1.text")); // NOI18N + jCheckBox1.setFocusPainted(false); + jCheckBox1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jCheckBox1ActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.jLabel5.text")); // NOI18N + + jTable2.setAutoCreateRowSorter(true); + jTable2.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null} + }, + new String [] { + "Title 1", "Title 2", "Title 3", "Title 4" + } + )); + jTable2.setFillsViewportHeight(true); + jTable2.setFocusable(false); + jTable2.setRequestFocusEnabled(false); + jTable2.setShowVerticalLines(false); + jTable2.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jTable2MouseClicked(evt); + } + }); + jScrollPane1.setViewportView(jTable2); + + org.openide.awt.Mnemonics.setLocalizedText(btnPlaceholders, org.openide.util.NbBundle.getMessage(CommandsPanel.class, "CommandsPanel.btnPlaceholders.text")); // NOI18N + btnPlaceholders.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnPlaceholdersActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(74, 74, 74) + .addComponent(jCheckBox1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cmdvalue, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnPlaceholders, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cmddescription))) + .addContainerGap()) + ); + + jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnPlaceholders, jButton1, jButton2}); + + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(cmddescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel4) + .addComponent(cmdvalue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(btnPlaceholders)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jCheckBox1) + .addComponent(jLabel5)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jButton1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton2) + .addContainerGap(78, Short.MAX_VALUE)))) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 304, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 252, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + String description = cmddescription.getText(); + description = description.replaceAll(" ", "_"); + String value = cmdvalue.getText(); + if (description.isEmpty()) { + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.DESCRIPTION_MANDATORY, NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + return; + } + PrefsUtil.store("command" + description, value); + jTable2.setModel(new PropertyTableModel("command")); + }//GEN-LAST:event_jButton1ActionPerformed + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + try { + PrefsUtil.remove("command" + cmddescription.getText().replaceAll(" ", "_")); + jTable2.setModel(new PropertyTableModel("command")); + } catch (BackingStoreException ex) { + // Exceptions.printStackTrace(ex); + } + + }//GEN-LAST:event_jButton2ActionPerformed + + private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed + if (cmdos == null) { + return; + } + boolean value = jCheckBox1.isSelected(); + String text = cmdvalue.getText(); + if (value && text != null && !text.startsWith(cmdos)) { + text = cmdos + text; + } else if (!value && text != null && text.startsWith(cmdos)) { + text = text.replaceAll(cmdos, ""); + } + cmdvalue.setText(text); + }//GEN-LAST:event_jCheckBox1ActionPerformed + + private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked + if (evt.getClickCount() == 1) { + final int thisrow = jTable2.getSelectedRow(); + if (-1 != thisrow) { + final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); + String description = (String) jTable2.getModel().getValueAt(row, 0); + String command = (String) jTable2.getModel().getValueAt(row, 1); + cmddescription.setText(description); + cmdvalue.setText(command); + } + } + }//GEN-LAST:event_jTable2MouseClicked + + private void btnPlaceholdersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPlaceholdersActionPerformed + new HelpCtx("me.dsnet.quickopener.placeholders").display(); + }//GEN-LAST:event_btnPlaceholdersActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnPlaceholders; + private javax.swing.JTextField cmddescription; + private javax.swing.JTextField cmdvalue; + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JCheckBox jCheckBox1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JPanel jPanel1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTable jTable2; + // End of variables declaration//GEN-END:variables +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.java index 7dd593f..5029050 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.java @@ -1,322 +1,322 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.prefs; - -import java.awt.BorderLayout; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JTextField; -import me.dsnet.quickopener.QuickMessages; -import me.dsnet.quickopener.prefs.shell.chooser.IShellConfigurator; -import me.dsnet.quickopener.prefs.shell.chooser.impl.GitBashConfigurator; -import org.openide.DialogDescriptor; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.NbBundle; - -/** - * - * @author SessonaD - */ -public class GeneralPanel extends javax.swing.JPanel { - - /** - * Creates new form GeneralPanel - */ - public GeneralPanel() { - initComponents(); - QuickOpenerProperty customSeparator=PrefsUtil.load(null,"generalseparator",getOSSeparator()); - jLabel2.setText(customSeparator.getValue()); - QuickOpenerProperty customShell=PrefsUtil.load(null,"customShell",null); - cShellLabel.setText((customShell.getValue()==null)?"not defined":customShell.getValue()); - QuickOpenerProperty confirmation=PrefsUtil.load(null,"confirmationDialogue","true"); - boolean isConfirmSelected = Boolean.parseBoolean(confirmation.getValue()); - confirmationCheckBox.setSelected(isConfirmSelected); - - shellConfigureButton.setEnabled(!getAvailableConfigurators().isEmpty()); - } - - private String getOSSeparator(){ - return System.getProperty("file.separator"); - } - - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - applyButton = new javax.swing.JButton(); - jTextField1 = new javax.swing.JTextField(); - jLabel5 = new javax.swing.JLabel(); - jLabel6 = new javax.swing.JLabel(); - cShellLabel = new javax.swing.JLabel(); - jLabel8 = new javax.swing.JLabel(); - applyCShellButton = new javax.swing.JButton(); - cshellTextField = new javax.swing.JTextField(); - jLabel7 = new javax.swing.JLabel(); - confirmationCheckBox = new javax.swing.JCheckBox(); - applyConfirmationButton = new javax.swing.JButton(); - shellConfigureButton = new javax.swing.JButton(); - resetButton = new javax.swing.JButton(); - - org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel3.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel4.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel1.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel2.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(applyButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.applyButton.text")); // NOI18N - applyButton.setFocusable(false); - applyButton.setRequestFocusEnabled(false); - applyButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - applyButtonActionPerformed(evt); - } - }); - - jTextField1.setText(org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jTextField1.text")); // NOI18N - - jLabel5.setLabelFor(jTextField1); - org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel5.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel6.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(cShellLabel, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.cShellLabel.text")); // NOI18N - - jLabel8.setLabelFor(cshellTextField); - org.openide.awt.Mnemonics.setLocalizedText(jLabel8, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel8.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(applyCShellButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.applyCShellButton.text")); // NOI18N - applyCShellButton.setFocusable(false); - applyCShellButton.setRequestFocusEnabled(false); - applyCShellButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - applyCShellButtonActionPerformed(evt); - } - }); - - cshellTextField.setText(org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.cshellTextField.text")); // NOI18N - - jLabel7.setLabelFor(confirmationCheckBox); - org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel7.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(confirmationCheckBox, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.confirmationCheckBox.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(applyConfirmationButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.applyConfirmationButton.text")); // NOI18N - applyConfirmationButton.setFocusable(false); - applyConfirmationButton.setRequestFocusEnabled(false); - applyConfirmationButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - applyConfirmationButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(shellConfigureButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.shellConfigureButton.text")); // NOI18N - shellConfigureButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - shellConfigureButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(resetButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.resetButton.text")); // NOI18N - resetButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - resetButtonActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel5)) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel7) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel8) - .addComponent(confirmationCheckBox, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel6) - .addGap(10, 10, 10) - .addComponent(cShellLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(cshellTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(shellConfigureButton) - .addGap(6, 6, 6)) - .addGroup(layout.createSequentialGroup() - .addComponent(jTextField1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(applyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(applyCShellButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(applyConfirmationButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(resetButton)))) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(applyButton) - .addComponent(jLabel2) - .addComponent(jLabel1) - .addComponent(jLabel5) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel6) - .addComponent(cShellLabel) - .addComponent(jLabel8) - .addComponent(applyCShellButton) - .addComponent(shellConfigureButton) - .addComponent(cshellTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(applyConfirmationButton)) - .addGroup(layout.createSequentialGroup() - .addGap(7, 7, 7) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(confirmationCheckBox) - .addComponent(jLabel7)))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE) - .addComponent(resetButton)) - ); - }// //GEN-END:initComponents - - private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed - String customSep = jTextField1.getText(); - if(customSep!=null && !customSep.isEmpty()){ - PrefsUtil.store("generalseparator" , customSep); - jLabel2.setText(customSep); - }else{ - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.SEPARATOR_NULL,NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - } - }//GEN-LAST:event_applyButtonActionPerformed - - private void applyCShellButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyCShellButtonActionPerformed - String cshell = cshellTextField.getText(); - if(cshell!=null && !cshell.isEmpty()){ - PrefsUtil.store("customShell" , cshell); - cShellLabel.setText(cshell); - }else{ - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.CUSTOM_SHELL,NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - } - }//GEN-LAST:event_applyCShellButtonActionPerformed - - private void applyConfirmationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyConfirmationButtonActionPerformed - }//GEN-LAST:event_applyConfirmationButtonActionPerformed - - private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed - PrefsUtil.removeSingleProperty("customShell"); - cShellLabel.setText("not defined"); - cshellTextField.setText("not defined"); - - confirmationCheckBox.setSelected(false); - PrefsUtil.store("confirmationDialogue", (confirmationCheckBox.isSelected()) ? "true" : "false"); - - PrefsUtil.removeSingleProperty("generalseparator"); - jLabel2.setText(getOSSeparator()); - jTextField1.setText(""); - - }//GEN-LAST:event_resetButtonActionPerformed - - @NbBundle.Messages( - {"LBL_Form_Label=Choose a configurator:", - "LBL_Dialog=Configurator",} - ) - private void shellConfigureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shellConfigureButtonActionPerformed - JTextField shellTextField = cshellTextField; - - List labels = new ArrayList(); - for (IShellConfigurator configurator : getAvailableConfigurators()) { - if (configurator.isAvailable()) { - labels.add(configurator.getLabel()); - } - } - - final JList jList = new JList(labels.toArray(new String[labels.size()])); - JPanel form = new JPanel(new BorderLayout()); - form.add(jList, BorderLayout.CENTER); - form.add(new JLabel(Bundle.LBL_Form_Label()), BorderLayout.NORTH); - jList.setSelectedIndex(0); - DialogDescriptor dd = new DialogDescriptor(form, Bundle.LBL_Dialog()); - Object result = DialogDisplayer.getDefault().notify(dd); - if (result == NotifyDescriptor.OK_OPTION) { - IShellConfigurator configurator = getAvailableConfigurators().get(jList.getSelectedIndex()); - - String configure = configurator.configure(); - if (null != configure) { - shellTextField.setText(configure); - } - } - }//GEN-LAST:event_shellConfigureButtonActionPerformed - - private List getAvailableConfigurators() { - //TODO externalize the configuration of available configurators - List allconfigurators = Arrays.asList((IShellConfigurator) new GitBashConfigurator()); - List availableConfigurators = new ArrayList(); - for (IShellConfigurator configurator : allconfigurators) { - if (configurator.isAvailable()) { - availableConfigurators.add(configurator); - } - } - return availableConfigurators; - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton applyButton; - private javax.swing.JButton applyCShellButton; - private javax.swing.JButton applyConfirmationButton; - private javax.swing.JLabel cShellLabel; - private javax.swing.JCheckBox confirmationCheckBox; - private javax.swing.JTextField cshellTextField; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JLabel jLabel6; - private javax.swing.JLabel jLabel7; - private javax.swing.JLabel jLabel8; - private javax.swing.JTextField jTextField1; - private javax.swing.JButton resetButton; - private javax.swing.JButton shellConfigureButton; - // End of variables declaration//GEN-END:variables -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener.prefs; + +import java.awt.BorderLayout; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JTextField; +import me.dsnet.quickopener.QuickMessages; +import me.dsnet.quickopener.prefs.shell.chooser.IShellConfigurator; +import me.dsnet.quickopener.prefs.shell.chooser.impl.GitBashConfigurator; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.NbBundle; + +/** + * + * @author SessonaD + */ +public class GeneralPanel extends javax.swing.JPanel { + + /** + * Creates new form GeneralPanel + */ + public GeneralPanel() { + initComponents(); + QuickOpenerProperty customSeparator=PrefsUtil.load(null,"generalseparator",getOSSeparator()); + jLabel2.setText(customSeparator.getValue()); + QuickOpenerProperty customShell=PrefsUtil.load(null,"customShell",null); + cShellLabel.setText((customShell.getValue()==null)?"not defined":customShell.getValue()); + QuickOpenerProperty confirmation=PrefsUtil.load(null,"confirmationDialogue","true"); + boolean isConfirmSelected = Boolean.parseBoolean(confirmation.getValue()); + confirmationCheckBox.setSelected(isConfirmSelected); + + shellConfigureButton.setEnabled(!getAvailableConfigurators().isEmpty()); + } + + private String getOSSeparator(){ + return System.getProperty("file.separator"); + } + + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel3 = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + applyButton = new javax.swing.JButton(); + jTextField1 = new javax.swing.JTextField(); + jLabel5 = new javax.swing.JLabel(); + jLabel6 = new javax.swing.JLabel(); + cShellLabel = new javax.swing.JLabel(); + jLabel8 = new javax.swing.JLabel(); + applyCShellButton = new javax.swing.JButton(); + cshellTextField = new javax.swing.JTextField(); + jLabel7 = new javax.swing.JLabel(); + confirmationCheckBox = new javax.swing.JCheckBox(); + applyConfirmationButton = new javax.swing.JButton(); + shellConfigureButton = new javax.swing.JButton(); + resetButton = new javax.swing.JButton(); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel3.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel4.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel1.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel2.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(applyButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.applyButton.text")); // NOI18N + applyButton.setFocusable(false); + applyButton.setRequestFocusEnabled(false); + applyButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + applyButtonActionPerformed(evt); + } + }); + + jTextField1.setText(org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jTextField1.text")); // NOI18N + + jLabel5.setLabelFor(jTextField1); + org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel5.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel6.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(cShellLabel, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.cShellLabel.text")); // NOI18N + + jLabel8.setLabelFor(cshellTextField); + org.openide.awt.Mnemonics.setLocalizedText(jLabel8, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel8.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(applyCShellButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.applyCShellButton.text")); // NOI18N + applyCShellButton.setFocusable(false); + applyCShellButton.setRequestFocusEnabled(false); + applyCShellButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + applyCShellButtonActionPerformed(evt); + } + }); + + cshellTextField.setText(org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.cshellTextField.text")); // NOI18N + + jLabel7.setLabelFor(confirmationCheckBox); + org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel7.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(confirmationCheckBox, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.confirmationCheckBox.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(applyConfirmationButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.applyConfirmationButton.text")); // NOI18N + applyConfirmationButton.setFocusable(false); + applyConfirmationButton.setRequestFocusEnabled(false); + applyConfirmationButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + applyConfirmationButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(shellConfigureButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.shellConfigureButton.text")); // NOI18N + shellConfigureButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + shellConfigureButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(resetButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.resetButton.text")); // NOI18N + resetButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + resetButtonActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel5)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel7) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel8) + .addComponent(confirmationCheckBox, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel6) + .addGap(10, 10, 10) + .addComponent(cShellLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(cshellTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(shellConfigureButton) + .addGap(6, 6, 6)) + .addGroup(layout.createSequentialGroup() + .addComponent(jTextField1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(applyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(applyCShellButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(applyConfirmationButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(resetButton)))) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(applyButton) + .addComponent(jLabel2) + .addComponent(jLabel1) + .addComponent(jLabel5) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel6) + .addComponent(cShellLabel) + .addComponent(jLabel8) + .addComponent(applyCShellButton) + .addComponent(shellConfigureButton) + .addComponent(cshellTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(applyConfirmationButton)) + .addGroup(layout.createSequentialGroup() + .addGap(7, 7, 7) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(confirmationCheckBox) + .addComponent(jLabel7)))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE) + .addComponent(resetButton)) + ); + }// //GEN-END:initComponents + + private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed + String customSep = jTextField1.getText(); + if(customSep!=null && !customSep.isEmpty()){ + PrefsUtil.store("generalseparator" , customSep); + jLabel2.setText(customSep); + }else{ + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.SEPARATOR_NULL,NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + } + }//GEN-LAST:event_applyButtonActionPerformed + + private void applyCShellButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyCShellButtonActionPerformed + String cshell = cshellTextField.getText(); + if(cshell!=null && !cshell.isEmpty()){ + PrefsUtil.store("customShell" , cshell); + cShellLabel.setText(cshell); + }else{ + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.CUSTOM_SHELL,NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + } + }//GEN-LAST:event_applyCShellButtonActionPerformed + + private void applyConfirmationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyConfirmationButtonActionPerformed + }//GEN-LAST:event_applyConfirmationButtonActionPerformed + + private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed + PrefsUtil.removeSingleProperty("customShell"); + cShellLabel.setText("not defined"); + cshellTextField.setText("not defined"); + + confirmationCheckBox.setSelected(false); + PrefsUtil.store("confirmationDialogue", (confirmationCheckBox.isSelected()) ? "true" : "false"); + + PrefsUtil.removeSingleProperty("generalseparator"); + jLabel2.setText(getOSSeparator()); + jTextField1.setText(""); + + }//GEN-LAST:event_resetButtonActionPerformed + + @NbBundle.Messages( + {"LBL_Form_Label=Choose a configurator:", + "LBL_Dialog=Configurator",} + ) + private void shellConfigureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shellConfigureButtonActionPerformed + JTextField shellTextField = cshellTextField; + + List labels = new ArrayList<>(); + for (IShellConfigurator configurator : getAvailableConfigurators()) { + if (configurator.isAvailable()) { + labels.add(configurator.getLabel()); + } + } + + final JList jList = new JList(labels.toArray(new String[labels.size()])); + JPanel form = new JPanel(new BorderLayout()); + form.add(jList, BorderLayout.CENTER); + form.add(new JLabel(Bundle.LBL_Form_Label()), BorderLayout.NORTH); + jList.setSelectedIndex(0); + DialogDescriptor dd = new DialogDescriptor(form, Bundle.LBL_Dialog()); + Object result = DialogDisplayer.getDefault().notify(dd); + if (result == NotifyDescriptor.OK_OPTION) { + IShellConfigurator configurator = getAvailableConfigurators().get(jList.getSelectedIndex()); + + String configure = configurator.configure(); + if (null != configure) { + shellTextField.setText(configure); + } + } + }//GEN-LAST:event_shellConfigureButtonActionPerformed + + private List getAvailableConfigurators() { + //TODO externalize the configuration of available configurators + List allconfigurators = Arrays.asList((IShellConfigurator) new GitBashConfigurator()); + List availableConfigurators = new ArrayList<>(); + for (IShellConfigurator configurator : allconfigurators) { + if (configurator.isAvailable()) { + availableConfigurators.add(configurator); + } + } + return availableConfigurators; + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton applyButton; + private javax.swing.JButton applyCShellButton; + private javax.swing.JButton applyConfirmationButton; + private javax.swing.JLabel cShellLabel; + private javax.swing.JCheckBox confirmationCheckBox; + private javax.swing.JTextField cshellTextField; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; + private javax.swing.JLabel jLabel7; + private javax.swing.JLabel jLabel8; + private javax.swing.JTextField jTextField1; + private javax.swing.JButton resetButton; + private javax.swing.JButton shellConfigureButton; + // End of variables declaration//GEN-END:variables +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PlacesPanel.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PlacesPanel.java index 6a97b48..e5466e1 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PlacesPanel.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PlacesPanel.java @@ -1,251 +1,249 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.prefs; - -import me.dsnet.quickopener.QuickMessages; -import me.dsnet.quickopener.actions.popup.PropertyTableModel; -import java.io.File; -import java.util.List; -import java.util.prefs.BackingStoreException; -import javax.swing.JTable; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.Exceptions; -/** - * - * @author SessonaD - */ -public class PlacesPanel extends javax.swing.JPanel { - - /** - * Creates new form PlacesPanel - */ - public PlacesPanel() { - super(); - initComponents(); - jTable2.setModel(new PropertyTableModel("folder")); - jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); - jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); - jTable2.getColumnModel().getColumn(0).setMaxWidth(400); - jTable2.getColumnModel().getColumn(0).setMinWidth(100); - } - - private boolean checkValidFolder(String path){ - File f=new File(path); - return(f.exists() && f.isDirectory()); - } - - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jPanel2 = new javax.swing.JPanel(); - jLabel2 = new javax.swing.JLabel(); - folderDescriptionTextField = new javax.swing.JTextField(); - jLabel3 = new javax.swing.JLabel(); - favoritePathTextField = new javax.swing.JTextField(); - addFolderButton = new javax.swing.JButton(); - jButton3 = new javax.swing.JButton(); - jButton5 = new javax.swing.JButton(); - jScrollPane1 = new javax.swing.JScrollPane(); - jTable2 = new javax.swing.JTable(); - - jLabel2.setLabelFor(folderDescriptionTextField); - org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.jLabel2.text")); // NOI18N - - folderDescriptionTextField.setText(org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.folderDescriptionTextField.text")); // NOI18N - - jLabel3.setLabelFor(favoritePathTextField); - org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.jLabel3.text")); // NOI18N - - favoritePathTextField.setText(org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.favoritePathTextField.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(addFolderButton, org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.addFolderButton.text")); // NOI18N - addFolderButton.setToolTipText(org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.addFolderButton.toolTipText")); // NOI18N - addFolderButton.setFocusPainted(false); - addFolderButton.setRequestFocusEnabled(false); - addFolderButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - addFolderButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(jButton3, org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.jButton3.text")); // NOI18N - jButton3.setFocusPainted(false); - jButton3.setRequestFocusEnabled(false); - jButton3.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton3ActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(jButton5, org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.jButton5.text")); // NOI18N - jButton5.setFocusPainted(false); - jButton5.setRequestFocusEnabled(false); - jButton5.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton5ActionPerformed(evt); - } - }); - - jTable2.setAutoCreateRowSorter(true); - jTable2.setModel(new javax.swing.table.DefaultTableModel( - new Object [][] { - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null} - }, - new String [] { - "Title 1", "Title 2", "Title 3", "Title 4" - } - )); - jTable2.setFillsViewportHeight(true); - jTable2.setFocusable(false); - jTable2.setGridColor(new java.awt.Color(204, 204, 204)); - jTable2.setRequestFocusEnabled(false); - jTable2.setShowVerticalLines(false); - jTable2.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - jTable2MouseClicked(evt); - } - }); - jScrollPane1.setViewportView(jTable2); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addComponent(folderDescriptionTextField) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(addFolderButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jButton3) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jButton5)) - .addComponent(favoritePathTextField)) - .addContainerGap()) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 471, Short.MAX_VALUE) - .addContainerGap())) - ); - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel2) - .addComponent(folderDescriptionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(addFolderButton) - .addComponent(jButton3) - .addComponent(jButton5)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(favoritePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(252, Short.MAX_VALUE)) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addGap(73, 73, 73) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) - .addGap(16, 16, 16))) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 319, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 314, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - }// //GEN-END:initComponents - - private void addFolderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFolderButtonActionPerformed - String description = folderDescriptionTextField.getText(); - description =description.replaceAll(" ", "_"); - String value = favoritePathTextField.getText(); - if(! checkValidFolder(value) || description.isEmpty()){ - if(description.isEmpty()){ - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.DESCRIPTION_MANDATORY,NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - }else{ - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.FOLDER_INVALID,NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - } - return; - } - PrefsUtil.store("folder" + description, value); - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.FOLDER_ADDED); - DialogDisplayer.getDefault().notify(d); - jTable2.setModel(new PropertyTableModel("folder")); - }//GEN-LAST:event_addFolderButtonActionPerformed - - private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed - try { - PrefsUtil.remove("folder"+folderDescriptionTextField.getText().replaceAll(" ", "_")); - jTable2.setModel(new PropertyTableModel("folder")); - } catch (BackingStoreException ex) { - //Exceptions.printStackTrace(ex); - } - }//GEN-LAST:event_jButton3ActionPerformed - - private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed - try { - PrefsUtil.removeAll("folder"); - jTable2.setModel(new PropertyTableModel("folder")); - } catch (BackingStoreException ex) { - //Exceptions.printStackTrace(ex); - } - }//GEN-LAST:event_jButton5ActionPerformed - - private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked - if (evt.getClickCount() == 1) { - final int thisrow = jTable2.getSelectedRow(); - if (-1 != thisrow) { - final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); - String desc = (String) jTable2.getModel().getValueAt(row, 0); - String path = (String) jTable2.getModel().getValueAt(row, 1); - folderDescriptionTextField.setText(desc); - favoritePathTextField.setText(path); - } - } - }//GEN-LAST:event_jTable2MouseClicked - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton addFolderButton; - private javax.swing.JTextField favoritePathTextField; - private javax.swing.JTextField folderDescriptionTextField; - private javax.swing.JButton jButton3; - private javax.swing.JButton jButton5; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JPanel jPanel2; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTable jTable2; - // End of variables declaration//GEN-END:variables -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener.prefs; + +import me.dsnet.quickopener.QuickMessages; +import me.dsnet.quickopener.actions.popup.PropertyTableModel; +import java.io.File; +import java.util.prefs.BackingStoreException; +import javax.swing.JTable; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +/** + * + * @author SessonaD + */ +public class PlacesPanel extends javax.swing.JPanel { + + /** + * Creates new form PlacesPanel + */ + public PlacesPanel() { + super(); + initComponents(); + jTable2.setModel(new PropertyTableModel("folder")); + jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); + jTable2.getColumnModel().getColumn(0).setMaxWidth(400); + jTable2.getColumnModel().getColumn(0).setMinWidth(100); + } + + private boolean checkValidFolder(String path){ + File f=new File(path); + return(f.exists() && f.isDirectory()); + } + + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jPanel2 = new javax.swing.JPanel(); + jLabel2 = new javax.swing.JLabel(); + folderDescriptionTextField = new javax.swing.JTextField(); + jLabel3 = new javax.swing.JLabel(); + favoritePathTextField = new javax.swing.JTextField(); + addFolderButton = new javax.swing.JButton(); + jButton3 = new javax.swing.JButton(); + jButton5 = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTable2 = new javax.swing.JTable(); + + jLabel2.setLabelFor(folderDescriptionTextField); + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.jLabel2.text")); // NOI18N + + folderDescriptionTextField.setText(org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.folderDescriptionTextField.text")); // NOI18N + + jLabel3.setLabelFor(favoritePathTextField); + org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.jLabel3.text")); // NOI18N + + favoritePathTextField.setText(org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.favoritePathTextField.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(addFolderButton, org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.addFolderButton.text")); // NOI18N + addFolderButton.setToolTipText(org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.addFolderButton.toolTipText")); // NOI18N + addFolderButton.setFocusPainted(false); + addFolderButton.setRequestFocusEnabled(false); + addFolderButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addFolderButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(jButton3, org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.jButton3.text")); // NOI18N + jButton3.setFocusPainted(false); + jButton3.setRequestFocusEnabled(false); + jButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton3ActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(jButton5, org.openide.util.NbBundle.getMessage(PlacesPanel.class, "PlacesPanel.jButton5.text")); // NOI18N + jButton5.setFocusPainted(false); + jButton5.setRequestFocusEnabled(false); + jButton5.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton5ActionPerformed(evt); + } + }); + + jTable2.setAutoCreateRowSorter(true); + jTable2.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null} + }, + new String [] { + "Title 1", "Title 2", "Title 3", "Title 4" + } + )); + jTable2.setFillsViewportHeight(true); + jTable2.setFocusable(false); + jTable2.setGridColor(new java.awt.Color(204, 204, 204)); + jTable2.setRequestFocusEnabled(false); + jTable2.setShowVerticalLines(false); + jTable2.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jTable2MouseClicked(evt); + } + }); + jScrollPane1.setViewportView(jTable2); + + javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); + jPanel2.setLayout(jPanel2Layout); + jPanel2Layout.setHorizontalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addComponent(folderDescriptionTextField) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(addFolderButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton5)) + .addComponent(favoritePathTextField)) + .addContainerGap()) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 471, Short.MAX_VALUE) + .addContainerGap())) + ); + jPanel2Layout.setVerticalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(folderDescriptionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(addFolderButton) + .addComponent(jButton3) + .addComponent(jButton5)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(favoritePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(252, Short.MAX_VALUE)) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addGap(73, 73, 73) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) + .addGap(16, 16, 16))) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 319, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 314, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + private void addFolderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFolderButtonActionPerformed + String description = folderDescriptionTextField.getText(); + description =description.replaceAll(" ", "_"); + String value = favoritePathTextField.getText(); + if(! checkValidFolder(value) || description.isEmpty()){ + if(description.isEmpty()){ + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.DESCRIPTION_MANDATORY,NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + }else{ + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.FOLDER_INVALID,NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + } + return; + } + PrefsUtil.store("folder" + description, value); + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.FOLDER_ADDED); + DialogDisplayer.getDefault().notify(d); + jTable2.setModel(new PropertyTableModel("folder")); + }//GEN-LAST:event_addFolderButtonActionPerformed + + private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed + try { + PrefsUtil.remove("folder"+folderDescriptionTextField.getText().replaceAll(" ", "_")); + jTable2.setModel(new PropertyTableModel("folder")); + } catch (BackingStoreException ex) { + //Exceptions.printStackTrace(ex); + } + }//GEN-LAST:event_jButton3ActionPerformed + + private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed + try { + PrefsUtil.removeAll("folder"); + jTable2.setModel(new PropertyTableModel("folder")); + } catch (BackingStoreException ex) { + //Exceptions.printStackTrace(ex); + } + }//GEN-LAST:event_jButton5ActionPerformed + + private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked + if (evt.getClickCount() == 1) { + final int thisrow = jTable2.getSelectedRow(); + if (-1 != thisrow) { + final int row = jTable2.getRowSorter().convertRowIndexToModel(thisrow); + String desc = (String) jTable2.getModel().getValueAt(row, 0); + String path = (String) jTable2.getModel().getValueAt(row, 1); + folderDescriptionTextField.setText(desc); + favoritePathTextField.setText(path); + } + } + }//GEN-LAST:event_jTable2MouseClicked + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton addFolderButton; + private javax.swing.JTextField favoritePathTextField; + private javax.swing.JTextField folderDescriptionTextField; + private javax.swing.JButton jButton3; + private javax.swing.JButton jButton5; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JPanel jPanel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTable jTable2; + // End of variables declaration//GEN-END:variables +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PrefsUtil.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PrefsUtil.java index 8bf0f84..be31e64 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PrefsUtil.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PrefsUtil.java @@ -63,7 +63,7 @@ public static QuickOpenerProperty load(String prefix,String key, String defaultV } public static List getAllMatching(String prefix) throws BackingStoreException{ - List list = new ArrayList (); + List list = new ArrayList<> (); for(String key:NbPreferences.forModule(QuickOpenerPanel.class).keys()){ if(key.startsWith(prefix)){ String desc =key.replace(prefix, ""); diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerOptionsPanelController.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerOptionsPanelController.java index c111c95..ad37c39 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerOptionsPanelController.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerOptionsPanelController.java @@ -1,78 +1,87 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.prefs; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import javax.swing.JComponent; -import org.netbeans.spi.options.OptionsPanelController; -import org.openide.util.HelpCtx; -import org.openide.util.Lookup; - -@OptionsPanelController.SubRegistration(location = "Advanced", - id = "QuickOpener", - displayName = "#AdvancedOption_DisplayName_QuickOpener", - keywords = "#AdvancedOption_Keywords_QuickOpener", - keywordsCategory = "Advanced/QuickOpener") -@org.openide.util.NbBundle.Messages({"AdvancedOption_DisplayName_QuickOpener=QuickOpener", "AdvancedOption_Keywords_QuickOpener=quickopener"}) -public final class QuickOpenerOptionsPanelController extends OptionsPanelController { - - private QuickOpenerPanel panel; - private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - private boolean changed; - - public void update() { - getPanel().load(); - changed = false; - } - - public void applyChanges() { - getPanel().store(); - changed = false; - } - - public void cancel() { - // need not do anything special, if no changes have been persisted yet - } - - public boolean isValid() { - return getPanel().valid(); - } - - public boolean isChanged() { - return changed; - } - - public HelpCtx getHelpCtx() { - return null; // new HelpCtx("...ID") if you have a help set - } - - public JComponent getComponent(Lookup masterLookup) { - return getPanel(); - } - - public void addPropertyChangeListener(PropertyChangeListener l) { - pcs.addPropertyChangeListener(l); - } - - public void removePropertyChangeListener(PropertyChangeListener l) { - pcs.removePropertyChangeListener(l); - } - - private QuickOpenerPanel getPanel() { - if (panel == null) { - panel = new QuickOpenerPanel(this); - } - return panel; - } - - void changed() { - if (!changed) { - changed = true; - pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); - } - pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); - } -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener.prefs; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import javax.swing.JComponent; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +@OptionsPanelController.SubRegistration(location = "Advanced", + id = "QuickOpener", + displayName = "#AdvancedOption_DisplayName_QuickOpener", + keywords = "#AdvancedOption_Keywords_QuickOpener", + keywordsCategory = "Advanced/QuickOpener") +@org.openide.util.NbBundle.Messages({"AdvancedOption_DisplayName_QuickOpener=QuickOpener", "AdvancedOption_Keywords_QuickOpener=quickopener"}) +public final class QuickOpenerOptionsPanelController extends OptionsPanelController { + + private QuickOpenerPanel panel; + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private boolean changed; + + @Override + public void update() { + getPanel().load(); + changed = false; + } + + @Override + public void applyChanges() { + getPanel().store(); + changed = false; + } + + @Override + public void cancel() { + // need not do anything special, if no changes have been persisted yet + } + + @Override + public boolean isValid() { + return getPanel().valid(); + } + + @Override + public boolean isChanged() { + return changed; + } + + @Override + public HelpCtx getHelpCtx() { + return null; // new HelpCtx("...ID") if you have a help set + } + + @Override + public JComponent getComponent(Lookup masterLookup) { + return getPanel(); + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + private QuickOpenerPanel getPanel() { + if (panel == null) { + panel = new QuickOpenerPanel(this); + } + return panel; + } + + void changed() { + if (!changed) { + changed = true; + pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); + } + pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); + } +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerPanel.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerPanel.java index 0b6c1c4..de2221a 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerPanel.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerPanel.java @@ -1,145 +1,148 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.prefs; - -import java.awt.CardLayout; -import java.awt.LayoutManager; - -public final class QuickOpenerPanel extends javax.swing.JPanel { - - private final QuickOpenerOptionsPanelController controller; - - - QuickOpenerPanel(QuickOpenerOptionsPanelController controller) { - this.controller = controller; - initComponents(); - jList1.setSelectedIndex(0); - commandsPanel1.setVisible(false); - placesPanel1.setVisible(true); - generalPanel1.setVisible(false); - } - - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - - jTabbedPane1 = new javax.swing.JTabbedPane(); - jSplitPane1 = new javax.swing.JSplitPane(); - jPanel1 = new javax.swing.JPanel(); - jList1 = new javax.swing.JList(); - jLabel1 = new javax.swing.JLabel(); - jRightPanel = new javax.swing.JPanel(); - placesPanel1 = new me.dsnet.quickopener.prefs.PlacesPanel(); - commandsPanel1 = new me.dsnet.quickopener.prefs.CommandsPanel(); - generalPanel1 = new me.dsnet.quickopener.prefs.GeneralPanel(); - - jSplitPane1.setBorder(null); - jSplitPane1.setDividerSize(0); - - jList1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); - jList1.setModel(new javax.swing.AbstractListModel() { - String[] strings = { "Places", "Commands", "General Options" }; - public int getSize() { return strings.length; } - public Object getElementAt(int i) { return strings[i]; } - }); - jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); - jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() { - public void valueChanged(javax.swing.event.ListSelectionEvent evt) { - jList1ValueChanged(evt); - } - }); - - jLabel1.setLabelFor(jList1); - org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(QuickOpenerPanel.class, "QuickOpenerPanel.jLabel1.text")); // NOI18N - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jList1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(jLabel1) - .addGap(0, 0, 0) - .addComponent(jList1, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)) - ); - - jSplitPane1.setLeftComponent(jPanel1); - - jRightPanel.setLayout(new java.awt.CardLayout()); - jRightPanel.add(placesPanel1, "placesPanel1"); - jRightPanel.add(commandsPanel1, "commandsPanel1"); - jRightPanel.add(generalPanel1, "generalPanel1"); - - jSplitPane1.setRightComponent(jRightPanel); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jSplitPane1) - .addGap(0, 0, 0)) - ); - }// //GEN-END:initComponents - - private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged - LayoutManager layout = jRightPanel.getLayout(); - if (layout instanceof CardLayout) { - CardLayout cardLayout = (CardLayout) layout; - - - if(jList1.getSelectedIndex()==0){ - cardLayout.show(jRightPanel, "placesPanel1"); - }else if(jList1.getSelectedIndex()==1){ - cardLayout.show(jRightPanel, "commandsPanel1"); - }else{ - cardLayout.show(jRightPanel, "generalPanel1"); - } - } - }//GEN-LAST:event_jList1ValueChanged - - - - void load() { - } - - void store() { - } - - boolean valid() { - return true; - } - // Variables declaration - do not modify//GEN-BEGIN:variables - private me.dsnet.quickopener.prefs.CommandsPanel commandsPanel1; - private me.dsnet.quickopener.prefs.GeneralPanel generalPanel1; - private javax.swing.JLabel jLabel1; - private javax.swing.JList jList1; - private javax.swing.JPanel jPanel1; - private javax.swing.JPanel jRightPanel; - private javax.swing.JSplitPane jSplitPane1; - private javax.swing.JTabbedPane jTabbedPane1; - private me.dsnet.quickopener.prefs.PlacesPanel placesPanel1; - // End of variables declaration//GEN-END:variables -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.dsnet.quickopener.prefs; + +import java.awt.CardLayout; +import java.awt.LayoutManager; + +public final class QuickOpenerPanel extends javax.swing.JPanel { + + private final QuickOpenerOptionsPanelController controller; + + + QuickOpenerPanel(QuickOpenerOptionsPanelController controller) { + this.controller = controller; + initComponents(); + jList1.setSelectedIndex(0); + commandsPanel1.setVisible(false); + placesPanel1.setVisible(true); + generalPanel1.setVisible(false); + } + + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jTabbedPane1 = new javax.swing.JTabbedPane(); + jSplitPane1 = new javax.swing.JSplitPane(); + jPanel1 = new javax.swing.JPanel(); + jList1 = new javax.swing.JList(); + jLabel1 = new javax.swing.JLabel(); + jRightPanel = new javax.swing.JPanel(); + placesPanel1 = new me.dsnet.quickopener.prefs.PlacesPanel(); + commandsPanel1 = new me.dsnet.quickopener.prefs.CommandsPanel(); + generalPanel1 = new me.dsnet.quickopener.prefs.GeneralPanel(); + + jSplitPane1.setBorder(null); + jSplitPane1.setDividerSize(0); + + jList1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); + jList1.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Places", "Commands", "General Options" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); + jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() { + public void valueChanged(javax.swing.event.ListSelectionEvent evt) { + jList1ValueChanged(evt); + } + }); + + jLabel1.setLabelFor(jList1); + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(QuickOpenerPanel.class, "QuickOpenerPanel.jLabel1.text")); // NOI18N + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jList1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel1) + .addGap(0, 0, 0) + .addComponent(jList1, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)) + ); + + jSplitPane1.setLeftComponent(jPanel1); + + jRightPanel.setLayout(new java.awt.CardLayout()); + jRightPanel.add(placesPanel1, "placesPanel1"); + jRightPanel.add(commandsPanel1, "commandsPanel1"); + jRightPanel.add(generalPanel1, "generalPanel1"); + + jSplitPane1.setRightComponent(jRightPanel); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, 0) + .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, 0) + .addComponent(jSplitPane1) + .addGap(0, 0, 0)) + ); + }// //GEN-END:initComponents + + private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged + LayoutManager layout = jRightPanel.getLayout(); + if (layout instanceof CardLayout) { + CardLayout cardLayout = (CardLayout) layout; + + switch (jList1.getSelectedIndex()) { + case 0: + cardLayout.show(jRightPanel, "placesPanel1"); + break; + case 1: + cardLayout.show(jRightPanel, "commandsPanel1"); + break; + default: + cardLayout.show(jRightPanel, "generalPanel1"); + break; + } + } + }//GEN-LAST:event_jList1ValueChanged + + + + void load() { + } + + void store() { + } + + boolean valid() { + return true; + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private me.dsnet.quickopener.prefs.CommandsPanel commandsPanel1; + private me.dsnet.quickopener.prefs.GeneralPanel generalPanel1; + private javax.swing.JLabel jLabel1; + private javax.swing.JList jList1; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jRightPanel; + private javax.swing.JSplitPane jSplitPane1; + private javax.swing.JTabbedPane jTabbedPane1; + private me.dsnet.quickopener.prefs.PlacesPanel placesPanel1; + // End of variables declaration//GEN-END:variables +} From f17b1dd686c466060d4968779bd3554c8b9615e4 Mon Sep 17 00:00:00 2001 From: Javatlacati <> Date: Sat, 11 Nov 2017 07:10:15 -0600 Subject: [PATCH 2/2] Attenfing issue #80. Adding license headers to all sources. --- QuickOpener/nb-configuration.xml | 18 ++ .../oscommands/commands/Commands.java | 16 ++ .../commands/LinuxGnomeCommands.java | 16 ++ .../oscommands/commands/LinuxKdeCommands.java | 16 ++ .../commands/LinuxLxdeCommands.java | 16 ++ .../commands/LinuxUnknownCommands.java | 16 ++ .../commands/LinuxXfceCommands.java | 16 ++ .../oscommands/commands/MacOSCommands.java | 16 ++ .../commands/SupportedFeatures.java | 16 ++ .../commands/UnknownOSCommands.java | 16 ++ .../oscommands/commands/WindowsCommands.java | 16 ++ .../oscommands/detector/OSDetector.java | 16 ++ .../oscommands/detector/OperatingSystem.java | 20 ++ .../java/me/dsnet/quickopener/LAFUtils.java | 16 ++ .../java/me/dsnet/quickopener/PathFinder.java | 16 +- .../me/dsnet/quickopener/QuickMessages.java | 87 ++++---- .../AbstractFileContextAwareAction.java | 110 +++++----- .../dsnet/quickopener/actions/FileSystem.java | 130 ++++++------ .../me/dsnet/quickopener/actions/Path.java | 16 ++ .../dsnet/quickopener/actions/RunCommand.java | 16 +- .../dsnet/quickopener/actions/Terminal.java | 190 ++++++++++-------- .../quickopener/actions/ToolbarPresenter.java | 156 +++++++------- .../actions/VerticalSeparator.java | 16 +- .../popup/CustomCommandPopupAction.java | 16 ++ .../popup/CustomFileSystemPopupAction.java | 16 ++ .../popup/CustomTerminalPopupAction.java | 16 ++ .../actions/popup/DialogCustomCommandRun.java | 16 +- .../actions/popup/DialogCustomFileSystem.java | 16 +- .../actions/popup/DialogCustomTerminal.java | 16 +- .../actions/popup/DialogueFileSelector.java | 16 +- .../actions/popup/PropertyTableModel.java | 16 +- .../quickopener/prefs/CommandsPanel.java | 16 +- .../dsnet/quickopener/prefs/GeneralPanel.form | 114 +++++++++-- .../dsnet/quickopener/prefs/GeneralPanel.java | 150 ++++++++++++-- .../dsnet/quickopener/prefs/PlacesPanel.java | 16 +- .../me/dsnet/quickopener/prefs/PrefsUtil.java | 16 +- .../QuickOpenerOptionsPanelController.java | 16 +- .../quickopener/prefs/QuickOpenerPanel.java | 16 +- .../prefs/QuickOpenerProperty.java | 16 +- .../filemanager/IFileManagerConfigurator.java | 46 +++++ .../impl/CajaFileManagerConfigurator.java | 82 ++++++++ .../impl/SpaceFileManagerConfigurator.java | 83 ++++++++ .../shell/chooser/IShellConfigurator.java | 81 ++++---- .../chooser/impl/GitBashConfigurator.java | 17 +- .../impl/MateTerminalConfigurator.java | 83 ++++++++ .../dsnet/quickopener/prefs/Bundle.properties | 78 +++---- 46 files changed, 1493 insertions(+), 432 deletions(-) create mode 100644 QuickOpener/nb-configuration.xml create mode 100644 QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/IFileManagerConfigurator.java create mode 100644 QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/impl/CajaFileManagerConfigurator.java create mode 100644 QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/impl/SpaceFileManagerConfigurator.java create mode 100644 QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/impl/MateTerminalConfigurator.java diff --git a/QuickOpener/nb-configuration.xml b/QuickOpener/nb-configuration.xml new file mode 100644 index 0000000..98cd079 --- /dev/null +++ b/QuickOpener/nb-configuration.xml @@ -0,0 +1,18 @@ + + + + + + gpl30 + + diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/Commands.java b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/Commands.java index adc1631..ba19cfb 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/Commands.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/Commands.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.commands; diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxGnomeCommands.java b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxGnomeCommands.java index 6e9258b..7008cad 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxGnomeCommands.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxGnomeCommands.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.commands; import com.sessonad.oscommands.detector.OperatingSystem; diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxKdeCommands.java b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxKdeCommands.java index 68f8c62..4bb755e 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxKdeCommands.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxKdeCommands.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.commands; import com.sessonad.oscommands.detector.OperatingSystem; diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxLxdeCommands.java b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxLxdeCommands.java index 5b41090..037fff4 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxLxdeCommands.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxLxdeCommands.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.commands; import com.sessonad.oscommands.detector.OperatingSystem; diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxUnknownCommands.java b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxUnknownCommands.java index 1db5818..1e1a7f2 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxUnknownCommands.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxUnknownCommands.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.commands; import com.sessonad.oscommands.detector.OperatingSystem; diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxXfceCommands.java b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxXfceCommands.java index 80c2bf4..f4c0ac9 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxXfceCommands.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/LinuxXfceCommands.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.commands; import com.sessonad.oscommands.detector.OperatingSystem; diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/MacOSCommands.java b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/MacOSCommands.java index bff98b5..41dfc38 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/MacOSCommands.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/MacOSCommands.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.commands; import com.sessonad.oscommands.detector.OperatingSystem; diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/SupportedFeatures.java b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/SupportedFeatures.java index 05265a5..4995706 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/SupportedFeatures.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/SupportedFeatures.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.commands; /** diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/UnknownOSCommands.java b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/UnknownOSCommands.java index ffab3e7..bff2f16 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/UnknownOSCommands.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/UnknownOSCommands.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.commands; import com.sessonad.oscommands.detector.OperatingSystem; diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/WindowsCommands.java b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/WindowsCommands.java index e51515c..df98f9d 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/commands/WindowsCommands.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/commands/WindowsCommands.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.commands; import com.sessonad.oscommands.detector.OperatingSystem; diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OSDetector.java b/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OSDetector.java index a8ad633..cc919b8 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OSDetector.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OSDetector.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.detector; /** diff --git a/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OperatingSystem.java b/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OperatingSystem.java index fe99199..46a5881 100644 --- a/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OperatingSystem.java +++ b/QuickOpener/src/main/java/com/sessonad/oscommands/detector/OperatingSystem.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.sessonad.oscommands.detector; import com.sessonad.oscommands.commands.SupportedFeatures; @@ -54,4 +70,8 @@ public boolean isFeatured(SupportedFeatures feature){ return features.contains(feature); } + public boolean isLinux(){ + return this.equals(OperatingSystem.LINUX_GNOME)|| this.equals(OperatingSystem.LINUX_KDE)|| this.equals(OperatingSystem.LINUX_LXDE)|| this.equals(OperatingSystem.LINUX_XFCE)|| this.equals(OperatingSystem.LINUX_UNKNOWN); + } + } diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/LAFUtils.java b/QuickOpener/src/main/java/me/dsnet/quickopener/LAFUtils.java index 2822aa6..b0efdd7 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/LAFUtils.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/LAFUtils.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.dsnet.quickopener; import java.text.MessageFormat; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/PathFinder.java b/QuickOpener/src/main/java/me/dsnet/quickopener/PathFinder.java index 75bee48..acb4fd4 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/PathFinder.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/PathFinder.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/QuickMessages.java b/QuickOpener/src/main/java/me/dsnet/quickopener/QuickMessages.java index c1e8a07..9a828ec 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/QuickMessages.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/QuickMessages.java @@ -1,37 +1,50 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener; - -/** - * - * @author SessonaD - */ -public enum QuickMessages { - - NO_FILE_IN_SELECTION ("There are no files associated with the current selection."), - CONFIRM_COMMAND_PREFIX ("You are about to launch the following command:\n\n"), - CONFIRM_COMMAND_SUFFIX ("\n\nAre you sure?"), - DESCRIPTION_MANDATORY ("A description is mandatory."), - FOLDER_INVALID ("The folder specified is not valid or does not exists."), - FOLDER_ADDED ("Folder added as favorite."), - SEPARATOR_NULL ("Separator cannot be empty."), - CUSTOM_SHELL ("Custom shell cannot be empty."), - NO_COMMAND ("No command given."), - NO_DEFAULT_PARAMETERS ("Some placeholders could not be replaced."), - DEFAULT_COMMAND_PARAMETERS ("A default command cannot contain parameters."), - NOT_IN_FILE_SYSTEM ("The file does not exists in the file system."); - - private String message; - - private QuickMessages(String message) { - this.message = message; - } - - @Override - public String toString() { - return message ; - } - -} +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.dsnet.quickopener; + +/** + * + * @author SessonaD + */ +public enum QuickMessages { + + NO_FILE_IN_SELECTION ("There are no files associated with the current selection."), + CONFIRM_COMMAND_PREFIX ("You are about to launch the following command:\n\n"), + CONFIRM_COMMAND_SUFFIX ("\n\nAre you sure?"), + DESCRIPTION_MANDATORY ("A description is mandatory."), + FOLDER_INVALID ("The folder specified is not valid or does not exists."), + FOLDER_ADDED ("Folder added as favorite."), + SEPARATOR_NULL ("Separator cannot be empty."), + CUSTOM_SHELL ("Custom shell cannot be empty."), + CUSTOM_FILEMANAGER ("Custom file manager cannot be empty."), + NO_COMMAND ("No command given."), + NO_DEFAULT_PARAMETERS ("Some placeholders could not be replaced."), + DEFAULT_COMMAND_PARAMETERS ("A default command cannot contain parameters."), + NOT_IN_FILE_SYSTEM ("The file does not exists in the file system."); + + private String message; + + private QuickMessages(String message) { + this.message = message; + } + + @Override + public String toString() { + return message ; + } + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/AbstractFileContextAwareAction.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/AbstractFileContextAwareAction.java index 9ea829f..a8577f6 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/AbstractFileContextAwareAction.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/AbstractFileContextAwareAction.java @@ -1,47 +1,63 @@ -package me.dsnet.quickopener.actions; - -import java.io.File; -import me.dsnet.quickopener.PathFinder; -import org.openide.loaders.DataObject; -import org.openide.nodes.Node; -import org.openide.util.HelpCtx; -import org.openide.util.actions.NodeAction; - -public abstract class AbstractFileContextAwareAction extends NodeAction { - - private File file; - - protected File getFile() { - return file; - } - - @Override - protected boolean asynchronous() { - return false; - } - - @Override - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - - @Override - public abstract String getName(); - - @Override - protected boolean enable(Node[] activatedNodes) { - file = null; - if (null != activatedNodes && activatedNodes.length == 1) { - - file = PathFinder.getActiveFile(activatedNodes[0].getLookup().lookup(DataObject.class), false); - } - return null != file; - } - - @Override - protected abstract String iconResource(); - - @Override - protected abstract void performAction(Node[] activatedNodes); - -} +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.dsnet.quickopener.actions; + +import java.io.File; +import me.dsnet.quickopener.PathFinder; +import org.openide.loaders.DataObject; +import org.openide.nodes.Node; +import org.openide.util.HelpCtx; +import org.openide.util.actions.NodeAction; + +public abstract class AbstractFileContextAwareAction extends NodeAction { + + private File file; + + protected File getFile() { + return file; + } + + @Override + protected boolean asynchronous() { + return false; + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + public abstract String getName(); + + @Override + protected boolean enable(Node[] activatedNodes) { + file = null; + if (null != activatedNodes && activatedNodes.length == 1) { + + file = PathFinder.getActiveFile(activatedNodes[0].getLookup().lookup(DataObject.class), false); + } + return null != file; + } + + @Override + protected abstract String iconResource(); + + @Override + protected abstract void performAction(Node[] activatedNodes); + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/FileSystem.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/FileSystem.java index 897c6b4..350a4d0 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/FileSystem.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/FileSystem.java @@ -1,57 +1,73 @@ -package me.dsnet.quickopener.actions; - -import com.sessonad.oscommands.commands.Commands; -import me.dsnet.quickopener.QuickMessages; -import java.io.File; -import org.netbeans.api.annotations.common.StaticResource; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.awt.ActionID; -import org.openide.awt.ActionRegistration; -import org.openide.nodes.Node; -import org.openide.util.NbBundle.Messages; - -/** - * - * @author SessonaD - * @author markiewb (contributor) - */ -@ActionID( - category = "Tools", - id = "me.dsnet.quickopener.actions.FileSystem") -@ActionRegistration( - lazy = false, - displayName = "#CTL_FileSystem" -) -@Messages("CTL_FileSystem=Open in File Manager") -public final class FileSystem extends AbstractFileContextAwareAction { - - @StaticResource - private static final String icon = "me/dsnet/quickopener/icons/folder-documents-icon.png"; - - @Override - public String getName() { - return Bundle.CTL_FileSystem(); - } - - @Override - protected String iconResource() { - return icon; - } - - @Override - protected void performAction(Node[] activatedNodes) { - File file = getFile(); - - if (file == null) { - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_FILE_IN_SELECTION, NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - return; - } - try { - Commands.getPlatform().browseInFileSystemToFileOrDir(file); - } catch (Exception ex) { - }//ex.printStackTrace();} - } - -} +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.dsnet.quickopener.actions; + +import com.sessonad.oscommands.commands.Commands; +import me.dsnet.quickopener.QuickMessages; +import java.io.File; +import org.netbeans.api.annotations.common.StaticResource; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; +import org.openide.nodes.Node; +import org.openide.util.NbBundle.Messages; + +/** + * + * @author SessonaD + * @author markiewb (contributor) + */ +@ActionID( + category = "Tools", + id = "me.dsnet.quickopener.actions.FileSystem") +@ActionRegistration( + lazy = false, + displayName = "#CTL_FileSystem" +) +@Messages("CTL_FileSystem=Open in File Manager") +public final class FileSystem extends AbstractFileContextAwareAction { + + @StaticResource + private static final String icon = "me/dsnet/quickopener/icons/folder-documents-icon.png"; + + @Override + public String getName() { + return Bundle.CTL_FileSystem(); + } + + @Override + protected String iconResource() { + return icon; + } + + @Override + protected void performAction(Node[] activatedNodes) { + File file = getFile(); + + if (file == null) { + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_FILE_IN_SELECTION, NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + return; + } + try { + Commands.getPlatform().browseInFileSystemToFileOrDir(file); + } catch (Exception ex) { + }//ex.printStackTrace();} + } + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Path.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Path.java index 210297f..6f09034 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Path.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Path.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.dsnet.quickopener.actions; import java.awt.HeadlessException; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/RunCommand.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/RunCommand.java index 0a30fb6..1a1c203 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/RunCommand.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/RunCommand.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.actions; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Terminal.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Terminal.java index 92f0833..a222731 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Terminal.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/Terminal.java @@ -1,87 +1,103 @@ -package me.dsnet.quickopener.actions; - -import com.sessonad.oscommands.commands.Commands; -import me.dsnet.quickopener.PathFinder; -import me.dsnet.quickopener.QuickMessages; -import me.dsnet.quickopener.prefs.PrefsUtil; -import me.dsnet.quickopener.prefs.QuickOpenerProperty; -import java.io.File; -import org.netbeans.api.annotations.common.StaticResource; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.awt.ActionID; -import org.openide.awt.ActionRegistration; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.loaders.DataObject; -import org.openide.nodes.Node; -import org.openide.util.NbBundle.Messages; -import org.openide.util.Utilities; - -/** - * - * @author SessonaD - * @author markiewb (contributor) - */ -@ActionID( - category = "Tools", - id = "me.dsnet.quickopener.actions.Terminal") -@ActionRegistration( - lazy = false, - displayName = "#CTL_Terminal" -) -@Messages("CTL_Terminal=Open in Terminal") -public final class Terminal extends AbstractFileContextAwareAction { - - @StaticResource - private static final String icon = "me/dsnet/quickopener/icons/terminal.png"; - - @Override - public String getName() { - return Bundle.CTL_Terminal(); - } - - @Override - protected String iconResource() { - return icon; - } - - @Override - protected void performAction(Node[] activatedNodes) { - File file = getFile(); - - try { - FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(file)); - DataObject dataObj = DataObject.find(fo); - String path = PathFinder.getActivePath(dataObj, true); - if (path == null) { - NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_FILE_IN_SELECTION, NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(d); - return; - } - //open in os shell or in the custom one if defined - QuickOpenerProperty customShell = PrefsUtil.load(null, "customShell", null); - if (customShell.getValue() == null) { - Commands.getPlatform().openInShell(path); - } else { - customShellOpen(customShell.getValue(), path); - } - } catch (Exception ex) { - } - } - - private void customShellOpen(String customShell, String workingDir) throws Exception { - String shellTitle = ""; - String fullCommand; - if (Utilities.isWindows()) { - //support git bash this way - //cmd /c start /D workingDIR "" D:\tools\Git\bin\sh.exe --login -i - fullCommand = String.format("cmd /c start /D %s \"%s\" %s", workingDir, shellTitle, customShell); - } else { - fullCommand = customShell; - } - - Runtime.getRuntime().exec(fullCommand, null, new File(workingDir)); - } - -} +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.dsnet.quickopener.actions; + +import com.sessonad.oscommands.commands.Commands; +import me.dsnet.quickopener.PathFinder; +import me.dsnet.quickopener.QuickMessages; +import me.dsnet.quickopener.prefs.PrefsUtil; +import me.dsnet.quickopener.prefs.QuickOpenerProperty; +import java.io.File; +import org.netbeans.api.annotations.common.StaticResource; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataObject; +import org.openide.nodes.Node; +import org.openide.util.NbBundle.Messages; +import org.openide.util.Utilities; + +/** + * + * @author SessonaD + * @author markiewb (contributor) + */ +@ActionID( + category = "Tools", + id = "me.dsnet.quickopener.actions.Terminal") +@ActionRegistration( + lazy = false, + displayName = "#CTL_Terminal" +) +@Messages("CTL_Terminal=Open in Terminal") +public final class Terminal extends AbstractFileContextAwareAction { + + @StaticResource + private static final String icon = "me/dsnet/quickopener/icons/terminal.png"; + + @Override + public String getName() { + return Bundle.CTL_Terminal(); + } + + @Override + protected String iconResource() { + return icon; + } + + @Override + protected void performAction(Node[] activatedNodes) { + File file = getFile(); + + try { + FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(file)); + DataObject dataObj = DataObject.find(fo); + String path = PathFinder.getActivePath(dataObj, true); + if (path == null) { + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_FILE_IN_SELECTION, NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + return; + } + //open in os shell or in the custom one if defined + QuickOpenerProperty customShell = PrefsUtil.load(null, "customShell", null); + if (customShell.getValue() == null) { + Commands.getPlatform().openInShell(path); + } else { + customShellOpen(customShell.getValue(), path); + } + } catch (Exception ex) { + } + } + + private void customShellOpen(String customShell, String workingDir) throws Exception { + String shellTitle = ""; + String fullCommand; + if (Utilities.isWindows()) { + //support git bash this way + //cmd /c start /D workingDIR "" D:\tools\Git\bin\sh.exe --login -i + fullCommand = String.format("cmd /c start /D %s \"%s\" %s", workingDir, shellTitle, customShell); + } else { + fullCommand = customShell; + } + + Runtime.getRuntime().exec(fullCommand, null, new File(workingDir)); + } + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/ToolbarPresenter.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/ToolbarPresenter.java index 3beb521..564492d 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/ToolbarPresenter.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/ToolbarPresenter.java @@ -1,70 +1,86 @@ -/** - * - * @author SessonaD - */ -package me.dsnet.quickopener.actions; - -import me.dsnet.quickopener.actions.popup.CustomCommandPopupAction; -import me.dsnet.quickopener.actions.popup.CustomFileSystemPopupAction; -import me.dsnet.quickopener.actions.popup.CustomTerminalPopupAction; -import java.awt.Component; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JPopupMenu; -import org.openide.awt.DropDownButtonFactory; -import org.openide.util.ImageUtilities; -import org.openide.util.NbBundle.Messages; -import org.openide.util.actions.Presenter; - -@Messages("CTL_CustomCommand=Launch custom command") -public final class ToolbarPresenter implements Presenter.Toolbar { - - public ToolbarPresenter(){ - } - - @Override - public Component getToolbarPresenter() { - - final ImageIcon run16 = ImageUtilities.loadImageIcon("me/dsnet/quickopener/icons/run.png", false); - final ImageIcon run32 = ImageUtilities.loadImageIcon("me/dsnet/quickopener/icons/run24.png", false); - final ImageIcon folder = ImageUtilities.loadImageIcon("me/dsnet/quickopener/icons/folder-documents-icon-cu.png",false); - final ImageIcon terminal = ImageUtilities.loadImageIcon("me/dsnet/quickopener/icons/terminal-cu.png",false); - - CustomCommandPopupAction cAction=new CustomCommandPopupAction("Launch custom command...",run16); - CustomTerminalPopupAction tAction=new CustomTerminalPopupAction("Open shell in...",terminal); - CustomFileSystemPopupAction fAction=new CustomFileSystemPopupAction("Open filesystem in...",folder); - - //popup - JPopupMenu popup = new JPopupMenu(); - popup.add(cAction); - popup.addSeparator(); - popup.add(tAction); - popup.add(fAction); - - //button - final JButton dropDownButton = DropDownButtonFactory.createDropDownButton(run16,popup); - dropDownButton.addActionListener(cAction); - dropDownButton.addPropertyChangeListener("PreferredIconSize", new PropertyChangeListener(){ - @Override - public void propertyChange(PropertyChangeEvent evt) - { - boolean useSmallIcon = true; - final Object prop = evt.getNewValue(); - if (prop instanceof Integer) { - if(((Integer)prop).intValue()==24) { - useSmallIcon = false; - } - } - if(useSmallIcon){ - dropDownButton.setIcon(run16); - }else { - dropDownButton.setIcon(run32); - } - } - }); - return dropDownButton; - } - -} +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.dsnet.quickopener.actions; + +import me.dsnet.quickopener.actions.popup.CustomCommandPopupAction; +import me.dsnet.quickopener.actions.popup.CustomFileSystemPopupAction; +import me.dsnet.quickopener.actions.popup.CustomTerminalPopupAction; +import java.awt.Component; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JPopupMenu; +import org.openide.awt.DropDownButtonFactory; +import org.openide.util.ImageUtilities; +import org.openide.util.NbBundle.Messages; +import org.openide.util.actions.Presenter; + +/** + * + * @author SessonaD + */ +@Messages("CTL_CustomCommand=Launch custom command") +public final class ToolbarPresenter implements Presenter.Toolbar { + + public ToolbarPresenter(){ + } + + @Override + public Component getToolbarPresenter() { + + final ImageIcon run16 = ImageUtilities.loadImageIcon("me/dsnet/quickopener/icons/run.png", false); + final ImageIcon run32 = ImageUtilities.loadImageIcon("me/dsnet/quickopener/icons/run24.png", false); + final ImageIcon folder = ImageUtilities.loadImageIcon("me/dsnet/quickopener/icons/folder-documents-icon-cu.png",false); + final ImageIcon terminal = ImageUtilities.loadImageIcon("me/dsnet/quickopener/icons/terminal-cu.png",false); + + CustomCommandPopupAction cAction=new CustomCommandPopupAction("Launch custom command...",run16); + CustomTerminalPopupAction tAction=new CustomTerminalPopupAction("Open shell in...",terminal); + CustomFileSystemPopupAction fAction=new CustomFileSystemPopupAction("Open filesystem in...",folder); + + //popup + JPopupMenu popup = new JPopupMenu(); + popup.add(cAction); + popup.addSeparator(); + popup.add(tAction); + popup.add(fAction); + + //button + final JButton dropDownButton = DropDownButtonFactory.createDropDownButton(run16,popup); + dropDownButton.addActionListener(cAction); + dropDownButton.addPropertyChangeListener("PreferredIconSize", new PropertyChangeListener(){ + @Override + public void propertyChange(PropertyChangeEvent evt) + { + boolean useSmallIcon = true; + final Object prop = evt.getNewValue(); + if (prop instanceof Integer) { + if(((Integer)prop).intValue()==24) { + useSmallIcon = false; + } + } + if(useSmallIcon){ + dropDownButton.setIcon(run16); + }else { + dropDownButton.setIcon(run32); + } + } + }); + return dropDownButton; + } + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/VerticalSeparator.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/VerticalSeparator.java index 1061b8b..41b4d16 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/VerticalSeparator.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/VerticalSeparator.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.actions; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomCommandPopupAction.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomCommandPopupAction.java index defb6db..150b16f 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomCommandPopupAction.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomCommandPopupAction.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.dsnet.quickopener.actions.popup; import java.awt.Dimension; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomFileSystemPopupAction.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomFileSystemPopupAction.java index 373c687..71688ab 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomFileSystemPopupAction.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomFileSystemPopupAction.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.dsnet.quickopener.actions.popup; import com.sessonad.oscommands.commands.Commands; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomTerminalPopupAction.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomTerminalPopupAction.java index 5e91b04..3382c97 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomTerminalPopupAction.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/CustomTerminalPopupAction.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.dsnet.quickopener.actions.popup; import com.sessonad.oscommands.commands.Commands; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomCommandRun.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomCommandRun.java index ca21223..08987be 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomCommandRun.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomCommandRun.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.actions.popup; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomFileSystem.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomFileSystem.java index 0a50d14..7ec5a04 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomFileSystem.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomFileSystem.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.actions.popup; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomTerminal.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomTerminal.java index dc04a82..46ea4e9 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomTerminal.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogCustomTerminal.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.actions.popup; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogueFileSelector.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogueFileSelector.java index f7e760d..8e50e3d 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogueFileSelector.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/DialogueFileSelector.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.actions.popup; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/PropertyTableModel.java b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/PropertyTableModel.java index 75f045e..40d301c 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/PropertyTableModel.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/actions/popup/PropertyTableModel.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.actions.popup; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/CommandsPanel.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/CommandsPanel.java index 917ee67..a25b200 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/CommandsPanel.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/CommandsPanel.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.prefs; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.form b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.form index 302adbd..0a7cb2c 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.form +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.form @@ -33,7 +33,7 @@ - + @@ -46,12 +46,8 @@ - - - - - - + + @@ -76,13 +72,39 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -107,20 +129,27 @@ + + + + + + + + + + - + - - - - - - + + + - + @@ -262,5 +291,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.java index 5029050..4d36d38 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/GeneralPanel.java @@ -13,8 +13,12 @@ import javax.swing.JPanel; import javax.swing.JTextField; import me.dsnet.quickopener.QuickMessages; +import me.dsnet.quickopener.prefs.filemanager.IFileManagerConfigurator; +import me.dsnet.quickopener.prefs.filemanager.impl.CajaFileManagerConfigurator; +import me.dsnet.quickopener.prefs.filemanager.impl.SpaceFileManagerConfigurator; import me.dsnet.quickopener.prefs.shell.chooser.IShellConfigurator; import me.dsnet.quickopener.prefs.shell.chooser.impl.GitBashConfigurator; +import me.dsnet.quickopener.prefs.shell.chooser.impl.MateTerminalConfigurator; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; @@ -35,6 +39,8 @@ public GeneralPanel() { jLabel2.setText(customSeparator.getValue()); QuickOpenerProperty customShell=PrefsUtil.load(null,"customShell",null); cShellLabel.setText((customShell.getValue()==null)?"not defined":customShell.getValue()); + QuickOpenerProperty customFileManager=PrefsUtil.load(null,"customFileManager",null); + cFileManagerLabel.setText(customFileManager.getValue()==null ? "not defined" : customFileManager.getValue()); QuickOpenerProperty confirmation=PrefsUtil.load(null,"confirmationDialogue","true"); boolean isConfirmSelected = Boolean.parseBoolean(confirmation.getValue()); confirmationCheckBox.setSelected(isConfirmSelected); @@ -73,6 +79,12 @@ private void initComponents() { applyConfirmationButton = new javax.swing.JButton(); shellConfigureButton = new javax.swing.JButton(); resetButton = new javax.swing.JButton(); + applyCFileManagerButton = new javax.swing.JButton(); + fileManagerConfigureButton = new javax.swing.JButton(); + cFileManagerTextField = new javax.swing.JTextField(); + jLabel9 = new javax.swing.JLabel(); + cFileManagerLabel = new javax.swing.JLabel(); + jLabel10 = new javax.swing.JLabel(); org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel3.text")); // NOI18N @@ -142,6 +154,31 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); + org.openide.awt.Mnemonics.setLocalizedText(applyCFileManagerButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.applyCFileManagerButton.text")); // NOI18N + applyCFileManagerButton.setFocusable(false); + applyCFileManagerButton.setRequestFocusEnabled(false); + applyCFileManagerButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + applyCFileManagerButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(fileManagerConfigureButton, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.fileManagerConfigureButton.text")); // NOI18N + fileManagerConfigureButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + fileManagerConfigureButtonActionPerformed(evt); + } + }); + + cFileManagerTextField.setText(org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.cFileManagerTextField.text")); // NOI18N + + jLabel9.setLabelFor(cshellTextField); + org.openide.awt.Mnemonics.setLocalizedText(jLabel9, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel9.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(cFileManagerLabel, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.cFileManagerLabel.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel10, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel10.text")); // NOI18N + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -159,11 +196,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel5)) .addGroup(layout.createSequentialGroup() - .addComponent(jLabel7) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel8) - .addComponent(confirmationCheckBox, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addGap(258, 258, 258) + .addComponent(jLabel8))) .addGroup(layout.createSequentialGroup() .addComponent(jLabel6) .addGap(10, 10, 10) @@ -180,11 +214,32 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(applyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(applyCShellButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(applyConfirmationButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(applyCShellButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) - .addComponent(resetButton)))) + .addComponent(resetButton)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel7) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(confirmationCheckBox, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(193, 193, 193) + .addComponent(applyConfirmationButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(258, 258, 258) + .addComponent(jLabel9)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel10) + .addGap(10, 10, 10) + .addComponent(cFileManagerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cFileManagerTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(fileManagerConfigureButton) + .addGap(6, 6, 6) + .addComponent(applyCFileManagerButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -204,16 +259,23 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(applyCShellButton) .addComponent(shellConfigureButton) .addComponent(cshellTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel10) + .addComponent(cFileManagerLabel) + .addComponent(jLabel9) + .addComponent(applyCFileManagerButton) + .addComponent(fileManagerConfigureButton) + .addComponent(cFileManagerTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 3, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 5, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(applyConfirmationButton)) - .addGroup(layout.createSequentialGroup() - .addGap(7, 7, 7) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(confirmationCheckBox) - .addComponent(jLabel7)))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(confirmationCheckBox) + .addComponent(jLabel7))) + .addGap(18, 18, 18) .addComponent(resetButton)) ); }// //GEN-END:initComponents @@ -288,9 +350,47 @@ private void shellConfigureButtonActionPerformed(java.awt.event.ActionEvent evt) } }//GEN-LAST:event_shellConfigureButtonActionPerformed + private void applyCFileManagerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyCFileManagerButtonActionPerformed + String cFileManager = cFileManagerTextField.getText(); + if(cFileManager!=null && !cFileManager.isEmpty()){ + PrefsUtil.store("customFileManager" , cFileManager); + cFileManagerLabel.setText(cFileManager); + }else{ + NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.CUSTOM_FILEMANAGER,NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(d); + } + }//GEN-LAST:event_applyCFileManagerButtonActionPerformed + + private void fileManagerConfigureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileManagerConfigureButtonActionPerformed + JTextField fileManagerTextField = cFileManagerTextField; + + List labels = new ArrayList<>(); + for (IFileManagerConfigurator configurator : getAvailableFileManagerConfigurators()) { + if (configurator.isAvailable()) { + labels.add(configurator.getLabel()); + } + } + + final JList jList = new JList(labels.toArray(new String[labels.size()])); + JPanel form = new JPanel(new BorderLayout()); + form.add(jList, BorderLayout.CENTER); + form.add(new JLabel(Bundle.LBL_Form_Label()), BorderLayout.NORTH); + jList.setSelectedIndex(0); + DialogDescriptor dd = new DialogDescriptor(form, Bundle.LBL_Dialog()); + Object result = DialogDisplayer.getDefault().notify(dd); + if (result == NotifyDescriptor.OK_OPTION) { + IFileManagerConfigurator configurator = getAvailableFileManagerConfigurators().get(jList.getSelectedIndex()); + + String configure = configurator.configure(); + if (null != configure) { + fileManagerTextField.setText(configure); + } + } + }//GEN-LAST:event_fileManagerConfigureButtonActionPerformed + private List getAvailableConfigurators() { //TODO externalize the configuration of available configurators - List allconfigurators = Arrays.asList((IShellConfigurator) new GitBashConfigurator()); + List allconfigurators = Arrays.asList(new GitBashConfigurator(), new MateTerminalConfigurator()); List availableConfigurators = new ArrayList<>(); for (IShellConfigurator configurator : allconfigurators) { if (configurator.isAvailable()) { @@ -299,15 +399,32 @@ private List getAvailableConfigurators() { } return availableConfigurators; } + + private List getAvailableFileManagerConfigurators() { + //TODO externalize the configuration of available configurators + List allconfigurators = Arrays.asList(new CajaFileManagerConfigurator(), new SpaceFileManagerConfigurator()); + List availableConfigurators = new ArrayList<>(); + for (IFileManagerConfigurator configurator : allconfigurators) { + if (configurator.isAvailable()) { + availableConfigurators.add(configurator); + } + } + return availableConfigurators; + } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton applyButton; + private javax.swing.JButton applyCFileManagerButton; private javax.swing.JButton applyCShellButton; private javax.swing.JButton applyConfirmationButton; + private javax.swing.JLabel cFileManagerLabel; + private javax.swing.JTextField cFileManagerTextField; private javax.swing.JLabel cShellLabel; private javax.swing.JCheckBox confirmationCheckBox; private javax.swing.JTextField cshellTextField; + private javax.swing.JButton fileManagerConfigureButton; private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; @@ -315,6 +432,7 @@ private List getAvailableConfigurators() { private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; + private javax.swing.JLabel jLabel9; private javax.swing.JTextField jTextField1; private javax.swing.JButton resetButton; private javax.swing.JButton shellConfigureButton; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PlacesPanel.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PlacesPanel.java index e5466e1..decd62a 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PlacesPanel.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PlacesPanel.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.prefs; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PrefsUtil.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PrefsUtil.java index be31e64..28bbd9a 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PrefsUtil.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/PrefsUtil.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.prefs; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerOptionsPanelController.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerOptionsPanelController.java index ad37c39..f10162f 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerOptionsPanelController.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerOptionsPanelController.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.prefs; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerPanel.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerPanel.java index de2221a..9539429 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerPanel.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerPanel.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.prefs; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerProperty.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerProperty.java index ad0c0ef..2bfa131 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerProperty.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/QuickOpenerProperty.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.prefs; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/IFileManagerConfigurator.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/IFileManagerConfigurator.java new file mode 100644 index 0000000..ac9fb68 --- /dev/null +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/IFileManagerConfigurator.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.dsnet.quickopener.prefs.filemanager; + +/** + * Strategy the configuration of a custom shell + * + * @author javatlacati + */ +public interface IFileManagerConfigurator { + + /** + * Starts the configurator. In most cases this will open a set up dialog. + * + * @return shell command + */ + String configure(); + + /** + * + * @return description for showing in the UI + */ + String getLabel(); + + /** + * Allows a configurator to be available per OS-platform/installed program. + * + * @return true, if this configurator is available + */ + boolean isAvailable(); + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/impl/CajaFileManagerConfigurator.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/impl/CajaFileManagerConfigurator.java new file mode 100644 index 0000000..94f890d --- /dev/null +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/impl/CajaFileManagerConfigurator.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.dsnet.quickopener.prefs.filemanager.impl; + +import com.sessonad.oscommands.detector.OSDetector; +import java.io.File; +import javax.swing.JOptionPane; +import me.dsnet.quickopener.prefs.filemanager.IFileManagerConfigurator; +import org.openide.filesystems.FileChooserBuilder; +import org.openide.filesystems.FileUtil; +import org.openide.util.NbBundle; + +/** + * + * @author javatlacati + */ +@NbBundle.Messages({ + "CAJA_label=Caja", + "CAJA_ApproveTextBtn=Choose", + "CAJA_title=Choose the installation folder of '%s'", + "CAJA_exefile=%s%/usr/bin/caja", + "CAJA_exefilenotfound=Selected folder '%s' does not contain a caja installation.", + "CAJA_dir=caja", + "CAJA_command=%s%/usr/bin/caja", +}) +public class CajaFileManagerConfigurator implements IFileManagerConfigurator { + + @Override + public String configure() { + File dir; + dir = new FileChooserBuilder(Bundle.CAJA_dir()) + .setTitle(String.format(Bundle.CAJA_title(), getLabel())) + .setDirectoriesOnly(true) + .setSelectionApprover(new FileChooserBuilder.SelectionApprover() { + + @Override + public boolean approve(File[] files) { + if (null != files && files.length == 1) { + String absolutePath = FileUtil.normalizeFile(files[0]).getAbsolutePath(); + String exeFile = String.format(Bundle.CAJA_exefile(), absolutePath, File.separator); + final boolean exists = new File(exeFile).exists(); + if (!exists) { + JOptionPane.showMessageDialog(null, String.format(Bundle.CAJA_exefilenotfound(), absolutePath)); + } + return exists; + } + return false; + } + }) + .setApproveText(Bundle.CAJA_ApproveTextBtn()).showOpenDialog(); + + if (dir != null) { + return String.format(Bundle.CAJA_command(), FileUtil.normalizeFile(dir).getAbsolutePath(), File.separator); + } else { + return null; + } + } + + @Override + public String getLabel() { + return Bundle.CAJA_label(); + } + + @Override + public boolean isAvailable() { + return OSDetector.detectOS().isLinux(); + } +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/impl/SpaceFileManagerConfigurator.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/impl/SpaceFileManagerConfigurator.java new file mode 100644 index 0000000..7408379 --- /dev/null +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/filemanager/impl/SpaceFileManagerConfigurator.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.dsnet.quickopener.prefs.filemanager.impl; + +import com.sessonad.oscommands.detector.OSDetector; +import java.io.File; +import javax.swing.JOptionPane; +import me.dsnet.quickopener.prefs.filemanager.IFileManagerConfigurator; +import org.openide.filesystems.FileChooserBuilder; +import org.openide.filesystems.FileUtil; +import org.openide.util.NbBundle; + +/** + * + * @author javatlacati + */ +@NbBundle.Messages({ + "SPACEFM_label=SpaceFM", + "SPACEFM_ApproveTextBtn=Choose", + "SPACEFM_title=Choose the installation folder of '%s'", + "SPACEFM_exefile=%s%/usr/bin/spacefm", + "SPACEFM_exefilenotfound=Selected folder '%s' does not contain a caja installation.", + "SPACEFM_dir=spacefm", + "SPACEFM_command=%s%/usr/bin/spacefm", +}) +public class SpaceFileManagerConfigurator implements IFileManagerConfigurator{ + + @Override + public String configure() { + File dir; + dir = new FileChooserBuilder(Bundle.SPACEFM_dir()) + .setTitle(String.format(Bundle.SPACEFM_title(), getLabel())) + .setDirectoriesOnly(true) + .setSelectionApprover(new FileChooserBuilder.SelectionApprover() { + + @Override + public boolean approve(File[] files) { + if (null != files && files.length == 1) { + String absolutePath = FileUtil.normalizeFile(files[0]).getAbsolutePath(); + String exeFile = String.format(Bundle.SPACEFM_exefile(), absolutePath, File.separator); + final boolean exists = new File(exeFile).exists(); + if (!exists) { + JOptionPane.showMessageDialog(null, String.format(Bundle.SPACEFM_exefilenotfound(), absolutePath)); + } + return exists; + } + return false; + } + }) + .setApproveText(Bundle.SPACEFM_ApproveTextBtn()).showOpenDialog(); + + if (dir != null) { + return String.format(Bundle.SPACEFM_command(), FileUtil.normalizeFile(dir).getAbsolutePath(), File.separator); + } else { + return null; + } + } + + @Override + public String getLabel() { + return Bundle.SPACEFM_label(); + } + + @Override + public boolean isAvailable() { + return OSDetector.detectOS().isLinux(); + } + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/IShellConfigurator.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/IShellConfigurator.java index ad7a064..d5b5454 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/IShellConfigurator.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/IShellConfigurator.java @@ -1,35 +1,46 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package me.dsnet.quickopener.prefs.shell.chooser; - -/** - * Strategy the configuration of a custom shell - * - * @author markiewb - */ -public interface IShellConfigurator { - - /** - * Starts the configurator. In most cases this will open a set up dialog. - * - * @return shell command - */ - String configure(); - - /** - * - * @return description for showing in the UI - */ - String getLabel(); - - /** - * Allows a configurator to be available per OS-platform/installed program. - * - * @return true, if this configurator is available - */ - boolean isAvailable(); - -} +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.dsnet.quickopener.prefs.shell.chooser; + +/** + * Strategy the configuration of a custom shell + * + * @author markiewb + */ +public interface IShellConfigurator { + + /** + * Starts the configurator. In most cases this will open a set up dialog. + * + * @return shell command + */ + String configure(); + + /** + * + * @return description for showing in the UI + */ + String getLabel(); + + /** + * Allows a configurator to be available per OS-platform/installed program. + * + * @return true, if this configurator is available + */ + boolean isAvailable(); + +} diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/impl/GitBashConfigurator.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/impl/GitBashConfigurator.java index 2659e09..cb7d642 100644 --- a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/impl/GitBashConfigurator.java +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/impl/GitBashConfigurator.java @@ -1,7 +1,18 @@ /* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.dsnet.quickopener.prefs.shell.chooser.impl; diff --git a/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/impl/MateTerminalConfigurator.java b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/impl/MateTerminalConfigurator.java new file mode 100644 index 0000000..578befd --- /dev/null +++ b/QuickOpener/src/main/java/me/dsnet/quickopener/prefs/shell/chooser/impl/MateTerminalConfigurator.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.dsnet.quickopener.prefs.shell.chooser.impl; + +import com.sessonad.oscommands.detector.OSDetector; +import java.io.File; +import javax.swing.JOptionPane; +import me.dsnet.quickopener.prefs.shell.chooser.IShellConfigurator; +import org.openide.filesystems.FileChooserBuilder; +import org.openide.filesystems.FileUtil; +import org.openide.util.NbBundle; + +/** + * + * @author javatlacati + */ +@NbBundle.Messages({ + "MATETERMINAL_dir=mate-terminal", + "MATETERMINAL_ApproveTextBtn=Choose", + "MATETERMINAL_title=Choose the installation folder of '%s'", + "MATETERMINAL_exefile=%s%/usr/bin/mate-terminal", + "MATETERMINAL_exefilenotfound=Selected folder '%s' does not contain a mate-terminal installation.", + "MATETERMINAL_command=%s%/usr/bin/mate-terminal", + "MATETERMINAL_label=mate-terminal" +}) +public class MateTerminalConfigurator implements IShellConfigurator{ + + @Override + public String configure() { + File dir; + dir = new FileChooserBuilder(Bundle.MATETERMINAL_dir()) + .setTitle(String.format(Bundle.MATETERMINAL_title(), getLabel())) + .setDirectoriesOnly(true) + .setSelectionApprover(new FileChooserBuilder.SelectionApprover() { + + @Override + public boolean approve(File[] files) { + if (null != files && files.length == 1) { + String absolutePath = FileUtil.normalizeFile(files[0]).getAbsolutePath(); + String exeFile = String.format(Bundle.MATETERMINAL_exefile(), absolutePath, File.separator); + final boolean exists = new File(exeFile).exists(); + if (!exists) { + JOptionPane.showMessageDialog(null, String.format(Bundle.MATETERMINAL_exefilenotfound(), absolutePath)); + } + return exists; + } + return false; + } + }) + .setApproveText(Bundle.MATETERMINAL_ApproveTextBtn()).showOpenDialog(); + + if (dir != null) { + return String.format(Bundle.MATETERMINAL_command(), FileUtil.normalizeFile(dir).getAbsolutePath(), File.separator); + } else { + return null; + } + } + + @Override + public String getLabel() { + return Bundle.MATETERMINAL_label(); + } + + @Override + public boolean isAvailable() { + return OSDetector.detectOS().isLinux(); + } + +} diff --git a/QuickOpener/src/main/resources/me/dsnet/quickopener/prefs/Bundle.properties b/QuickOpener/src/main/resources/me/dsnet/quickopener/prefs/Bundle.properties index c49f84d..f692d05 100644 --- a/QuickOpener/src/main/resources/me/dsnet/quickopener/prefs/Bundle.properties +++ b/QuickOpener/src/main/resources/me/dsnet/quickopener/prefs/Bundle.properties @@ -1,36 +1,42 @@ -PlacesPanel.jButton5.text=De&lete All -PlacesPanel.jButton3.text=&Delete -PlacesPanel.addFolderButton.text=&Add -PlacesPanel.favoritePathTextField.text= -PlacesPanel.jLabel3.text=&Path: -PlacesPanel.folderDescriptionTextField.text= -PlacesPanel.jLabel2.text=De&scription: -CommandsPanel.jLabel1.text=&Description: -CommandsPanel.jLabel5.text=(for this OS is '') -CommandsPanel.jCheckBox1.text=Add p&refix -CommandsPanel.jButton2.text=De&lete -CommandsPanel.jLabel4.text=&Command: -CommandsPanel.jButton1.text=&Add -CommandsPanel.cmddescription.text= -CommandsPanel.cmdvalue.text= -CommandsPanel.jButton1.toolTipText=Add or modify the command -PlacesPanel.addFolderButton.toolTipText=Add or modify place -GeneralPanel.jLabel1.text=Path separator: -GeneralPanel.jLabel2.text=\\ -GeneralPanel.jLabel3.text=jLabel3 -GeneralPanel.jLabel4.text=jLabel4 -GeneralPanel.jTextField1.text= -GeneralPanel.jLabel5.text=&Custom: -GeneralPanel.applyButton.text=&Apply -GeneralPanel.jLabel6.text=Custom shell: -GeneralPanel.jLabel8.text=C&ustom: -GeneralPanel.cshellTextField.text= -GeneralPanel.applyCShellButton.text=A&pply -GeneralPanel.cShellLabel.text=not defined -GeneralPanel.jLabel7.text=Confirmation on &default command: -GeneralPanel.applyConfirmationButton.text=App&ly -GeneralPanel.confirmationCheckBox.text= -QuickOpenerPanel.jLabel1.text=Categor&y: -GeneralPanel.shellConfigureButton.text=C&onfigure... -GeneralPanel.resetButton.text=&Reset to defaults -CommandsPanel.btnPlaceholders.text=&Placeholders... +PlacesPanel.jButton5.text=De&lete All +PlacesPanel.jButton3.text=&Delete +PlacesPanel.addFolderButton.text=&Add +PlacesPanel.favoritePathTextField.text= +PlacesPanel.jLabel3.text=&Path: +PlacesPanel.folderDescriptionTextField.text= +PlacesPanel.jLabel2.text=De&scription: +CommandsPanel.jLabel1.text=&Description: +CommandsPanel.jLabel5.text=(for this OS is '') +CommandsPanel.jCheckBox1.text=Add p&refix +CommandsPanel.jButton2.text=De&lete +CommandsPanel.jLabel4.text=&Command: +CommandsPanel.jButton1.text=&Add +CommandsPanel.cmddescription.text= +CommandsPanel.cmdvalue.text= +CommandsPanel.jButton1.toolTipText=Add or modify the command +PlacesPanel.addFolderButton.toolTipText=Add or modify place +GeneralPanel.jLabel1.text=Path separator: +GeneralPanel.jLabel2.text=\\ +GeneralPanel.jLabel3.text=jLabel3 +GeneralPanel.jLabel4.text=jLabel4 +GeneralPanel.jTextField1.text= +GeneralPanel.jLabel5.text=&Custom: +GeneralPanel.applyButton.text=&Apply +GeneralPanel.jLabel6.text=Custom shell: +GeneralPanel.jLabel8.text=C&ustom: +GeneralPanel.cshellTextField.text= +GeneralPanel.applyCShellButton.text=A&pply +GeneralPanel.cShellLabel.text=not defined +GeneralPanel.jLabel7.text=Confirmation on &default command: +GeneralPanel.applyConfirmationButton.text=App&ly +GeneralPanel.confirmationCheckBox.text= +QuickOpenerPanel.jLabel1.text=Categor&y: +GeneralPanel.shellConfigureButton.text=C&onfigure... +GeneralPanel.resetButton.text=&Reset to defaults +CommandsPanel.btnPlaceholders.text=&Placeholders... +GeneralPanel.jLabel10.text=Custom file manager: +GeneralPanel.jLabel9.text=C&ustom: +GeneralPanel.cFileManagerLabel.text=not defined +GeneralPanel.cFileManagerTextField.text= +GeneralPanel.applyCFileManagerButton.text=A&pply +GeneralPanel.fileManagerConfigureButton.text=C&onfigure...