Example usage for javax.swing JOptionPane YES_OPTION

List of usage examples for javax.swing JOptionPane YES_OPTION

Introduction

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

Prototype

int YES_OPTION

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

Click Source Link

Document

Return value from class method if YES is chosen.

Usage

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

public void fileSavePatchAs(SpinCADPatch p) {
    // Create a file chooser
    String savedPath = prefs.get("MRUPatchFolder", "");
    final JFileChooser fc = new JFileChooser(savedPath);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("SpinCAD Files", "spcd");
    fc.setFileFilter(filter);//from  w w  w . j  a v a2  s.  c om
    fc.setSelectedFile(new File(p.patchFileName));
    int returnVal = fc.showSaveDialog(new JFrame());
    // need to process user canceling box right here
    if (returnVal == JFileChooser.APPROVE_OPTION) {

        // In response to a button click:
        File fileToBeSaved = fc.getSelectedFile();

        if (!fileToBeSaved.getAbsolutePath().endsWith(".spcd")) {
            fileToBeSaved = new File(fc.getSelectedFile() + ".spcd");
        }
        int n = JOptionPane.YES_OPTION;
        if (fileToBeSaved.exists()) {
            JFrame frame = new JFrame();
            n = JOptionPane.showConfirmDialog(frame, "Would you like to overwrite it?", "File already exists!",
                    JOptionPane.YES_NO_OPTION);
        }
        if (n == JOptionPane.YES_OPTION) {
            try {
                String filePath = fileToBeSaved.getPath();
                String fileName = fileToBeSaved.getName();
                p.patchFileName = fileName;
                fileSavePatch(p);
                recentPatchFileList.add(fileToBeSaved);
                saveMRUPatchFolder(filePath);

            } catch (Exception e) { // thrown over in SpinCADFile.java
                e.printStackTrace();
                SpinCADDialogs.MessageBox("File save failed!", "look at stack trace for info");
            } finally {
                p.setChanged(false);
            }
        }
    }
}

From source file:App.java

/**
 * Initialize the contents of the frame.
 *//*  w w w.ja va  2  s  .  c  o m*/
