Example usage for javax.swing JOptionPane OK_OPTION

List of usage examples for javax.swing JOptionPane OK_OPTION

Introduction

In this page you can find the example usage for javax.swing JOptionPane OK_OPTION.

Prototype

int OK_OPTION

To view the source code for javax.swing JOptionPane OK_OPTION.

Click Source Link

Document

Return value form class method if OK is chosen.

Usage

From source file:org.omegat.gui.align.AlignPanelController.java

private boolean confirmSaveTMX(AlignPanel panel) {
    BeadTableModel model = (BeadTableModel) panel.table.getModel();
    boolean needsReview = false;
    for (MutableBead bead : model.getData()) {
        if (bead.status == MutableBead.Status.NEEDS_REVIEW) {
            needsReview = true;// www . ja v  a  2  s .c  o m
            break;
        }
    }
    if (needsReview) {
        return JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(panel,
                OStrings.getString("ALIGNER_DIALOG_NEEDSREVIEW_CONFIRM_MESSAGE"),
                OStrings.getString("ALIGNER_DIALOG_CONFIRM_TITLE"), JOptionPane.OK_CANCEL_OPTION);
    } else {
        return true;
    }
}

From source file:org.orbisgis.mapeditor.map.MapEditor.java

/**
 * The use want to export the rendering into a file.
 *//* ww  w.  j av a  2  s  . c  o  m*/
