Example usage for javax.swing JOptionPane CLOSED_OPTION

List of usage examples for javax.swing JOptionPane CLOSED_OPTION

Introduction

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

Prototype

int CLOSED_OPTION

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

Click Source Link

Document

Return value from class method if user closes window without selecting anything, more than likely this should be treated as either a CANCEL_OPTION or NO_OPTION.

Usage

From source file:net.sf.jabref.gui.JabRefFrame.java

/**
 * General info dialog.  The MacAdapter calls this method when "Quit"
 * is selected from the application menu, Cmd-Q is pressed, or "Quit" is selected from the Dock.
 * The function returns a boolean indicating if quitting is ok or not.
 * <p>/*from  w ww . j  a  v a  2 s .  c o  m*/
 * Non-OSX JabRef calls this when choosing "Quit" from the menu
 * <p>
 * SIDE EFFECT: tears down JabRef
 *
 * @return true if the user chose to quit; false otherwise
 */
public boolean quit() {
    // Ask here if the user really wants to close, if the base
    // has not been saved since last save.
    boolean close = true;
    List<String> filenames = new ArrayList<>();
    if (tabbedPane.getTabCount() > 0) {
        for (int i = 0; i < tabbedPane.getTabCount(); i++) {
            if (getBasePanelAt(i).isModified()) {
                tabbedPane.setSelectedIndex(i);
                String filename;

                if (getBasePanelAt(i).getBibDatabaseContext().getDatabaseFile() == null) {
                    filename = GUIGlobals.UNTITLED_TITLE;
                } else {
                    filename = getBasePanelAt(i).getBibDatabaseContext().getDatabaseFile().getAbsolutePath();
                }
                int answer = showSaveDialog(filename);

                if ((answer == JOptionPane.CANCEL_OPTION) || (answer == JOptionPane.CLOSED_OPTION)) {
                    return false;
                }
                if (answer == JOptionPane.YES_OPTION) {
                    // The user wants to save.
                    try {
                        //getCurrentBasePanel().runCommand("save");
                        SaveDatabaseAction saveAction = new SaveDatabaseAction(getCurrentBasePanel());
                        saveAction.runCommand();
                        if (saveAction.isCanceled() || !saveAction.isSuccess()) {
                            // The action was either canceled or unsuccessful.
                            // Break!
                            output(Localization.lang("Unable to save database"));
                            close = false;
                        }
                    } catch (Throwable ex) {
                        // Something prevented the file
                        // from being saved. Break!!!
                        close = false;
                        break;
                    }
                }
            }

            if (getBasePanelAt(i).getBibDatabaseContext().getDatabaseFile() != null) {
                filenames.add(getBasePanelAt(i).getBibDatabaseContext().getDatabaseFile().getAbsolutePath());
            }
        }
    }

    if (close) {
        for (int i = 0; i < tabbedPane.getTabCount(); i++) {
            if (getBasePanelAt(i).isSaving()) {
                // There is a database still being saved, so we need to wait.
                WaitForSaveOperation w = new WaitForSaveOperation(this);
                w.show(); // This method won't return until canceled or the save operation is done.
                if (w.canceled()) {
                    return false; // The user clicked cancel.
                }
            }
        }

        tearDownJabRef(filenames);
        return true;
    }

    return false;
}

From source file:edu.ku.brc.specify.conversion.GenericDBConversion.java

/**
 * @return/*  w  w  w.j ava2  s.c o m*/
 */
