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:org.jtheque.ui.impl.UIUtilsImpl.java

@Override
public boolean askUserForConfirmation(final String text, final String title) {
    boolean yes = false;

    Window parent = null;/*from  www.j  a v a 2 s  .  c o  m*/

    if (SimplePropertiesCache.get(MAIN_VIEW_CACHE, Window.class) != null) {
        parent = SimplePropertiesCache.get(MAIN_VIEW_CACHE, Window.class);
    }

    final Window p = parent;

    final int[] response = new int[1];

    if (SwingUtilities.isEventDispatchThread()) {
        response[0] = JOptionPane.showConfirmDialog(parent, text, title, JOptionPane.YES_NO_OPTION);
    } else {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    response[0] = JOptionPane.showConfirmDialog(p, text, title, JOptionPane.YES_NO_OPTION);
                }
            });
        } catch (InterruptedException e) {
            LoggerFactory.getLogger(getClass()).error(e.getMessage(), e);
        } catch (InvocationTargetException e) {
            LoggerFactory.getLogger(getClass()).error(e.getMessage(), e);
        }
    }

    if (response[0] == JOptionPane.YES_OPTION) {
        yes = true;
    }

    return yes;
}

From source file:csh.vctt.launcher.Launcher.java

/**
 * Prompt the user to select their character from a dialog.
 * @return Unique id number of the selected character.
 *///from   w  w w  .  j a  v  a 2  s. c  o  m
private String getPlayerSelection() {
    String selectedId = "-1";

    String outfitMembersJson = DataManager.execQuery(DataManager.M_OUTFITMEMBER_SELECT_QUERY);
    List<Player> outfitMembers = DataManager.getOutfitMembers(outfitMembersJson);
    Object[] outfitMembersArrObj = outfitMembers.toArray();
    Player[] outfitMembersArr = new Player[outfitMembersArrObj.length];
    for (int i = 0; i < outfitMembersArrObj.length; i++) {
        outfitMembersArr[i] = (Player) outfitMembersArrObj[i];
    }

    JList<Player> memSelList = new JList<Player>(outfitMembersArr);
    memSelList.setVisibleRowCount(10);

    JScrollPane memScrollPane = new JScrollPane(memSelList);
    memScrollPane.setPreferredSize(new Dimension(200, 400));

    int userAction = JOptionPane.showConfirmDialog(null, memScrollPane, "Select Character and Press Ok",
            JOptionPane.PLAIN_MESSAGE);

    Player selectedPlayer = null;
    if (userAction == JOptionPane.YES_OPTION) {
        selectedPlayer = memSelList.getSelectedValue();
    }

    if (selectedPlayer != null) {
        selectedId = selectedPlayer.getId();
    }

    return selectedId;
}

From source file:com.floreantpos.bo.ui.explorer.QuickMaintenanceExplorer.java

