Example usage for javax.swing JOptionPane OK_CANCEL_OPTION

List of usage examples for javax.swing JOptionPane OK_CANCEL_OPTION

Introduction

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

Prototype

int OK_CANCEL_OPTION

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

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:com.opendoorlogistics.studio.AppFrame.java

private boolean canCloseDatastore() {
    if (loaded == null) {
        return true;
    }/*from w w w  . j  a  va 2  s.  c  o m*/

    if (loaded.isModified()) {
        if (JOptionPane.showConfirmDialog(this,
                "Spreadsheet has been modified but not saved. Continue without saving?",
                "Changes will be lost!", JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) {
            return false;
        }
    }

    return true;
}

From source file:com.cmsoftware.keyron.vista.admin.AgregarEmpleado.java

private void guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarActionPerformed
    if (validarCampos()) {
        String mensaje = "<html>";
        mensaje += "<font size=4>Desea agregar el empleado con los siguientes datos?</font><br><br><hr><br>";
        mensaje += "<font size=4><b>Cdula: </b>" + cedula.getText().trim().toLowerCase() + "</font><br>";
        mensaje += "<font size=4><b>Nombre: </b>" + nombre.getText().trim().toLowerCase() + "</font><br>";
        mensaje += "<font size=4><b>Apellido: </b>" + apellido.getText().trim().toLowerCase() + "</font><br>";
        mensaje += "<font size=4><b>Direccin: </b>" + direccion.getText().trim().toLowerCase()
                + "</font><br>";
        mensaje += "<font size=4><b>Telfono: </b>" + telefono.getText().trim().toLowerCase() + "</font><br>";
        mensaje += "<font size=4><b>Correo: </b>" + email.getText().trim().toLowerCase()
                + "</font><br><br><hr><br>";
        mensaje += "</html>";
        int respuesta = JOptionPane.showConfirmDialog(null, mensaje, "Confirmar Operacin - Keyron",
                JOptionPane.OK_CANCEL_OPTION);
        if (respuesta == 0) {
            deshabilitarCampos();/*from w ww . j  a v a2  s . c  o m*/
            guardarEmpleado();
        }
    }
}

From source file:course_generator.param.frmEditCurve.java

/**
 * Add a new curve to the curve list/*from w  w  w  .  j  a v  a 2s .  c  om*/
 */
protected void AddCurve() {
    if (!bEditMode) {

        JPanel panel = new JPanel(new GridLayout(0, 1));
        panel.add(new JLabel(bundle.getString("frmEditCurve.AddCurvePanel.name.text")));
        JTextField tfName = new JTextField("");
        panel.add(tfName);
        int result = JOptionPane.showConfirmDialog(this, panel,
                bundle.getString("frmEditCurve.AddCurvePanel.title"), JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE);
        if ((result == JOptionPane.OK_OPTION) && (!tfName.getText().isEmpty())) {
            if (Utils.FileExist(Utils.GetHomeDir() + "/" + CgConst.CG_DIR + "/" + tfName.getText() + ".par")) {
                JOptionPane.showMessageDialog(this,
                        bundle.getString("frmEditCurve.AddCurvePanelPanel.fileexist"));
                return;
            }

            //-- Add the 2 extrem points to the list and sort the list (not really necessary...)
            param = new ParamData();
            param.name = tfName.getText();
            param.data.add(new CgParam(-50.0, 0));
            param.data.add(new CgParam(50.0, 0));
            Collections.sort(param.data);

            //-- Update
            tablemodel.setParam(param);

            Old_Paramfile = Paramfile;
            Paramfile = param.name;

            bEditMode = true;
            ChangeEditStatus();
            RefreshView();
        }
    }
}

From source file:net.sf.nmedit.nomad.core.Nomad.java

public boolean askStopApplication() {
    if (!stopped) {
        for (Document d : getDocumentManager().getDocuments()) {
            if (d.isModified()) {
                Nomad n = Nomad.sharedInstance();
                int result = JOptionPane.showConfirmDialog(n.getWindow().getRootPane(),
                        "Are you sure you want to quit without saving " + d.getTitle()
                                + " ?\nChanges will not be lost upon quit, as the patch will be saved in the current session.",
                        "", JOptionPane.OK_CANCEL_OPTION);
                if (result != JOptionPane.OK_OPTION)
                    return false;

            }//from  ww  w .  j a va2s  . co m
        }
        stop();
        return stopped;
    }
    return false;
}

From source file:jboost.visualization.HistogramFrame.java

