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._17od.upm.gui.DatabaseActions.java

private boolean getLatestVersionOfDatabase() throws TransportException, ProblemReadingDatabaseFile, IOException,
        CryptoException, PasswordDatabaseException {
    boolean latestVersionDownloaded = false;

    // Ensure we're working with the latest version of the database
    if (databaseHasRemoteInstance() && localDatabaseDirty) {
        int answer = JOptionPane.showConfirmDialog(mainWindow, Translator.translate("askSyncWithRemoteDB"),
                Translator.translate("syncDatabase"), JOptionPane.YES_NO_OPTION);
        if (answer == JOptionPane.YES_OPTION) {
            latestVersionDownloaded = syncWithRemoteDatabase();
        }/*from   www .  j  a  v  a  2 s . c  o  m*/
    } else {
        latestVersionDownloaded = true;
    }

    return latestVersionDownloaded;
}

From source file:com.floreantpos.ui.forms.CustomerForm.java

@Override
public boolean delete() {
    try {/* w ww  .  j a va  2 s .  c  om*/
        Customer bean2 = getBean();
        if (bean2 == null)
            return false;

        int option = POSMessageDialog.showYesNoQuestionDialog(POSUtil.getBackOfficeWindow(),
                "Are you sure to delete selected table?", "Confirm"); //$NON-NLS-1$ //$NON-NLS-2$
        if (option != JOptionPane.YES_OPTION) {
            return false;
        }
        CustomerDAO.getInstance().delete(bean2);
        return true;
    } catch (Exception e) {
        POSMessageDialog.showError(POSUtil.getBackOfficeWindow(), e.getMessage(), e);
    }
    return false;
}

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

/**
 * Initialize and add one tab for each report set to jTabbedPane1
 *///from   w  ww .j  a va2 s.co  m
public void generateReportTabs() {
    jReportsTabbedPane.invalidate();
    while (jReportsTabbedPane.getTabCount() > 0) {
        ReportTableTab tab = (ReportTableTab) jReportsTabbedPane.getComponentAt(0);
        tab.deregister();
        jReportsTabbedPane.removeTabAt(0);
    }

    String[] plans = ReportManager.getSingleton().getGroups();

    //insert default tab to first place
    for (String plan : plans) {
        ReportTableTab tab = new ReportTableTab(plan, this);
        jReportsTabbedPane.addTab(plan, tab);
    }

    for (int i = 0; i < jReportsTabbedPane.getTabCount(); i++) {
        final TabPaneComponent component = new TabPaneComponent(jReportsTabbedPane);
        component.setStopEditingListener(new GenericEventListener() {
            @Override
            public void event() {
                int i = jReportsTabbedPane.indexOfTabComponent(component);
                ReportTableTab tab = (ReportTableTab) jReportsTabbedPane.getComponentAt(i);
                String newName = component.getEditedText();
                if (!newName.equals(tab.getReportSet())) {
                    newName = newName.trim();
                    if (newName.length() == 0) {
                        JOptionPaneHelper.showWarningBox(jReportsTabbedPane,
                                "'" + newName + "' ist ein ungltiger Setname", "Fehler");
                        return;
                    }
                    if (ReportManager.getSingleton().groupExists(newName)) {
                        JOptionPaneHelper.showWarningBox(jReportsTabbedPane,
                                "Es existiert bereits ein Berichtset mit dem Namen '" + newName + "'",
                                "Fehler");
                        return;
                    }

                    ReportManager.getSingleton().renameGroup(tab.getReportSet(), newName);
                }
            }
        });

        component.setCloseTabListener(new GenericEventListener() {
            @Override
            public void event() {
                int i = jReportsTabbedPane.indexOfTabComponent(component);
                ReportTableTab tab = (ReportTableTab) jReportsTabbedPane.getComponentAt(i);
                if (JOptionPaneHelper.showQuestionConfirmBox(jReportsTabbedPane,
                        "Befehlsplan '" + tab.getReportSet()
                                + "' und alle darin enthaltenen Berichte wirklich lschen? ",
                        "Lschen", "Nein", "Ja") == JOptionPane.YES_OPTION) {
                    ReportManager.getSingleton().removeGroup(tab.getReportSet());
                }
            }
        });

        if (i == 0 || i == 1) {
            component.setCloseable(false);
            component.setEditable(false);
        }

        jReportsTabbedPane.setTabComponentAt(i, component);
    }

    jReportsTabbedPane.revalidate();
    ReportTableTab tab = getActiveTab();
    if (tab != null) {
        tab.updateSet();
    }
}