public void onExportMapRendering() {
    // Show Dialog to select image size
    final String WIDTH_T = "width";
    final String HEIGHT_T = "height";
    final String RATIO_CHECKBOX_T = "ratio checkbox";
    final String TRANSPARENT_BACKGROUND_T = "background";
    final String DPI_T = "dpi";
    final int textWidth = 8;
    final MultiInputPanel inputPanel = new MultiInputPanel(I18N.tr("Export parameters"));

    inputPanel.addInput(TRANSPARENT_BACKGROUND_T, "", "True",
            new CheckBoxChoice(true, "<html>" + I18N.tr("Transparent\nbackground") + "</html>"));

    inputPanel.addInput(DPI_T, I18N.tr("DPI"),
            String.valueOf((int) (MapImageWriter.MILLIMETERS_BY_INCH / MapImageWriter.DEFAULT_PIXEL_SIZE)),
            new TextBoxType(textWidth));

    TextBoxType tbWidth = new TextBoxType(textWidth);
    inputPanel.addInput(WIDTH_T, I18N.tr("Width (pixels)"), String.valueOf(mapControl.getImage().getWidth()),
            tbWidth);
    TextBoxType tbHeight = new TextBoxType(textWidth);
    inputPanel.addInput(HEIGHT_T, I18N.tr("Height (pixels)"), String.valueOf(mapControl.getImage().getHeight()),
            tbHeight);

    tbHeight.getComponent().addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            userChangedHeight = true;
        }

        @Override
        public void focusLost(FocusEvent e) {
            updateWidth();
        }

        private void updateWidth() {
            if (userChangedHeight) {
                if (inputPanel.getInput(RATIO_CHECKBOX_T).equals("true")) {
                    // Change image width to keep ratio
                    final String heightString = inputPanel.getInput(HEIGHT_T);
                    if (!heightString.isEmpty()) {
                        try {
                            final Envelope adjExtent = mapControl.getMapTransform().getAdjustedExtent();
                            final double ratio = adjExtent.getWidth() / adjExtent.getHeight();
                            final int height = Integer.parseInt(heightString);
                            final long newWidth = Math.round(height * ratio);
                            inputPanel.setValue(WIDTH_T, String.valueOf(newWidth));
                        } catch (NumberFormatException e) {
                        }
                    }
                }
            }
            userChangedWidth = false;
        }
    });

    tbWidth.getComponent().addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            userChangedWidth = true;
        }

        @Override
        public void focusLost(FocusEvent e) {
            updateHeight();
        }

        private void updateHeight() {
            if (userChangedWidth) {
                if (inputPanel.getInput(RATIO_CHECKBOX_T).equals("true")) {
                    // Change image height to keep ratio
                    final String widthString = inputPanel.getInput(WIDTH_T);
                    if (!widthString.isEmpty()) {
                        try {
                            final Envelope adjExtent = mapControl.getMapTransform().getAdjustedExtent();
                            final double ratio = adjExtent.getHeight() / adjExtent.getWidth();
                            final int width = Integer.parseInt(widthString);
                            final long newHeight = Math.round(width * ratio);
                            inputPanel.setValue(HEIGHT_T, String.valueOf(newHeight));
                        } catch (NumberFormatException e) {
                        }
                    }
                }
            }
            userChangedHeight = false;
        }
    });

    inputPanel.addInput(RATIO_CHECKBOX_T, "", new CheckBoxChoice(true, I18N.tr("Keep ratio")));

    inputPanel.addValidation(new MIPValidationInteger(WIDTH_T, I18N.tr("Width (pixels)")));
    inputPanel.addValidation(new MIPValidationInteger(HEIGHT_T, I18N.tr("Height (pixels)")));
    inputPanel.addValidation(new MIPValidationInteger(DPI_T, I18N.tr("DPI")));

    JButton refreshButton = new JButton(I18N.tr("Reset extent"));
    refreshButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            inputPanel.setValue(WIDTH_T, String.valueOf(mapControl.getImage().getWidth()));
            inputPanel.setValue(HEIGHT_T, String.valueOf(mapControl.getImage().getHeight()));
        }
    });

    // Show the dialog and get the user's choice.
    int userChoice = JOptionPane.showOptionDialog(this, inputPanel.getComponent(),
            I18N.tr("Export map as image"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
            MapEditorIcons.getIcon("map_catalog"),
            new Object[] { I18N.tr("OK"), I18N.tr("Cancel"), refreshButton }, null);

    // If the user clicked OK, then show the save image dialog.
    if (userChoice == JOptionPane.OK_OPTION) {
        MapImageWriter mapImageWriter = new MapImageWriter(mapContext.getLayerModel());
        mapImageWriter
                .setPixelSize(MapImageWriter.MILLIMETERS_BY_INCH / Double.valueOf(inputPanel.getInput(DPI_T)));
        // If the user want a background color, let him choose one
        if (!Boolean.valueOf(inputPanel.getInput(TRANSPARENT_BACKGROUND_T))) {
            ColorPicker colorPicker = new ColorPicker(Color.white);
            if (!UIFactory.showDialog(colorPicker, true, true)) {
                return;
            }
            mapImageWriter.setBackgroundColor(colorPicker.getColor());
        }
        // Save the picture in which location
        final SaveFilePanel outfilePanel = new SaveFilePanel("MapEditor.ExportInFile",
                I18N.tr("Save the map as image : " + mapContext.getTitle()));
        outfilePanel.addFilter("png", I18N.tr("Portable Network Graphics"));
        outfilePanel.addFilter("tiff", I18N.tr("Tagged Image File Format"));
        outfilePanel.addFilter("jpg", I18N.tr("Joint Photographic Experts Group"));
        outfilePanel.addFilter("pdf", I18N.tr("Portable Document Format"));
        outfilePanel.loadState(); // Load last use path
        // Show save into dialog
        if (UIFactory.showDialog(outfilePanel, true, true)) {
            File outFile = outfilePanel.getSelectedFile();
            String fileName = FilenameUtils.getExtension(outFile.getName());
            if (fileName.equalsIgnoreCase("png")) {
                mapImageWriter.setFormat(MapImageWriter.Format.PNG);
            } else if (fileName.equalsIgnoreCase("jpg")) {
                mapImageWriter.setFormat(MapImageWriter.Format.JPEG);
            } else if (fileName.equalsIgnoreCase("pdf")) {
                mapImageWriter.setFormat(MapImageWriter.Format.PDF);
            } else {
                mapImageWriter.setFormat(MapImageWriter.Format.TIFF);
            }
            mapImageWriter.setBoundingBox(mapContext.getBoundingBox());
            int width = Integer.valueOf(inputPanel.getInput(WIDTH_T));
            int height = Integer.valueOf(inputPanel.getInput(HEIGHT_T));

            mapImageWriter.setWidth(width);
            mapImageWriter.setHeight(height);
            execute(new ExportRenderingIntoFile(mapImageWriter, outFile));
        }
    }
}

