Example usage for org.apache.commons.lang SystemUtils IS_OS_MAC_OSX

List of usage examples for org.apache.commons.lang SystemUtils IS_OS_MAC_OSX

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils IS_OS_MAC_OSX.

Prototype

boolean IS_OS_MAC_OSX

To view the source code for org.apache.commons.lang SystemUtils IS_OS_MAC_OSX.

Click Source Link

Document

Is true if this is Mac.

The field will return false if OS_NAME is null.

Usage

From source file:phex.gui.tabs.library.LibraryTab.java

private JPanel createTreePanel(MouseHandler mouseHandler) {
    JPanel panel = new JPanel();
    CellConstraints cc = new CellConstraints();
    FormLayout layout = new FormLayout("fill:d:grow", // columns
            "fill:d:grow, 1dlu, p"); //rows
    PanelBuilder tabBuilder = new PanelBuilder(layout, panel);

    sharingTreeModel = new SharingTreeModel();
    mainTree = new JTree(sharingTreeModel);
    mainTree.setMinimumSize(new Dimension(0, 0));
    mainTree.setRowHeight(0);//  ww  w.  ja  v  a2 s. c o  m
    mainTree.setCellRenderer(new SharingTreeRenderer());
    mainTree.addMouseListener(mouseHandler);

    mainTree.getSelectionModel().addTreeSelectionListener(new SelectionHandler());
    ToolTipManager.sharedInstance().registerComponent(mainTree);

    // open up first level of nodes
    TreeNode root = (TreeNode) sharingTreeModel.getRoot();
    int count = root.getChildCount();
    for (int i = 0; i < count; i++) {
        mainTree.expandPath(new TreePath(new Object[] { root, root.getChildAt(i) }));
    }

    JScrollPane treeScrollPane = new JScrollPane(mainTree);
    tabBuilder.add(treeScrollPane, cc.xywh(1, 1, 1, 1));

    FWToolBar shareToolbar = new FWToolBar(FWToolBar.HORIZONTAL);
    shareToolbar.setBorderPainted(false);
    shareToolbar.setFloatable(false);
    tabBuilder.add(shareToolbar, cc.xy(1, 3));

    FWAction action = new AddShareFolderAction();
    addTabAction(ADD_SHARE_FOLDER_ACTION_KEY, action);
    shareToolbar.addAction(action);

    action = new RemoveShareFolderAction();
    addTabAction(REMOVE_SHARE_FOLDER_ACTION_KEY, action);
    shareToolbar.addAction(action);

    if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) {
        action = new ExploreFolderAction();
        addTabAction(EXPLORE_FOLDER_ACTION_KEY, action);
    }

    return panel;
}

From source file:phex.gui.tabs.library.LibraryTreePane.java

private void prepareComponent() {
    CellConstraints cc = new CellConstraints();
    FormLayout layout = new FormLayout("fill:d:grow", // columns
            "fill:d:grow, 1dlu, p"); //rows
    PanelBuilder tabBuilder = new PanelBuilder(layout, this);

    sharingTreeModel = new SharingTreeModel();
    mainTree = new JTree(sharingTreeModel);
    mainTree.setMinimumSize(new Dimension(0, 0));
    mainTree.setRowHeight(0);/* www .j  a va  2 s. co m*/
    mainTree.setCellRenderer(new SharingTreeRenderer());
    mainTree.addMouseListener(new MouseHandler());

    mainTree.getSelectionModel().addTreeSelectionListener(new SelectionHandler());
    ToolTipManager.sharedInstance().registerComponent(mainTree);

    // open up first level of nodes
    TreeNode root = (TreeNode) sharingTreeModel.getRoot();
    int count = root.getChildCount();
    for (int i = 0; i < count; i++) {
        mainTree.expandPath(new TreePath(new Object[] { root, root.getChildAt(i) }));
    }

    JScrollPane treeScrollPane = new JScrollPane(mainTree);
    tabBuilder.add(treeScrollPane, cc.xywh(1, 1, 1, 1));

    FWToolBar shareToolbar = new FWToolBar(FWToolBar.HORIZONTAL);
    shareToolbar.setBorderPainted(false);
    shareToolbar.setFloatable(false);
    tabBuilder.add(shareToolbar, cc.xy(1, 3));

    addShareFolderAction = new AddShareFolderAction();
    shareToolbar.addAction(addShareFolderAction);

    removeShareFolderAction = new RemoveShareFolderAction();
    shareToolbar.addAction(removeShareFolderAction);

    if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) {
        exploreFolderAction = new ExploreFolderAction();
    }

    fileTreePopup = new FWPopupMenu();
    fileTreePopup.addAction(addShareFolderAction);
    fileTreePopup.addAction(removeShareFolderAction);

    if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) {
        fileTreePopup.addAction(exploreFolderAction);
    }
}