private static void quickMaintainMenuItem(MenuItem menuItem) {
    try {//from w w  w . j a va 2 s .co  m
        if (menuItem.getId() != null) {
            if (btnCopy.isSelected()) {
                MenuItem newMenuItem = new MenuItem();
                PropertyUtils.copyProperties(newMenuItem, menuItem);
                newMenuItem.setId(null);
                newMenuItem.setFractionalUnit(menuItem.isFractionalUnit());
                newMenuItem.setDisableWhenStockAmountIsZero(menuItem.isDisableWhenStockAmountIsZero());
                newMenuItem.setShowImageOnly(menuItem.isShowImageOnly());
                menuItem = newMenuItem;
            } else if (btnDelete.isSelected()) {
                if (POSMessageDialog.showYesNoQuestionDialog(POSUtil.getFocusedWindow(),
                        POSConstants.CONFIRM_DELETE, POSConstants.DELETE) != JOptionPane.YES_OPTION) {
                    return;
                }
                MenuItemDAO foodItemDAO = new MenuItemDAO();
                if (menuItem.getDiscounts() != null && menuItem.getDiscounts().size() > 0) {
                    foodItemDAO.releaseParentAndDelete(menuItem);
                } else {
                    try {
                        foodItemDAO.delete(menuItem.getId());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                OrderView.getInstance().getItemView().updateView(menuItem);
                return;
            }
        } else {
            menuItem.addToorderTypeList(OrderView.getInstance().getTicketView().getTicket().getOrderType());
        }
        MenuItemForm editor = new MenuItemForm(menuItem);
        BeanEditorDialog dialog = new BeanEditorDialog(Application.getPosWindow(), editor);
        dialog.open();
        if (dialog.isCanceled())
            return;
        OrderView.getInstance().getItemView().updateView(menuItem);
        return;
    } catch (Exception e) {
        return;
    }
}

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

private void deleteReadButtonActionPerformed(ActionEvent e) {
    int response = JOptionPane.showConfirmDialog(this,
            "Se borrar el tag seleccionado.\nEsta operacin no se puede deshacer.\nContinuar?", "Borrar tags",
            JOptionPane.WARNING_MESSAGE);
    if (response == JOptionPane.YES_OPTION) {
        try {//from   w ww .  ja  va2 s .  co m
            List<Rfid> rfids = tagTableModel.getData();
            for (Rfid rfid : rfids) {
                rfidDao.delete(rfid);
            }
            tagTableModel.setData(new ArrayList<Rfid>());
            tagTableModel.fireTableDataChanged();
        } catch (SQLException e1) {
            JOptionPane.showMessageDialog(this, "No se pudieron borrar todos los tags. " + e1.getMessage(),
                    "Error borrando tags", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:com.openbravo.pos.customers.CustomersPayment.java

/**
 *
 * @return//from   w w w . j  a  v a 2s  . com
 */
@Override
public boolean deactivate() {
    if (dirty.isDirty()) {
        int res = JOptionPane.showConfirmDialog(this, AppLocal.getIntString("message.wannasave"),
                AppLocal.getIntString("title.editor"), JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (res == JOptionPane.YES_OPTION) {
            save();
            return true;
        } else {
            return res == JOptionPane.NO_OPTION;
        }
    } else {
        return true;
    }
}

From source file:de.dakror.virtualhub.client.dialog.ChooseCatalogDialog.java

public static void show(ClientFrame frame, final JSONArray data) {
    final JDialog dialog = new JDialog(frame, "Katalog whlen", true);
    dialog.setSize(400, 300);/*from w ww .  ja va 2  s.com*/
    dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            Client.currentClient.disconnect();
            System.exit(0);
        }
    });

    JPanel contentPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    dialog.setContentPane(contentPane);
    DefaultListModel dlm = new DefaultListModel();
    for (int i = 0; i < data.length(); i++) {
        try {
            dlm.addElement(data.getJSONObject(i).getString("name"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    final JList catalogs = new JList(dlm);
    catalogs.setDragEnabled(false);
    catalogs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JScrollPane jsp = new JScrollPane(catalogs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jsp.setPreferredSize(new Dimension(396, 200));
    contentPane.add(jsp);

    JPanel mods = new JPanel(new GridLayout(1, 2));
    mods.setPreferredSize(new Dimension(50, 22));
    mods.add(new JButton(new AbstractAction("+") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            String name = JOptionPane.showInputDialog(dialog,
                    "Bitte geben Sie den Namen des neuen Katalogs ein.", "Katalog hinzufgen",
                    JOptionPane.PLAIN_MESSAGE);
            if (name != null && name.length() > 0) {
                DefaultListModel dlm = (DefaultListModel) catalogs.getModel();
                for (int i = 0; i < dlm.getSize(); i++) {
                    if (dlm.get(i).toString().equals(name)) {
                        JOptionPane.showMessageDialog(dialog,
                                "Es existert bereits ein Katalog mit diesem Namen!",
                                "Katalog bereits vorhanden!", JOptionPane.ERROR_MESSAGE);
                        actionPerformed(e);
                        return;
                    }
                }

                try {
                    dlm.addElement(name);
                    JSONObject o = new JSONObject();
                    o.put("name", name);
                    o.put("sources", new JSONArray());
                    o.put("tags", new JSONArray());
                    data.put(o);
                    Client.currentClient.sendPacket(new Packet0Catalogs(data));
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    }));
    mods.add(new JButton(new AbstractAction("-") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (catalogs.getSelectedIndex() != -1) {
                if (JOptionPane.showConfirmDialog(dialog,
                        "Sind Sie sicher, dass Sie diesen\r\nKatalog unwiderruflich lschen wollen?",
                        "Katalog lschen", JOptionPane.YES_NO_CANCEL_OPTION,
                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                    DefaultListModel dlm = (DefaultListModel) catalogs.getModel();
                    data.remove(catalogs.getSelectedIndex());
                    dlm.remove(catalogs.getSelectedIndex());
                    try {
                        Client.currentClient.sendPacket(new Packet0Catalogs(data));
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    }));

    contentPane.add(mods);

    JLabel l = new JLabel("");
    l.setPreferredSize(new Dimension(396, 14));
    contentPane.add(l);

    JSeparator sep = new JSeparator(JSeparator.HORIZONTAL);
    sep.setPreferredSize(new Dimension(396, 10));
    contentPane.add(sep);

    JPanel buttons = new JPanel(new GridLayout(1, 2));
    buttons.setPreferredSize(new Dimension(396, 22));
    buttons.add(new JButton(new AbstractAction("Abbrechen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            Client.currentClient.disconnect();
            System.exit(0);
        }
    }));
    buttons.add(new JButton(new AbstractAction("Katalog whlen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (catalogs.getSelectedIndex() != -1) {
                try {
                    Client.currentClient
                            .setCatalog(new Catalog(data.getJSONObject(catalogs.getSelectedIndex())));
                    Client.currentClient.frame.setTitle("- " + Client.currentClient.getCatalog().getName());
                    dialog.dispose();
                } catch (JSONException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }));

    dialog.add(buttons);

    dialog.setLocationRelativeTo(frame);
    dialog.setResizable(false);
    dialog.setVisible(true);
}

From source file:nosqltools.MainForm.java

/**
 * Creates new form MainForm and sets the necessary properties for the main
 * form/*from w ww  .  j  av a  2 s  .c om*/
 */
public MainForm() {
    Image img = null;
    try {
        img = ImageIO.read(new File("resources/mongoicon.png"));
    } catch (IOException e) {
    }
    this.setIconImage(img);
    initComponents();
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    fc.setFileFilter(filter);

    textArea = new RSyntaxTextArea(20, 60);
    textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
    textArea.setCodeFoldingEnabled(true);
    textArea.setAntiAliasingEnabled(true);
    Table_JSON.addMouseListener(new java.awt.event.MouseAdapter() {
        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            int row = Table_JSON.rowAtPoint(evt.getPoint());
            int col = Table_JSON.columnAtPoint(evt.getPoint());

            JOptionPane.showMessageDialog(null,
                    "Value in the cell clicked :" + " " + Table_JSON.getValueAt(row, col).toString());

            if (json_util.isArray(Table_JSON.getValueAt(row, col).toString())) {
                if (JOptionPane.showConfirmDialog(null, "View the array as a table:", "VIEW",
                        JOptionPane.OK_CANCEL_OPTION) == JOptionPane.YES_OPTION) {
                    Panel_Views.setEnabled(false);
                    Panel_Connections.setEnabled(false);
                    jMenuBar1.setEnabled(false);

                    if (row >= 0 && col >= 0) {

                        TableForm tableForm = new TableForm(Table_JSON.getValueAt(row, col).toString());
                    }
                }
            }
        }
    });
    RTextScrollPane sp = new RTextScrollPane(textArea);
    sp.setFoldIndicatorEnabled(true);
    Panel_Text.add(sp);
    Save_File.setEnabled(false);

    Panel_Text.setVisible(false);
    Panel_Table.setVisible(false);
    Panel_Hierarchical.setVisible(false);
    Panel_Compare.setVisible(false);
    Panel_Compare_Upper.setVisible(false);
    Panel_Connect.setVisible(false);

    util.changeTextAreaTheme(textArea);

}

From source file:edu.ku.brc.specify.tasks.InteractionsProcessor.java

/**
 * Asks where the source of the Loan Preps should come from.
 * @return the source enum//w w w  .  ja v a2  s. c om
 */
protected ASK_TYPE askSourceOfPreps(final boolean hasInfoReqs, final boolean hasColObjRS,
        final T currPrepProvider) {
    String label;
    if (hasInfoReqs && hasColObjRS) {
        label = getResourceString("NEW_INTER_USE_RS_IR");

    } else if (hasInfoReqs) {
        label = getResourceString("NEW_INTER_USE_IR");
    } else {
        label = getResourceString("NEW_INTER_USE_RS");
    }

    boolean isForAcc = isFor == forAcc;
    Object[] options = new Object[!isForAcc
            || (isForAcc && ((!hasInfoReqs && !hasColObjRS) || currPrepProvider != null)) ? 2 : 3];
    Integer dosOpt = null;
    Integer rsOpt = null;
    Integer noneOpt = null;
    if (!isForAcc || currPrepProvider != null) {
        options[0] = label;
        options[1] = getResourceString("NEW_INTER_ENTER_CATNUM");
        rsOpt = JOptionPane.YES_OPTION;
        dosOpt = JOptionPane.NO_OPTION;
    } else {
        if (options.length == 2) {
            options[0] = getResourceString("NEW_INTER_ENTER_CATNUM");
            options[1] = getResourceString("NEW_INTER_EMPTY");
            dosOpt = JOptionPane.YES_OPTION;
            noneOpt = JOptionPane.NO_OPTION;
        } else {
            options[0] = label;
            options[1] = getResourceString("NEW_INTER_ENTER_CATNUM");
            options[2] = getResourceString("NEW_INTER_EMPTY");
            rsOpt = JOptionPane.YES_OPTION;
            dosOpt = JOptionPane.NO_OPTION;
            noneOpt = JOptionPane.CANCEL_OPTION;
        }
    }

    int userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
            getResourceString("NEW_INTER_CHOOSE_RSOPT"), getResourceString("NEW_INTER_CHOOSE_RSOPT_TITLE"),
            JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
    if (userChoice == dosOpt) {
        return ASK_TYPE.EnterDataObjs;
    } else if (rsOpt != null && userChoice == rsOpt) {
        return ASK_TYPE.ChooseRS;
    } else if (noneOpt != null && userChoice == noneOpt) {
        return ASK_TYPE.None;
    }

    return ASK_TYPE.Cancel;
}

From source file:Main_Window.java

public Main_Window() {
    super("Google Places Application"); //First call Constructor of JFrame

    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //We do not want our application to terminate when a JFrame is closed
    this.addWindowListener(new java.awt.event.WindowAdapter() {
        @Override/*from w  w  w .j  a v a2 s.  c  o  m*/
        public void windowClosing(java.awt.event.WindowEvent windowEvent) {
            int Answer = JOptionPane.showConfirmDialog(null, "Exit Application ? ", "Exit ? ",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (Answer == JOptionPane.YES_OPTION) {
                if (POI_List.isEmpty()) {
                    POI_List.clear();
                }
                if (Distances_List.isEmpty()) {
                    Distances_List.clear();
                }
                if (Temp_List.isEmpty()) {
                    Temp_List.clear();
                }
                if (Distances_List_2.isEmpty()) {
                    Distances_List_2.clear();
                }
                System.exit(1);
            } else {
                setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
            }
        }
    });
    //The listener object created from that class is then registered with a Window using the window's addWindowListener method.

    //
    this.setSize(1100, 700); // Size of Window
    this.setLocationRelativeTo(null); // Display Window in center of Screen
    this.setVisible(true);
    this.getContentPane().setBackground(Color.LIGHT_GRAY);
    //

    //Initialization of J Components
    POIS_Label = new JLabel("Points of Interest:");
    POIS_Label.setForeground(Color.black);
    POIS_Label.setFont(new Font("Courier New", Font.BOLD, 25));
    POIS_Label.setBounds(600, 30, 350, 150);

    Retrieve_POIs_Button = new JButton("Retrieve POIs");
    Retrieve_POIs_Button.setForeground(Color.black);
    Retrieve_POIs_Button.setFont(new Font("Courier New", Font.BOLD, 35));
    Retrieve_POIs_Button.setBounds(25, 450, 350, 150);

    Open_Status = new JRadioButton(" Open Now?");
    Open_Status.setForeground(Color.black);
    Open_Status.setBackground(Color.LIGHT_GRAY);
    Open_Status.setBounds(20, 380, 100, 30);

    Welcome_Label = new JLabel("Welcome to Google Places");
    Welcome_Label.setForeground(Color.BLUE);
    Welcome_Label.setFont(new Font("Courier New", Font.BOLD, 35));
    Welcome_Label.setBounds(240, 20, 600, 60);

    Latitude_Label = new JLabel("Latitude:");
    Latitude_Label.setForeground(Color.BLACK);
    Latitude_Label.setFont(new Font("Courier New", Font.PLAIN, 25));
    Latitude_Label.setBounds(15, 80, 200, 100);

    Longitude_Label = new JLabel("Longitude:");
    Longitude_Label.setForeground(Color.BLACK);
    Longitude_Label.setFont(new Font("Courier New", Font.PLAIN, 25));
    Longitude_Label.setBounds(15, 130, 250, 100);

    Radius_Label = new JLabel("Radius:");
    Radius_Label.setForeground(Color.BLACK);
    Radius_Label.setFont(new Font("Courier New", Font.PLAIN, 25));
    Radius_Label.setBounds(15, 180, 250, 100);

    Category_Label = new JLabel("Category:");
    Category_Label.setForeground(Color.BLACK);
    Category_Label.setFont(new Font("Courier New", Font.PLAIN, 25));
    Category_Label.setBounds(15, 250, 250, 100);

    Latitude_TextField = new JTextField(7);
    Latitude_TextField.setForeground(Color.BLACK);
    Latitude_TextField.setBounds(165, 116, 180, 30);

    Longitude_TextField = new JTextField(7);
    Longitude_TextField.setForeground(Color.BLACK);
    Longitude_TextField.setBounds(170, 168, 180, 30);

    Radius_TextField = new JTextField(7);
    Radius_TextField.setForeground(Color.BLACK);
    Radius_TextField.setBounds(125, 215, 180, 30);

    Categories = new JComboBox(Categories_Names);
    Categories.setForeground(Color.BLACK);
    Categories.setBackground(Color.white);
    Categories.setBounds(15, 320, 180, 30);

    POI_List = new ArrayList();

    pane = getContentPane(); //Manager
    pane.setLayout(null); // Deactivate Manager Layout

    //JPANEL
    P = new JPanel();
    P.setBackground(Color.GRAY);
    P.setBounds(600, 120, 450, 180);
    P.setBackground(Color.GRAY);

    pane.add(P);
    pane.add(POIS_Label);
    pane.add(Retrieve_POIs_Button);
    pane.add(Welcome_Label);
    pane.add(Longitude_Label);
    pane.add(Latitude_Label);
    pane.add(Radius_Label);
    pane.add(Category_Label);
    pane.add(Latitude_TextField);
    pane.add(Longitude_TextField);
    pane.add(Radius_TextField);
    pane.add(Categories);
    pane.add(Open_Status);

    Retrieve_POIs_Button.addActionListener(this);

    setContentPane(pane);

}

From source file:com.mindcognition.mindraider.ui.swing.explorer.NotebooksTreeToolbar.java

public void actionPerformed(ActionEvent e) {
    // find notebook through node's user object URI, discard notebook (move it to the archive), 
    // tags are preserved until notebook is erased

    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) explorerJPanel.getNotebooksTree()
            .getLastSelectedPathComponent();
    if (selectedNode.getDepth() == 0) {
        // it is leaf node - a notebook

        final String notebookUri = ((NotebookNodeUserObject) selectedNode.getUserObject()).getNotebookUri();
        ResourceDescriptor resourceDescriptor = MindRaider.labelCustodian.getOutlineDescriptor(notebookUri);
        if (JOptionPane.showConfirmDialog(MindRaider.mainJFrame,
                "Do you really want to discard Outline '"
                        + (resourceDescriptor != null ? resourceDescriptor.getLabel() : notebookUri) + "'?",
                "Archive Outline", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

            // discard the notebook from ALL folders where it presents
            MindRaider.labelCustodian.discardOutline(notebookUri);
            explorerJPanel.refresh();//w ww  . ja v a 2  s .  c om
            OutlineJPanel.getInstance().clear();
            MindRaider.spidersGraph.clear();
            MindRaider.profile.setActiveOutlineUri(null);
            return;
        }
    } else {
        JOptionPane.showMessageDialog(MindRaider.mainJFrame, "Please select Outline to be discarded!");
    }
}