From source file:org.orbisgis.view.map.MapEditor.java

/**
 * The use want to export the rendering into a file.
 *//*from  w w  w .j  a va  2s .co  m*/
public void onExportMapRendering() {
    // Show Dialog to select image size
    final String WIDTH_T = "width";
    final String HEIGHT_T = "height";
    final String RATIO_T = "ratio";
    final String TRANSPARENT_BACKGROUND_T = "background";
    final String DPI_T = "dpi";
    final int textWidth = 8;
    String[] RATIO = new String[] { "UPDATE_EXTENT", "FIX_WIDTH", "FIX_HEIGHT" };
    String[] RATIO_LABELS = new String[] { I18N.tr("Change extent"), I18N.tr("Update height to keep ratio"),
            I18N.tr("Update width to keep ratio") };
    MultiInputPanel inputPanel = new MultiInputPanel(I18N.tr("Export parameters"));

    inputPanel.addInput(WIDTH_T, I18N.tr("Width (pixels)"), String.valueOf(mapControl.getImage().getWidth()),
            new TextBoxType(textWidth));
    inputPanel.addInput(HEIGHT_T, I18N.tr("Height (pixels)"), String.valueOf(mapControl.getImage().getHeight()),
            new TextBoxType(textWidth));

    ComboBoxChoice comboBoxChoice = new ComboBoxChoice(RATIO, RATIO_LABELS);
    comboBoxChoice.setValue(RATIO[0]);
    inputPanel.addInput(RATIO_T, I18N.tr("Ratio"), comboBoxChoice);

    inputPanel.addInput(DPI_T, I18N.tr("DPI"),
            String.valueOf((int) (MapImageWriter.MILLIMETERS_BY_INCH / MapImageWriter.DEFAULT_PIXEL_SIZE)),
            new TextBoxType(textWidth));
    inputPanel.addInput(TRANSPARENT_BACKGROUND_T, "", "True",
            new CheckBoxChoice(true, "<html>" + I18N.tr("Transparent\nbackground") + "</html>"));

    inputPanel.addValidation(new MIPValidationInteger(WIDTH_T, I18N.tr("Width (pixels)")));
    inputPanel.addValidation(new MIPValidationInteger(HEIGHT_T, I18N.tr("Height (pixels)")));
    inputPanel.addValidation(new MIPValidationInteger(DPI_T, I18N.tr("DPI")));

    // Show the dialog and get the user's choice.
    int userChoice = JOptionPane.showConfirmDialog(this, inputPanel.getComponent(),
            I18N.tr("Export map as image"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
            OrbisGISIcon.getIcon("map_catalog"));

    // If the user clicked OK, then show the save image dialog.
    if (userChoice == JOptionPane.OK_OPTION) {
        MapImageWriter mapImageWriter = new MapImageWriter(mapContext.getLayerModel());
        mapImageWriter
                .setPixelSize(MapImageWriter.MILLIMETERS_BY_INCH / Double.valueOf(inputPanel.getInput(DPI_T)));
        // If the user want a background color, let him choose one
        if (!Boolean.valueOf(inputPanel.getInput(TRANSPARENT_BACKGROUND_T))) {
            ColorPicker colorPicker = new ColorPicker(Color.white);
            if (!UIFactory.showDialog(colorPicker, true, true)) {
                return;
            }
            mapImageWriter.setBackgroundColor(colorPicker.getColor());
        }
        // Save the picture in which location
        final SaveFilePanel outfilePanel = new SaveFilePanel("MapEditor.ExportInFile",
                I18N.tr("Save the map as image : " + mapContext.getTitle()));
        outfilePanel.setConfirmOverwrite(true);
        outfilePanel.addFilter("png", I18N.tr("Portable Network Graphics"));
        outfilePanel.addFilter("tiff", I18N.tr("Tagged Image File Format"));
        outfilePanel.loadState(); // Load last use path
        // Show save into dialog
        if (UIFactory.showDialog(outfilePanel, true, true)) {
            File outFile = outfilePanel.getSelectedFile();
            String fileName = FilenameUtils.getExtension(outFile.getName());
            if (fileName.equalsIgnoreCase("png")) {
                mapImageWriter.setFormat(MapImageWriter.Format.PNG);
            } else {
                mapImageWriter.setFormat(MapImageWriter.Format.TIFF);
            }
            mapImageWriter.setBoundingBox(mapContext.getBoundingBox());
            int width = Integer.valueOf(inputPanel.getInput(WIDTH_T));
            int height = Integer.valueOf(inputPanel.getInput(HEIGHT_T));
            Envelope adjExtent = mapControl.getMapTransform().getAdjustedExtent();
            if (comboBoxChoice.getValue().equals(RATIO[1])) {
                // Change image height to keep ratio
                height = (int) (width * (adjExtent.getHeight() / adjExtent.getWidth()));
            } else if (comboBoxChoice.getValue().equals(RATIO[2])) {
                width = (int) (height * (adjExtent.getWidth() / adjExtent.getHeight()));
            }
            mapImageWriter.setWidth(width);
            mapImageWriter.setHeight(height);
            ExportRenderingIntoFile renderingIntoFile = new ExportRenderingIntoFile(mapImageWriter, outFile);
            BackgroundManager bm = Services.getService(BackgroundManager.class);
            bm.nonBlockingBackgroundOperation(renderingIntoFile);
        }
    }
}

From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java

protected void removeDeviceButtonActionPerformed(ActionEvent evt) {
    int index = deviceList.getSelectedIndex();
    if (index != -1) {
        PanboxDevice selDevice = client.getDeviceList().get(deviceList.getSelectedIndex());
        ShareListModel connectedShares = client.getDeviceShares(selDevice);
        if (connectedShares.getSize() > 0) {
            // We still know shares for that the device has been added!
            String shareText = "";
            for (int i = 0; i < connectedShares.getSize(); ++i) {
                shareText += ("- " + connectedShares.get(i).getName() + "<br>");
            }/*from   w ww. j a  va2 s. com*/
            String message = MessageFormat.format(
                    bundle.getString("client.deviceList.removeDevice.shareExistsMsg"), shareText,
                    selDevice.getDeviceName());
            int okResult = JOptionPane.showConfirmDialog(this, message,
                    bundle.getString("client.deviceList.removeDevice.reallyTitle"),
                    JOptionPane.WARNING_MESSAGE);
            if (okResult == JOptionPane.OK_OPTION) {
                try {
                    // TODO: Also remove device from connected known shares
                    client.deviceManager.removeDevice(selDevice);
                    client.refreshDeviceListModel();
                } catch (DeviceManagerException e) {
                    logger.error("RemoveDevice : Operation failed.", e);
                }
            } else {
                logger.debug("RemoveDevice : Operation cancled.");
            }
        } else {
            // No shares are known for this device. So removing should not
            // be a problem!
            String message = MessageFormat.format(
                    bundle.getString("client.deviceList.removeDevice.shareNotExistsMsg"),
                    selDevice.getDeviceName());
            int okResult = JOptionPane.showConfirmDialog(this, message,
                    bundle.getString("client.deviceList.removeDevice.reallyTitle"),
                    JOptionPane.WARNING_MESSAGE);
            if (okResult == JOptionPane.OK_OPTION) {
                try {
                    client.deviceManager.removeDevice(selDevice);
                    client.refreshDeviceListModel();
                } catch (DeviceManagerException e) {
                    logger.error("RemoveDevice : Operation failed.", e);
                }
            } else {
                logger.debug("RemoveDevice : Operation cancled.");
            }
        }

        checkIfRemoveDeviceShouldBeEnabled();
    } else {
        logger.error(PanboxClientGUI.class.getName()
                + " : Remove device was called even if it should not be possible");
    }
}

From source file:org.parosproxy.paros.control.Control.java

public void exit(boolean noPrompt, final File openOnExit) {
    boolean isNewState = model.getSession().isNewState();
    int rootCount = 0;
    if (!Constant.isLowMemoryOptionSet()) {
        rootCount = model.getSession().getSiteTree().getChildCount(model.getSession().getSiteTree().getRoot());
    }//ww w.jav a2s. co  m
    boolean askOnExit = view != null
            && Model.getSingleton().getOptionsParam().getViewParam().getAskOnExitOption() > 0;
    boolean sessionUnsaved = isNewState && rootCount > 0;

    if (!noPrompt) {
        List<String> list = getExtensionLoader().getUnsavedResources();
        if (sessionUnsaved && askOnExit) {
            list.add(0, Constant.messages.getString("menu.file.exit.message.sessionResNotSaved"));
        }

        String message = null;
        String activeActions = wrapEntriesInLiTags(getExtensionLoader().getActiveActions());
        if (list.size() > 0) {
            String unsavedResources = wrapEntriesInLiTags(list);

            if (activeActions.isEmpty()) {
                message = MessageFormat.format(
                        Constant.messages.getString("menu.file.exit.message.resourcesNotSaved"),
                        unsavedResources);
            } else {
                message = MessageFormat.format(
                        Constant.messages.getString("menu.file.exit.message.resourcesNotSavedAndActiveActions"),
                        unsavedResources, activeActions);
            }
        } else if (!activeActions.isEmpty()) {
            message = MessageFormat.format(Constant.messages.getString("menu.file.exit.message.activeActions"),
                    activeActions);
        }

        if (message != null && view.showConfirmDialog(message) != JOptionPane.OK_OPTION) {
            return;
        }
    }

    if (sessionUnsaved) {
        control.discardSession();
    }

    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            // ZAP: Changed to use the option compact database.
            control.shutdown(Model.getSingleton().getOptionsParam().getDatabaseParam().isCompactDatabase());
            log.info(Constant.PROGRAM_TITLE + " terminated.");

            if (openOnExit != null && Desktop.isDesktopSupported()) {
                try {
                    log.info("Openning file " + openOnExit.getAbsolutePath());
                    Desktop.getDesktop().open(openOnExit);
                } catch (IOException e) {
                    log.error("Failed to open file " + openOnExit.getAbsolutePath(), e);
                }
            }
            System.exit(0);
        }
    });

    if (view != null) {
        WaitMessageDialog dialog = view
                .getWaitMessageDialog(Constant.messages.getString("menu.file.shuttingDown")); // ZAP: i18n
        t.start();
        dialog.setVisible(true);
    } else {
        t.start();
    }
}

