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.floreantpos.actions.ViewChangeAction.java

private void saveTicketIfNeeded() {
    OrderView orderView = OrderView.getInstance();
    if (!orderView.isVisible()) {
        return;/*from w  w  w  . j  av a  2s . co  m*/
    }
    Ticket currentTicket = orderView.getCurrentTicket();
    if (currentTicket == null)
        return;
    if (!currentTicket.getTicketItems().isEmpty()) {
        if (hasNewItem(currentTicket)) {
            if (POSMessageDialog.showYesNoQuestionDialog(POSUtil.getFocusedWindow(),
                    Messages.getString("ViewChangeAction.1"), //$NON-NLS-1$
                    Messages.getString("ViewChangeAction.2")) == JOptionPane.YES_OPTION) { //$NON-NLS-1$
                orderView.getTicketView().saveTicketIfNeeded();
            }
        } else
            orderView.getTicketView().saveTicketIfNeeded();
    }
}

From source file:fi.elfcloud.client.tree.ClusterHierarchyModel.java

public void removeSelected(TreePath[] paths) {
    if (paths.length == 1) {
        ClusterTreeNode node = (ClusterTreeNode) paths[0].getLastPathComponent();
        String dialogTitle = Messages.getString("ClusterHierarchyModel.title_vault_remove_dialog"); //$NON-NLS-1$

        if (node instanceof DataItemNode) {
            dialogTitle = Messages.getString("ClusterHierarchyModel.title_dataitem_remove_dialog"); //$NON-NLS-1$
        } else if (node.getParentId() > 0) {
            dialogTitle = Messages.getString("ClusterHierarchyModel.title_cluster_remove_dialog"); //$NON-NLS-1$
        }/*from  www .  j  av a 2  s  . c o m*/

        int n = JOptionPane.showConfirmDialog(null,
                Messages.getString("ClusterHierarchyModel.dialog_remove_question") + node.getName() + "?", //$NON-NLS-1$ //$NON-NLS-2$
                dialogTitle, JOptionPane.YES_NO_OPTION);
        switch (n) {
        case JOptionPane.YES_OPTION:
            removePaths(paths);
            break;
        default:
            break;
        }
    } else if (paths.length > 1) {
        int n = JOptionPane.showConfirmDialog(null,
                Messages.getString("ClusterHierarchyModel.dialog_remove_multiple_items_question"), //$NON-NLS-1$
                Messages.getString("ClusterHierarchyModel.dialog_remove_multiple_items_title_1") //$NON-NLS-1$
                        + Integer.toString(paths.length)
                        + Messages.getString("ClusterHierarchyModel.dialog_remove_multiple_items_title_2"), //$NON-NLS-1$
                JOptionPane.YES_NO_OPTION);
        switch (n) {
        case JOptionPane.YES_OPTION:
            removePaths(paths);
            break;
        default:
            break;
        }
    }
}

From source file:it.imtech.configuration.ChooseServer.java

/**
 * Connection serrver test, acquiring certificate if exists.
 * @param uri - Selected server URI//from ww  w  . j  a  va  2  s.c  o m
 * @return 
 */
public static boolean testServerConnection(String uri) {
    Server s = (Server) choose_server.getSelectedItem();

    boolean result = true;
    String outputFile = Globals.USER_DIR + "certs" + Utility.getSep() + "jssecacerts.jks";

    //Aggiungo Keystore Temporaneo
    if (new File(outputFile).isFile()) {
        System.setProperty("javax.net.ssl.keyStore", outputFile);
        System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
        System.setProperty("javax.net.ssl.trustStore", outputFile);
        System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
    }

    try {
        URL url = new URL("https://" + uri);
        URLConnection con = url.openConnection();
        Reader reader = new InputStreamReader(con.getInputStream());
    } catch (SSLHandshakeException ex) {
        ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE,
                Globals.loader);
        Object[] options = { Utility.getBundleString("voc1", bundle), Utility.getBundleString("voc2", bundle) };

        int n = JOptionPane.showOptionDialog(null, Utility.getBundleString("phcertadd", bundle),
                Utility.getBundleString("phcertadd", bundle), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

        if (n == JOptionPane.YES_OPTION) {
            String[] run = new String[1];
            run[0] = uri + ":443";
            AddToStoreKey.createAndShowGUI(run);
            result = false;
        }
    } catch (Exception ex) {
    }

    return result;
}

From source file:com.stefanbrenner.droplet.ui.DevicePanel.java

/**
 * Create the panel./*from   w  w w.j ava2  s  .c  o  m*/
 */
