{"id":1771,"date":"2015-01-09T00:39:14","date_gmt":"2015-01-08T23:39:14","guid":{"rendered":"http:\/\/www.jensd.de\/wordpress\/?p=1771"},"modified":"2015-01-09T00:39:14","modified_gmt":"2015-01-08T23:39:14","slug":"shichimifx-1-0-4-released","status":"publish","type":"post","link":"https:\/\/www.jensd.de\/wordpress\/?p=1771","title":{"rendered":"ShichimiFX 1.0.4 released"},"content":{"rendered":"<p>I have released ShichimiFX 1.0.4.<\/p>\n<p>Get the code from my <a title=\"Bitbucket Repo\" href=\"https:\/\/bitbucket.org\/Jerady\/shichimifx\" target=\"_blank\">ShichimiFX Bitbucket Repo<\/a><\/p>\n<p><strong>Maven<\/strong><br \/>\n[xml]<br \/>\n<dependency><br \/>\n  <groupId>de.jensd<\/groupId><br \/>\n  <artifactId>shichimifx<\/artifactId><br \/>\n  <version>1.0.4<\/version><br \/>\n<\/dependency><br \/>\n[\/xml]<\/p>\n<p>This release contains 2 new utility classes I needed for <a href=\"http:\/\/mqttfx.org\" title=\"http:\/\/mqttfx.org\" target=\"_blank\">MQTT.fx<\/a>&#8216;s script editing function <code><strong>Desktop<\/strong><\/code> and <code><strong>Shell<\/strong><\/code>.<\/p>\n<p>By now I used to open a script for editing with the system default editor via <code><strong>java.awt.Desktop<\/strong><\/code>. So far this works well on my Mac but there were issues on Windows and Linux. To get rid of these issues I create my own <code><strong>Desktop<\/strong><\/code> class to open the script directly with the system shell:<\/p>\n<p><code><strong>Desktop<\/strong><\/code><br \/>\n[java]<br \/>\npublic class Desktop {<\/p>\n<p>    public static boolean edit(String fileToEdit) {<br \/>\n        return openWithSystem(fileToEdit);<br \/>\n    }<\/p>\n<p>    private static boolean openWithSystem(String fileToOpen) {<br \/>\n        if (OS.isLinux()) {<br \/>\n            if (Shell.canOpen(&#8220;gnome-open&#8221;, fileToOpen)) {<br \/>\n                return true;<br \/>\n            } else if (Shell.canOpen(&#8220;kde-open&#8221;, fileToOpen)) {<br \/>\n                return true;<br \/>\n            } else if (Shell.canOpen(&#8220;xdg-open&#8221;, fileToOpen)) {<br \/>\n                return true;<br \/>\n            }<br \/>\n        } else if (OS.isWindows()) {<br \/>\n            if (Shell.canOpen(&#8220;explorer&#8221;, fileToOpen)) {<br \/>\n                return true;<br \/>\n            }<br \/>\n        } else if (OS.isMac()) {<br \/>\n            if (Shell.canOpen(&#8220;open&#8221;, fileToOpen)) {<br \/>\n                return true;<br \/>\n            }<br \/>\n        }<br \/>\n        return false;<br \/>\n    }<br \/>\n}<br \/>\n[\/java]<\/p>\n<p><code><strong>Shell<\/strong><\/code><br \/>\n[java]<br \/>\npublic class Shell {<\/p>\n<p>    public static boolean canOpen(String&#8230; command) {<br \/>\n        try {<br \/>\n            ProcessBuilder builder = new ProcessBuilder(command);<br \/>\n            Process process = builder.directory(new File(System.getProperty(&#8220;user.home&#8221;))).start();<br \/>\n            if (process == null) {<br \/>\n                return false;<br \/>\n            }<br \/>\n            try {<br \/>\n                process.exitValue();<br \/>\n                \/\/ if this does not throw an IllegalThreadStateException the process is not running\/has exited immediately<br \/>\n                return false;<br \/>\n            } catch (IllegalThreadStateException e) {<br \/>\n                \/\/ the process seems to be in a running state<br \/>\n                return true;<br \/>\n            }<br \/>\n        } catch (IOException ex) {<br \/>\n            return false;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static List<String> prepareOpenFileLine(String command, String fileToOpen) {<br \/>\n        List<String> commandList = new ArrayList<>();<br \/>\n        for (String s : command.split(&#8221; &#8220;)) {<br \/>\n            commandList.add(s.trim());<br \/>\n        }<br \/>\n        commandList.add(fileToOpen);<br \/>\n        return commandList;<br \/>\n    }<\/p>\n<p>    public static Optional<Process> execute(List<String> command) throws IOException {<br \/>\n        return execute(new File(System.getProperty(&#8220;user.home&#8221;)), command);<br \/>\n    }<\/p>\n<p>    public static Optional<Process> execute(File directory, String&#8230; command) throws IOException {<br \/>\n        return execute(directory, Arrays.asList(command));<br \/>\n    }<\/p>\n<p>    public static Optional<Process> execute(String&#8230; command) throws IOException {<br \/>\n        return Shell.execute(new File(System.getProperty(&#8220;user.home&#8221;)), command);<br \/>\n    }<\/p>\n<p>    public static Optional<Process> execute(File directory, List<String> command) throws IOException {<br \/>\n        ProcessBuilder builder = new ProcessBuilder(command);<br \/>\n        Process process = builder.directory(directory).start();<br \/>\n        return Optional.of(process);<br \/>\n    }<br \/>\n}<br \/>\n[\/java]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have released ShichimiFX 1.0.4. Get the code from my ShichimiFX Bitbucket Repo Maven [xml] de.jensd shichimifx 1.0.4 [\/xml] This release contains 2 new utility classes I needed for MQTT.fx&#8216;s script editing function Desktop and Shell. By now I used to open a script for editing with the system default editor via java.awt.Desktop. So far&hellip; <span class=\"clear\"><\/span><a href=\"https:\/\/www.jensd.de\/wordpress\/?p=1771\" class=\"more-link read-more\" rel=\"bookmark\">Continue Reading <span class=\"screen-reader-text\">ShichimiFX 1.0.4 released<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"footnotes":"","_jetpack_memberships_contains_paid_content":false,"jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[12,52,9,4,49],"tags":[77,108,80,76,63,105],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p38FCL-sz","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1771"}],"collection":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1771"}],"version-history":[{"count":5,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1771\/revisions"}],"predecessor-version":[{"id":1776,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1771\/revisions\/1776"}],"wp:attachment":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}