From source file:phex.update.UpdateDownloader.java

public static void createUpdateDownload() throws URIException {
    String uriStr;/*from w  w  w .java 2 s .co  m*/

    if (SystemUtils.IS_OS_MAC_OSX) {
        uriStr = UpdatePrefs.UPDATE_URI_MAC_OSX;
    } else if (SystemUtils.IS_OS_WINDOWS) {
        uriStr = UpdatePrefs.UPDATE_URI_WINDOWS;
    } else {
        uriStr = UpdatePrefs.UPDATE_URI_OTHER;
    }
    createDownload(uriStr);
}

From source file:phex.utils.SystemProperties.java

private static File initPhexConfigRoot() {
    // to prevent problems wait with assigning userPath...
    String tmpUserPath = System.getProperty(PHEX_CONFIG_PATH_SYSPROP);
    if (StringUtils.isEmpty(tmpUserPath)) {
        if (SystemUtils.IS_OS_WINDOWS) {
            String appDataEnv = System.getenv("APPDATA");
            if (StringUtils.isEmpty(appDataEnv)) {
                tmpUserPath = System.getProperty("user.home") + File.separator + "Application Data";
            }/*from  www  .j  ava  2  s .c  o  m*/
            // I2P:
            // Avoid interference with Phex by having a differently named config directory.
            tmpUserPath = appDataEnv + File.separator + "I2Phex" + File.separator;
        } else if (SystemUtils.IS_OS_MAC_OSX) {
            tmpUserPath = System.getProperty("user.home") + File.separator + "Library" + File.separator
                    + "Application Support";
            // I2P:
            // Avoid interference with Phex by having a differently named config directory.
            tmpUserPath = tmpUserPath + File.separator + "I2Phex" + File.separator;
        } else {
            // I2P:
            // Avoid interference with Phex by having a differently named config directory.
            tmpUserPath = System.getProperty("user.home") + File.separator + ".i2phex" + File.separator;
        }
    } else {
        if (!tmpUserPath.endsWith(File.separator)) {
            tmpUserPath = tmpUserPath + File.separator;
        }
    }
    File dir = new File(tmpUserPath);
    return dir;
}

From source file:phex.utils.SystemShellExecute.java

public static void exploreFolder(File dir) throws IOException {
    String path;/*from  w  ww.j  a  va 2  s.  co  m*/
    try {
        path = dir.getCanonicalPath();
    } catch (IOException ioe) {
        path = dir.getPath();
    }

    String command = null;
    if (SystemUtils.IS_OS_WINDOWS) {
        command = "explorer";
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        command = "open";
    }
    if (command == null) {
        return;
    }
    String[] cmdArr = new String[] { command, path };
    Runtime.getRuntime().exec(cmdArr);
}

From source file:phex.utils.SystemShellExecute.java

public static void launchFile(File file) throws IOException {
    String path;//w w w .  j  a va2s .co  m
    try {
        path = file.getCanonicalPath();
    } catch (IOException ioe) {
        path = file.getPath();
    }

    if (SystemUtils.IS_OS_WINDOWS) {
        WindowsShellExecute.executeViaShell(path);
        return;
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        String command = "open";
        String[] cmdArr = new String[] { command, path };
        Runtime.getRuntime().exec(cmdArr);
        return;
    } else {
        launchOtherOsFile(path);
    }
}

From source file:program.RunProgram.java

public static boolean isExecutableFound(workflow_properties prop) {

    if (config.getBoolean("UseAlternative")) {
        //-CASE Alternative
        String executable = prop.getAlternative();
        if (!prop.isSet("AlternativeExecutable") || executable.equals(""))
            return false;
        return (Util.FileExists(executable));
    }/*  ww  w.j a  va  2 s. c o  m*/
    //--CASE WebServices  or internal application (java code)
    if (prop.getBoolean("WebServices") || prop.getBoolean("InternalArmadilloApplication")) {
        return true;
    } else if (SystemUtils.IS_OS_WINDOWS) {
        //--Windows
        String executable = prop.getExecutable();
        if (!prop.isSet("Executable") || executable.equals(""))
            return false;
        return (Util.FileExists(executable));
    } else if (config.getBoolean("MacOSX") || SystemUtils.IS_OS_MAC_OSX) {
        //--CASE MAC OS X
        String executable = prop.getExecutableMacOSX();
        if (!prop.isSet("ExecutableMacOSX") || executable.equals(""))
            return false;
        return (Util.FileExists(executable));
    } else if (config.getBoolean("Linux") || SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_UNIX) {
        //--CASE Linux?
        String executable = prop.getExecutableLinux();
        if (!prop.isSet("ExecutableLinux") || executable.equals(""))
            return false;
        return (Util.FileExists(executable));
    }

    return false;
}