From source file:edu.umass.cs.gnsserver.installer.EC2Runner.java

private static boolean showDialog(String message, final long timeout) {
    try {/*from  w w  w  .  j  a  v a2 s  .  c  om*/
        int dialog = JOptionPane.YES_NO_OPTION;
        JOptionPane optionPane = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE,
                JOptionPane.YES_NO_OPTION);
        final JDialog dlg = optionPane.createDialog("Error");
        new Thread(new Runnable() {
            @Override
            public void run() {
                {
                    ThreadUtils.sleep(timeout);
                    dlg.dispose();
                }
            }
        }).start();
        dlg.setVisible(true);
        int value = ((Integer) optionPane.getValue()).intValue();
        if (value == JOptionPane.YES_OPTION) {
            return true;
        } else {
            return false;
        }
    } catch (RuntimeException e) {
        return true;
    }
}

From source file:com.diversityarrays.kdxplore.trials.SampleGroupExportDialog.java

private void handleExportAction(boolean closeWhenDone) {

    String filename = filepathText.getText().trim();

    OmittedEntities entities = exportExclusionBox.createOmittedObject(this.excludeThesePlotIds,
            this.excludeTheseTraitIds, this.excludeTheseSampleIds);

    this.excludeTheseTraitIds = entities.omittedTraits;

    final Integer maxDatabaseVersionForWorkPackage = kdsmartVersion3option.isSelected()
            ? WorkPackageFactory.MAX_DBVERSION_FOR_KDSMART_2
            : MIN_DB_VERSION_FOR_KDSMART_3;

    BackgroundTask<File, Void> task = new BackgroundTask<File, Void>("Exporting...", true) {

        @Override/*from  w ww  .j a  v  a 2  s  .  c  o  m*/
        public File generateResult(Closure<Void> publishPartial) throws Exception {

            if (!haveCollectedSamples) {

                // Need the KdxSamples into the sampleGroup
                TrialItemVisitor<Sample> visitor = new TrialItemVisitor<Sample>() {

                    @Override
                    public void setExpectedItemCount(int count) {
                    }

                    @Override
                    public boolean consumeItem(Sample s) throws IOException {
                        if (s instanceof KdxSample) {
                            boolean suppressed = ((KdxSample) s).isSuppressed();
                            if (suppressed) {
                                excludeTheseSampleIds.add(s.getSampleId());
                                return true;
                            }

                            if (!excludeTheseTraitIds.contains(s.getTraitId())
                                    && !excludeThesePlotIds.contains(s.getPlotId())) {
                                sampleGroup.addSample((KdxSample) s);

                            }
                        }
                        return true;
                    }
                };

                kdxploreDatabase.getKDXploreKSmartDatabase().visitSamplesForTrial(
                        SampleGroupChoice.create(sampleGroup.getSampleGroupId()), sampleGroup.getTrialId(),
                        SampleOrder.ALL_UNORDERED, visitor);

                haveCollectedSamples = true;
            }

            return doExport(filename, maxDatabaseVersionForWorkPackage, entities);
        }

        @Override
        public void onCancel(CancellationException e) {
        }

        @Override
        public void onException(Throwable cause) {
            GuiUtil.errorMessage(SampleGroupExportDialog.this, cause, getTitle());
        }

        @Override
        public void onTaskComplete(File result) {
            if (result != null) {
                int answer = JOptionPane.showConfirmDialog(SampleGroupExportDialog.this,
                        "Saved: " + result.getPath() + "\nOpen containing directory?", getTitle(),
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

                if (answer == JOptionPane.YES_OPTION) {
                    try {
                        net.pearcan.util.Util.openFile(result.getParentFile());
                    } catch (IOException e) {
                        GuiUtil.errorMessage(SampleGroupExportDialog.this, e.getMessage(),
                                "Failed: " + getTitle());
                    }
                }

                if (closeWhenDone) {
                    dispose();
                }
            }
        }
    };

    backgroundRunner.runBackgroundTask(task);

}

From source file:com.floreantpos.ui.views.payment.SettleTicketDialog.java

public void settleTicket(PosTransaction transaction) {
    try {/*from   w w  w  .  j  ava  2 s  . c  o  m*/
        final double dueAmount = ticket.getDueAmount();

        confirmLoyaltyDiscount(ticket);

        PosTransactionService transactionService = PosTransactionService.getInstance();
        transactionService.settleTicket(ticket, transaction);

        //FIXME
        printTicket(ticket, transaction);

        showTransactionCompleteMsg(dueAmount, transaction.getTenderAmount(), ticket, transaction);

        if (ticket.getDueAmount() > 0.0) {
            int option = JOptionPane.showConfirmDialog(Application.getPosWindow(),
                    POSConstants.CONFIRM_PARTIAL_PAYMENT, POSConstants.MDS_POS, JOptionPane.YES_NO_OPTION);

            if (option != JOptionPane.YES_OPTION) {

                setCanceled(false);
                dispose();
            }

            setTicket(ticket);
        } else {
            setCanceled(false);
            dispose();
        }
    } catch (UnknownHostException e) {
        POSMessageDialog.showError(Application.getPosWindow(), Messages.getString("SettleTicketDialog.12")); //$NON-NLS-1$
    } catch (Exception e) {
        POSMessageDialog.showError(this, POSConstants.ERROR_MESSAGE, e);
    }
}

From source file:AppSpringLayout.java

/**
 * Initialize the contents of the frame.
 *///from   ww w  .j  a v a2 s .  c om
private void initialize() {

    frame = new JFrame();
    frame.setBounds(0, 0, 850, 750);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    springLayout = new SpringLayout();
    frame.getContentPane().setLayout(springLayout);
    frame.setLocationRelativeTo(null);

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

    btnTurnCameraOn = new JButton("Turn camera on");
    springLayout.putConstraint(SpringLayout.WEST, btnTurnCameraOn, 51, SpringLayout.WEST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, btnTurnCameraOn, -581, SpringLayout.EAST,
            frame.getContentPane());
    frame.getContentPane().add(btnTurnCameraOn);

    urlTextField = new JTextField();
    springLayout.putConstraint(SpringLayout.SOUTH, btnTurnCameraOn, -6, SpringLayout.NORTH, urlTextField);
    springLayout.putConstraint(SpringLayout.WEST, urlTextField, 0, SpringLayout.WEST, btnTurnCameraOn);
    springLayout.putConstraint(SpringLayout.EAST, urlTextField, 274, SpringLayout.WEST, frame.getContentPane());
    frame.getContentPane().add(urlTextField);
    urlTextField.setColumns(10);

    originalImageLabel = new JLabel("");
    springLayout.putConstraint(SpringLayout.NORTH, originalImageLabel, 102, SpringLayout.NORTH,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, originalImageLabel, 34, SpringLayout.WEST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, originalImageLabel, -326, SpringLayout.SOUTH,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, originalImageLabel, -566, SpringLayout.EAST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, urlTextField, -6, SpringLayout.NORTH, originalImageLabel);
    frame.getContentPane().add(originalImageLabel);

    btnAnalyseImage = new JButton("Analyse image");
    springLayout.putConstraint(SpringLayout.NORTH, btnAnalyseImage, 6, SpringLayout.SOUTH, originalImageLabel);
    springLayout.putConstraint(SpringLayout.WEST, btnAnalyseImage, 58, SpringLayout.WEST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, btnAnalyseImage, 252, SpringLayout.WEST,
            frame.getContentPane());
    frame.getContentPane().add(btnAnalyseImage);

    lblTags = new JLabel("Tags:");
    frame.getContentPane().add(lblTags);

    lblDescription = new JLabel("Description:");
    springLayout.putConstraint(SpringLayout.WEST, lblDescription, 84, SpringLayout.EAST, lblTags);
    springLayout.putConstraint(SpringLayout.NORTH, lblTags, 0, SpringLayout.NORTH, lblDescription);
    springLayout.putConstraint(SpringLayout.NORTH, lblDescription, 6, SpringLayout.SOUTH, btnAnalyseImage);
    springLayout.putConstraint(SpringLayout.SOUTH, lblDescription, -269, SpringLayout.SOUTH,
            frame.getContentPane());
    frame.getContentPane().add(lblDescription);

    tagsTextArea = new JTextArea();
    springLayout.putConstraint(SpringLayout.NORTH, tagsTextArea, 459, SpringLayout.NORTH,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, tagsTextArea, 10, SpringLayout.WEST, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, tagsTextArea, -727, SpringLayout.EAST,
            frame.getContentPane());
    frame.getContentPane().add(tagsTextArea);

    descriptionTextArea = new JTextArea();
    springLayout.putConstraint(SpringLayout.NORTH, descriptionTextArea, 0, SpringLayout.SOUTH, lblDescription);
    springLayout.putConstraint(SpringLayout.WEST, descriptionTextArea, 18, SpringLayout.EAST, tagsTextArea);
    descriptionTextArea.setLineWrap(true);
    descriptionTextArea.setWrapStyleWord(true);
    frame.getContentPane().add(descriptionTextArea);

    lblImageType = new JLabel("Image type");
    springLayout.putConstraint(SpringLayout.WEST, lblTags, 0, SpringLayout.WEST, lblImageType);
    springLayout.putConstraint(SpringLayout.NORTH, lblImageType, 10, SpringLayout.SOUTH, tagsTextArea);
    springLayout.putConstraint(SpringLayout.WEST, lblImageType, 20, SpringLayout.WEST, frame.getContentPane());
    frame.getContentPane().add(lblImageType);

    lblSize = new JLabel("Size");
    springLayout.putConstraint(SpringLayout.NORTH, lblSize, 21, SpringLayout.SOUTH, lblImageType);
    springLayout.putConstraint(SpringLayout.WEST, lblSize, 20, SpringLayout.WEST, frame.getContentPane());
    frame.getContentPane().add(lblSize);

    lblLicense = new JLabel("License");
    springLayout.putConstraint(SpringLayout.WEST, lblLicense, 20, SpringLayout.WEST, frame.getContentPane());
    frame.getContentPane().add(lblLicense);

    lblSafeSearch = new JLabel("Safe search");
    springLayout.putConstraint(SpringLayout.WEST, lblSafeSearch, 10, SpringLayout.WEST, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, lblSafeSearch, 139, SpringLayout.SOUTH,
            frame.getContentPane());
    frame.getContentPane().add(lblSafeSearch);

    String[] licenseTypes = { "unspecified", "Public", "Share", "ShareCommercially", "Modify" };
    licenseBox = new JComboBox(licenseTypes);
    springLayout.putConstraint(SpringLayout.WEST, licenseBox, 28, SpringLayout.EAST, lblLicense);
    frame.getContentPane().add(licenseBox);

    String[] sizeTypes = { "unspecified", "Small", "Medium", "Large", "Wallpaper" };
    sizeBox = new JComboBox(sizeTypes);
    springLayout.putConstraint(SpringLayout.WEST, sizeBox, 50, SpringLayout.EAST, lblSize);
    springLayout.putConstraint(SpringLayout.EAST, sizeBox, -556, SpringLayout.EAST, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, licenseBox, 0, SpringLayout.EAST, sizeBox);
    frame.getContentPane().add(sizeBox);

    String[] imageTypes = { "unspecified", "AnimategGif", "Clipart", "Line", "Photo" };
    imageTypeBox = new JComboBox(imageTypes);
    springLayout.putConstraint(SpringLayout.SOUTH, descriptionTextArea, -6, SpringLayout.NORTH, imageTypeBox);
    springLayout.putConstraint(SpringLayout.NORTH, imageTypeBox, 547, SpringLayout.NORTH,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, tagsTextArea, -6, SpringLayout.NORTH, imageTypeBox);
    springLayout.putConstraint(SpringLayout.WEST, imageTypeBox, 6, SpringLayout.EAST, lblImageType);
    springLayout.putConstraint(SpringLayout.EAST, imageTypeBox, -556, SpringLayout.EAST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.NORTH, sizeBox, 10, SpringLayout.SOUTH, imageTypeBox);
    frame.getContentPane().add(imageTypeBox);

    btnBrowse = new JButton("Browse");
    springLayout.putConstraint(SpringLayout.WEST, btnBrowse, 0, SpringLayout.WEST, btnTurnCameraOn);
    springLayout.putConstraint(SpringLayout.EAST, btnBrowse, -583, SpringLayout.EAST, frame.getContentPane());
    frame.getContentPane().add(btnBrowse);

    lblSafeSearch_1 = new JLabel("Safe search");
    springLayout.putConstraint(SpringLayout.WEST, lblSafeSearch_1, 20, SpringLayout.WEST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, lblLicense, -17, SpringLayout.NORTH, lblSafeSearch_1);
    frame.getContentPane().add(lblSafeSearch_1);

    String[] safeSearchTypes = { "Strict", "Moderate", "Off" };
    safeSearchBox = new JComboBox(safeSearchTypes);
    springLayout.putConstraint(SpringLayout.SOUTH, licenseBox, -6, SpringLayout.NORTH, safeSearchBox);
    springLayout.putConstraint(SpringLayout.WEST, safeSearchBox, 4, SpringLayout.EAST, lblSafeSearch_1);
    springLayout.putConstraint(SpringLayout.EAST, safeSearchBox, 0, SpringLayout.EAST, licenseBox);
    frame.getContentPane().add(safeSearchBox);

    btnSearchForSimilar = new JButton("Search for similar images");
    springLayout.putConstraint(SpringLayout.SOUTH, lblSafeSearch_1, -13, SpringLayout.NORTH,
            btnSearchForSimilar);
    springLayout.putConstraint(SpringLayout.SOUTH, safeSearchBox, -6, SpringLayout.NORTH, btnSearchForSimilar);
    springLayout.putConstraint(SpringLayout.NORTH, btnSearchForSimilar, 689, SpringLayout.NORTH,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, btnSearchForSimilar, 36, SpringLayout.WEST,
            frame.getContentPane());
    frame.getContentPane().add(btnSearchForSimilar);

    btnCancel = new JButton("Cancel");
    springLayout.putConstraint(SpringLayout.NORTH, btnCancel, 0, SpringLayout.NORTH, btnBrowse);
    btnCancel.setVisible(false);
    frame.getContentPane().add(btnCancel);

    btnSave = new JButton("Save");
    springLayout.putConstraint(SpringLayout.WEST, btnCancel, 6, SpringLayout.EAST, btnSave);
    springLayout.putConstraint(SpringLayout.NORTH, btnSave, 0, SpringLayout.NORTH, btnBrowse);
    btnSave.setVisible(false);
    frame.getContentPane().add(btnSave);

    btnTakeAPicture = new JButton("Take a picture");
    springLayout.putConstraint(SpringLayout.WEST, btnTakeAPicture, 114, SpringLayout.EAST, btnBrowse);
    springLayout.putConstraint(SpringLayout.WEST, btnSave, 6, SpringLayout.EAST, btnTakeAPicture);
    springLayout.putConstraint(SpringLayout.NORTH, btnTakeAPicture, 0, SpringLayout.NORTH, btnBrowse);
    btnTakeAPicture.setVisible(false);
    frame.getContentPane().add(btnTakeAPicture);

    //// JScrollPane scroll = new JScrollPane(list);
    // Constraints c = springLayout.getConstraints(list);
    // frame.getContentPane().add(scroll, c);

    list = new JList();
    JScrollPane scroll = new JScrollPane(list);
    springLayout.putConstraint(SpringLayout.EAST, descriptionTextArea, -89, SpringLayout.WEST, list);
    springLayout.putConstraint(SpringLayout.EAST, list, -128, SpringLayout.EAST, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, list, 64, SpringLayout.EAST, licenseBox);
    springLayout.putConstraint(SpringLayout.NORTH, list, 0, SpringLayout.NORTH, btnTurnCameraOn);
    springLayout.putConstraint(SpringLayout.SOUTH, list, -35, SpringLayout.SOUTH, lblSafeSearch_1);

    Constraints c = springLayout.getConstraints(list);
    frame.getContentPane().add(scroll, c);

    // frame.getContentPane().add(list);

    progressBar = new JProgressBar();
    springLayout.putConstraint(SpringLayout.NORTH, progressBar, 15, SpringLayout.SOUTH, list);
    springLayout.putConstraint(SpringLayout.WEST, progressBar, 24, SpringLayout.EAST, safeSearchBox);
    springLayout.putConstraint(SpringLayout.EAST, progressBar, 389, SpringLayout.WEST, btnTakeAPicture);
    progressBar.setIndeterminate(true);
    progressBar.setStringPainted(true);
    progressBar.setVisible(false);
    Border border = BorderFactory
            .createTitledBorder("We are checking every image, pixel by pixel, it may take a while...");
    progressBar.setBorder(border);
    frame.getContentPane().add(progressBar);

    labelTryLinks = new JLabel();
    labelTryLinks.setVisible(false);
    springLayout.putConstraint(SpringLayout.NORTH, labelTryLinks, -16, SpringLayout.SOUTH, btnSearchForSimilar);
    springLayout.putConstraint(SpringLayout.WEST, labelTryLinks, -61, SpringLayout.EAST, licenseBox);
    springLayout.putConstraint(SpringLayout.SOUTH, labelTryLinks, 0, SpringLayout.SOUTH, btnSearchForSimilar);
    springLayout.putConstraint(SpringLayout.EAST, labelTryLinks, 0, SpringLayout.EAST, licenseBox);
    frame.getContentPane().add(labelTryLinks);

    lblFoundLinks = new JLabel("");
    springLayout.putConstraint(SpringLayout.NORTH, lblFoundLinks, -29, SpringLayout.NORTH, progressBar);
    springLayout.putConstraint(SpringLayout.WEST, lblFoundLinks, 6, SpringLayout.EAST, scroll);
    springLayout.putConstraint(SpringLayout.SOUTH, lblFoundLinks, -13, SpringLayout.NORTH, progressBar);
    springLayout.putConstraint(SpringLayout.EAST, lblFoundLinks, -10, SpringLayout.EAST,
            frame.getContentPane());
    frame.getContentPane().add(lblFoundLinks);

    numberOfImagesToSearchFor = new JTextField();
    springLayout.putConstraint(SpringLayout.NORTH, numberOfImagesToSearchFor, 0, SpringLayout.NORTH,
            tagsTextArea);
    springLayout.putConstraint(SpringLayout.WEST, numberOfImagesToSearchFor, 6, SpringLayout.EAST,
            descriptionTextArea);
    springLayout.putConstraint(SpringLayout.EAST, numberOfImagesToSearchFor, -36, SpringLayout.WEST, scroll);
    frame.getContentPane().add(numberOfImagesToSearchFor);
    numberOfImagesToSearchFor.setColumns(10);

    JLabel lblNumberOfImages = new JLabel("Number");
    springLayout.putConstraint(SpringLayout.NORTH, lblNumberOfImages, 0, SpringLayout.NORTH, lblTags);
    springLayout.putConstraint(SpringLayout.WEST, lblNumberOfImages, 31, SpringLayout.EAST, btnAnalyseImage);
    springLayout.putConstraint(SpringLayout.EAST, lblNumberOfImages, -6, SpringLayout.WEST, scroll);
    frame.getContentPane().add(lblNumberOfImages);

    // label to get coordinates for web camera panel
    // lblNewLabel_1 = new JLabel("New label");
    // springLayout.putConstraint(SpringLayout.NORTH, lblNewLabel_1, 0,
    // SpringLayout.NORTH, btnTurnCameraOn);
    // springLayout.putConstraint(SpringLayout.WEST, lblNewLabel_1, 98,
    // SpringLayout.EAST, originalImagesLabel);
    // springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel_1, -430,
    // SpringLayout.SOUTH, lblSafeSearch_1);
    // springLayout.putConstraint(SpringLayout.EAST, lblNewLabel_1, 0,
    // SpringLayout.EAST, btnCancel);
    // frame.getContentPane().add(lblNewLabel_1);

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

    btnTurnCameraOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("turn camera on");
            turnCameraOn();
            btnCancel.setVisible(true);
            btnTakeAPicture.setVisible(true);
        }
    });

    btnTakeAPicture.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            btnSave.setVisible(true);
            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);
        }
    });

    btnSave.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() {
        public void actionPerformed(ActionEvent e) {
            btnTakeAPicture.setVisible(false);
            btnCancel.setVisible(false);
            btnSave.setVisible(false);
            webcam.close();
            panel.setVisible(false);
        }
    });

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

    btnAnalyseImage.addActionListener(new ActionListener() {
        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) {

            listModel.clear();

            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 = descriptionTextArea.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20");
            String tagsString = tagsTextArea.getText().replace(" ", "%20").replace("\r", "%20").replace("\n",
                    "%20");

            String numberOfImages = numberOfImagesToSearchFor.getText();

            try {
                int numberOfImagesTry = Integer.parseInt(numberOfImages);
                System.out.println(numberOfImagesTry);

                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);
                            workingUrls = searchToDisplayOnJList(searchParameters, imageTypeString,
                                    sizeTypeString, licenseTypeString, safeSearchTypeString, numberOfImages);
                        }
                    });
                    // start searching in a separate thread
                    t1.start();
                } else {
                    JOptionPane.showMessageDialog(null,
                            "Please choose first an image to analyse or insert search parameters");
                }
            } catch (NumberFormatException e1) {
                JOptionPane.showMessageDialog(null, "Please insert a valid number of images to search for");
                e1.printStackTrace();

            }
        }
    });

    list.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            int i = list.getSelectedIndex();

            if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                try {
                    file = fc.getSelectedFile();
                    File output = new File(file.toString());
                    // check if file already exists, ask user if they
                    // wish to overwrite it
                    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;
                        }
                    }
                    try {

                        URL fileNameAsUrl = new URL(linksResponse[i]);
                        originalImage = ImageIO.read(fileNameAsUrl);
                        ImageIO.write(toBufferedImage(originalImage), "jpeg", output);
                        System.out.println("image saved, in the folder: " + output.getAbsolutePath());

                    } catch (MalformedURLException e1) {
                        e1.printStackTrace();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                } catch (NullPointerException e2) {
                    e2.getMessage();
                }
            }
        }
    });
}