private File selectPDFFile() {

    File fFile = new File("default.pdf");
    JFileChooser fc = new JFileChooser();

    // Start in current directory
    fc.setCurrentDirectory(new File("."));

    // Set filter for Java source files.
    fc.setFileFilter(new FileFilter() {

        public boolean accept(File f) {
            String path = f.getAbsolutePath();
            if (f.isDirectory() || path.endsWith(".pdf"))
                return true;
            else/*from   w  w w  .  ja v  a 2  s. c om*/
                return false;
        }

        public String getDescription() {
            return "PDF Files";
        }
    });

    // Set to a default name for save.
    fc.setSelectedFile(fFile);

    // Open chooser dialog
    int result = fc.showSaveDialog(this);

    if (result == JFileChooser.CANCEL_OPTION) {
        return null;
    } else if (result == JFileChooser.APPROVE_OPTION) {
        fFile = fc.getSelectedFile();
        if (fFile.exists()) {
            int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (response == JOptionPane.CANCEL_OPTION)
                return null;
        }
        return fFile;
    } else {
        return null;
    }
}

From source file:pi.bestdeal.gui.InterfacePrincipale.java

private void Update_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Update_ButtonActionPerformed
    DealDAO dealdao = DealDAO.getInstance();
    Modifier_Ajouter modaj = new Modifier_Ajouter();
    Deal abc = new Deal();
    Deal deal = new Deal();
    int idd = (int) jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 0);
    List<Deal> listdeal = dealdao
            .displayDealById((int) jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 0));
    for (Deal a : listdeal) {
        abc = a;//from  www.j  a  va  2s .c  o m
    }
    modaj.txtTitre.setText(abc.getTitreDeal_Deal());
    modaj.txtDesc.setText(abc.getDescDeal_Deal());
    modaj.txtPrix.setText(abc.getPrixDeal_Deal().toString());
    modaj.txtValidation.setText(String.valueOf(abc.getNbrAchatValidation()));
    modaj.jdateDebut.setDate(abc.getDateDebutDeal_Deal());
    modaj.jdateFin.setDate(abc.getDateFinDeal_Deal());
    if (abc.isStatutDeal() == true) {
        modaj.jCheckBox1.setSelected(true);
    } else {
        modaj.jCheckBox1.setSelected(false);
    }
    if (abc.getEtatDeal_Deal().toString().equals("Pass")) {
        modaj.jComboBox1.setSelectedIndex(0);
    }
    if (abc.getEtatDeal_Deal().toString().equals("Courant")) {
        modaj.jComboBox1.setSelectedIndex(1);
    }
    if (abc.getEtatDeal_Deal().toString().equals("Comming")) {
        modaj.jComboBox1.setSelectedIndex(2);
    }

    if (abc.getCategorie_Deal().toString().equalsIgnoreCase("High-Tech")) {
        modaj.ComboCategorie.setSelectedIndex(0);
    }
    if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Bricolage")) {
        modaj.ComboCategorie.setSelectedIndex(1);
    }
    if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Bijouterie")) {
        modaj.ComboCategorie.setSelectedIndex(2);
    }
    if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Vacances&Sorties")) {
        modaj.ComboCategorie.setSelectedIndex(3);
    }

    if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Beaut")) {
        modaj.ComboCategorie.setSelectedIndex(4);
    }
    if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Accessoires&Vtements")) {
        modaj.ComboCategorie.setSelectedIndex(5);
    }
    if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Divers")) {
        modaj.ComboCategorie.setSelectedIndex(6);
    }
    abc.setEtatDeal_Deal(modaj.jComboBox1.getSelectedItem().toString());
    int result = JOptionPane.showConfirmDialog(null, modaj, "Test", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE);
    if (result == JOptionPane.OK_OPTION) {

        deal.setTitreDeal_Deal(modaj.txtTitre.getText());
        Vendeur vendeur = new Vendeur();
        VendeurDAO daov = VendeurDAO.getInstance();
        for (Vendeur a : daov.displayvendeurByNom(modaj.jList1.getSelectedValue().toString())) {
            vendeur = a;
        }
        deal.setIdDeal_Deal(idd);
        deal.setDescDeal_Deal(modaj.txtDesc.getText());
        deal.setPrixDeal_Deal(Double.valueOf(modaj.txtPrix.getText()));
        deal.setNbrAchatValidation(Integer.valueOf(modaj.txtValidation.getText()));
        deal.setNbrAchatActuelDeal_Deal(0);
        deal.setNbrAffichage_Deal(0);
        deal.setEtatDeal_Deal(modaj.jComboBox1.getSelectedItem().toString());
        java.util.Date d1 = modaj.jdateDebut.getCalendar().getTime();
        java.sql.Date sqlDate = new java.sql.Date(d1.getTime());
        java.util.Date d2 = modaj.jdateFin.getCalendar().getTime();
        java.sql.Date sqlDate2 = new java.sql.Date(d2.getTime());
        deal.setDateDebutDeal_Deal(sqlDate);
        deal.setDateFinDeal_Deal(sqlDate2);
        deal.setCategorie_Deal(modaj.ComboCategorie.getSelectedItem().toString());

        deal.setIdVendeur_Deal(vendeur.getIdVendeur());
        if (modaj.jCheckBox1.isSelected()) {
            deal.setStatutDeal_Deal(true);
        } else {
            deal.setStatutDeal_Deal(false);
        }
        int f = dealdao.updateDeal(deal);
        if (f == 1) {
            JOptionPane.showMessageDialog(null, "Deal modifi");

            DealTableModel mymodel = new DealTableModel(list.displayDeal());
            jTable1.setModel(mymodel);
            jTable1.removeColumn(jTable1.getColumn("ID"));
            jTable1.removeColumn(jTable1.getColumn("Description"));
            jTable1.removeColumn(jTable1.getColumn("Achat Actuel"));
            jTable1.removeColumn(jTable1.getColumn("Etat"));
            jTable1.removeColumn(jTable1.getColumn("Statut"));
            jTable1.removeColumn(jTable1.getColumn("Nombre d'Affichage"));
            jTable1.removeColumn(jTable1.getColumn("Vendeur"));
            jTable1.getColumnModel().setColumnMargin(20);
            if (!list.displayDeal().isEmpty()) {
                jTable1.setRowSelectionInterval(0, 0);
            }
        }
    } else {
        System.out.println("Cancelled");
    }

}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_demand.java