From source file:org.parosproxy.paros.control.MenuFileControl.java

public void newSession(boolean isPromptNewSession) throws ClassNotFoundException, Exception {

    if (isPromptNewSession) {
        if (!informStopActiveActions()) {
            return;
        }/*www  . jav  a  2 s .  co m*/

        // ZAP: i18n
        if (model.getSession().isNewState()) {
            if (view.showConfirmDialog(
                    Constant.messages.getString("menu.file.discardSession")) != JOptionPane.OK_OPTION) {
                return;
            }
            control.discardSession();
        } else if (view.showConfirmDialog(
                Constant.messages.getString("menu.file.closeSession")) != JOptionPane.OK_OPTION) {
            return;
        }
    }

    int newSessionOption = model.getOptionsParam().getDatabaseParam().getNewSessionOption();

    if (model.getOptionsParam().getDatabaseParam().isNewSessionPrompt()) {
        PersistSessionDialog psd = new PersistSessionDialog(View.getSingleton().getMainFrame());
        // Set up the default option - ie the same one the user chose last time
        switch (newSessionOption) {
        case DatabaseParam.NEW_SESSION_TIMESTAMPED:
            psd.setTimestampChosen();
            break;
        case DatabaseParam.NEW_SESSION_USER_SPECIFIED:
            psd.setPersistChosen();
            break;
        case DatabaseParam.NEW_SESSION_TEMPORARY:
            psd.setTemporaryChosen();
            break;
        default:
            break;
        }

        psd.setVisible(true);

        if (psd.isTimestampChosen()) {
            newSessionOption = DatabaseParam.NEW_SESSION_TIMESTAMPED;
        } else if (psd.isPersistChosen()) {
            newSessionOption = DatabaseParam.NEW_SESSION_USER_SPECIFIED;
        } else {
            newSessionOption = DatabaseParam.NEW_SESSION_TEMPORARY;
        }
        // Save for next time
        model.getOptionsParam().getDatabaseParam().setNewSessionOption(newSessionOption);
        model.getOptionsParam().getDatabaseParam().setNewSessionPrompt(!psd.isDontAskAgain());
    }

    switch (newSessionOption) {
    case DatabaseParam.NEW_SESSION_TIMESTAMPED:
        String filename = getTimestampFilename();
        if (filename != null) {
            this.newSession(filename);
        } else {
            control.newSession();
        }
        break;
    case DatabaseParam.NEW_SESSION_USER_SPECIFIED:
        control.newSession();
        this.saveAsSession();
        break;
    default:
        control.newSession();
        break;
    }
}

