Example usage for org.apache.commons.lang3 SystemUtils IS_OS_MAC

List of usage examples for org.apache.commons.lang3 SystemUtils IS_OS_MAC

Introduction

In this page you can find the example usage for org.apache.commons.lang3 SystemUtils IS_OS_MAC.

Prototype

boolean IS_OS_MAC

To view the source code for org.apache.commons.lang3 SystemUtils IS_OS_MAC.

Click Source Link

Document

Is true if this is Mac.

Usage

From source file:com.willwinder.universalgcodesender.ExperimentalWindow.java

/**
 * @param args the command line arguments
 */// ww  w.  j ava  2s. c  om
public static void main(String args[]) {

    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* 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(ExperimentalWindow.class.getName())
                .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName())
                .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName())
                .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName())
                .log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    // Fix look and feel to use CMD+C/X/V/A instead of CTRL
    if (SystemUtils.IS_OS_MAC) {
        Collection<InputMap> ims = new ArrayList<>();
        ims.add((InputMap) UIManager.get("TextField.focusInputMap"));
        ims.add((InputMap) UIManager.get("TextArea.focusInputMap"));
        ims.add((InputMap) UIManager.get("EditorPane.focusInputMap"));
        ims.add((InputMap) UIManager.get("FormattedTextField.focusInputMap"));
        ims.add((InputMap) UIManager.get("PasswordField.focusInputMap"));
        ims.add((InputMap) UIManager.get("TextPane.focusInputMap"));

        int c = KeyEvent.VK_C;
        int v = KeyEvent.VK_V;
        int x = KeyEvent.VK_X;
        int a = KeyEvent.VK_A;
        int meta = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

        for (InputMap im : ims) {
            im.put(KeyStroke.getKeyStroke(c, meta), DefaultEditorKit.copyAction);
            im.put(KeyStroke.getKeyStroke(v, meta), DefaultEditorKit.pasteAction);
            im.put(KeyStroke.getKeyStroke(x, meta), DefaultEditorKit.cutAction);
            im.put(KeyStroke.getKeyStroke(a, meta), DefaultEditorKit.selectAllAction);
        }
    }

    /* Create the form */
    //        GUIBackend backend = new GUIBackend();
    final ExperimentalWindow mw = new ExperimentalWindow();

    /* Apply the settings to the ExperimentalWindow bofore showing it */

    mw.setSize(mw.backend.getSettings().getMainWindowSettings().width,
            mw.backend.getSettings().getMainWindowSettings().height);
    mw.setLocation(mw.backend.getSettings().getMainWindowSettings().xLocation,
            mw.backend.getSettings().getMainWindowSettings().yLocation);

    mw.addComponentListener(new ComponentListener() {
        @Override
        public void componentResized(ComponentEvent ce) {
            mw.backend.getSettings().getMainWindowSettings().height = ce.getComponent().getSize().height;
            mw.backend.getSettings().getMainWindowSettings().width = ce.getComponent().getSize().width;
        }

        @Override
        public void componentMoved(ComponentEvent ce) {
            mw.backend.getSettings().getMainWindowSettings().xLocation = ce.getComponent().getLocation().x;
            mw.backend.getSettings().getMainWindowSettings().yLocation = ce.getComponent().getLocation().y;
        }

        @Override
        public void componentShown(ComponentEvent ce) {
        }

        @Override
        public void componentHidden(ComponentEvent ce) {
        }
    });

    /* Display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            mw.setVisible(true);
        }
    });

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            mw.connectionPanel.saveSettings();
            mw.commandPanel.saveSettings();

            if (mw.pendantUI != null) {
                mw.pendantUI.stop();
            }
        }
    });
}

From source file:com.mirth.connect.manager.ServiceControllerFactory.java

public static ServiceController getServiceController() throws Exception {
    synchronized (ServiceController.class) {
        if (serviceController == null) {
            if (SystemUtils.IS_OS_WINDOWS) {
                serviceController = new WindowsServiceController();
            } else if (SystemUtils.IS_OS_MAC) {
                serviceController = new MacServiceController();
            } else if (SystemUtils.IS_OS_UNIX) {
                serviceController = new LinuxServiceController();
            } else {
                throw new Exception("Operating system must be Windows, Mac, or Unix/Linux.");
            }/*  w  w w  . j av  a  2 s.c o m*/
        }

        return serviceController;
    }
}

From source file:com.synopsys.integration.util.OperatingSystemType.java

public static OperatingSystemType determineFromSystem() {
    if (SystemUtils.IS_OS_MAC) {
        return MAC;
    } else if (SystemUtils.IS_OS_WINDOWS) {
        return WINDOWS;
    } else {//from  ww  w.j a v a  2 s  .c o  m
        return LINUX;
    }
}

From source file:com.officialgenius.brainiac.Brainiac.java

/**
 * Get Dropbox path of the system/* w ww .j  a va2 s.c om*/
 * @return path of dropbox folder
 * @throws IOException
 */

