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.SE.myPlayer.MusicPlayerGUI.java

private void deletePlaylist_PopUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deletePlaylist_PopUpActionPerformed
        int dialogResult = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete PLAYLIST",
                "Delete Playlist", JOptionPane.OK_CANCEL_OPTION);
        if (dialogResult == JOptionPane.YES_OPTION) {
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) folder_Playlist_Tree.getSelectionPath()
                    .getLastPathComponent();
            sd.deletePlaylist(selectedNode.toString());
            ObjectBean beanx = new ObjectBean();
            for (ObjectBean list1 : list) {
                if (list1.getTitle().equals(selectedNode.toString())) {
                    list1.getMpg().dispose();
                    beanx = list1;/*from w ww. ja  v a  2s  . c o m*/
                }
            }
            list.remove(beanx);
            addJMenuItemsToPopUP();

            getSongTable("library");
            treeReferesh();
        }
    }

From source file:GUI.MainWindow.java

public void addAffectedHost() {

    System.out.println("==addAffectedHost");

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) this.VulnTree.getLastSelectedPathComponent();
    if (node == null) {
        return;//from   w w  w. j av  a2s .  co m
    }

    Vulnerability vuln = (Vulnerability) node.getUserObject();
    //ManageAffectedHosts.setVisible(true) ;

    // Old way of doing it
    JTextField ip_address = new JTextField();
    JTextField hostname = new JTextField();
    JTextField port_number = new JTextField();
    port_number.setText("0");
    JTextField protocol = new JTextField();
    protocol.setText("tcp");

    Object[] message = { "IP Address:", ip_address, "Hostname:", hostname, "Port Number:", port_number,
            "Protocol:", protocol };

    String new_ip = null;
    String new_hostname = null;
    String new_port_number = null;
    String new_protocol = null;

    while (new_ip == null || new_hostname == null || new_port_number == null || new_protocol == null) {
        int option = JOptionPane.showConfirmDialog(null, message, "Add affected host",
                JOptionPane.OK_CANCEL_OPTION);
        if (option == JOptionPane.OK_OPTION) {

            new_ip = ip_address.getText();
            new_hostname = hostname.getText();
            new_port_number = port_number.getText();
            new_protocol = protocol.getText();
            Host host = new Host();
            host.setIp_address(new_ip);
            host.setHostname(new_hostname);
            host.setPortnumber(new_port_number);
            host.setProtocol(new_protocol);
            vuln.addAffectedHost(host);
            DefaultTableModel dtm = (DefaultTableModel) this.VulnAffectedHostsTable.getModel();
            dtm.addRow(host.getAsVector());
            dtm.fireTableDataChanged();

        } else {
            return; // End the infinite loop
        }

    }

}

From source file:de.huxhorn.lilith.swing.MainFrame.java