public DevicePanel(final JComponent parent, final IDroplet droplet, final T device) {

    this.parent = parent;

    setDevice(device);

    setLayout(new BorderLayout(0, 5));
    setBorder(BorderFactory.createLineBorder(Color.BLACK));
    setBackground(DropletColors.getBackgroundColor(device));

    BeanAdapter<T> adapter = new BeanAdapter<T>(device, true);

    // device name textfield
    txtName = BasicComponentFactory.createTextField(adapter.getValueModel(IDevice.PROPERTY_NAME));
    txtName.setHorizontalAlignment(SwingConstants.CENTER);
    txtName.setColumns(1);
    txtName.setToolTipText(device.getName());
    adapter.addBeanPropertyChangeListener(IDevice.PROPERTY_NAME, new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            txtName.setToolTipText(device.getName());
        }
    });
    add(txtName, BorderLayout.NORTH);

    // actions panel with scroll pane
    actionsPanel = new JPanel();
    actionsPanel.setLayout(new BoxLayout(actionsPanel, BoxLayout.Y_AXIS));
    actionsPanel.setBackground(getBackground());

    JScrollPane scrollPane = new JScrollPane(actionsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    // resize vertical scrollbar
    scrollPane.getVerticalScrollBar().putClientProperty("JComponent.sizeVariant", "mini"); //$NON-NLS-1$ //$NON-NLS-2$
    SwingUtilities.updateComponentTreeUI(scrollPane);
    // we need no border
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    add(scrollPane, BorderLayout.CENTER);

    {
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1));

        createAddButton(panel);

        // remove button
        JButton btnRemove = new JButton(Messages.getString("ActionDevicePanel.removeDevice")); //$NON-NLS-1$
        btnRemove.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent action) {
                int retVal = JOptionPane.showConfirmDialog(DevicePanel.this,
                        Messages.getString("ActionDevicePanel.removeDevice") + " '" + device.getName() + "'?", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                        StringUtils.EMPTY, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (retVal == JOptionPane.YES_OPTION) {
                    droplet.removeDevice(device);
                }
            }
        });
        btnRemove.setFocusable(false);
        panel.add(btnRemove);

        add(panel, BorderLayout.SOUTH);
    }

}

From source file:grafix.principal.Comandos.java

static public void cmdAplicarDefault() {
    ControleRegistro.alertaRegistro();/*from   w  ww . j a  va2 s .  co m*/
    try {
        if (JOptionPane.showConfirmDialog(Controle.getTela(),
                "Deseja desfazer todas as configuraes da janela?", "Confirmar ao",
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            Controle.getJanelaAtiva().setConfiguracoesJanela(new ConfiguracoesJanela());
            Controle.getTela().atualizarJanelasGraficos();
        }
    } catch (Exception ex) {
        semJanelaAtiva();
    }
}

From source file:com.tiempometa.muestradatos.JMuestraDatos.java

public JMuestraDatos() {
    initComponents();//  w  w  w  .j  a v a 2  s  .c o m
    this.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent we) {
            int response = JOptionPane.showConfirmDialog(null, "Seguro que deseas cerrar la aplicacin?",
                    "Cerrar Programa", JOptionPane.WARNING_MESSAGE);
            if (response == JOptionPane.YES_OPTION) {
                ReaderContext.stopReading();
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                try {
                    ReaderContext.disconnectUsbReader();
                } catch (ReaderException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                System.exit(0);
            }
        }
    });
    loadSettings();
    if (ReaderContext.getSettings().getDatabaseName() == null) {
        JOptionPane.showMessageDialog(this,
                "No se ha configurado la aplicacin.\nFavor de configurar antes de continuar",
                "Sin configuracin", JOptionPane.WARNING_MESSAGE);
    } else {
        setDatabase(new File(ReaderContext.getSettings().getDatabaseName()));
    }
    ReaderContext.addReadingListener(this);
    ReaderContext.addReaderStatusListener(this);
    Thread thread = new Thread(systemTime);
    thread.start();
}

From source file:gdt.jgui.entity.bookmark.JBookmarksEditor.java