public static String getDropBoxPath() throws IOException {
    Diodable diode = null;
    if (SystemUtils.IS_OS_WINDOWS) {
        diode = new WindowsDiode();
    } else if (SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC) {
        diode = new NixDiode();
    }
    return diode != null ? diode.getDropBoxPath() : null;
}

From source file:com.o2d.pkayjava.editor.utils.Overlap2DUtils.java

private static String getMyDocumentsLocation() {
    String myDocuments = null;//from  w  w w .jav a  2  s . c  o m
    try {
        if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
            myDocuments = System.getProperty("user.home") + File.separator + "Documents";
        }
        if (SystemUtils.IS_OS_WINDOWS) {
            Process p = Runtime.getRuntime().exec(
                    "reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v personal");
            p.waitFor();

            InputStream in = p.getInputStream();
            byte[] b = new byte[in.available()];
            in.read(b);
            in.close();

            myDocuments = new String(b);
            myDocuments = myDocuments.split("\\s\\s+")[4];
        }
        if (SystemUtils.IS_OS_LINUX) {
            myDocuments = System.getProperty("user.home") + File.separator + "Documents";
        }

    } catch (Throwable t) {
        t.printStackTrace();
    }

    return myDocuments;
}

From source file:com.flowpowered.engine.render.DeployNatives.java

public static void deploy() throws Exception {
    final String osPath;
    final String[] nativeLibs;
    if (SystemUtils.IS_OS_WINDOWS) {
        nativeLibs = new String[] { "jinput-dx8_64.dll", "jinput-dx8.dll", "jinput-raw_64.dll",
                "jinput-raw.dll", "jinput-wintab.dll", "lwjgl.dll", "lwjgl64.dll", "OpenAL32.dll",
                "OpenAL64.dll" };
        osPath = "windows/";
    } else if (SystemUtils.IS_OS_MAC) {
        nativeLibs = new String[] { "libjinput-osx.jnilib", "liblwjgl.jnilib", "openal.dylib" };
        osPath = "mac/";
    } else if (SystemUtils.IS_OS_LINUX) {
        nativeLibs = new String[] { "liblwjgl.so", "liblwjgl64.so", "libopenal.so", "libopenal64.so",
                "libjinput-linux.so", "libjinput-linux64.so" };
        osPath = "linux/";
    } else {//from   ww w  . ja  v a2s . co  m
        throw new IllegalStateException("Could not get lwjgl natives for OS \"" + SystemUtils.OS_NAME + "\".");
    }
    final File nativesDir = new File("natives" + File.separator + osPath);
    nativesDir.mkdirs();
    for (String nativeLib : nativeLibs) {
        final File nativeFile = new File(nativesDir, nativeLib);
        if (!nativeFile.exists()) {
            FileUtils.copyInputStreamToFile(DeployNatives.class.getResourceAsStream("/" + nativeLib),
                    nativeFile);
        }
    }
    final String nativesPath = nativesDir.getAbsolutePath();
    System.setProperty("org.lwjgl.librarypath", nativesPath);
    System.setProperty("net.java.games.input.librarypath", nativesPath);
}

From source file:com.willwinder.universalgcodesender.MainWindow.java

/**
 * @param args the command line arguments
 *//*from ww  w .j  av a  2s. com*/