public CollectionResultType initialize() {

    collectionInfoList = CollectionInfo.getCollectionInfoList(oldDBConn, false);
    //fixIdaho();
    if (collectionInfoList == null) {
        if (CollectionInfo.isAskForFix()) {
            if (ConvertTaxonHelper.fixTaxonomicUnitType(oldDBConn)) {
                collectionInfoList = CollectionInfo.getCollectionInfoList(oldDBConn, true);
            } else {
                try {
                    oldDBConn.close();
                } catch (SQLException e) {
                }
                System.exit(0);
            }
        } else {
            try {
                oldDBConn.close();
            } catch (SQLException e) {
            }
            System.exit(0);
        }
    }

    collectionInfoShortList = CollectionInfo.getFilteredCollectionInfoList();

    if (collectionInfoList != null && collectionInfoList.size() > 0) {
        int paleoCnt = 0;

        // This is a Hash of TaxonObjectType to see how many collections use the same TaxonObjectType
        HashMap<Integer, HashSet<CollectionInfo>> taxonomyTypeHash = new HashMap<Integer, HashSet<CollectionInfo>>();

        // Get a List for each type of Paleo Collection, hashed by the Root Id
        HashMap<Integer, Vector<CollectionInfo>> paleoColInfoHash = new HashMap<Integer, Vector<CollectionInfo>>();
        HashMap<Integer, HashSet<DisciplineType.STD_DISCIPLINES>> paleoDispTypeHash = new HashMap<Integer, HashSet<DisciplineType.STD_DISCIPLINES>>();

        for (CollectionInfo colInfo : collectionInfoShortList) {
            // Tracks a 'set' of CollectionInfo objects for each TaxonomyTypeId
            HashSet<CollectionInfo> taxonomyTypeSet = taxonomyTypeHash.get(colInfo.getTaxonomyTypeId());
            if (taxonomyTypeSet == null) {
                System.out.println("Creating TxTypeID: " + colInfo.getTaxonomyTypeId() + "  From "
                        + colInfo.getCatSeriesName());

                taxonomyTypeSet = new HashSet<CollectionInfo>();
                taxonomyTypeHash.put(colInfo.getTaxonomyTypeId(), taxonomyTypeSet);
            } else {
                System.out.println("Adding TxTypeID: " + colInfo.getTaxonomyTypeId() + "  From "
                        + colInfo.getCatSeriesName() + "  " + taxonomyTypeSet.size());
            }
            taxonomyTypeSet.add(colInfo);

            //---
            DisciplineType dType = getStandardDisciplineName(colInfo.getTaxonomyTypeName(),
                    colInfo.getColObjTypeName(), colInfo.getCatSeriesName());
            colInfo.setDisciplineTypeObj(dType);

            if (dType != null && dType.isPaleo()) {
                Vector<CollectionInfo> ciList = paleoColInfoHash.get(colInfo.getTaxonNameId());
                if (ciList == null) {
                    ciList = new Vector<CollectionInfo>();
                    paleoColInfoHash.put(colInfo.getTaxonNameId(), ciList);
                }
                ciList.add(colInfo);

                HashSet<DisciplineType.STD_DISCIPLINES> typeDispSet = paleoDispTypeHash
                        .get(colInfo.getTaxonNameId());
                if (typeDispSet == null) {
                    typeDispSet = new HashSet<DisciplineType.STD_DISCIPLINES>();
                    paleoDispTypeHash.put(colInfo.getTaxonNameId(), typeDispSet);
                }
                typeDispSet.add(colInfo.getDisciplineTypeObj().getDisciplineType());

                paleoCnt++;
            }
            System.out.println("--------------------------------------");
            //System.out.println(colInfo.toString()+"\n");
        } // for loop

        int cnt = 0;
        StringBuilder msg = new StringBuilder();
        for (Integer taxonomyTypId : taxonomyTypeHash.keySet()) {
            HashSet<CollectionInfo> taxonomyTypeSet = taxonomyTypeHash.get(taxonomyTypId);
            if (taxonomyTypeSet.size() > 1) {
                msg.append(
                        String.format("<html>TaxonomyTypeId %d has more than one Discpline/Collection:<br><OL>",
                                taxonomyTypId));
                for (CollectionInfo ci : taxonomyTypeSet) {
                    msg.append(String.format("<LI>%s - %s - %s</LI>", ci.getCatSeriesName(),
                            ci.getColObjTypeName(), ci.getTaxonomyTypeName()));
                }
                msg.append("</OL>");
                cnt++;
            }
        }

        if (cnt > 0) {
            JOptionPane.showConfirmDialog(null, msg.toString(), "Taxomony Type Issues",
                    JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE);
        }

        // Will be zero for no Paleo collections
        if (paleoCnt > 1) {
            // Check to see if they all use the same tree
            if (paleoColInfoHash.size() > 1) {
                msg.setLength(0);
                // We get here when there is more than one Taxon Tree for the Paleo Collections
                for (Integer treeId : paleoColInfoHash.keySet()) {
                    Vector<CollectionInfo> ciList = paleoColInfoHash.get(treeId);
                    CollectionInfo colInfo = ciList.get(0);
                    msg.append(String.format("The following collections use Taxon Tree '%s':\n",
                            colInfo.getTaxonomyTypeName()));
                    for (CollectionInfo ci : paleoColInfoHash.get(treeId)) {
                        DisciplineType dType = getStandardDisciplineName(ci.getTaxonomyTypeName(),
                                ci.getColObjTypeName(), ci.getCatSeriesName());

                        String name = String.format("%s / %s / %s / %s / %s", ci.getCatSeriesPrefix(),
                                ci.getCatSeriesName(), ci.getColObjTypeName(), ci.getTaxonomyTypeName(),
                                dType.toString());
                        msg.append(name);
                        msg.append("\n");
                    }
                    msg.append("\n");
                }

                JOptionPane.showConfirmDialog(null, msg.toString(), "Paleo Taxon Tree Issues",
                        JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE);

            } else {
                StringBuilder colNames = new StringBuilder();
                for (Integer treeId : paleoColInfoHash.keySet()) {
                    for (CollectionInfo ci : paleoColInfoHash.get(treeId)) {
                        colNames.append("<LI>");
                        colNames.append(ci.getCatSeriesName());
                        colNames.append("</LI>");
                    }
                }

                // You get here when all the Paleo Disciplines use the same tree
                String msgStr = "<html>All the Paleo Collections need to use the same Taxon Tree and<br>therefore needs to be in the same discipline:<br><ol>";
                JOptionPane.showConfirmDialog(null, msgStr + colNames.toString(), "Paleo Taxon Tree Issues",
                        JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE);

                for (Integer treeId : paleoColInfoHash.keySet()) {
                    Vector<CollectionInfo> ciList = paleoColInfoHash.get(treeId);
                    CollectionInfo colInfo = ciList.get(0);
                    for (CollectionInfo ci : paleoColInfoHash.get(treeId)) {
                        ci.setDisciplineTypeObj(colInfo.getDisciplineTypeObj());
                    }
                }
            }
            //
        }

        DefaultTableModel model = CollectionInfo.getCollectionInfoTableModel(false);
        if (model.getRowCount() > 1) {
            TableWriter colInfoTblWriter = convLogger.getWriter("colinfo.html", "Collection Info");

            colInfoTblWriter.startTable();
            colInfoTblWriter.logHdr(CollectionInfoModel.getHeaders());

            Object[] row = new Object[model.getColumnCount()];
            for (int r = 0; r < model.getRowCount(); r++) {
                for (int i = 0; i < model.getColumnCount(); i++) {
                    row[i] = model.getValueAt(r, i);
                }
                colInfoTblWriter.logObjRow(row);
            }
            colInfoTblWriter.endTable();
            colInfoTblWriter.println("<BR><h3>Collections to be Created.</h3>");
            colInfoTblWriter.startTable();
            colInfoTblWriter.logHdr(CollectionInfoModel.getHeaders());

            model = CollectionInfo.getCollectionInfoTableModel(true);
            row = new Object[model.getColumnCount()];
            for (int r = 0; r < model.getRowCount(); r++) {
                for (int i = 0; i < model.getColumnCount(); i++) {
                    row[i] = model.getValueAt(r, i);
                }
                colInfoTblWriter.logObjRow(row);
            }
            colInfoTblWriter.endTable();
            colInfoTblWriter.close();

            File file = new File(colInfoTblWriter.getFileName());
            if (file != null && file.exists()) {
                try {
                    AttachmentUtils.openURI(file.toURI());

                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }

        for (CollectionInfo ci : CollectionInfo.getFilteredCollectionInfoList()) {
            String sql = "select preparationmethod, ct.* from usyscollobjprepmeth pt inner join usysmetafieldsetsubtype st on st.fieldsetsubtypeid = pt.fieldsetsubtypeid "
                    + "inner join collectionobjecttype ct1 on ct1.collectionobjecttypeid = st.fieldvalue "
                    + "inner join collectionobjecttype ct on ct.collectionobjecttypename = replace(ct1.collectionobjecttypename, ' Preparation', '') "
                    + "inner join catalogseriesdefinition csd on csd.objecttypeid = ct.collectionobjecttypeid "
                    + "inner join catalogseries cs on cs.catalogseriesid = csd.catalogseriesid "
                    + "WHERE csd.catalogseriesid = " + ci.getCatSeriesId();

            System.out.println("\n------------------");
            System.out.println(ci.getCatSeriesName());
            System.out.println(sql);
            System.out.println("------------------");

            int i = 0;
            Vector<Object[]> list = BasicSQLUtils.query(oldDBConn, sql);
            if (list.size() > 0) {
                for (Object[] row : list) {
                    System.out.print(i + " - ");
                    for (Object col : row) {
                        System.out.print(col != null ? col.toString() : "null");
                        System.out.print(", ");
                    }
                    System.out.println();
                    i++;
                }
            } else {
                System.out.println("No Results");
            }

            sql = "select ct.*, (select relatedsubtypevalues from usysmetacontrol c "
                    + "left join usysmetafieldsetsubtype fst on fst.fieldsetsubtypeid = c.fieldsetsubtypeid "
                    + "where objectid = 10290 and ct.taxonomytypeid = c.relatedsubtypevalues) as DeterminationTaxonType "
                    + "from collectiontaxonomytypes ct where ct.biologicalobjecttypeid = "
                    + ci.getColObjTypeId();

            sql = String.format(
                    "SELECT CollectionTaxonomyTypesID, BiologicalObjectTypeID, CollectionObjectTypeName FROM (select ct.*, "
                            + "(SELECT distinct relatedsubtypevalues FROM usysmetacontrol c "
                            + "LEFT JOIN usysmetafieldsetsubtype fst ON fst.fieldsetsubtypeid = c.fieldsetsubtypeid "
                            + "WHERE objectid = 10290 AND ct.taxonomytypeid = c.relatedsubtypevalues) AS DeterminationTaxonType "
                            + "FROM collectiontaxonomytypes ct WHERE ct.biologicalobjecttypeid = %d) T1 "
                            + "INNER JOIN collectionobjecttype cot ON T1.biologicalobjecttypeid = cot.CollectionObjectTypeID",
                    ci.getColObjTypeId());

            System.out.println("\n------------------");
            System.out.println(ci.getColObjTypeName());
            System.out.println(sql);
            System.out.println("------------------");

            i = 0;
            list = BasicSQLUtils.query(oldDBConn, sql);
            if (list.size() > 0) {
                for (Object[] row : list) {
                    System.out.print(i + " - ");
                    for (Object col : row) {
                        System.out.print(col != null ? col.toString() : "null");
                        System.out.print(", ");
                    }
                    System.out.println();
                    i++;
                }
            } else {
                System.out.println("No Results");
            }
        }

        /*
                
        String sql = " select ct.*, (select relatedsubtypevalues from usysmetacontrol c " +
          "left join usysmetafieldsetsubtype fst on fst.fieldsetsubtypeid = c.fieldsetsubtypeid " +
          "where objectid = 10290 and ct.taxonomytypeid = c.relatedsubtypevalues) as DeterminationTaxonType " +
          "from collectiontaxonomytypes ct where ct.biologicalobjecttypeid = 13";
                
        System.out.println("\n------------------");
        System.out.println("List of the taxonomytypes associated with a CollectionObjectTypeID");
        System.out.println(sql);
        System.out.println("------------------");
                
        int i = 0;
        Vector<Object[]> list = BasicSQLUtils.query(oldDBConn, sql);
        if (list.size() > 0)
        {
        for (Object[] row : list)
        {
            System.out.print(i+" - ");
            for (Object col: row)
            {
                System.out.print(col != null ? col.toString() : "null");
                System.out.print(", ");
            }
            System.out.println();
        }
        } else
        {
        System.out.println("No Results");
        }*/

        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,2px,f:p:g,10px,p,2px,p:g,8px"));

        JTable tableTop = new JTable(CollectionInfo.getCollectionInfoTableModel(false));
        JTable tableBot = new JTable(
                CollectionInfo.getCollectionInfoTableModel(!CollectionInfo.DOING_ACCESSSION));

        int rows = 10;
        tableTop.setPreferredScrollableViewportSize(new Dimension(
                tableTop.getPreferredScrollableViewportSize().width, rows * tableTop.getRowHeight()));
        tableBot.setPreferredScrollableViewportSize(new Dimension(
                tableBot.getPreferredScrollableViewportSize().width, rows * tableBot.getRowHeight()));

        pb.add(UIHelper.createLabel("Available Specify 5 Taxononmic Types", SwingConstants.CENTER),
                cc.xy(1, 1));
        pb.add(UIHelper.createScrollPane(tableTop), cc.xy(1, 3));

        pb.add(UIHelper.createLabel("Specify 5 Collections to be Created", SwingConstants.CENTER), cc.xy(1, 5));
        pb.add(UIHelper.createScrollPane(tableBot), cc.xy(1, 7));

        pb.setDefaultDialogBorder();
        CustomDialog dlg = new CustomDialog(null, "Taxononic Types", true, pb.getPanel());
        dlg.createUI();

        dlg.setSize(1024, 500);

        UIHelper.centerWindow(dlg);
        dlg.setAlwaysOnTop(true);
        dlg.setVisible(true);

        if (dlg.isCancelled()) {
            return CollectionResultType.eCancel;
        }

        Pair<CollectionInfo, DisciplineType> pair = CollectionInfo.getDisciplineType(oldDBConn);
        if (pair == null || pair.second == null) {
            CollectionInfo colInfo = pair.first;
            disciplineType = getStandardDisciplineName(colInfo.getTaxonomyTypeName(),
                    colInfo.getColObjTypeName(), colInfo.getCatSeriesName());
        } else {
            disciplineType = pair.second;
        }

        return disciplineType != null ? CollectionResultType.eOK : CollectionResultType.eError;
    }
    return CollectionResultType.eError;
}

From source file:fll.scheduler.SchedulerUI.java

/**
 * If there is more than 1 sheet, prompt, otherwise just use the sheet.
 * //from   w  w  w  .  j  ava2 s.  c o  m
 * @return the sheet name or null if the user canceled
 * @throws IOException
 * @throws InvalidFormatException
 */
public static String promptForSheetName(final File selectedFile) throws InvalidFormatException, IOException {
    final List<String> sheetNames = ExcelCellReader.getAllSheetNames(selectedFile);
    if (sheetNames.size() == 1) {
        return sheetNames.get(0);
    } else {
        final String[] options = sheetNames.toArray(new String[sheetNames.size()]);
        final int choosenOption = JOptionPane.showOptionDialog(null, "Choose which sheet to work with",
                "Choose Sheet", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                options[0]);
        if (JOptionPane.CLOSED_OPTION == choosenOption) {
            return null;
        }
        return options[choosenOption];
    }
}

From source file:lejos.pc.charting.LogChartFrame.java

/** if file exists, ask user to append or overwrite. sets this.theLogFile.
 * @return 0 to replace, 1 to append, 2 to cancel
 *//*  www . j a v  a2 s  . c  om*/
private int getFileAppend() {
    JFrame frame = new JFrame("DialogDemo");
    int n = 0;
    Object[] options = { "Replace it", "Add to it", "Cancel" };
    // if the log file field is empty, the PC logger will handle it. we need to make sure the title is appropo
    this.theLogFile = new File(FQPathTextArea.getText(), logFileTextField.getText());
    if (theLogFile.isFile()) {
        n = JOptionPane.showOptionDialog(frame,
                "File \"" + getCanonicalName(theLogFile) + "\" exists.\nWhat do you want to do?",
                "I have a Question...", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, //do not use a custom Icon
                options, //the titles of buttons
                options[0]); //default is "Replace it"
    }
    frame = null;
    if (n == JOptionPane.CLOSED_OPTION)
        n = 2;
    return n;
}

From source file:net.rptools.maptool.client.functions.InputFunction.java

@Override
public Object childEvaluate(Parser parser, String functionName, List<Object> parameters)
        throws EvaluationException, ParserException {
    // Extract the list of specifier strings from the parameters
    // "name | value | prompt | inputType | options"
    List<String> varStrings = new ArrayList<String>();
    for (Object param : parameters) {
        String paramStr = (String) param;
        if (StringUtils.isEmpty(paramStr)) {
            continue;
        }//from   www .jav  a2 s.  co  m
        // Multiple vars can be packed into a string, separated by "##"
        List<String> substrings = new ArrayList<String>();
        StrListFunctions.parse(paramStr, substrings, "##");
        for (String varString : substrings) {
            if (StringUtils.isEmpty(paramStr)) {
                continue;
            }
            varStrings.add(varString);
        }
    }

    // Create VarSpec objects from each variable's specifier string
    List<VarSpec> varSpecs = new ArrayList<VarSpec>();
    for (String specifier : varStrings) {
        VarSpec vs;
        try {
            vs = new VarSpec(specifier);
        } catch (VarSpec.SpecifierException se) {
            throw new ParameterException(se.msg);
        } catch (InputType.OptionException oe) {
            throw new ParameterException(I18N.getText("macro.function.input.invalidOptionType", oe.key,
                    oe.value, oe.type, specifier));
        }
        varSpecs.add(vs);
    }

    // Check if any variables were defined
    if (varSpecs.isEmpty())
        return BigDecimal.ONE; // No work to do, so treat it as a successful invocation.

    // UI step 1 - First, see if a token is in context.
    VariableResolver varRes = parser.getVariableResolver();
    Token tokenInContext = null;
    if (varRes instanceof MapToolVariableResolver) {
        tokenInContext = ((MapToolVariableResolver) varRes).getTokenInContext();
    }
    String dialogTitle = "Input Values";
    if (tokenInContext != null) {
        String name = tokenInContext.getName(), gm_name = tokenInContext.getGMName();
        boolean isGM = MapTool.getPlayer().isGM();
        String extra = "";

        if (isGM && gm_name != null && gm_name.compareTo("") != 0)
            extra = " for " + gm_name;
        else if (name != null && name.compareTo("") != 0)
            extra = " for " + name;

        dialogTitle = dialogTitle + extra;
    }

    // UI step 2 - build the panel with the input fields
    InputPanel ip = new InputPanel(varSpecs);

    // Calculate the height
    // TODO: remove this workaround
    int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
    int maxHeight = screenHeight * 3 / 4;
    Dimension ipPreferredDim = ip.getPreferredSize();
    if (maxHeight < ipPreferredDim.height) {
        ip.modifyMaxHeightBy(maxHeight - ipPreferredDim.height);
    }

    // UI step 3 - show the dialog
    JOptionPane jop = new JOptionPane(ip, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog dlg = jop.createDialog(MapTool.getFrame(), dialogTitle);

    // Set up callbacks needed for desired runtime behavior
    dlg.addComponentListener(new FixupComponentAdapter(ip));

    dlg.setVisible(true);
    int dlgResult = JOptionPane.CLOSED_OPTION;
    try {
        dlgResult = (Integer) jop.getValue();
    } catch (NullPointerException npe) {
    }
    dlg.dispose();

    if (dlgResult == JOptionPane.CANCEL_OPTION || dlgResult == JOptionPane.CLOSED_OPTION)
        return BigDecimal.ZERO;

    // Finally, assign values from the dialog box to the variables
    for (ColumnPanel cp : ip.columnPanels) {
        List<VarSpec> panelVars = cp.varSpecs;
        List<JComponent> panelControls = cp.inputFields;
        int numPanelVars = panelVars.size();
        StringBuilder allAssignments = new StringBuilder(); // holds all values assigned in this tab

        for (int varCount = 0; varCount < numPanelVars; varCount++) {
            VarSpec vs = panelVars.get(varCount);
            JComponent comp = panelControls.get(varCount);
            String newValue = null;
            switch (vs.inputType) {
            case TEXT: {
                newValue = ((JTextField) comp).getText();
                break;
            }
            case LIST: {
                Integer index = ((JComboBox) comp).getSelectedIndex();
                if (vs.optionValues.optionEquals("VALUE", "STRING")) {
                    newValue = vs.valueList.get(index);
                } else { // default is "NUMBER"
                    newValue = index.toString();
                }
                break;
            }
            case CHECK: {
                Integer value = ((JCheckBox) comp).isSelected() ? 1 : 0;
                newValue = value.toString();
                break;
            }
            case RADIO: {
                // This code assumes that the Box container returns components
                // in the same order that they were added.
                Component[] comps = ((Box) comp).getComponents();
                int componentCount = 0;
                Integer index = 0;
                for (Component c : comps) {
                    if (c instanceof JRadioButton) {
                        JRadioButton radio = (JRadioButton) c;
                        if (radio.isSelected())
                            index = componentCount;
                    }
                    componentCount++;
                }
                if (vs.optionValues.optionEquals("VALUE", "STRING")) {
                    newValue = vs.valueList.get(index);
                } else { // default is "NUMBER"
                    newValue = index.toString();
                }
                break;
            }
            case LABEL: {
                newValue = null;
                // The variable name is ignored and not set.
                break;
            }
            case PROPS: {
                // Read out and assign all the subvariables.
                // The overall return value is a property string (as in StrPropFunctions.java) with all the new settings.
                Component[] comps = ((JPanel) comp).getComponents();
                StringBuilder sb = new StringBuilder();
                int setVars = 0; // "NONE", no assignments made
                if (vs.optionValues.optionEquals("SETVARS", "SUFFIXED"))
                    setVars = 1;
                if (vs.optionValues.optionEquals("SETVARS", "UNSUFFIXED"))
                    setVars = 2;
                if (vs.optionValues.optionEquals("SETVARS", "TRUE"))
                    setVars = 2; // for backward compatibility
                for (int compCount = 0; compCount < comps.length; compCount += 2) {
                    String key = ((JLabel) comps[compCount]).getText().split("\\:")[0]; // strip trailing colon
                    String value = ((JTextField) comps[compCount + 1]).getText();
                    sb.append(key);
                    sb.append("=");
                    sb.append(value);
                    sb.append(" ; ");
                    switch (setVars) {
                    case 0:
                        // Do nothing
                        break;
                    case 1:
                        parser.setVariable(key + "_", value);
                        break;
                    case 2:
                        parser.setVariable(key, value);
                        break;
                    }
                }
                newValue = sb.toString();
                break;
            }
            default:
                // should never happen
                newValue = null;
                break;
            }
            // Set the variable to the value we got from the dialog box.
            if (newValue != null) {
                parser.setVariable(vs.name, newValue.trim());
                allAssignments.append(vs.name + "=" + newValue.trim() + " ## ");
            }
        }
        if (cp.tabVarSpec != null) {
            parser.setVariable(cp.tabVarSpec.name, allAssignments.toString());
        }
    }

    return BigDecimal.ONE; // success

    // for debugging:
    //return debugOutput(varSpecs);
}

From source file:edu.ku.brc.specify.tasks.subpane.security.SecurityAdminPane.java

@Override
public boolean aboutToShutdown() {
    boolean result = true;
    if (formHasChanged()) {
        String msg = String.format(getResourceString("SaveChanges"), getTitle());
        JFrame topFrame = (JFrame) UIRegistry.getTopWindow();

        int rv = JOptionPane.showConfirmDialog(topFrame, msg, getResourceString("SaveChangesTitle"),
                JOptionPane.YES_NO_CANCEL_OPTION);
        if (rv == JOptionPane.YES_OPTION) {
            doSave(false);// w  ww . j  ava 2s.  c  o m
        } else if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
            return false;
        } else if (rv == JOptionPane.NO_OPTION) {
            // nothing
        }
    }
    return result;
}

From source file:com.t3.client.ui.T3Frame.java

public void closingMaintenance() {
    if (AppPreferences.getSaveReminder()) {
        if (TabletopTool.getPlayer().isGM()) {
            int result = TabletopTool.confirmImpl(I18N.getText("msg.title.saveCampaign"),
                    JOptionPane.YES_NO_CANCEL_OPTION, "msg.confirm.saveCampaign", (Object[]) null);
            //            int result = JOptionPane.showConfirmDialog(TabletopTool.getFrame(), I18N.getText("msg.confirm.saveCampaign"), I18N.getText("msg.title.saveCampaign"), JOptionPane.YES_NO_CANCEL_OPTION);

            if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
                return;
            }//from www .ja  v  a  2s  .  co m
            if (result == JOptionPane.YES_OPTION) {
                final Observer callback = new Observer() {
                    @Override
                    public void update(java.util.Observable o, Object arg) {
                        if (arg instanceof String) {
                            // There was an error during the save -- don't terminate TabletopTool!
                        } else {
                            TabletopTool.getFrame().close();
                        }
                    }
                };
                ActionEvent ae = new ActionEvent(callback, 0, "close");
                AppActions.SAVE_CAMPAIGN.actionPerformed(ae);
                return;
            }
        } else {
            if (!TabletopTool.confirm("msg.confirm.disconnecting")) {
                return;
            }
        }
    }
    close();
}

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

public void closingMaintenance() {
    if (AppPreferences.getSaveReminder()) {
        if (MapTool.getPlayer().isGM()) {
            int result = MapTool.confirmImpl(I18N.getText("msg.title.saveCampaign"),
                    JOptionPane.YES_NO_CANCEL_OPTION, "msg.confirm.saveCampaign", (Object[]) null);
            //            int result = JOptionPane.showConfirmDialog(MapTool.getFrame(), I18N.getText("msg.confirm.saveCampaign"), I18N.getText("msg.title.saveCampaign"), JOptionPane.YES_NO_CANCEL_OPTION);

            if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
                return;
            }// w  w w. j av  a2  s . c  o  m
            if (result == JOptionPane.YES_OPTION) {
                final Observer callback = new Observer() {
                    public void update(java.util.Observable o, Object arg) {
                        if (arg instanceof String) {
                            // There was an error during the save -- don't terminate MapTool!
                        } else {
                            MapTool.getFrame().close();
                        }
                    }
                };
                ActionEvent ae = new ActionEvent(callback, 0, "close");
                AppActions.SAVE_CAMPAIGN.actionPerformed(ae);
                return;
            }
        } else {
            if (!MapTool.confirm("msg.confirm.disconnecting")) {
                return;
            }
        }
    }
    close();
}

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

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    l.info("Remove game action activated");
    //JOptionPane conf = new JOptionPane();
    if (jTable1.getSelectedRow() >= 0) {
        int result = JOptionPane.showConfirmDialog(rootPane, "Are you sure you want to delete?", "Confirmation",
                2, 3);//from  w ww.  j a v  a2  s  . c o m
        //JDialog dialog = conf.createDialog(jPanel1, "Are you sure u want to delete?");
        //dialog.show();
        //Object selectedValue = conf.getValue();

        l.trace("Game delete dialog code: " + result);
        if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
            l.trace("Game delete cancelled");
        } else if (result == JOptionPane.OK_OPTION) {
            DefaultTableModel mdl = (DefaultTableModel) jTable1.getModel();
            String name = (String) mdl.getValueAt(jTable1.getSelectedRow(), 0);
            if (name != null) {
                l.trace("Removing game: " + name);
                GamelistStorage.removeGame(name);
                SettingsManager.getStorage().removeGame(name);
                mdl.removeRow(jTable1.getSelectedRow());
                l.debug("Game removed: " + name);
            } else {
                mdl.removeRow(jTable1.getSelectedRow());
                l.trace("Empty row - just erasing in table");
            }
        }
    }
    MainFrame.updateGameInterfaceFromStorage();
}

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

public boolean alertRefresh() {
    boolean cancelRefresh = false;

    if (PlatformUI.MIRTH_FRAME.isSaveEnabled()) {
        int option = JOptionPane.showConfirmDialog(PlatformUI.MIRTH_FRAME,
                "<html>Any unsaved changes will be lost.<br>Would you like to continue?</html>", "Warning",
                JOptionPane.YES_NO_OPTION);

        if (option == JOptionPane.NO_OPTION || option == JOptionPane.CLOSED_OPTION) {
            cancelRefresh = true;/*from   w  ww  . j  a  v a  2s  . com*/
        } else {
            setSaveEnabled(false);
        }
    }

    return cancelRefresh;
}