/**
 * Get context menu.//w  ww.  java2 s  .  c om
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = super.getContextMenu();
    mia = null;
    int cnt = menu.getItemCount();
    if (cnt > 0) {
        mia = new JMenuItem[cnt];
        for (int i = 0; i < cnt; i++)
            mia[i] = menu.getItem(i);
    }
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //            System.out.println("BookmarksEditor:getConextMenu:menu selected");
            menu.removeAll();
            if (mia != null) {
                for (JMenuItem mi : mia)
                    menu.add(mi);
            }
            if (hasSelectedItems()) {
                menu.addSeparator();
                JMenuItem copyItem = new JMenuItem("Copy");
                copyItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        copy();
                    }
                });
                menu.add(copyItem);
                JMenuItem deleteItem = new JMenuItem("Delete");
                deleteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?",
                                    "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                            if (response == JOptionPane.YES_OPTION) {
                                String[] sa = JBookmarksEditor.this.listSelectedItems();
                                if (sa == null)
                                    return;
                                String bookmarkKey$;
                                Entigrator entigrator = console.getEntigrator(entihome$);
                                Sack entity = entigrator.getEntityAtKey(entityKey$);
                                for (String aSa : sa) {
                                    bookmarkKey$ = Locator.getProperty(aSa, BOOKMARK_KEY);
                                    if (bookmarkKey$ == null)
                                        continue;
                                    entity.removeElementItem("jbookmark", bookmarkKey$);
                                }
                                entigrator.save(entity);
                                JConsoleHandler.execute(console, getLocator());
                            }
                        } catch (Exception ee) {
                            LOGGER.severe(ee.toString());
                        }
                    }
                });
                menu.add(deleteItem);
            }
            if (hasToPaste()) {
                JMenuItem pasteItem = new JMenuItem("Paste");
                pasteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        paste();
                    }
                });
                menu.add(pasteItem);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    return menu;
}

From source file:com.peter.javaautoupdater.JavaAutoUpdater.java

public static void run(String ftpHost, int ftpPort, String ftpUsername, String ftpPassword,
        boolean isLocalPassiveMode, boolean isRemotePassiveMode, String basePath, String softwareName,
        String args[]) {//  w w  w .  j  a v  a 2s  .c  o m
    System.out.println("jarName=" + jarName);
    for (String arg : args) {
        if (arg.toLowerCase().trim().equals("-noautoupdate")) {
            return;
        }
    }
    JavaAutoUpdater.basePath = basePath;
    JavaAutoUpdater.softwareName = softwareName;
    JavaAutoUpdater.args = args;

    if (!jarName.endsWith(".jar") || jarName.startsWith("JavaAutoUpdater-")) {
        if (isDebug) {
            jarName = "test.jar";
        } else {
            return;
        }
    }
    JProgressBarDialog d = new JProgressBarDialog(new JFrame(), "Auto updater", true);

    d.progressBar.setIndeterminate(true);
    d.progressBar.setStringPainted(true);
    d.progressBar.setString("Updating");
    //      d.addCancelEventListener(this);
    Thread longRunningThread = new Thread() {
        public void run() {
            d.progressBar.setString("checking latest version");
            System.out.println("checking latest version");

            FTPClient ftp = new FTPClient();
            try {
                ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
                ftp.connect(ftpHost, ftpPort);
                int reply = ftp.getReplyCode();
                System.out.println("reply=" + reply + ", " + FTPReply.isPositiveCompletion(reply));
                if (!FTPReply.isPositiveCompletion(reply)) {
                    ftp.disconnect();
                    JOptionPane.showMessageDialog(null, "FTP server refused connection", "error",
                            JOptionPane.ERROR_MESSAGE);
                }
                d.progressBar.setString("connected to ftp");
                System.out.println("connected to ftp");
                boolean success = ftp.login(ftpUsername, ftpPassword);
                if (!success) {
                    ftp.disconnect();
                    JOptionPane.showMessageDialog(null, "FTP login fail, can't update software", "error",
                            JOptionPane.ERROR_MESSAGE);
                }
                if (isLocalPassiveMode) {
                    ftp.enterLocalPassiveMode();
                }
                if (isRemotePassiveMode) {
                    ftp.enterRemotePassiveMode();
                }
                FTPFile[] ftpFiles = ftp.listFiles(basePath, new FTPFileFilter() {
                    @Override
                    public boolean accept(FTPFile file) {
                        if (file.getName().startsWith(softwareName)) {
                            return true;
                        } else {
                            return false;
                        }
                    }
                });
                if (ftpFiles.length > 0) {
                    FTPFile targetFile = ftpFiles[ftpFiles.length - 1];
                    System.out.println("targetFile : " + targetFile.getName() + " , " + targetFile.getSize()
                            + "!=" + new File(jarName).length());
                    if (!targetFile.getName().equals(jarName)
                            || targetFile.getSize() != new File(jarName).length()) {
                        int r = JOptionPane.showConfirmDialog(null,
                                "Confirm to update to " + targetFile.getName(), "Question",
                                JOptionPane.YES_NO_OPTION);
                        if (r == JOptionPane.YES_OPTION) {
                            //ftp.enterRemotePassiveMode();
                            d.progressBar.setString("downloading " + targetFile.getName());
                            ftp.setFileType(FTP.BINARY_FILE_TYPE);
                            ftp.setFileTransferMode(FTP.BINARY_FILE_TYPE);

                            d.progressBar.setIndeterminate(false);
                            d.progressBar.setMaximum(100);
                            CopyStreamAdapter streamListener = new CopyStreamAdapter() {

                                @Override
                                public void bytesTransferred(long totalBytesTransferred, int bytesTransferred,
                                        long streamSize) {
                                    int percent = (int) (totalBytesTransferred * 100 / targetFile.getSize());
                                    d.progressBar.setValue(percent);
                                }
                            };
                            ftp.setCopyStreamListener(streamListener);
                            try (FileOutputStream fos = new FileOutputStream(targetFile.getName())) {
                                ftp.retrieveFile(basePath + "/" + targetFile.getName(), fos);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            d.progressBar.setString("restarting " + targetFile.getName());
                            restartApplication(targetFile.getName());
                        }
                    }

                }
                ftp.logout();
                ftp.disconnect();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };
    d.thread = longRunningThread;
    d.setVisible(true);
}

From source file:com.tiempometa.muestradatos.JReadTags.java

private void deleteSelectedButtonActionPerformed(ActionEvent e) {
    int response = JOptionPane.showConfirmDialog(this,
            "Se borrarn los tags seleccionados.\nEsta operacin no se puede deshacer.\nContinuar?",
            "Borrar tags seleccionados", JOptionPane.WARNING_MESSAGE);
    if (response == JOptionPane.YES_OPTION) {
        int[] rows = tagReadTable.getSelectedRows();
        List<Rfid> removedItems = new ArrayList<Rfid>();
        for (int i = 0; i < rows.length; i++) {
            Rfid rfid = tagTableModel.getData().get(tagReadTable.convertRowIndexToModel(rows[i]));
            try {
                rfidDao.delete(rfid);/*from w  ww.  j  a  v  a  2  s. co  m*/
                removedItems.add(rfid);
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
        for (int i = 0; i < removedItems.size(); i++) {
            Rfid rfid = removedItems.get(i);
            tagTableModel.getData().remove(rfid);
        }
        tagTableModel.fireTableDataChanged();
    }
}