From source file:org.parosproxy.paros.control.MenuFileControl.java

private boolean informStopActiveActions() {
    String activeActions = wrapEntriesInLiTags(control.getExtensionLoader().getActiveActions());
    if (!activeActions.isEmpty()) {
        String message = Constant.messages.getString("menu.file.session.activeactions", activeActions);
        if (view.showConfirmDialog(message) != JOptionPane.OK_OPTION) {
            return false;
        }//  ww w  .  j  a  va2s .c  o  m
    }
    return true;
}

From source file:org.parosproxy.paros.control.MenuToolsControl.java

public void options(String panel) {
    OptionsDialog dialog = view.getOptionsDialog(Constant.messages.getString("options.dialog.title"));
    dialog.initParam(model.getOptionsParam());

    int result = dialog.showDialog(false, panel);
    if (result == JOptionPane.OK_OPTION) {
        try {//from   ww w. j a v a  2 s. c o  m
            model.getOptionsParam().getConfig().save();
        } catch (ConfigurationException e) {
            logger.error(e.getMessage(), e);
            view.showWarningDialog(Constant.messages.getString("menu.tools.options.errorSavingOptions"));
            return;
        }
        // ZAP: Notify all OptionsChangedListener.
        control.getExtensionLoader().optionsChangedAllPlugin(model.getOptionsParam());

        control.getProxy().stopServer();
        control.getProxy().startServer();
    }
}