From source file:com.projity.pm.task.ProjectFactory.java

/**
 * @param project//w  w  w  .j  av a  2 s.c  om
 * @param allowCancel
 * @param prompt
 * @return null if cancelled
 */
public Job getRemoveProjectJob(final Project project, boolean allowCancel, boolean prompt,
        boolean calledFromSwing) {
    Job job = null;
    if (prompt && project.needsSaving()) {
        //         final boolean[] lock=new boolean[]{false};
        //            SwingUtilities.invokeLater(new Runnable(){
        //               public void run(){
        //                  Alert.okCancel("test");
        //                  synchronized (lock) {
        //                     lock[0]=true;
        //                     lock.notifyAll();
        //                  }
        //                }
        //            });
        //         synchronized(lock){
        //            while (!lock[0]){
        //               try{
        //                     lock.wait();
        //                  }catch (InterruptedException e) {}
        //            }
        //         }

        int promptResult = promptForSave(project, allowCancel);
        if (promptResult == JOptionPane.YES_OPTION) {
            SaveOptions opt = new SaveOptions();
            opt.setLocal(project.isLocal());
            if (project.isLocal()) {
                String fileName = project.getFileName();
                if (fileName == null) {
                    fileName = SessionFactory.getInstance().getLocalSession().chooseFileName(true,
                            project.getGuessedFileName());
                }
                if (fileName == null)
                    return null;
                project.setFileName(fileName);
                opt.setFileName(fileName);
                opt.setImporter(LocalSession.getImporter(project.getFileType()));
            }
            job = getSaveProjectJob(project, opt);
        } else if (promptResult == JOptionPane.CANCEL_OPTION)
            return null;
    }

    final ArrayList toRemove = new ArrayList();
    final ArrayList projects = new ArrayList();
    DeepChildWalker.recursivelyTreatBranch(portfolio.getNodeModel(), project, new Closure() {
        public void execute(Object arg0) {
            Node node = (Node) arg0;
            Object impl = node.getImpl();
            if (!(impl instanceof Project))
                return;
            final Project p = (Project) impl;
            toRemove.add(node);
            if (Environment.getStandAlone() || project.isLockable()) {
                projects.add(p);
            }
        }
    });

    Job closeProjectJob = getCloseProjectsOnServerJob(projects);
    if (closeProjectJob == null) {
        closeProjectJob = new Job(SessionFactory.getInstance().getJobQueue(), "closeProjects", "Closing...",
                false);

    }
    if (job == null)
        job = closeProjectJob;
    else
        job.addJob(closeProjectJob);

    job.addRunnable(new JobRunnable("Local: closeProjects") {
        public Object run() throws Exception {
            Iterator i = toRemove.iterator();
            while (i.hasNext()) {
                Node node = (Node) i.next();
                Project p = (Project) node.getImpl();
                portfolio.handleExternalTasks(p, false, false); // external link handling
                p.getResourcePool().removeProject(p);
                p.disconnect();
                portfolio.getObjectEventManager().fireDeleteEvent(this, p);
                portfolio.getNodeModel().remove(node, NodeModel.EVENT);

                removeClosingProject(project.getUniqueId());
            }
            System.gc(); // clean up memory used by projects
            return null; //return not used anyway
        }
    }, /*!calledFromSwing*/false, false, calledFromSwing, false);
    return job;
}