private void initialize() {

    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(1000, 750);
    frame.getContentPane().setLayout(null);

    FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "jpeg", "png");
    fc = new JFileChooser();
    fc.setFileFilter(filter);
    frame.getContentPane().add(fc);

    stepOne = new JLabel("");
    stepOne.setToolTipText("here comes something");
    stepOne.setIcon(new ImageIcon("img/stepOne.png"));
    stepOne.setBounds(266, -4, 67, 49);
    frame.getContentPane().add(stepOne);

    btnBrowse = new JButton("Browse");
    btnBrowse.setBounds(66, 6, 117, 29);
    frame.getContentPane().add(btnBrowse);

    btnTurnWebcamOn = new JButton("Take a picture with webcam");
    btnTurnWebcamOn.setBounds(66, 34, 212, 29);
    frame.getContentPane().add(btnTurnWebcamOn);

    JButton btnTakePictureWithWebcam = new JButton("Take a picture");
    btnTakePictureWithWebcam.setBounds(430, 324, 117, 29);
    frame.getContentPane().add(btnTakePictureWithWebcam);
    btnTakePictureWithWebcam.setVisible(false);

    JButton btnCancel = new JButton("Cancel");
    btnCancel.setBounds(542, 324, 117, 29);
    frame.getContentPane().add(btnCancel);
    btnCancel.setVisible(false);

    JButton btnSaveImage = new JButton("Save image");
    btnSaveImage.setBounds(497, 357, 117, 29);
    frame.getContentPane().add(btnSaveImage);
    btnSaveImage.setVisible(false);

    urlField = new JTextField();
    urlField.setBounds(66, 67, 220, 26);
    frame.getContentPane().add(urlField);
    urlField.setColumns(10);

    originalImageLabel = new JLabel();
    originalImageLabel.setHorizontalAlignment(SwingConstants.CENTER);
    originalImageLabel.setBounds(33, 98, 300, 300);
    frame.getContentPane().add(originalImageLabel);

    stepTwo = new JLabel("");
    stepTwo.setToolTipText("here comes something else");
    stepTwo.setIcon(new ImageIcon("img/stepTwo.png"));
    stepTwo.setBounds(266, 413, 67, 49);
    frame.getContentPane().add(stepTwo);

    btnAnalyse = new JButton("Analyse image");
    btnAnalyse.setBounds(68, 423, 196, 29);
    frame.getContentPane().add(btnAnalyse);

    tagsField = new JTextArea();
    tagsField.setBounds(23, 479, 102, 89);
    tagsField.setLineWrap(true);
    tagsField.setWrapStyleWord(true);
    frame.getContentPane().add(tagsField);
    tagsField.setColumns(10);

    lblTags = new JLabel("Tags:");
    lblTags.setBounds(46, 451, 61, 16);
    frame.getContentPane().add(lblTags);

    descriptionField = new JTextArea();
    descriptionField.setLineWrap(true);
    descriptionField.setWrapStyleWord(true);
    descriptionField.setBounds(137, 479, 187, 89);
    frame.getContentPane().add(descriptionField);
    descriptionField.setColumns(10);

    lblDescription = new JLabel("Description:");
    lblDescription.setBounds(163, 451, 77, 16);
    frame.getContentPane().add(lblDescription);

    stepThree = new JLabel("");
    stepThree.setToolTipText("here comes something different");
    stepThree.setIcon(new ImageIcon("img/stepThree.png"));
    stepThree.setBounds(266, 685, 67, 49);
    frame.getContentPane().add(stepThree);

    JLabel lblImageType = new JLabel("Image type");
    lblImageType.setBounds(23, 580, 102, 16);
    frame.getContentPane().add(lblImageType);

    String[] imageTypes = { "unspecified", "AnimategGif", "Clipart", "Line", "Photo" };
    JComboBox imageTypeBox = new JComboBox(imageTypes);
    imageTypeBox.setBounds(137, 580, 187, 23);
    frame.getContentPane().add(imageTypeBox);

    JLabel lblSizeType = new JLabel("Size");
    lblSizeType.setBounds(23, 608, 102, 16);
    frame.getContentPane().add(lblSizeType);

    String[] sizeTypes = { "unspecified", "Small", "Medium", "Large", "Wallpaper" };
    JComboBox sizeBox = new JComboBox(sizeTypes);
    sizeBox.setBounds(137, 608, 187, 23);
    frame.getContentPane().add(sizeBox);

    JLabel lblLicenseType = new JLabel("License");
    lblLicenseType.setBounds(23, 636, 102, 16);
    frame.getContentPane().add(lblLicenseType);

    String[] licenseTypes = { "unspecified", "Public", "Share", "ShareCommercially", "Modify" };
    JComboBox licenseBox = new JComboBox(licenseTypes);
    licenseBox.setBounds(137, 636, 187, 23);
    frame.getContentPane().add(licenseBox);

    JLabel lblSafeSearchType = new JLabel("Safe search");
    lblSafeSearchType.setBounds(23, 664, 102, 16);
    frame.getContentPane().add(lblSafeSearchType);

    String[] safeSearchTypes = { "Strict", "Moderate", "Off" };
    JComboBox safeSearchBox = new JComboBox(safeSearchTypes);
    safeSearchBox.setBounds(137, 664, 187, 23);
    frame.getContentPane().add(safeSearchBox);

    btnSearchForSimilar = new JButton("Search for similar images");
    btnSearchForSimilar.setVisible(true);
    btnSearchForSimilar.setBounds(66, 695, 189, 29);
    frame.getContentPane().add(btnSearchForSimilar);

    // label to try urls to display images, not shown on the main frame
    labelTryLinks = new JLabel();
    labelTryLinks.setBounds(0, 0, 100, 100);

    foundImagesLabel1 = new JLabel();
    foundImagesLabel1.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel1.setBounds(400, 49, 250, 250);
    frame.getContentPane().add(foundImagesLabel1);

    foundImagesLabel2 = new JLabel();
    foundImagesLabel2.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel2.setBounds(400, 313, 250, 250);
    frame.getContentPane().add(foundImagesLabel2);

    foundImagesLabel3 = new JLabel();
    foundImagesLabel3.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel3.setBounds(673, 49, 250, 250);
    frame.getContentPane().add(foundImagesLabel3);

    foundImagesLabel4 = new JLabel();
    foundImagesLabel4.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel4.setBounds(673, 313, 250, 250);
    frame.getContentPane().add(foundImagesLabel4);

    progressBar = new JProgressBar();
    progressBar.setIndeterminate(true);
    progressBar.setStringPainted(true);
    progressBar.setBounds(440, 602, 440, 29);

    Border border = BorderFactory
            .createTitledBorder("We are checking every image, pixel by pixel, it may take a while...");
    progressBar.setBorder(border);
    frame.getContentPane().add(progressBar);
    progressBar.setVisible(false);

    btnHelp = new JButton("");
    btnHelp.setBorderPainted(false);
    ImageIcon btnIcon = new ImageIcon("img/helpRed.png");
    btnHelp.setIcon(btnIcon);
    btnHelp.setBounds(917, 4, 77, 59);
    frame.getContentPane().add(btnHelp);

    // all action listeners
    btnBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
                openFilechooser();
            }
        }
    });

    btnTurnWebcamOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            setAllFoundImagesLabelsAndPreviewsToNull();
            btnTakePictureWithWebcam.setVisible(true);
            btnCancel.setVisible(true);
            turnCameraOn();
        }
    });

    btnTakePictureWithWebcam.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            btnSaveImage.setVisible(true);
            // take a photo with web camera
            imageWebcam = webcam.getImage();
            originalImage = imageWebcam;

            // to mirror the image we create a temporary file, flip it
            // horizontally and then delete

            // get user's name to store file in the user directory
            String user = System.getProperty("user.home");
            String fileName = user + "/webCamPhoto.jpg";
            File newFile = new File(fileName);

            try {
                ImageIO.write(originalImage, "jpg", newFile);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            try {
                originalImage = (BufferedImage) ImageIO.read(newFile);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            newFile.delete();
            originalImage = mirrorImage(originalImage);
            icon = scaleBufferedImage(originalImage, originalImageLabel);
            originalImageLabel.setIcon(icon);
        }
    });

    btnSaveImage.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                try {

                    file = fc.getSelectedFile();
                    File output = new File(file.toString());
                    // check if image already exists
                    if (output.exists()) {
                        int response = JOptionPane.showConfirmDialog(null, //
                                "Do you want to replace the existing file?", //
                                "Confirm", JOptionPane.YES_NO_OPTION, //
                                JOptionPane.QUESTION_MESSAGE);
                        if (response != JOptionPane.YES_OPTION) {
                            return;
                        }
                    }
                    ImageIO.write(toBufferedImage(originalImage), "jpg", output);
                    System.out.println("Your image has been saved in the folder " + file.getPath());
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    });

    btnCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            btnTakePictureWithWebcam.setVisible(false);
            btnCancel.setVisible(false);
            btnSaveImage.setVisible(false);
            webcam.close();
            panel.setVisible(false);
        }
    });

    urlField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (urlField.getText().length() > 0) {
                String linkNew = urlField.getText();
                getImageFromHttp(linkNew, originalImageLabel);
                originalImage = imageResponses;
            }
        }
    });

    btnAnalyse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            Token computerVisionToken = new Token();
            String computerVisionTokenFileName = "APIToken.txt";

            try {
                computerVisionImageToken = computerVisionToken.getApiToken(computerVisionTokenFileName);
                try {
                    analyse();
                } catch (NullPointerException e1) {
                    // if user clicks on "analyze" button without uploading
                    // image or posts a broken link
                    JOptionPane.showMessageDialog(null, "Please choose an image");
                    e1.printStackTrace();
                }
            } catch (NullPointerException e1) {
                e1.printStackTrace();
            }
        }
    });

    btnSearchForSimilar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            // clear labels in case there were results of previous search
            setAllFoundImagesLabelsAndPreviewsToNull();

            System.out.println("==========================================");
            System.out.println("new search");
            System.out.println("==========================================");

            Token bingImageToken = new Token();
            String bingImageTokenFileName = "SearchApiToken.txt";

            bingToken = bingImageToken.getApiToken(bingImageTokenFileName);

            // in case user edited description or tags, update it and
            // replace new line character, spaces and breaks with %20
            text = descriptionField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20");
            String tagsString = tagsField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n",
                    "%20");

            imageTypeString = imageTypeBox.getSelectedItem().toString();
            sizeTypeString = sizeBox.getSelectedItem().toString();
            licenseTypeString = licenseBox.getSelectedItem().toString();
            safeSearchTypeString = safeSearchBox.getSelectedItem().toString();

            searchParameters = tagsString + text;
            System.out.println("search parameters: " + searchParameters);

            if (searchParameters.length() != 0) {

                // add new thread for searching, so that progress bar and
                // searching could run simultaneously
                Thread t1 = new Thread(new Runnable() {
                    @Override
                    public void run() {

                        progressBar.setVisible(true);
                        searchForSimilarImages(searchParameters, imageTypeString, sizeTypeString,
                                licenseTypeString, safeSearchTypeString);
                    }

                });
                // start searching for similar images in a separate thread
                t1.start();
            } else {
                JOptionPane.showMessageDialog(null,
                        "Please choose first an image to analyse or insert search parameters");
            }
        }
    });

    foundImagesLabel1.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel1.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(firstImageUrl);
                }
            }
        }
    });

    foundImagesLabel2.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel2.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(secondImageUrl);
                }
            }
        }
    });

    foundImagesLabel3.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel3.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(thirdImageUrl);
                }
            }
        }
    });

    foundImagesLabel4.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel4.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(fourthImageUrl);
                }
            }
        }
    });

    btnHelp.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // TODO write help
            HelpFrame help = new HelpFrame();
        }
    });
}