public static void createLinkDemandGUI(final NetworkElementType networkElementType,
        final IVisualizationCallback callback) {
    final NetPlan netPlan = callback.getDesign();
    final JComboBox originNodeSelector = new WiderJComboBox();
    final JComboBox destinationNodeSelector = new WiderJComboBox();

    for (Node node : netPlan.getNodes()) {
        final String nodeName = node.getName();
        String nodeLabel = "Node " + node.getIndex();
        if (!nodeName.isEmpty())
            nodeLabel += " (" + nodeName + ")";

        originNodeSelector.addItem(StringLabeller.of(node.getId(), nodeLabel));
        destinationNodeSelector.addItem(StringLabeller.of(node.getId(), nodeLabel));
    }//from  ww w  . java 2  s  .  c o m

    ItemListener nodeListener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            long originNodeId = (long) ((StringLabeller) originNodeSelector.getSelectedItem()).getObject();
            long destinationNodeId = (long) ((StringLabeller) destinationNodeSelector.getSelectedItem())
                    .getObject();
            callback.putTransientColorInElementTopologyCanvas(
                    Arrays.asList(netPlan.getNodeFromId(originNodeId)), Color.GREEN);
            callback.putTransientColorInElementTopologyCanvas(
                    Arrays.asList(netPlan.getNodeFromId(destinationNodeId)), Color.CYAN);
        }
    };

    originNodeSelector.addItemListener(nodeListener);
    destinationNodeSelector.addItemListener(nodeListener);

    originNodeSelector.setSelectedIndex(0);
    destinationNodeSelector.setSelectedIndex(1);

    JPanel pane = new JPanel();
    pane.add(networkElementType == NetworkElementType.LINK ? new JLabel("Origin node: ")
            : new JLabel("Ingress node: "));
    pane.add(originNodeSelector);
    pane.add(Box.createHorizontalStrut(15));
    pane.add(networkElementType == NetworkElementType.LINK ? new JLabel("Destination node: ")
            : new JLabel("Egress node: "));
    pane.add(destinationNodeSelector);

    while (true) {
        int result = JOptionPane.showConfirmDialog(null, pane,
                "Please enter end nodes for the new " + networkElementType, JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (result != JOptionPane.OK_OPTION)
            return;

        try {
            long originNodeId = (long) ((StringLabeller) originNodeSelector.getSelectedItem()).getObject();
            long destinationNodeId = (long) ((StringLabeller) destinationNodeSelector.getSelectedItem())
                    .getObject();
            Node originNode = netPlan.getNodeFromId(originNodeId);
            Node destinationNode = netPlan.getNodeFromId(destinationNodeId);

            if (netPlan.getNodeFromId(originNodeId) == null)
                throw new Net2PlanException("Node of id: " + originNodeId + " does not exist");
            if (netPlan.getNodeFromId(destinationNodeId) == null)
                throw new Net2PlanException("Node of id: " + destinationNodeId + " does not exist");

            if (networkElementType == NetworkElementType.LINK) {
                final Link e = netPlan.addLink(originNode, destinationNode, 0, 0, 200000, null);
                callback.getVisualizationState()
                        .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.LINK));
                callback.getVisualizationState().pickLink(e);
                callback.updateVisualizationAfterPick();
                callback.getUndoRedoNavigationManager().addNetPlanChange();

            } else {
                final Demand d = netPlan.addDemand(originNode, destinationNode, 0, null);
                callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.DEMAND));
                callback.getVisualizationState().pickDemand(d);
                callback.updateVisualizationAfterPick();
                callback.getUndoRedoNavigationManager().addNetPlanChange();
            }

            break;
        } catch (Throwable ex) {
            ErrorHandling.showErrorDialog(ex.getMessage(), "Error adding " + networkElementType);
        }
    }
}