From source file:org.parosproxy.paros.extension.autoupdate.ExtensionAutoUpdate.java

/**
 * This method initializes menuItemEncoder   
 *    /*  w w  w.  ja va2s  .c  o  m*/
 * @return javax.swing.JMenuItem   
 */
private JMenuItem getMenuItemCheckUpdate() {
    if (menuItemCheckUpdate == null) {
        menuItemCheckUpdate = new JMenuItem();
        menuItemCheckUpdate.setText("Check for Updates...");
        if (!Constant.isWindows() && !Constant.isLinux()) {
            menuItemCheckUpdate.setEnabled(false);
        }
        menuItemCheckUpdate.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent e) {

                Thread t = new Thread(new Runnable() {
                    public void run() {
                        manualCheckStarted = true;
                        newestVersionName = getNewestVersionName();

                        if (waitDialog != null) {
                            waitDialog.hide();
                            waitDialog = null;
                        }
                        EventQueue.invokeLater(new Runnable() {
                            public void run() {

                                if (newestVersionName == null) {
                                    getView().showMessageDialog(
                                            "There is no new update available.  Paros may periodically check for update.");
                                } else if (newestVersionName.equals("")) {
                                    getView().showWarningDialog(
                                            "Error encountered.  Please check manually for new updates.");

                                } else {
                                    int result = getView()
                                            .showConfirmDialog("There is a newer version of Paros: "
                                                    + newestVersionName.replaceAll("\\.dat", "")
                                                    + "\nProceed to download?");
                                    if (result == JOptionPane.OK_OPTION) {
                                        waitDialog = getView().getWaitMessageDialog("Download in progress...");
                                        Thread t = new Thread(new Runnable() {
                                            public void run() {
                                                ExtensionAutoUpdate.this.download(false);
                                            }
                                        });
                                        t.start();
                                        waitDialog.show();

                                    }
                                }

                            }
                        });

                    }
                });
                waitDialog = getView().getWaitMessageDialog("Checking if newer version exists...");
                t.start();
                waitDialog.show();
            }

        });

    }
    return menuItemCheckUpdate;
}

