Example usage for javax.swing JOptionPane showOptionDialog

List of usage examples for javax.swing JOptionPane showOptionDialog

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType,
        int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException 

Source Link

Document

Brings up a dialog with a specified icon, where the initial choice is determined by the initialValue parameter and the number of choices is determined by the optionType parameter.

Usage

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

@SuppressWarnings("empty-statement")
private void jMenuItemShutdownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemShutdownActionPerformed
    Object[] opt = { "Yes", "No" };

    String message = "Are you shure you want to shutdown the server?";
    int op = JOptionPane.showOptionDialog(this, message, "Shut down Server", JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, opt, opt[1]);

    if (op == 0) {
        //Logout from GUI Server
        if (clientCore.isAdmin()) {

            if (AdminRefs.getInstance().unsavedSettings()) {
                Object[] opt1 = { "Save", "Discard" };

                message = "There are unsaved Server Settings.\nDo you want to save them?";
                op = JOptionPane.showOptionDialog(this, message, "Unsaved Server Settings",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt1, opt1[0]);

                if (op == 0) {
                    AdminRefs.getInstance().saveSettings();
                }//from  w w w. j  a  v a  2s  .c  o m

            }
        }

        if (clientCore.isUser()) {
            if (ClientOptions.getInstance().unsavedSettings()) {
                Object[] opt2 = { "Save", "Discard" };

                message = "There are unsaved Client Settings.\nDo you want to save them?";
                op = JOptionPane.showOptionDialog(this, message, "Unsaved Client Settings",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt2, opt2[0]);

                if (op == 0) {
                    ClientOptions.getInstance().saveSettings();
                }
            }
        }

        QueryHistorySupport.getInstance().saveQueryHistory();

        if (clientCore.isAdmin()) {
            AdminRefs.getInstance().shutdownServer();
        }

        System.exit(0);
    }
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed
    //Logout from GUI Server
    try {/*from   w ww  .jav a 2 s.com*/
        if (clientCore.isAdmin() && AdminRefs.getInstance().unsavedSettings()) {
            Object[] opt = { "Save", "Discard", "Cancel" };

            String message = "There are unsaved Server Settings.\nDo you want to save them?";
            int op = JOptionPane.showOptionDialog(this, message, "Unsaved Server Settings",
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]);

            if (op == 0) {
                AdminRefs.getInstance().saveSettings();
            }

            if (op == 2) {
                return;
            }
        }

        if (clientCore.isUser() && ClientOptions.getInstance().unsavedSettings()) {
            Object[] opt = { "Save", "Discard", "Cancel" };

            String message = "There are unsaved Client Settings.\nDo you want to save them?";
            int op = JOptionPane.showOptionDialog(this, message, "Unsaved Client Settings",
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]);

            if (op == 0) {
                ClientOptions.getInstance().saveSettings();
            }

            if (op == 2) {
                return;
            }
        }

        if (clientCore.isAdmin()) {
            AdminRefs.getInstance().logout();
        }

        searchTree.unexportSearchSignal();
        clientCore.getUser().logout();

    } catch (RemoteException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    }
    File toDelete = new File("pluginClasses");
    String[] deleteArray = toDelete.list();
    if (deleteArray != null) {
        for (String fileName : deleteArray) {
            File f = new File("pluginClasses/" + fileName);
            f.delete();
        }
    }
    QueryHistorySupport.getInstance().saveQueryHistory();

    if (Main.isFixedClient()) {
        clientCore.stopKeepAlives();
        this.dispose();

        TrayIconCreator.getInstance().distroyTrayIcon();
    } else {
        System.exit(0);
    }
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
    File toDelete = new File("pluginClasses");
    String[] deleteArray = toDelete.list();
    if (deleteArray != null) {
        for (String fileName : deleteArray) {
            File f = new File("pluginClasses/" + fileName);
            f.delete();/* ww  w. j  a v a  2  s .  c  o m*/
        }
    }
    if (clientCore.isAdmin() && AdminRefs.getInstance().unsavedSettings()) {
        Object[] opt = { "Save", "Discard", "Cancel" };

        String message = "There are unsaved Server Settings.\nDo you want to save them?";
        int op = JOptionPane.showOptionDialog(this, message, "Unsaved Server Settings",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]);

        if (op == 0) {
            AdminRefs.getInstance().saveSettings();
        }

        if (op == 2) {
            return;
        }
    }

    if (ClientOptions.getInstance().unsavedSettings()) {
        Object[] opt = { "Save", "Discard", "Cancel" };

        String message = "There are unsaved Client Settings.\nDo you want to save them?";
        int op = JOptionPane.showOptionDialog(this, message, "Unsaved Client Settings",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]);

        if (op == 0) {
            ClientOptions.getInstance().saveSettings();
        }

        if (op == 2) {
            return;
        }
    }

    QueryHistorySupport.getInstance().saveQueryHistory();

    if (clientCore.isAdmin()) {
        AdminRefs.getInstance().shutdownServer();
    }

    System.exit(0);
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private void jTreeResultsKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTreeResultsKeyReleased
    if (KeyEvent.VK_DELETE == evt.getKeyCode() && clientCore.isAdmin()) {
        ArrayList<String> files = getSelectedLocalFiles();

        if (files != null && !files.isEmpty()) {
            try {
                Object[] opt = { "Remove and Delete", "Remove", "Cancel" };
                String message = "Are you sure you want to remove these files from Index Engine?";

                int op = JOptionPane.showOptionDialog(this, message, "Remove Files",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, opt, opt[2]);

                if (op == 0) {
                    AdminRefs.getInstance().getIndexOptions().removeFilesFromIndexer(files, true);
                }/*from  ww  w.  j av a 2 s  . c  o m*/
                if (op == 1) {
                    AdminRefs.getInstance().getIndexOptions().removeFilesFromIndexer(files, false);
                }
            } catch (RemoteException ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:ro.nextreports.designer.querybuilder.QueryBuilderPanel.java

private void initUI() {
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.setDividerLocation(250);/*  w  w w. j  a va  2s  .  c  o  m*/
    split.setOneTouchExpandable(true);

    JToolBar toolBar = new JToolBar();
    toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders
    toolBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
    toolBar.setBorderPainted(false);

    // add refresh action
    toolBar.add(new AbstractAction() {

        public Object getValue(String key) {
            if (AbstractAction.SMALL_ICON.equals(key)) {
                return ImageUtil.getImageIcon("refresh");
            } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) {
                return I18NSupport.getString("querybuilder.refresh");
            }

            return super.getValue(key);
        }

        public void actionPerformed(ActionEvent e) {
            try {
                if (Globals.getConnection() == null) {
                    return;
                }

                // refresh tables, views, procedures
                TreeUtil.refreshDatabase();

                // add new queries to tree
                TreeUtil.refreshQueries();

                // add new reports to tree
                TreeUtil.refreshReports();

                // add new charts to tree
                TreeUtil.refreshCharts();

            } catch (Exception ex) {
                Show.error(ex);
            }
        }

    });

    // add expand action
    toolBar.add(new AbstractAction() {

        public Object getValue(String key) {
            if (AbstractAction.SMALL_ICON.equals(key)) {
                return ImageUtil.getImageIcon("expandall");
            } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) {
                return I18NSupport.getString("querybuilder.expand.all");
            }

            return super.getValue(key);
        }

        public void actionPerformed(ActionEvent e) {
            TreeUtil.expandAll(dbBrowserTree);
        }

    });

    // add collapse action
    toolBar.add(new AbstractAction() {

        public Object getValue(String key) {
            if (AbstractAction.SMALL_ICON.equals(key)) {
                return ImageUtil.getImageIcon("collapseall");
            } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) {
                return I18NSupport.getString("querybuilder.collapse.all");
            }

            return super.getValue(key);
        }

        public void actionPerformed(ActionEvent e) {
            TreeUtil.collapseAll(dbBrowserTree);
        }

    });

    // add properties button
    /*
      JButton propButton = new MagicButton(new AbstractAction() {
            
      public Object getValue(String key) {
          if (AbstractAction.SMALL_ICON.equals(key)) {
              return ImageUtil.getImageIcon("properties");
          }
            
          return super.getValue(key);
      }
            
      public void actionPerformed(ActionEvent e) {
          DBBrowserPropertiesPanel joinPanel = new DBBrowserPropertiesPanel();
          JDialog dlg = new DBBrowserPropertiesDialog(joinPanel);
          dlg.pack();
          dlg.setResizable(false);
          Show.centrateComponent(Globals.getMainFrame(), dlg);
          dlg.setVisible(true);
      }
            
      });
      propButton.setToolTipText(I18NSupport.getString("querybuilder.properties"));
      */
    //browserButtonsPanel.add(propButton);

    //        ro.nextreports.designer.util.SwingUtil.registerButtonsForFocus(browserButtonsPanel);

    browserPanel = new JXPanel(new BorderLayout());
    browserPanel.add(toolBar, BorderLayout.NORTH);

    // browser tree
    JScrollPane scroll = new JScrollPane(dbBrowserTree);
    browserPanel.add(scroll, BorderLayout.CENTER);
    split.setLeftComponent(browserPanel);

    tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
    //        tabbedPane.putClientProperty(Options.EMBEDDED_TABS_KEY, Boolean.TRUE); // look like eclipse

    JSplitPane split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    split2.setResizeWeight(0.66);
    split2.setOneTouchExpandable(true);

    // desktop pane
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    desktop.setDropTarget(
            new DropTarget(desktop, DnDConstants.ACTION_MOVE, new DesktopPaneDropTargetListener(), true));

    // create the toolbar
    JToolBar toolBar2 = new JToolBar();
    toolBar2.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders
    toolBar2.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
    toolBar2.setBorderPainted(false);

    Action distinctAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            if (distinctButton.isSelected()) {
                selectQuery.setDistinct(true);
            } else {
                selectQuery.setDistinct(false);
            }
        }

    };
    distinctAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("query.distinct"));
    distinctAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.distinct"));
    toolBar2.add(distinctButton = new JToggleButton(distinctAction));

    Action groupByAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            groupBy = groupByButton.isSelected();
            Globals.getEventBus().publish(new GroupByEvent(QueryBuilderPanel.this.desktop, groupBy));
        }

    };
    groupByAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("query.group_by"));
    groupByAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.group.by"));
    toolBar2.add(groupByButton = new JToggleButton(groupByAction));

    Action clearAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            clear(false);
        }

    };
    clearAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("clear"));
    clearAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.clear"));
    toolBar2.add(clearAction);

    // add separator
    SwingUtil.addCustomSeparator(toolBar2);

    // add run button
    Action runQueryAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            selectSQLViewTab();
            sqlView.doRun();
        }

    };
    runQueryAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("run"));
    KeyStroke ks = KeyStroke.getKeyStroke(ShortcutsUtil.getShortcut("query.run.accelerator", "control 4"));
    runQueryAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("run.query") + " ("
            + ShortcutsUtil.getShortcut("query.run.accelerator.display", "Ctrl 4") + ")");
    runQueryAction.putValue(Action.ACCELERATOR_KEY, ks);
    toolBar2.add(runQueryAction);
    // register run query shortcut
    GlobalHotkeyManager hotkeyManager = GlobalHotkeyManager.getInstance();
    InputMap inputMap = hotkeyManager.getInputMap();
    ActionMap actionMap = hotkeyManager.getActionMap();
    inputMap.put((KeyStroke) runQueryAction.getValue(Action.ACCELERATOR_KEY), "runQueryAction");
    actionMap.put("runQueryAction", runQueryAction);

    JScrollPane scroll2 = new JScrollPane(desktop, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll2.setPreferredSize(DBTablesDesktopPane.PREFFERED_SIZE);
    DecoratedScrollPane.decorate(scroll2);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new GridBagLayout());
    topPanel.add(toolBar2, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    topPanel.add(scroll2, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

    split2.setTopComponent(topPanel);
    designPanel = new DesignerTablePanel(selectQuery);
    split2.setBottomComponent(designPanel);
    split2.setDividerLocation(400);

    tabbedPane.addTab(I18NSupport.getString("querybuilder.query.designer"), ImageUtil.getImageIcon("designer"),
            split2);
    tabbedPane.setMnemonicAt(0, 'D');

    sqlView = new SQLViewPanel();
    sqlView.getEditorPane().setDropTarget(new DropTarget(sqlView.getEditorPane(), DnDConstants.ACTION_MOVE,
            new SQLViewDropTargetListener(), true));
    tabbedPane.addTab(I18NSupport.getString("querybuilder.query.editor"), ImageUtil.getImageIcon("sql"),
            sqlView);
    tabbedPane.setMnemonicAt(1, 'E');

    split.setRightComponent(tabbedPane);

    // register a change listener
    tabbedPane.addChangeListener(new ChangeListener() {

        // this method is called whenever the selected tab changes
        public void stateChanged(ChangeEvent ev) {
            if (ev.getSource() == QueryBuilderPanel.this.tabbedPane) {
                // get current tab
                int sel = QueryBuilderPanel.this.tabbedPane.getSelectedIndex();
                if (sel == 1) { // sql view
                    String query;
                    if (!synchronizedPanels) {
                        query = sqlView.getQueryString();
                        synchronizedPanels = true;
                    } else {
                        if (Globals.getConnection() != null) {
                            query = getSelectQuery().toString();
                        } else {
                            query = "";
                        }
                        //                     if (query.equals("")) {
                        //                        query = sqlView.getQueryString();
                        //                     }
                    }
                    if (resetTable) {
                        sqlView.clear();
                        resetTable = false;
                    }
                    //System.out.println("query="+query);
                    sqlView.setQueryString(query);
                } else if (sel == 0) { // design view
                    if (queryWasModified(false)) {
                        Object[] options = { I18NSupport.getString("optionpanel.yes"),
                                I18NSupport.getString("optionpanel.no") };
                        String m1 = I18NSupport.getString("querybuilder.lost");
                        String m2 = I18NSupport.getString("querybuilder.continue");
                        int option = JOptionPane.showOptionDialog(Globals.getMainFrame(),
                                "<HTML>" + m1 + "<BR>" + m2 + "</HTML>",
                                I18NSupport.getString("querybuilder.confirm"), JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

                        if (option != JOptionPane.YES_OPTION) {
                            synchronizedPanels = false;
                            tabbedPane.setSelectedIndex(1);
                        } else {
                            resetTable = true;
                        }
                    }
                } else if (sel == 2) { // report view

                }
            }
        }

    });

    //        this.add(split, BorderLayout.CENTER);

    parametersPanel = new ParametersPanel();
}

From source file:ro.nextreports.designer.util.MessageUtil.java

public static boolean showReconnect() {
    Dialect dialect = null;/*w w w.j  a v  a2s . c  o  m*/
    try {
        dialect = Globals.getDialect();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    // current connection is broken
    if ((dialect == null) || !ConnectionUtil.isValidConnection(Globals.getConnection(), dialect)) {
        // try to create a new connection (if a connection pool is used, current connection can expire after some time)
        try {
            LOG.warn(".... Connection was lost. Try to recreate the database connection.");
            Globals.createConnection(DefaultDataSourceManager.getInstance().getConnectedDataSource());
        } catch (ConnectionException e) {
            LOG.warn(".... Connection recreation was not possible.");
            LOG.error(e.getMessage(), e);
            // connection is really down                                                
            int option = JOptionPane.showOptionDialog(Globals.getMainFrame(),
                    I18NSupport.getString("connection.broken"), I18NSupport.getString("error"),
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE, null,
                    new String[] { I18NSupport.getString("save"), I18NSupport.getString("base.dialog.close") },
                    I18NSupport.getString("base.dialog.close"));
            if (option != JOptionPane.OK_OPTION) {
                return true;
            } else {
                // forced save (we should be able to save the report anyway to not lost the work)
                LOG.warn(".... Forced save was called.");
                new SaveAction(true).actionPerformed(null);
            }

            return true;
        }
    }
    return false;
}

From source file:ro.nextreports.designer.util.NextReportsUtil.java

/**
 * Helper method which is used when a query from a report is modified
 * @return true if the query has to be modified, and in this case
 * a new report will be regenerated//from w w w  . java 2 s . co  m
 */
public static boolean doQueryOperation() {
    if (Globals.isReportLoaded()) {
        Object[] options = { I18NSupport.getString("report.util.yes"),
                I18NSupport.getString("report.util.no") };
        int option = JOptionPane.showOptionDialog(Globals.getMainFrame(),
                I18NSupport.getString("report.regenerated"), I18NSupport.getString("report.util.confirm"),
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

        return (option == JOptionPane.YES_OPTION);
    } else {
        return true;
    }
}

From source file:ro.nextreports.designer.util.NextReportsUtil.java

/**
 * Helper method for report recreation/*from w  ww .  j a  v  a 2 s.  c  o m*/
 * @return true if report will be recreated
 */
public static boolean reportRecreation() {
    if (Globals.isReportLoaded()) {
        Object[] options = { I18NSupport.getString("report.util.yes"),
                I18NSupport.getString("report.util.no") };
        int option = JOptionPane.showOptionDialog(Globals.getMainFrame(),
                I18NSupport.getString("report.util.query.modified"),
                I18NSupport.getString("report.util.confirm"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

        return (option == JOptionPane.YES_OPTION);
    } else {
        return true;
    }
}

From source file:ro.nextreports.designer.wizpublish.DownloadListWizardPanel.java

private boolean overwriteBulk(JDialog parent, String message) {
    Object[] options = { I18NSupport.getString("report.util.yes"), I18NSupport.getString("report.util.no") };
    int option = JOptionPane.showOptionDialog(parent,
            message + "\n" + I18NSupport.getString("wizard.publish.entities.overwrite"),
            I18NSupport.getString("report.util.confirm"), JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

    return (option == JOptionPane.YES_OPTION);
}

From source file:ro.nextreports.designer.wizpublish.JcrBrowserTree.java

private boolean overwrite(String message) {
    Object[] options = { I18NSupport.getString("report.util.yes"), I18NSupport.getString("report.util.no") };
    int option = JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor(JcrBrowserTree.this), message,
            I18NSupport.getString("report.util.confirm"), JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

    return (option == JOptionPane.YES_OPTION);
}