public static void main(String args[]) {

    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* 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(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    }
    //</editor-fold>

    // Fix look and feel to use CMD+C/X/V/A instead of CTRL
    if (SystemUtils.IS_OS_MAC) {
        Collection<InputMap> ims = new ArrayList<>();
        ims.add((InputMap) UIManager.get("TextField.focusInputMap"));
        ims.add((InputMap) UIManager.get("TextArea.focusInputMap"));
        ims.add((InputMap) UIManager.get("EditorPane.focusInputMap"));
        ims.add((InputMap) UIManager.get("FormattedTextField.focusInputMap"));
        ims.add((InputMap) UIManager.get("PasswordField.focusInputMap"));
        ims.add((InputMap) UIManager.get("TextPane.focusInputMap"));

        int c = KeyEvent.VK_C;
        int v = KeyEvent.VK_V;
        int x = KeyEvent.VK_X;
        int a = KeyEvent.VK_A;
        int meta = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

        for (InputMap im : ims) {
            im.put(KeyStroke.getKeyStroke(c, meta), DefaultEditorKit.copyAction);
            im.put(KeyStroke.getKeyStroke(v, meta), DefaultEditorKit.pasteAction);
            im.put(KeyStroke.getKeyStroke(x, meta), DefaultEditorKit.cutAction);
            im.put(KeyStroke.getKeyStroke(a, meta), DefaultEditorKit.selectAllAction);
        }
    }

    /* Create the form */
    GUIBackend backend = new GUIBackend();
    final MainWindow mw = new MainWindow(backend);

    /* Apply the settings to the MainWindow bofore showing it */
    mw.arrowMovementEnabled.setSelected(mw.settings.isManualModeEnabled());
    mw.stepSizeSpinner.setValue(mw.settings.getManualModeStepSize());
    boolean unitsAreMM = mw.settings.getDefaultUnits().equals("mm");
    mw.mmRadioButton.setSelected(unitsAreMM);
    mw.inchRadioButton.setSelected(!unitsAreMM);
    mw.fileChooser = new JFileChooser(mw.settings.getLastOpenedFilename());
    mw.commPortComboBox.setSelectedItem(mw.settings.getPort());
    mw.baudrateSelectionComboBox.setSelectedItem(mw.settings.getPortRate());
    mw.scrollWindowCheckBox.setSelected(mw.settings.isScrollWindowEnabled());
    mw.showVerboseOutputCheckBox.setSelected(mw.settings.isVerboseOutputEnabled());
    mw.showCommandTableCheckBox.setSelected(mw.settings.isCommandTableEnabled());
    mw.showCommandTableCheckBoxActionPerformed(null);
    mw.firmwareComboBox.setSelectedItem(mw.settings.getFirmwareVersion());

    mw.setSize(mw.settings.getMainWindowSettings().width, mw.settings.getMainWindowSettings().height);
    mw.setLocation(mw.settings.getMainWindowSettings().xLocation,
            mw.settings.getMainWindowSettings().yLocation);

    mw.addComponentListener(new ComponentListener() {
        @Override
        public void componentResized(ComponentEvent ce) {
            mw.settings.getMainWindowSettings().height = ce.getComponent().getSize().height;
            mw.settings.getMainWindowSettings().width = ce.getComponent().getSize().width;
        }

        @Override
        public void componentMoved(ComponentEvent ce) {
            mw.settings.getMainWindowSettings().xLocation = ce.getComponent().getLocation().x;
            mw.settings.getMainWindowSettings().yLocation = ce.getComponent().getLocation().y;
        }

        @Override
        public void componentShown(ComponentEvent ce) {
        }

        @Override
        public void componentHidden(ComponentEvent ce) {
        }
    });

    /* Display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            mw.setVisible(true);
        }
    });

    mw.initFileChooser();

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            if (mw.fileChooser.getSelectedFile() != null) {
                mw.settings.setLastOpenedFilename(mw.fileChooser.getSelectedFile().getAbsolutePath());
            }

            mw.settings.setDefaultUnits(mw.inchRadioButton.isSelected() ? "inch" : "mm");
            mw.settings.setManualModeStepSize(mw.getStepSize());
            mw.settings.setManualModeEnabled(mw.arrowMovementEnabled.isSelected());
            mw.settings.setPort(mw.commPortComboBox.getSelectedItem().toString());
            mw.settings.setPortRate(mw.baudrateSelectionComboBox.getSelectedItem().toString());
            mw.settings.setScrollWindowEnabled(mw.scrollWindowCheckBox.isSelected());
            mw.settings.setVerboseOutputEnabled(mw.showVerboseOutputCheckBox.isSelected());
            mw.settings.setCommandTableEnabled(mw.showCommandTableCheckBox.isSelected());
            mw.settings.setFirmwareVersion(mw.firmwareComboBox.getSelectedItem().toString());
            SettingsFactory.saveSettings(mw.settings);

            if (mw.pendantUI != null) {
                mw.pendantUI.stop();
            }
        }
    });

    // Check command line for a file to open.
    boolean open = false;
    for (String arg : args) {
        if (open) {
            try {
                backend.setGcodeFile(new File(arg));
            } catch (Exception ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                System.exit(1);
            }
        }
        if (arg.equals("--open") || arg.equals("-o")) {
            open = true;
        }
    }
}

From source file:cuchaz.m3l.util.OperatingSystem.java

public static OperatingSystem get() {
    if (SystemUtils.IS_OS_WINDOWS) {
        return Windows;
    } else if (SystemUtils.IS_OS_MAC) {
        return Osx;
    }//from www . ja va  2  s. c  o m

    // just assume linux for everything else
    return Linux;
}

From source file:de.uniwue.info6.misc.StringTools.java

/**
 *
 *
 * @param path/*w w  w  . j  av a 2s  .c  o  m*/
 * @return
 */
public static String shortenUnixHomePath(String path) {
    if (path.startsWith(SystemUtils.USER_HOME) && (SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC)) {
        path = path.replaceFirst(SystemUtils.USER_HOME, "~");
    }
    return path;
}

From source file:io.vertx.config.vault.utils.VaultDownloader.java

private static URL getURL(String version) {
    StringBuilder url = new StringBuilder();
    url.append("https://releases.hashicorp.com/vault/").append(version).append("/vault_").append(version)
            .append("_");

    if (SystemUtils.IS_OS_MAC) {
        url.append("darwin_");
    } else if (SystemUtils.IS_OS_LINUX) {
        url.append("linux_");
    } else if (SystemUtils.IS_OS_WINDOWS) {
        url.append("windows_");
    } else {/*from   w  ww  .j ava 2s  .c  om*/
        throw new IllegalStateException("Unsupported operating system");
    }

    if (ArchUtils.getProcessor().is64Bit()) {
        url.append("amd64.zip");
    } else {
        url.append("386.zip");
    }

    System.out.println("Downloading " + url.toString());
    try {
        return new URL(url.toString());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}