Example usage for javax.swing JOptionPane QUESTION_MESSAGE

List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE

Introduction

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

Prototype

int QUESTION_MESSAGE

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

Click Source Link

Document

Used for questions.

Usage

From source file:com.ejisto.event.listener.SessionRecorderManager.java

@Override
public void onApplicationEvent(SessionRecorderStart event) {
    String contextPath = event.getWebApplicationContextPath();
    if (isEmpty(contextPath)) {
        List<String> contextPaths = webApplicationDescriptorDao.loadAll().stream()
                .map(WebApplicationDescriptor::getContextPath).collect(Collectors.toList());
        contextPath = (String) showInputDialog(application, getMessage("session.record.select.application"),
                getMessage("session.record.select.application.title"), JOptionPane.QUESTION_MESSAGE, null,
                contextPaths.toArray(), null);
        if (isEmpty(contextPath)) {
            return;
        }//from w w  w  .j  av a 2  s .c o m
    }
    WebApplicationDescriptor descriptor = webApplicationDescriptorDao.load(contextPath);
    if (descriptor.getWarFile() == null) {
        File war = GuiUtils.selectFile(application, getMessage("session.record.open.target"),
                settingsRepository.getSettingValue(LAST_FILESELECTION_PATH), false, settingsRepository, "war");
        if (war == null) {
            GuiUtils.showErrorMessage(application, getMessage("wizard.file.selected.default.text"));
            return;
        }
        descriptor.setWarFile(war);
    }
    startSessionRecording(descriptor);
}

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

/**
 * Connection serrver test, acquiring certificate if exists.
 * @param uri - Selected server URI//from w  w  w .  j  av a 2 s .  c  om
 * @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:br.org.acessobrasil.silvinha.vista.panels.PainelSenha.java

public PainelSenha() {

    lblNome = new JLabel(GERAL.USUARIO);
    lblPass = new JLabel(GERAL.SENHA);
    txtName = new JTextField(10);
    txtPass = new JPasswordField(10);

    GridBagLayout bag = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    this.setLayout(bag);

    lblNome.setHorizontalAlignment(JLabel.RIGHT);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 1.0;//from w  w w  .  jav a 2s  . c om
    gbc.insets = new Insets(2, 10, 2, 10);
    this.add(lblNome, gbc);

    txtName.setAlignmentX(SwingConstants.WEST);
    txtName.addActionListener(new ActivateNextTextFieldListener(txtPass));
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = new Insets(2, 0, 2, 10);
    this.add(txtName, gbc);

    lblPass.setHorizontalAlignment(JLabel.RIGHT);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridwidth = 1;
    gbc.weightx = 1.0;
    gbc.insets = new Insets(2, 10, 2, 10);
    this.add(lblPass, gbc);

    txtPass.setAlignmentX(SwingConstants.WEST);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = new Insets(2, 0, 2, 10);
    this.add(txtPass, gbc);

    setSize(300, 130);
    setLocation(300, 300);
    //      this.setBackground(corDefault);

    op = new JOptionPane(this, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    //      op.setBackground(corDefault);

}

From source file:SimpleAuthenticator.java

protected PasswordAuthentication getPasswordAuthentication() {

    // given a prompt?
    String prompt = getRequestingPrompt();
    if (prompt == null)
        prompt = "Please login...";

    // protocol/* w ww .ja  v  a  2  s.  c o m*/
    String protocol = getRequestingProtocol();
    if (protocol == null)
        protocol = "Unknown protocol";

    // get the host
    String host = null;
    InetAddress inet = getRequestingSite();
    if (inet != null)
        host = inet.getHostName();
    if (host == null)
        host = "Unknown host";

    // port
    String port = "";
    int portnum = getRequestingPort();
    if (portnum != -1)
        port = ", port " + portnum + " ";

    // Build the info string
    String info = "Connecting to " + protocol + " mail service on host " + host + port;

    //JPanel d = new JPanel();
    // XXX - for some reason using a JPanel here causes JOptionPane
    // to display incorrectly, so we workaround the problem using
    // an anonymous JComponent.
    JComponent d = new JComponent() {
    };

    GridBagLayout gb = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    d.setLayout(gb);
    c.insets = new Insets(2, 2, 2, 2);

    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 0.0;
    d.add(constrain(new JLabel(info), gb, c));
    d.add(constrain(new JLabel(prompt), gb, c));

    c.gridwidth = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    d.add(constrain(new JLabel("Username:"), gb, c));

    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;
    String user = getDefaultUserName();
    JTextField username = new JTextField(user, 20);
    d.add(constrain(username, gb, c));

    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.EAST;
    c.weightx = 0.0;
    d.add(constrain(new JLabel("Password:"), gb, c));

    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;
    JPasswordField password = new JPasswordField("", 20);
    d.add(constrain(password, gb, c));
    // XXX - following doesn't work
    if (user != null && user.length() > 0)
        password.requestFocus();
    else
        username.requestFocus();

    int result = JOptionPane.showConfirmDialog(frame, d, "Login", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);

    if (result == JOptionPane.OK_OPTION)
        return new PasswordAuthentication(username.getText(), password.getText());
    else
        return null;
}

From source file:sim.util.media.chart.SeriesAttributes.java