From source file:program.RunProgram.java

public String[] updateCommandLine(String[] cli) {
    //--Note: 50 is arbitrary number large enough...
    String[] command = new String[50];
    //--Initialization
    for (int i = 0; i < 50; i++) {
        if (i < cli.length) {
            command[i] = cli[i];/*from w w  w . j  av a 2 s.  c o m*/
        } else
            command[i] = "";
    }

    //--CASE 1. MacOSX (Warning, 1st because MAC_OSX is Linux (lol)
    if (config.getBoolean("MacOSX") || SystemUtils.IS_OS_MAC_OSX) {
        if (command[0].equalsIgnoreCase("cmd.exe"))
            for (int i = 0; i < command.length - 2; i++)
                command[i] = command[i + 2];

        //--Hack
        if (command[0].equalsIgnoreCase("java")) {
            //--Any extra command?
            //--We locate the good spot
            if (command[2].startsWith("-Xmx") || command[2].startsWith("-classpath")) {
                command[3] = properties.getExecutableMacOSX();
            } else {
                command[2] = properties.getExecutableMacOSX();
            }
        } else {
            command[0] = properties.getExecutableMacOSX();
        }
        // return command;
    } else if (config.getBoolean("Linux") || SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_UNIX) {
        //--or CASE 2.Linux?
        //--Test if we included the cmd.exe /C
        if (command[0].equalsIgnoreCase("cmd.exe"))
            for (int i = 0; i < command.length - 2; i++)
                command[i] = command[i + 2];
        //--Hack
        //--Hack
        if (command[0].equalsIgnoreCase("java")) {
            command[2] = properties.getExecutableLinux();
        } else {
            command[0] = properties.getExecutableLinux();
        }
    }

    //--Change the - to -- if found...
    //               for (int i=0; i<command.length;i++) {
    //                   if (command[i].startsWith("-")) command[i]="-"+command[i];
    //               }

    //--CASE 3. Use Alternative^
    if (properties.getBoolean("UseAlternative")) {
        command[0] = properties.getAlternative();
    }

    // Finally return the command
    return command;
}

From source file:program.RunProgram.java

/**
 * This is the the actual run of the program
 * 1-Execute in the thread the commandline
 * 2-Catch both stderr and stdout//from  www . ja  v a2  s .  c  o  m
 * 3-Put the program ExitValue in properties->ExitValue
 * 4-Put  both stderr and stdout in the output vector and in the "output"properties
 * @throws Exception
 */