From source file:uk.co.markfrimston.tasktree.Main.java

protected void promptAndRemove(DefaultMutableTreeNode node) {
    boolean canRemove = true;
    if (node.getChildCount() > 0) {
        int resp = JOptionPane.showConfirmDialog(this, "Item contains nested items. Remove anyway?");
        if (resp != JOptionPane.YES_OPTION) {
            canRemove = false;/*ww  w  .  j a va 2 s  .c o  m*/
        }
    }
    if (canRemove) {
        this.taskTree.removeTask(node);
    }
}

From source file:fll.scheduler.SchedulerUI.java

private void newScheduleDescription() {
    final int result = JOptionPane.showConfirmDialog(SchedulerUI.this,
            "This action will remove any changes to the current schedule and load the defaults. Do you want to continue?",
            "Question", JOptionPane.YES_NO_OPTION);
    if (JOptionPane.YES_OPTION == result) {
        mScheduleDescriptionFile = null;
        mDescriptionFilename.setText("");

        final SolverParams params = new SolverParams();
        mScheduleDescriptionEditor.setParams(params);
    }//from ww w. j  a v  a2s . c o m
}

From source file:fi.hoski.remote.ui.Admin.java

private void menuEvent() {
    JMenu eventMenu = new JMenu();
    TextUtil.populate(eventMenu, "EVENTS");
    menuBar.add(eventMenu);/*from  ww w  . j a v  a 2  s  .c om*/
    JMenu addEventMenu = new JMenu();
    TextUtil.populate(addEventMenu, "ADD EVENTS");
    eventMenu.add(addEventMenu);
    JMenu editEventMenu = new JMenu();
    TextUtil.populate(editEventMenu, "EDIT EVENTS");
    eventMenu.add(editEventMenu);
    JMenu deleteEventMenu = new JMenu();
    TextUtil.populate(deleteEventMenu, "DELETE EVENTS");
    eventMenu.add(deleteEventMenu);

    int index = 0;
    for (final EventType eventType : EventType.values()) {
        // add
        JMenuItem addItem = new JMenuItem();
        TextUtil.populate(addItem, eventType.name());
        addItem.addActionListener(creators[index++]);
        addEventMenu.add(addItem);
        // edit
        ActionListener editAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                Event selected = chooseEvent(eventType, "EDIT SELECTED");
                if (selected != null) {
                    EventEditor editor = new EventEditor(null);
                    editor.edit(selected);
                } else {
                    JOptionPane.showMessageDialog(frame, TextUtil.getText("NO SELECTION"),
                            TextUtil.getText("MESSAGE"), JOptionPane.INFORMATION_MESSAGE);
                }
            }
        };
        editAction = createActionListener(frame, editAction);
        JMenuItem editItem = new JMenuItem();
        TextUtil.populate(editItem, eventType.name());
        editItem.addActionListener(editAction);
        editEventMenu.add(editItem);
        // delete
        ActionListener deleteAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                List<Event> selected = chooseEvents(eventType, "DELETE SELECTED");
                if (selected != null && selected.size() >= 1) {
                    if (JOptionPane.showConfirmDialog(panel,
                            TextUtil.getText("CONFIRM DELETE")) == JOptionPane.YES_OPTION) {
                        dss.deleteEvents(selected);
                    }
                } else {
                    JOptionPane.showMessageDialog(frame, TextUtil.getText("NO SELECTION"),
                            TextUtil.getText("MESSAGE"), JOptionPane.INFORMATION_MESSAGE);
                }
            }
        };
        deleteAction = createActionListener(frame, deleteAction);
        JMenuItem deleteItem = new JMenuItem();
        TextUtil.populate(deleteItem, eventType.name());
        deleteItem.addActionListener(deleteAction);
        deleteEventMenu.add(deleteItem);
    }
}