void buildManipulators() {
    JButton removeButton = new JButton(I_CLOSE);
    removeButton.setPressedIcon(I_CLOSE_PRESSED);
    removeButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    removeButton.setBorderPainted(false);
    removeButton.setContentAreaFilled(false);
    removeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showOptionDialog(null, "Remove the Series " + getSeriesName() + "?", "Confirm",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    new Object[] { "Remove", "Cancel" }, null) == 0) // remove
                getGenerator().removeSeries(getSeriesIndex());
        }//from   w ww.  j  a  va 2s.c om
    });
    removeButton.setToolTipText("Remove this series");

    JButton upButton = new JButton(I_UP);
    upButton.setPressedIcon(I_UP_PRESSED);
    upButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    upButton.setBorderPainted(false);
    upButton.setContentAreaFilled(false);
    upButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), true);
        }
    });
    upButton.setToolTipText("Draw this series higher in the series order");

    JButton downButton = new JButton(I_DOWN);
    downButton.setPressedIcon(I_DOWN_PRESSED);
    downButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    downButton.setBorderPainted(false);
    downButton.setContentAreaFilled(false);
    downButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), false);
        }
    });
    downButton.setToolTipText("Draw this series lower in the series order");

    manipulators.add(removeButton);
    manipulators.add(upButton);
    manipulators.add(downButton);
}

From source file:edu.gmu.cs.sim.util.media.chart.SeriesAttributes.java

void buildManipulators() {
    JButton removeButton = new JButton(I_CLOSE);
    removeButton.setPressedIcon(I_CLOSE_PRESSED);
    removeButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    removeButton.setBorderPainted(false);
    removeButton.setContentAreaFilled(false);
    removeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showOptionDialog(null, "Remove the Series " + getSeriesName() + "?", "Confirm",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    new Object[] { "Remove", "Cancel" }, null) == 0) // remove
            {/*from  w  ww.  j a  v a2 s.c o m*/
                getGenerator().removeSeries(getSeriesIndex());
            }
        }
    });
    removeButton.setToolTipText("Remove this series");

    JButton upButton = new JButton(I_UP);
    upButton.setPressedIcon(I_UP_PRESSED);
    upButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    upButton.setBorderPainted(false);
    upButton.setContentAreaFilled(false);
    upButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), true);
        }
    });
    upButton.setToolTipText("Draw this series higher in the series order");

    JButton downButton = new JButton(I_DOWN);
    downButton.setPressedIcon(I_DOWN_PRESSED);
    downButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    downButton.setBorderPainted(false);
    downButton.setContentAreaFilled(false);
    downButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), false);
        }
    });
    downButton.setToolTipText("Draw this series lower in the series order");

    manipulators.add(removeButton);
    manipulators.add(upButton);
    manipulators.add(downButton);
}

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

/**
 * Create the panel./*from ww w  . j a  v a 2s .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:ste.travian.gui.WorldController.java

/**
 * Shows the dialog to edit the map URL.
 *//* ww w. ja  v  a 2s . c o  m*/
public void updateWorld() {
    MapUrlPanel mapUrlPanel = new MapUrlPanel();

    int result = JOptionPane.showOptionDialog(mainWindow, mapUrlPanel, mainWindow.getTitle(),
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
            new Object[] { "Download", "Cancel" }, null);

    if (result != JOptionPane.NO_OPTION) {
        try {
            load(mapUrlPanel.getUrl());
            load();
        } catch (Exception e) {
            mainWindow.error(e.getMessage(), e);
        }
    }
}

From source file:com._17od.upm.gui.DatabaseActions.java

/**
 * This method asks the user for the name of a new database and then creates
 * it. If the file already exists then the user is asked if they'd like to
 * overwrite it./*from  ww w . j a v a  2  s .  c o m*/
 * @throws CryptoException 
 * @throws IOException 
 */
public void newDatabase() throws IOException, CryptoException {

    File newDatabaseFile = getSaveAsFile(Translator.translate("newPasswordDatabase"));
    if (newDatabaseFile == null) {
        return;
    }

    final JPasswordField masterPassword = new JPasswordField("");
    boolean passwordsMatch = false;
    do {

        //Get a new master password for this database from the user
        JPasswordField confirmedMasterPassword = new JPasswordField("");
        JOptionPane pane = new JOptionPane(
                new Object[] { Translator.translate("enterMasterPassword"), masterPassword,
                        Translator.translate("confirmation"), confirmedMasterPassword },
                JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
        JDialog dialog = pane.createDialog(mainWindow, Translator.translate("masterPassword"));
        dialog.addWindowFocusListener(new WindowAdapter() {
            public void windowGainedFocus(WindowEvent e) {
                masterPassword.requestFocusInWindow();
            }
        });
        dialog.show();

        if (pane.getValue().equals(new Integer(JOptionPane.OK_OPTION))) {
            if (!Arrays.equals(masterPassword.getPassword(), confirmedMasterPassword.getPassword())) {
                JOptionPane.showMessageDialog(mainWindow, Translator.translate("passwordsDontMatch"));
            } else {
                passwordsMatch = true;
            }
        } else {
            return;
        }

    } while (passwordsMatch == false);

    if (newDatabaseFile.exists()) {
        newDatabaseFile.delete();
    }

    database = new PasswordDatabase(newDatabaseFile);
    dbPers = new PasswordDatabasePersistence(masterPassword.getPassword());
    saveDatabase();
    accountNames = new ArrayList();
    doOpenDatabaseActions();

    // If a "Database to Load on Startup" hasn't been set yet then ask the
    // user if they'd like to open this database on startup.
    if (Preferences.get(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP) == null
            || Preferences.get(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP).equals("")) {
        int option = JOptionPane.showConfirmDialog(mainWindow,
                Translator.translate("setNewLoadOnStartupDatabase"),
                Translator.translate("newPasswordDatabase"), JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION) {
            Preferences.set(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP,
                    newDatabaseFile.getAbsolutePath());
            Preferences.save();
        }
    }
}

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

/**
 * Get context menu.//  ww w . ja va2s . com
 * @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;
}