public boolean do_run() throws Exception {

    setStatus(status_running, "\tRunning program...");
    setStatus(status_running, "<-Program Output->");
    //--Run the thread and catch stdout and stderr
    if (Docker.isProgramUseDocker(properties) && Docker.isDockerHere()) {
        Docker.executeBashFile(properties);
        setStatus(status_running, properties.get("DockerSTD"));
        String s = properties.get("DockerSTD");
        s = s.toLowerCase();
        Pattern p = Pattern.compile(".*exit is -(\\d+)-.*");
        Matcher m = p.matcher(s);
        //Util.dm(m.toString());
        int i = -1;
        if (m.find()) {
            i = Integer.parseInt(m.group(1));
        }
        Util.dm("Docker exit value is >" + Integer.toString(i) + "<");
        properties.put("ExitValue", i);
    } else {
        ProcessBuilder pb = new ProcessBuilder(commandline);
        if (properties.isSet("RunningDirectory")) {
            pb.directory(new File(properties.get("RunningDirectory")));
        }

        r = Runtime.getRuntime();
        //--Test August 2011 - For Mac OS X
        if ((config.getBoolean("MacOSX") || SystemUtils.IS_OS_MAC_OSX)) {
            if (properties.isSet("RuntimeMacOSX")) {
                String execution_type = properties.get("RuntimeMacOSX");
                //--Default
                if (execution_type.startsWith("default")) {
                    //? Not suppose to exists...
                    p = pb.start();
                }
                //--Runtime (r.exec)
                if (execution_type.startsWith("runtime")) {
                    //--IF MAC_OSX, group option if UseRuntimeMacOSX
                    String cmdm = Util.toString(commandline);
                    cmdm = Util.replaceMultiSpacesByOne(cmdm);
                    cmdm = Util.removeTrailingSpace(cmdm);
                    /*
                    for (int i=0; i<commandline.length;i++) {
                    if (!commandline[i].equals(""))
                        cmdm+=commandline[i]+" ";
                    }
                    commandline=new String[1];
                    commandline[0]=cmdm;
                    */
                    p = r.exec(cmdm);
                }
                //--Bash...
                if (execution_type.startsWith("bash (.sh)")) {
                    //--Create a new bash file
                    Util u = new Util("RunProgram.sh");
                    u.println("#!/bin/sh");
                    u.println("echo \"Executing by bash command: " + properties.getName() + "\"");
                    u.println(Util.toString(commandline));
                    //--Return the application error code
                    u.println("exit $?");
                    u.close();
                    p = r.exec("sh RunProgram.sh");
                }
            } //--End RuntimeMacOSX
              //--Run time
            else {
                //--Create a new bash file
                Util u = new Util("RunProgram.sh");
                u.println("#!/bin/sh");
                u.println("echo \"Executing by bash command: " + properties.getName() + "\"");
                u.println(Util.toString(commandline));
                //--Return the application error code
                u.println("exit $?");
                u.close();
                p = r.exec("sh RunProgram.sh");
            }
        } else if ((config.getBoolean("Linux") || SystemUtils.IS_OS_LINUX)) {
            //                Util u = new Util("RunProgram"+Util.returnTimeCode()+".sh");
            //                u.println("#!/bin/sh");
            //                u.println("echo \"Executing by bash command: "+properties.getName()+"\"");
            //                u.println(Util.toString(commandline));
            //                //--Return the application error code
            //                u.println("exit $?");
            //                u.close();
            //                p=r.exec("sh "+u.log_filename);
            //                Util.deleteFile(u.log_filename);
            String cli = Util.toString(commandline).replace("\\s+", " ");
            p = r.exec(cli); // JG 2015
        } else {
            p = pb.start();
        }

        //pb.redirectErrorStream(true)
        InputStreamThread stderr = new InputStreamThread(p.getErrorStream());
        InputStreamThread stdout = new InputStreamThread(p.getInputStream());

        int exitvalue = p.waitFor();

        //--Wait for the exitValue
        properties.put("ExitValue", exitvalue);
    }
    return true;
}

From source file:program.RunProgram.java

/**
 * This is the the actual run of the program
 * 1-Execute in the thread the commandline
 * 2-Catch both stderr and stdout/*from  ww  w  .  j  a v  a  2s . c om*/
 * 3-Put the program exitValue in properties->exitValue
 * 4-Put  both stderr and stdout in the output vector and in the "output"properties
 * @throws Exception
 */
public boolean do_run_withoutWait() throws Exception {
    //--Run the thread and catch stdout and stderr
    //--Use alternative?

    r = Runtime.getRuntime();
    if (config.getBoolean("MacOSX") || SystemUtils.IS_OS_MAC_OSX) {
        //--Test August 2011 - For Mac OS X
        if (properties.isSet("RuntimeMacOSX")) {
            String execution_type = properties.get("RuntimeMacOSX");
            //--Runtime (r.exec)
            if (execution_type.startsWith("runtime")) {
                //System.out.println("Running by runtime...");
                //--IF MAC_OSX, group option if UseRuntimeMacOSX
                String cmdm = Util.toString(commandline);
                cmdm = Util.replaceMultiSpacesByOne(cmdm);
                cmdm = Util.removeTrailingSpace(cmdm);
                /*
                for (int i=0; i<commandline.length;i++) {
                cmdm+=commandline[i]+" ";
                }
                commandline=new String[1];
                commandline[0]=cmdm;
                */
                p = r.exec(cmdm);
            }

            //--Bash...
            if (execution_type.startsWith("bash (.sh)")) {
                //System.out.println("Running from bash...");
                //--Create a new bash file
                Util u = new Util("RunProgram.sh");
                u.println("#!/bin/sh");
                u.println("echo \"Executing by bash command: " + properties.getName() + "\"");
                u.println(Util.toString(commandline));
                //--Return the application error code
                u.println("exit $?");
                u.close();
                p = r.exec("sh RunProgram.sh");
            }
        } //--End RuntimeMacOSX
    } else {
        p = r.exec(commandline);
    }

    InputStreamThread stderr = new InputStreamThread(p.getErrorStream());
    InputStreamThread stdout = new InputStreamThread(p.getInputStream());

    //--Wait for the exitValue
    properties.put("ExitValue", 0);
    return true;
}