Search in sources :

Example 11 with Desktop

use of java.awt.Desktop in project tesb-studio-se by Talend.

the class AddRuntimeDirWizardPage method createControl.

/**
     * Create contents of the wizard.
     * 
     * @param parent
     */
@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    container.setLayout(new GridLayout(1, false));
    Composite body = new Composite(container, SWT.NONE);
    body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    body.setLayout(new GridLayout(1, false));
    ctlsRuntimeHome = new ArrayList<>();
    ctlsRuntimeArchive = new ArrayList<>();
    // Runtime Home Location
    {
        // Composite compCheck = new Composite(body, SWT.NONE);
        // compCheck.setLayout(new GridLayout(1, false));
        btnUseExistingContainer = new Button(body, SWT.RADIO);
        btnUseExistingContainer.setText(RunContainerMessages.getString("AddRuntimeDirWizardPage.UseExisting"));
        btnUseExistingContainer.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                validateRuntimeHome();
                updateWidgets();
            }
        });
        btnUseExistingContainer.setSelection(false);
        compExistingContainer = new Composite(body, SWT.NONE);
        compExistingContainer.setLayout(new GridLayout(3, false));
        compExistingContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        compExistingContainer.setBounds(0, 0, 64, 64);
        Label lblHome = new Label(compExistingContainer, SWT.NONE);
        GridData gd_lblHome = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
        gd_lblHome.widthHint = 116;
        lblHome.setLayoutData(gd_lblHome);
        //$NON-NLS-1$
        lblHome.setText(RunContainerMessages.getString("AddRuntimeDirWizardPage.Home"));
        txtRuntimeHome = new Text(compExistingContainer, SWT.BORDER);
        txtRuntimeHome.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        txtRuntimeHome.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                // Handle event
                btnUseExistingContainer.setSelection(true);
                validateRuntimeHome();
            }
        });
        Button btnNewButton = new Button(compExistingContainer, SWT.NONE);
        btnNewButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DirectoryDialog fileDialog = new DirectoryDialog(getShell(), SWT.OPEN | SWT.SHEET);
                String rtHome = fileDialog.open();
                if (rtHome != null) {
                    txtRuntimeHome.setText(rtHome);
                    btnUseExistingContainer.setSelection(true);
                }
            }
        });
        btnNewButton.setText(RunContainerMessages.getString("AddRuntimeDirWizardPage.DirButton"));
        ctlsRuntimeHome.add(txtRuntimeHome);
        ctlsRuntimeHome.add(btnNewButton);
    }
    Label separator = new Label(body, SWT.HORIZONTAL | SWT.SEPARATOR);
    separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // Runtime Distribution
    {
        // Composite compCheck = new Composite(body, SWT.NONE);
        // compCheck.setLayout(new GridLayout(1, false));
        btnInstallNewContainer = new Button(body, SWT.RADIO);
        btnInstallNewContainer.setText(RunContainerMessages.getString("AddRuntimeDirWizardPage.InstallNew"));
        btnInstallNewContainer.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                validateRuntimeArchive();
                updateWidgets();
            }
        });
        btnInstallNewContainer.setSelection(true);
        compNewContainer = new Composite(body, SWT.NONE);
        compNewContainer.setLayout(new GridLayout(3, false));
        compNewContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        compNewContainer.setBounds(0, 0, 64, 64);
        Label lblHome = new Label(compNewContainer, SWT.NONE);
        GridData gd_lblHome = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
        gd_lblHome.widthHint = 116;
        lblHome.setLayoutData(gd_lblHome);
        //$NON-NLS-1$
        lblHome.setText(RunContainerMessages.getString("AddRuntimeDirWizardPage.Install"));
        txtRuntimeArchive = new Text(compNewContainer, SWT.BORDER);
        txtRuntimeArchive.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        txtRuntimeArchive.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                // Handle event
                btnInstallNewContainer.setSelection(true);
                validateRuntimeArchive();
            }
        });
        Button btnNewButton = new Button(compNewContainer, SWT.NONE);
        btnNewButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN | SWT.SHEET);
                fileDialog.setFilterExtensions(new String[] { "*.zip" });
                String rtHome = fileDialog.open();
                if (rtHome != null) {
                    txtRuntimeArchive.setText(rtHome);
                    btnInstallNewContainer.setSelection(true);
                }
            }
        });
        btnNewButton.setText(RunContainerMessages.getString("AddRuntimeDirWizardPage.FileButton"));
        compTarget = new Composite(body, SWT.NONE);
        compTarget.setLayout(new GridLayout(3, false));
        compTarget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        compTarget.setBounds(0, 0, 64, 64);
        Label lblTarget = new Label(compTarget, SWT.NONE);
        lblTarget.setText("Install into:");
        GridData lblTargetGridData = new GridData();
        lblTargetGridData.horizontalSpan = 3;
        lblTarget.setLayoutData(lblTargetGridData);
        btnTargetDefault = new Button(compTarget, SWT.RADIO);
        btnTargetDefault.setText("default target folder");
        btnTargetDefault.setSelection(true);
        GridData btnTargetDefaultGridData = new GridData();
        btnTargetDefaultGridData.horizontalSpan = 0;
        btnTargetDefaultGridData.horizontalIndent = 20;
        btnTargetDefault.setLayoutData(btnTargetDefaultGridData);
        Link link = new Link(compTarget, SWT.NONE);
        link.setText("<a href=\"#\">STUDIO_HOME/esb/container</a>");
        link.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                Desktop desktop = Desktop.getDesktop();
                String defaultLocal = System.getProperty("user.dir") + File.separator + "esb";
                try {
                    desktop.open(new File(defaultLocal));
                } catch (IOException e1) {
                }
            }
        });
        Label lblBlank = new Label(compTarget, SWT.NONE);
        lblBlank.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        btnTargetCustom = new Button(compTarget, SWT.RADIO);
        btnTargetCustom.setText("custom target folder");
        btnTargetCustom.setSelection(false);
        btnTargetCustom.setEnabled(true);
        GridData btnTargetCustomGridData = new GridData();
        btnTargetCustomGridData.horizontalIndent = 20;
        btnTargetCustom.setLayoutData(btnTargetCustomGridData);
        txtTargetDir = new Text(compTarget, SWT.BORDER);
        txtTargetDir.setEnabled(false);
        txtTargetDir.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        txtTargetDir.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                btnInstallNewContainer.setSelection(true);
                btnTargetCustom.setSelection(true);
                validateRuntimeArchive();
            }
        });
        btnTargetDir = new Button(compTarget, SWT.NONE);
        btnTargetDir.setEnabled(false);
        btnTargetDir.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DirectoryDialog fileDialog = new DirectoryDialog(getShell(), SWT.OPEN | SWT.SHEET);
                String rtTarget = fileDialog.open();
                if (rtTarget != null) {
                    txtTargetDir.setText(rtTarget);
                }
            }
        });
        btnTargetDir.setText(RunContainerMessages.getString("AddRuntimeDirWizardPage.DirButton"));
        btnTargetDefault.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                btnTargetDir.setEnabled(false);
                txtTargetDir.setEnabled(false);
                validateRuntimeArchive();
            }
        });
        btnTargetCustom.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                btnTargetDir.setEnabled(true);
                txtTargetDir.setEnabled(true);
                validateRuntimeArchive();
            }
        });
        ctlsRuntimeArchive.add(compTarget);
    }
    updateWidgets();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Desktop(java.awt.Desktop) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) Link(org.eclipse.swt.widgets.Link) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 12 with Desktop