From source file:org.parosproxy.paros.extension.autoupdate.ExtensionAutoUpdate.java

public void download(final boolean silent) {

    if (newestVersionName == null) {
        return;/*from  w  ww .j  a  va 2 s .co  m*/
    }

    HttpMessage msg = new HttpMessage();
    try {
        msg.setRequestHeader(header);
        msg.setRequestBody(getBody(mirrorList[getRandom(mirrorList.length)], newestVersionName));

        getHttpSender().sendAndReceive(msg, true);

        if (msg.getResponseHeader().getStatusCode() != HttpStatusCode.OK) {
            throw new IOException();
        }

        if (silent && manualCheckStarted) {
            return;
        }

        File file = null;
        if (Constant.isWindows()) {
            file = new File("parosnew.exe");
        } else if (Constant.isLinux()) {
            file = new File("parosnew.zip");
        }

        FileOutputStream os = new FileOutputStream(file);
        os.write(msg.getResponseBody().getBytes());
        os.close();

        try {
            final File updateFile = file;
            EventQueue.invokeAndWait(new Runnable() {
                public void run() {

                    if (waitDialog != null) {
                        waitDialog.hide();
                    }

                    if (!silent) {
                        String s = "A newer verison has been downloaded.  It will be installed the \nnext time Paros is started.";
                        if (Constant.isLinux()) {
                            s = s + "  Note: Use startserver.sh to run Paros.";
                        }
                        getView().showMessageDialog(s);
                    } else {
                        String s = "A newer version is available.  Install the new version \nnext time Paros is started?";
                        if (Constant.isLinux()) {
                            s = s + "  Note: Use startserver.sh to run Paros.";
                        }
                        int result = getView().showConfirmDialog(s);
                        if (result != JOptionPane.OK_OPTION) {
                            updateFile.delete();
                        }
                    }
                }
            });
        } catch (Exception e) {
        }
    } catch (IOException e) {

        try {
            EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    if (waitDialog != null) {
                        waitDialog.hide();
                    }

                    if (!silent) {

                        getView().showWarningDialog("Error encountered.  Please download new updates manually");
                    }
                }
            });
        } catch (Exception e1) {
        }

        if (waitDialog != null) {
            waitDialog.hide();
        }
    } finally {
        httpSender.shutdown();
        httpSender = null;
    }
}