File tree 1 file changed +20
-14
lines changed
src/main/java/ai/nets/samj/gui/tools 1 file changed +20
-14
lines changed Original file line number Diff line number Diff line change 20
20
package ai .nets .samj .gui .tools ;
21
21
22
22
import java .awt .Desktop ;
23
- import java .net .URL ;
23
+ import java .net .URI ;
24
+ import java .net .URISyntaxException ;
25
+ import java .io .IOException ;
24
26
25
27
/**
26
28
* Class that contains helper tools for SAMJ
27
29
* @author Daniel Sage
28
30
* @author Carlos Garcia
31
+ * @author Vladimir Ulman
29
32
*/
30
33
public class Tools {
34
+ public static final String URL_WITH_DEFAULT_IJ_HELP = "https://github.com/segment-anything-models-java/SAMJ-IJ" ;
31
35
32
36
/**
33
- * Method that opens a website where there is some documentation about SAMJ
34
- * @return true if the method was able to access the website or false otherwise
37
+ * Opens user's default desktop web browser on the given 'url'.
35
38
*/
36
- static public boolean help () {
37
- String url = "https://github.com/segment-anything-models-java/SAMJ-IJ" ;
38
- Desktop desktop = Desktop .isDesktopSupported () ? Desktop .getDesktop () : null ;
39
- if (desktop != null && desktop .isSupported (Desktop .Action .BROWSE )) {
40
- try {
41
- desktop .browse (new URL (url ).toURI ());
42
- return true ;
39
+ public static void openUrlInWebBrowser (final String url ) {
40
+ final String myOS = System .getProperty ("os.name" ).toLowerCase ();
41
+ try {
42
+ if (myOS .contains ("mac" )) {
43
+ Runtime .getRuntime ().exec ("open " +url );
43
44
}
44
- catch ( Exception e ) {
45
- e . printStackTrace ( );
45
+ else if ( myOS . contains ( "nux" ) || myOS . contains ( "nix" ) ) {
46
+ Runtime . getRuntime (). exec ( "xdg-open " + url );
46
47
}
47
- }
48
- return false ;
48
+ else if (Desktop .isDesktopSupported ()) {
49
+ Desktop .getDesktop ().browse (new URI (url ));
50
+ }
51
+ else {
52
+ System .out .println ("Please, open this URL yourself: " +url );
53
+ }
54
+ } catch (IOException | URISyntaxException ignored ) {}
49
55
}
50
56
}
You can’t perform that action at this time.
0 commit comments