From source file:gmgen.util.MiscUtilities.java

/**
 * Copy a file/*from www  .j  av  a2s  .  co m*/
 * @param from_file
 * @param to_file
 * @throws IOException
 */
public static void copy(File from_file, File to_file) throws IOException {
    // First make sure the source file exists, is a file, and is readable.
    if (!from_file.exists()) {
        throw new IOException("FileCopy: no such source file: " + from_file.getPath());
    }

    if (!from_file.isFile()) {
        throw new IOException("FileCopy: can't copy directory: " + from_file.getPath());
    }

    if (!from_file.canRead()) {
        throw new IOException("FileCopy: source file is unreadable: " + from_file.getPath());
    }

    // If the destination is a directory, use the source file name
    // as the destination file name
    if (to_file.isDirectory()) {
        to_file = new File(to_file, from_file.getName());
    }

    // If the destination exists, make sure it is a writeable file
    // and ask before overwriting it.  If the destination doesn't
    // exist, make sure the directory exists and is writeable.
    if (to_file.exists()) {
        if (!to_file.canWrite()) {
            throw new IOException("FileCopy: destination file is unwriteable: " + to_file.getPath());
        }

        // Ask whether to overwrite it
        int choice = JOptionPane.showConfirmDialog(null, "Overwrite existing file " + to_file.getPath(),
                "File Exists", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

        if (choice != JOptionPane.YES_OPTION) {
            throw new IOException("FileCopy: existing file was not overwritten.");
        }
    } else {
        // if file doesn't exist, check if directory exists and is writeable.
        // If getParent() returns null, then the directory is the current dir.
        // so look up the user.dir system property to find out what that is.
        String parent = to_file.getParent(); // Get the destination directory

        if (parent == null) {
            parent = Globals.getDefaultPath(); // or CWD
        }

        File dir = new File(parent); // Convert it to a file.

        if (!dir.exists()) {
            throw new IOException("FileCopy: destination directory doesn't exist: " + parent);
        }

        if (dir.isFile()) {
            throw new IOException("FileCopy: destination is not a directory: " + parent);
        }

        if (!dir.canWrite()) {
            throw new IOException("FileCopy: destination directory is unwriteable: " + parent);
        }
    }

    // If we've gotten this far, then everything is okay.
    // So we copy the file, a buffer of bytes at a time.
    FileInputStream from = null; // Stream to read from source
    FileOutputStream to = null; // Stream to write to destination

    try {
        from = new FileInputStream(from_file); // Create input stream
        to = new FileOutputStream(to_file); // Create output stream

        byte[] buffer = new byte[4096]; // A buffer to hold file contents
        int bytes_read; // How many bytes in buffer

        while ((bytes_read = from.read(buffer)) != -1) { // Read bytes until EOF
            to.write(buffer, 0, bytes_read); //   write bytes
        }
    }

    // Always close the streams, even if exceptions were thrown
    finally {
        if (from != null) {
            try {
                from.close();
            } catch (IOException e) {
                //TODO: Should this really be ignored?
            }
        }

        if (to != null) {
            try {
                to.close();
            } catch (IOException e) {
                //TODO: Should this really be ignored?
            }
        }
    }
}

From source file:wsattacker.plugin.intelligentdos.ui.dialog.Result_NB.java

private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_saveBtnActionPerformed
    try {/*from  w ww.j av a 2 s .  co m*/
        JFileChooser fileChooser = new JFileChooser();
        int checker = fileChooser.showOpenDialog(null);
        if (checker == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();
            String message = "The selected file already exists.\nOverwrite?";
            if (!selectedFile.exists() || JOptionPane.showConfirmDialog(this, message, "Save result",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                if (!FilenameUtils.getExtension(selectedFile.getName()).equalsIgnoreCase(FILE_EXT_ZIP)) {
                    selectedFile = new File(selectedFile.getAbsoluteFile() + "." + FILE_EXT_ZIP);
                }

                btnController.save(selectedFile);
                // default title and icon
                JOptionPane.showMessageDialog(this, "Result has been saved to filesystem.");
            }
        }
    } catch (IOException e) {
        JOptionPane.showMessageDialog(this, e.getMessage(), "Fehler beim Schreiben", JOptionPane.ERROR_MESSAGE);
        logger.warn(e, e);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.obiba.onyx.jade.instrument.ricelake.RiceLakeWeightInstrumentRunner.java

/**
 * Displays a confirmation window when the application is closed by the user without saving.
 *//*from  w ww . j  a v a  2 s  .  c  o m*/
protected void confirmOnExit() {

    // Ask for confirmation only if data has been fetch from the device.
    if (saveButton.isEnabled()) {

        int wConfirmation = JOptionPane.showConfirmDialog(appWindow,
                resourceBundle.getString("Confirmation.Close_window"),
                resourceBundle.getString("Title.Confirmation"), JOptionPane.YES_NO_OPTION);

        // If confirmed, application is closed.
        if (wConfirmation == JOptionPane.YES_OPTION) {
            exitUI();
        }

    } else {
        exitUI();
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchWatchtowerFrame.java

private void deleteSelection() {
    int[] rows = jWatchtowerTable.getSelectedRows();
    if (rows.length == 0) {
        return;//from w  w  w.ja  v a 2  s  . c  o  m
    }
    String message = ((rows.length == 1) ? "Wachturmndorf " : (rows.length + " Wachturmdrfer "))
            + "wirklich lschen?";
    if (JOptionPaneHelper.showQuestionConfirmBox(this, message, "Lschen", "Nein",
            "Ja") == JOptionPane.YES_OPTION) {
        //get markers to remove
        List<Village> toRemove = new LinkedList<>();
        jWatchtowerTable.invalidate();
        for (int i = rows.length - 1; i >= 0; i--) {
            int row = jWatchtowerTable.convertRowIndexToModel(rows[i]);
            int col = jWatchtowerTable.convertColumnIndexToModel(1);
            Village v = ((KnownVillage) jWatchtowerTable.getModel().getValueAt(row, col)).getVillage();
            toRemove.add(v);
        }
        jWatchtowerTable.revalidate();
        //remove all selected markers and update the view once
        KnownVillageManager.getSingleton().removeWatchtowers(toRemove.toArray(new Village[] {}));
        showSuccess(
                toRemove.size() + ((toRemove.size() == 1) ? " Wachturm gelscht" : " Wachtrme gelscht"));
    }
}

From source file:latexstudio.editor.EditorTopComponent.java

public UnsavedWorkState canOpen() {

    if (isModified() && !isPreviewDisplayed()) {
        int userChoice = JOptionPane.showConfirmDialog(this,
                "This document has been modified. Do you want to save it first?", "Save document",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (userChoice == JOptionPane.YES_OPTION) {
            return UnsavedWorkState.SAVE_AND_OPEN;
        } else if (userChoice == JOptionPane.NO_OPTION) {
            return UnsavedWorkState.OPEN;
        } else {/*w ww.  j a va 2 s .  c o  m*/
            return UnsavedWorkState.CANCEL;
        }

    } else {
        return UnsavedWorkState.OPEN;
    }
}