From source file:com.codejumble.opentube.Main.java

/**
 * Opens the settings dialog and processes the changes performed (if
 * necessary)//from   ww  w.  j a  va2  s .com
 *
 * @param evt Swing event
 */
private void settingsItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsItemActionPerformed
    JTextField setting = new JTextField(configuredFolderForDownloadedMedia);
    Object[] settings = { "Downloads folder", setting };

    int option = JOptionPane.showConfirmDialog(null, settings, "Settings", JOptionPane.OK_CANCEL_OPTION);
    if (option == JOptionPane.OK_OPTION) {
        configuration.setProperty("downloadFolder", setting.getText());
        try {
            logger.info("Saving settings");
            configuration.save();
        } catch (ConfigurationException ex) {
            createErrorDialog(this, ex.getMessage(), "Fatal error");
        }
    }
}

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

protected void showAutoSyncSettings() {
    JCheckBox checkboxAutoSyncActive;
    JTextField fieldSyncInterval;
    JPanel panel = new JPanel(new BorderLayout());
    {// ww w  .  jav  a  2  s .  c  o  m
        checkboxAutoSyncActive = new JCheckBox("Automatische Synchronisierung aktiv");
        checkboxAutoSyncActive.setSelected(iliasProperties.isAutoSyncActive());
        panel.add(checkboxAutoSyncActive, BorderLayout.NORTH);
    }
    {
        JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
        panel2.add(new JLabel("Intervall in Minuten:"));
        fieldSyncInterval = new JTextField(String.valueOf(iliasProperties.getAutoSyncIntervalInSeconds() / 60),
                20);
        panel2.add(fieldSyncInterval);
        panel.add(panel2, BorderLayout.CENTER);
    }
    {
        panel.add(new JLabel(
                "<html>Sie knnen das Programm auch ohne GUI laufen lassen.<br>Weitere Informationen hierzu erhalten Sie, wenn Sie das Programm folgendermaen starten<br>java -jar &lt;name&gt;.jar help</html>"),
                BorderLayout.SOUTH);
    }

    if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(mainFrame, panel,
            "Automatische Synchronisierung einstellen", JOptionPane.OK_CANCEL_OPTION)) {
        iliasProperties.setAutoSyncActive(checkboxAutoSyncActive.isSelected());
        iliasProperties.setAutoSyncIntervalInSeconds(Integer.parseInt(fieldSyncInterval.getText()) * 60);
        saveProperties(iliasProperties);

        startOrStopAutoSync();
    }

}

From source file:jboost.visualization.HistogramFrame.java

private File selectDumpFile() {

    File fFile = new File("ExamplesDumpFile.txt");
    JFileChooser fc = new JFileChooser();

    // Start in current directory
    fc.setCurrentDirectory(new File("."));

    // Set filter for Java source files.
    fc.setFileFilter(new FileFilter() {

        public boolean accept(File f) {
            String path = f.getAbsolutePath();
            if (f.isDirectory() || path.endsWith(".txt"))
                return true;
            else// w  ww  .j  a v  a 2s .co  m
                return false;
        }

        public String getDescription() {
            return "Text Files";
        }
    });

    // Set to a default name for save.
    fc.setSelectedFile(fFile);

    // Open chooser dialog
    int result = fc.showSaveDialog(this);

    if (result == JFileChooser.CANCEL_OPTION) {
        return null;
    } else if (result == JFileChooser.APPROVE_OPTION) {
        fFile = fc.getSelectedFile();
        if (fFile.exists()) {
            int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (response == JOptionPane.CANCEL_OPTION)
                return null;
        }
        return fFile;
    } else {
        return null;
    }
}