From source file:com.ejie.uda.jsonI18nEditor.Editor.java

public boolean closeCurrentSession() {
    if (isDirty()) {
        int result = JOptionPane.showConfirmDialog(this, MessageBundle.get("dialogs.save.text"),
                MessageBundle.get("dialogs.save.title"), JOptionPane.YES_NO_CANCEL_OPTION);
        if (result == JOptionPane.YES_OPTION) {
            saveResources();/* w  w  w  .  java 2  s . co m*/
        }
        return result != JOptionPane.CANCEL_OPTION;
    }
    return true;
}

From source file:course_generator.param.frmEditCurve.java

/**
 * Delete the selected line in the points table
 *//*from ww w  . j ava2s .  c  o  m*/
protected void DeleteLine() {
    if (!bEditMode)
        return;

    int r = TablePoints.getSelectedRow();
    if (r >= 0) {
        Object[] options = { " " + bundle.getString("frmEditCurve.DeleteYes") + " ",
                " " + bundle.getString("frmEditCurve.DeleteNo") + " " };
        int ret = JOptionPane.showOptionDialog(this, bundle.getString("frmEditCurve.DeleteLineMessage"),
                bundle.getString("frmEditCurve.DeleteLineTitle"), JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE, null, options, options[1]);

        if (ret == JOptionPane.YES_OPTION) {
            param.data.remove(r);
            Collections.sort(param.data);
            RefreshView();
        }
    }
}