use of java.awt.Desktop in project bnd by bndtools.

the class Repository method open.

/*
	 * A utility to open a URL on different OS's browsers
	 * @param url the url to open
	 * @throws IOException
	 */
void open(String url) {
    try {
        try {
            Desktop desktop = Desktop.getDesktop();
            desktop.browse(new URI(url));
            return;
        } catch (Throwable e) {
        }
        String os = System.getProperty("os.name").toLowerCase();
        Runtime rt = Runtime.getRuntime();
        if (os.indexOf("mac") >= 0 || os.indexOf("darwin") >= 0) {
            rt.exec("open " + url);
        } else if (os.indexOf("win") >= 0) {
            // this doesn't support showing urls in the form of
            // "page.html#nameLink"
            rt.exec("rundll32 url.dll,FileProtocolHandler " + url);
        } else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0) {
            // Do a best guess on unix until we get a platform independent
            // way
            // Build a list of browsers to try, in this order.
            String[] browsers = { "epiphany", "firefox", "mozilla", "konqueror", "netscape", "opera", "links", "lynx" };
            // Build a command string which looks like
            // "browser1 "url" || browser2 "url" ||..."
            StringBuffer cmd = new StringBuffer();
            for (int i = 0; i < browsers.length; i++) cmd.append((i == 0 ? "" : " || ") + browsers[i] + " \"" + url + "\" ");
            rt.exec(new String[] { "sh", "-c", cmd.toString() });
        } else
            logger.debug("Open {}", url);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Desktop(java.awt.Desktop) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) SocketException(java.net.SocketException) IOException(java.io.IOException)

Example 13 with Desktop

use of java.awt.Desktop in project SAGU by brianmcmichael.

the class OpenURI method open.

public static void open(String url) {
    if (!Desktop.isDesktopSupported()) {
        System.err.println("Desktop is not supported (fatal)");
        System.exit(1);
    }
    if (url.length() == 0) {
        System.out.println("Usage: OpenURI [URI [URI ... ]]");
        System.exit(0);
    }
    Desktop desktop = Desktop.getDesktop();
    if (!desktop.isSupported(Desktop.Action.BROWSE)) {
        System.err.println("Desktop doesn't support the browse action (fatal)");
        System.exit(1);
    }
    try {
        URI uri = new URI(url);
        desktop.browse(uri);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}
Also used : Desktop(java.awt.Desktop) URI(java.net.URI)

Aggregations

Desktop (java.awt.Desktop)13 IOException (java.io.IOException)10 URI (java.net.URI)6 File (java.io.File)3 URISyntaxException (java.net.URISyntaxException)3 ROMFormatUnsupportedException (org.javatari.atari.cartridge.ROMFormatUnsupportedException)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 FileNotFoundException (java.io.FileNotFoundException)1 StringWriter (java.io.StringWriter)1 SocketException (java.net.SocketException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 BadLocationException (javax.swing.text.BadLocationException)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1