From source file:fr.insalyon.creatis.vip.vipcoworkapplet.Cowork.java

/** Initializes the applet Main */
@Override/*from   www.j av  a 2  s.  co  m*/
public void init() {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(Cowork.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(Cowork.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(Cowork.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(Cowork.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    }
    //</editor-fold>

    /* Create and display the applet */
    try {
        java.awt.EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                try {
                    sessionId = getParameter("sessionId");
                    email = getParameter("email");
                    endpoint = getCodeBase().toString() + "/fr.insalyon.creatis.vip.portal.Main/coworkservice";

                    DesignFrame frame = new DesignFrame(true);
                    frame.setAppletParams(endpoint, email, sessionId);

                    String home = System.getProperty("user.home");
                    File config = new File(home + File.separator + ".cowork/config");
                    PropertiesConfiguration pc = new PropertiesConfiguration(config);

                    String password = (String) pc.getProperty("password"),
                            login = (String) pc.getProperty("login");
                    PasswordDialog p = new PasswordDialog(null, "Please login to the knowledge base");
                    while (password == null || login == null) {
                        if (p.showDialog()) {

                            login = p.getName();
                            password = p.getPass();
                        }
                        if (login != null && password != null) {
                            if (JOptionPane.showConfirmDialog(null, "Remember credentials (unencrypted)?",
                                    "Rememeber?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                                pc.setProperty("password", password);
                                pc.setProperty("login", login);
                                pc.save();
                            }
                        }

                    }

                    KnowledgeBase kb = new KnowledgeBase("jdbc:mysql://" + getCodeBase().getHost() + "/cowork",
                            login, password, "http://cowork.i3s.cnrs.fr/");
                    frame.setKB(kb);
                    frame.setVisible(true);
                } catch (ConfigurationException ex) {
                    ex.printStackTrace();

                    JOptionPane.showMessageDialog(null, ExceptionUtils.getStackTrace(ex), "Error",
                            JOptionPane.ERROR_MESSAGE);
                } catch (SQLException ex) {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(null, ExceptionUtils.getStackTrace(ex), "Error",
                            JOptionPane.ERROR_MESSAGE);
                }

            }
        });
    } catch (Exception ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, ExceptionUtils.getStackTrace(ex), "Error",
                JOptionPane.ERROR_MESSAGE);
    }
}