public void importFile(File importFile) {
    if (logger.isInfoEnabled())
        logger.info("Import file: {}", importFile.getAbsolutePath());

    File parentFile = importFile.getParentFile();
    String inputName = importFile.getName();
    if (!importFile.isFile()) {
        String message = "'" + importFile.getAbsolutePath() + "' is not a file!";
        JOptionPane.showMessageDialog(this, message, "Can't import file...", JOptionPane.ERROR_MESSAGE);
        return;//from   w  ww  .  j a v a2s. c  o  m
    }
    if (!importFile.canRead()) {
        String message = "Can't read from '" + importFile.getAbsolutePath() + "'!";
        JOptionPane.showMessageDialog(this, message, "Can't import file...", JOptionPane.ERROR_MESSAGE);
        return;
    }

    File dataFile = new File(parentFile, inputName + FileConstants.FILE_EXTENSION);
    File indexFile = new File(parentFile, inputName + FileConstants.INDEX_FILE_EXTENSION);

    // check if file exists and warn in that case
    if (dataFile.isFile()) {
        // check if file is already open
        ViewContainer<?> viewContainer = resolveViewContainer(dataFile);
        if (viewContainer != null) {
            showView(viewContainer);
            String message = "File '" + dataFile.getAbsolutePath() + "' is already open.";
            JOptionPane.showMessageDialog(this, message, "File is already open...",
                    JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String dialogTitle = "Reimport file?";
        String message = "Data file does already exist!\nReimport data file right now?";
        int result = JOptionPane.showConfirmDialog(this, message, dialogTitle, JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (JOptionPane.OK_OPTION != result) {
            return;
        }

        if (dataFile.delete()) {
            if (logger.isInfoEnabled())
                logger.info("Deleted file '{}'.", dataFile.getAbsolutePath());
        }
    }
    if (indexFile.isFile()) {
        if (indexFile.delete()) {
            if (logger.isInfoEnabled())
                logger.info("Deleted file '{}'.", indexFile.getAbsolutePath());
        }
    }

    Map<String, String> metaData = new HashMap<String, String>();
    metaData.put(FileConstants.CONTENT_FORMAT_KEY, FileConstants.CONTENT_FORMAT_VALUE_PROTOBUF);
    metaData.put(FileConstants.CONTENT_TYPE_KEY, FileConstants.CONTENT_TYPE_VALUE_LOGGING);
    metaData.put(FileConstants.COMPRESSION_KEY, FileConstants.COMPRESSION_VALUE_GZIP);

    FileBuffer<EventWrapper<LoggingEvent>> buffer = loggingFileBufferFactory.createBuffer(dataFile, indexFile,
            metaData);

    ImportType type = resolveType(importFile);
    if (type == ImportType.LOG4J) {
        String name = "Importing Log4J XML file";
        String description = "Importing Log4J XML file '" + importFile.getAbsolutePath() + "'...";
        Task<Long> task = longTaskManager.startTask(new Log4jImportCallable(importFile, buffer), name,
                description);
        if (logger.isInfoEnabled())
            logger.info("Task-Name: {}", task.getName());
        return;
    }
    if (type == ImportType.JUL) {
        String name = "Importing java.util.logging XML file";
        String description = "Importing java.util.logging XML file '" + importFile.getAbsolutePath() + "'...";
        Task<Long> task = longTaskManager.startTask(new JulImportCallable(importFile, buffer), name,
                description);
        if (logger.isInfoEnabled())
            logger.info("Task-Name: {}", task.getName());
        return;
    }

    // show warning "Unknown type"
    String message = "Couldn't detect type of file '" + importFile.getAbsolutePath()
            + "'.\nFile is unsupported.";
    JOptionPane.showMessageDialog(this, message, "Unknown file type...", JOptionPane.WARNING_MESSAGE);
}

From source file:GUI.MainWindow.java

private void EditHostnameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditHostnameActionPerformed

    System.out.println("Edit Hostname Selected");
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) this.VulnTree.getLastSelectedPathComponent();
    if (node == null) {
        return;/*from w ww.j  a v a  2  s  .c  o  m*/
    }

    Object vuln_obj = node.getUserObject();
    if (!(vuln_obj instanceof Vulnerability)) {
        return;
    }

    Vulnerability current = (Vulnerability) vuln_obj;

    int row = this.VulnAffectedHostsTable.getSelectedRow();
    row = this.VulnAffectedHostsTable.convertRowIndexToModel(row);
    Object obj = this.VulnAffectedHostsTable.getModel().getValueAt(row, 0);
    if (obj instanceof Host) {
        Host previous = (Host) obj;

        JTextField hostname = new JTextField();
        hostname.setText(previous.getHostname());
        Object[] message = { "Hostname:", hostname };

        String new_hostname = null;
        while (new_hostname == null) {
            int option = JOptionPane.showConfirmDialog(null, message, "Modify Hostname",
                    JOptionPane.OK_CANCEL_OPTION);
            if (option == JOptionPane.OK_OPTION) {
                new_hostname = hostname.getText();
                Host modified = previous.clone(); // Clone the previous one
                modified.setHostname(new_hostname);
                new TreeUtils().modifyHostname((DefaultMutableTreeNode) this.VulnTree.getModel().getRoot(),
                        previous, modified);
                //current.modifyAffectedHost(previous, modified); // Update the Vulnerability object
                // Update the affected hosts table
                DefaultTableModel dtm = (DefaultTableModel) this.VulnAffectedHostsTable.getModel();
                // Clear the existing table
                dtm.setRowCount(0);

                // Set affected hosts into table
                Enumeration enums = current.getAffectedHosts().elements();
                while (enums.hasMoreElements()) {
                    Object obj2 = enums.nextElement();
                    if (obj instanceof Host) {
                        Host host = (Host) obj2;
                        Vector row2 = host.getAsVector(); // Gets the first two columns from the host
                        dtm.addRow(row2);
                    }
                }

            } else {
                return; // user cancelled or closed the prompt
            }
        }

    }

}

From source file:ded.ui.DiagramController.java

/** Delete the selected controllers and associated entities, if any. */
public void deleteSelected() {
    if (this.mode == Mode.DCM_SELECT) {
        IdentityHashSet<Controller> sel = this.getAllSelected();
        int n = sel.size();
        if (n > 1) {
            int choice = JOptionPane.showConfirmDialog(this, "Delete " + n + " elements?", "Confirm Deletion",
                    JOptionPane.OK_CANCEL_OPTION);
            if (choice != JOptionPane.OK_OPTION) {
                return;
            }//  w  w  w.j  a  v a 2  s.c  o m
        }

        this.deleteControllers(sel);
    }
}

From source file:com.mirth.connect.client.ui.Frame.java

/**
 * Alerts the user with a Ok/cancel option with the passed in 'message'
 *///from   ww  w . j a  v a2s. com
public boolean alertOkCancel(Component parentComponent, String message) {
    int option = JOptionPane.showConfirmDialog(getVisibleComponent(parentComponent), message,
            "Select an Option", JOptionPane.OK_CANCEL_OPTION);
    if (option == JOptionPane.OK_OPTION) {
        return true;
    } else {
        return false;
    }
}

From source file:fur.shadowdrake.minecraft.InstallPanel.java

private void forceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_forceActionPerformed
    if (force.isSelected()) {
        if (JOptionPane.showConfirmDialog(this,
                "Forcing a reinstall will clean up the directory resulting in a loss of all settings!",
                "Reinstall", JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
            force.setSelected(false);/* ww w  .j  a  va 2s .  c o m*/
            return;
        }
    }

    boolean isInstalled = false;
    for (Pack p : packList) {
        if (p.name.equals(modpackChooser.getSelectedItem())) {
            isInstalled = true;
        }
    }
    dirBox.setEnabled(!isInstalled || force.isSelected());
    browse.setEnabled(!isInstalled || force.isSelected());
}

From source file:ca.uviccscu.lp.server.main.MainFrame.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    l.info("Hash action activated");
    final ActionEvent ev = evt;
    if (!Shared.hashInProgress) {
        //final Game gg;
        if (jTable1.getSelectedRow() >= 0) {
            DefaultTableModel mdl = (DefaultTableModel) jTable1.getModel();
            String name = (String) mdl.getValueAt(jTable1.getSelectedRow(), 0);
            if (name != null) {
                MainFrame.lockInterface();
                SwingWorker worker = new SwingWorker<Void, Void>() {

                    @Override//from  w  ww.  java  2s .co m
                    public Void doInBackground() {
                        l.trace("Starting hashing");
                        MainFrame.lockInterface();
                        Shared.hashInProgress = true;
                        int row = jTable1.getSelectedRow();
                        String game = (String) jTable1.getModel().getValueAt(row, 0);
                        l.trace("Selection -  row: " + row + " and name " + game);
                        int status = GamelistStorage.getGame(game).gameStatus;
                        if (status == 0) {
                            File g = new File(GamelistStorage.getGame(game).gameAbsoluteFolderPath);
                            File tp = new File(SettingsManager.getTorrentFolderPath()
                                    + GamelistStorage.getGame(game).gameName + ".torrent");
                            try {
                                updateTask("Preparing to hash - wait!", true);
                                updateProgressBar(0, 0, 0, "...", false, true);
                                jButton5.setText("STOP");
                                //jButton5.setForeground(Color.RED);
                                jButton5.setEnabled(true);
                                jButton5.requestFocusInWindow();
                                MainFrame.setReportingActive();
                                GamelistStorage.getGame(game).gameStatus = 1;
                                MainFrame.updateGameInterfaceFromStorage();
                                TOTorrent t = TrackerManager.createNewTorrent(g, tp,
                                        new HashingProgressListener(game));
                                TrackerManager.getCore().addTorrentToTracker(t, tp.getAbsolutePath(),
                                        g.getAbsolutePath());
                                GamelistStorage.getGame(game).gameStatus = 2;
                                MainFrame.updateGameInterfaceFromStorage();
                                MainFrame.setReportingIdle();
                            } catch (Exception ex) {
                                l.error("Torrent create failed: " + game, ex);
                            }
                        } else if (status == 1 || status == 2) {
                            l.error("Game torrent already created");
                            int ans = JOptionPane.showConfirmDialog(null,
                                    "This game has already been hashed. Rehash?", "Hashing error",
                                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
                            if (ans == JOptionPane.OK_OPTION) {
                                GamelistStorage.getGame(game).gameStatus = 0;
                                File tp = new File(Shared.workingDirectory + Shared.torrentStoreSubDirectory
                                        + "\\" + GamelistStorage.getGame(game).gameName + ".torrent");
                                FileUtils.deleteQuietly(tp);
                                Shared.hashInProgress = false;
                                jButton5ActionPerformed(ev);
                                Shared.hashInProgress = true;
                            } else {
                                //
                            }
                        } else {
                            l.error("Game status invalid - hashing aborted");
                        }
                        return null;
                    }

                    @Override
                    public void done() {
                        MainFrame.setReportingIdle();
                        jButton5.setText("Hash selected");
                        //jButton5.setForeground(Color.WHITE);
                        MainFrame.unlockInterface();
                        Shared.hashInProgress = false;
                        MainFrame.updateGameInterfaceFromStorage();
                    }
                };
                worker.execute();
            } else {
                l.trace("Empty row - no action required");
            }
        }
    } else {
        try {
            l.trace("Stopping current hashing");
            TrackerManager.cancelNewTorrentCreation();
            int row = jTable1.getSelectedRow();
            String game = (String) jTable1.getModel().getValueAt(row, 0);
            GamelistStorage.getGame(game).gameStatus = 0;
            MainFrame.unlockInterface();
            MainFrame.updateGameInterfaceFromStorage();
        } catch (TOTorrentException ex) {
            l.info("Abort exception received as expected", ex);
        } catch (Exception ex) {
            l.error("Hash abort unexpected exception - abort failed");
        }
        jButton5.setText("Hash selected");
        jButton5.setForeground(Color.WHITE);
    }
}

From source file:com.nikonhacker.gui.EmulatorUI.java

private void openDecodeDialog() {
    JTextField sourceFile = new JTextField();
    JTextField destinationDir = new JTextField();
    FileSelectionPanel sourceFileSelectionPanel = new FileSelectionPanel("Source file", sourceFile, false);
    sourceFileSelectionPanel.setFileFilter(".bin", "Firmware file (*.bin)");
    final JComponent[] inputs = new JComponent[] { sourceFileSelectionPanel,
            new FileSelectionPanel("Destination dir", destinationDir, true) };
    if (JOptionPane.OK_OPTION == JOptionPane.showOptionDialog(this, inputs,
            "Choose source file and destination dir", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
            null, null, JOptionPane.DEFAULT_OPTION)) {
        try {//from  w w w .ja va  2 s.  com
            new FirmwareDecoder().decode(sourceFile.getText(), destinationDir.getText(), false);
            JOptionPane.showMessageDialog(this, "Decoding complete", "Done", JOptionPane.INFORMATION_MESSAGE);
        } catch (FirmwareFormatException e) {
            JOptionPane.showMessageDialog(this, e.getMessage() + "\nPlease see console for full stack trace",
                    "Error decoding files", JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }
    }
}

From source file:com.nikonhacker.gui.EmulatorUI.java

private void openEncodeDialog() {
    JTextField destinationFile = new JTextField();
    JTextField sourceFile1 = new JTextField();
    JTextField sourceFile2 = new JTextField();
    FileSelectionPanel destinationFileSelectionPanel = new FileSelectionPanel("Destination file",
            destinationFile, false);/*from  w  w  w  . j  a  va  2 s  . c  o  m*/
    destinationFileSelectionPanel.setFileFilter(".bin", "Encoded firmware file (*.bin)");
    FileSelectionPanel sourceFile1SelectionPanel = new FileSelectionPanel("Source file 1", sourceFile1, false);
    destinationFileSelectionPanel.setFileFilter("a*.bin", "Decoded A firmware file (a*.bin)");
    FileSelectionPanel sourceFile2SelectionPanel = new FileSelectionPanel("Source file 2", sourceFile2, false);
    destinationFileSelectionPanel.setFileFilter("b*.bin", "Decoded B firmware file (b*.bin)");
    final JComponent[] inputs = new JComponent[] { destinationFileSelectionPanel, sourceFile1SelectionPanel,
            sourceFile2SelectionPanel };
    if (JOptionPane.OK_OPTION == JOptionPane.showOptionDialog(this, inputs,
            "Choose target encoded file and source files", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.DEFAULT_OPTION)) {
        try {
            ArrayList<String> inputFilenames = new ArrayList<String>();
            inputFilenames.add(sourceFile1.getText());
            inputFilenames.add(sourceFile2.getText());
            new FirmwareEncoder().encode(inputFilenames, destinationFile.getText());
            JOptionPane.showMessageDialog(this, "Encoding complete", "Done", JOptionPane.INFORMATION_MESSAGE);
        } catch (FirmwareFormatException e) {
            JOptionPane.showMessageDialog(this, e.getMessage() + "\nPlease see console for full stack trace",
                    "Error encoding files", JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }
    }
}