Example usage for javax.swing JOptionPane CANCEL_OPTION

List of usage examples for javax.swing JOptionPane CANCEL_OPTION

Introduction

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

Prototype

int CANCEL_OPTION

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

Click Source Link

Document

Return value from class method if CANCEL is chosen.

Usage

From source file:com.mirth.connect.client.ui.dependencies.ChannelDependenciesWarningDialog.java

private void initComponents(final ChannelTask task, Set<ChannelDependency> dependencies,
        final Set<String> selectedChannelIds, Set<String> additionalChannelIds)
        throws ChannelDependencyException {
    additionalChannelIds.removeAll(selectedChannelIds);
    final OrderedChannels orderedChannels = ChannelDependencyUtil.getOrderedChannels(dependencies,
            new HashSet<String>(CollectionUtils.union(selectedChannelIds, additionalChannelIds)));
    final List<Set<String>> orderedChannelIds = orderedChannels.getOrderedIds();
    if (task.isForwardOrder()) {
        Collections.reverse(orderedChannelIds);
    }//from ww w . java  2s.  c om

    descriptionLabel = new JLabel(
            "<html>There are additional channels in the dependency chain.<br/><b>Bolded</b> channels will be "
                    + task.getFuturePassive() + " in the following order:</html>");

    channelsPane = new JTextPane();
    channelsPane.setContentType("text/html");
    HTMLEditorKit editorKit = new HTMLEditorKit();
    StyleSheet styleSheet = editorKit.getStyleSheet();
    styleSheet.addRule("div {font-family:\"Tahoma\";font-size:11;text-align:top}");
    channelsPane.setEditorKit(editorKit);
    channelsPane.setEditable(false);
    channelsPane.setBackground(getBackground());

    setTextPane(task, orderedChannels, orderedChannelIds, selectedChannelIds, false);

    descriptionScrollPane = new JScrollPane(channelsPane);

    includeCheckBox = new JCheckBox(WordUtils.capitalize(task.toString()) + " " + additionalChannelIds.size()
            + " additional channel" + (additionalChannelIds.size() == 1 ? "" : "s"));
    includeCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            setTextPane(task, orderedChannels, orderedChannelIds, selectedChannelIds,
                    includeCheckBox.isSelected());
        }
    });

    okButton = new JButton("OK");
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            result = JOptionPane.OK_OPTION;
            dispose();
        }
    });

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            result = JOptionPane.CANCEL_OPTION;
            dispose();
        }
    });
}

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 .  j  av a2s.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:modmanager.MainWindow.java

private void selectSkyrimDirectory(boolean force) {
    skyrimDirectoryChooser.setDialogTitle("Select Skyrim folder");
    skyrimDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    boolean chosen = false;

    while (skyrimDirectoryChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        /**//from   ww  w.  jav  a  2  s. c  om
         * Use a while loop to check for valid skyrim installation ...
         */
        if (!FileUtils.getFile(skyrimDirectoryChooser.getSelectedFile(), "TESV.exe").exists()) {
            int result = JOptionPane.showConfirmDialog(this,
                    "It seems that this directory does not contain Skyrim!\nContinue anyways?",
                    "Invalid Skyrim directory", JOptionPane.YES_NO_CANCEL_OPTION);

            if (result == JOptionPane.CANCEL_OPTION) {
                break;
            }
            if (result == JOptionPane.YES_OPTION) {
                chosen = true;
                break;
            }
        } else {
            chosen = true;
            break;
        }
    }

    if (force && !chosen) {
        System.exit(0);
    }

    modifications.setSkyrimDirectory(skyrimDirectoryChooser.getSelectedFile());
}

From source file:au.org.ala.delta.editor.ui.DirectiveFileEditor.java

@Override
public boolean canClose() {
    if (originalText.equals(getText())) {
        return true;
    }/*from   w  ww  .j ava  2  s  . c o m*/
    int result = _messageHelper.promtForSaveBeforeClosing();
    if (result == JOptionPane.CANCEL_OPTION) {
        return false;
    } else if (result == JOptionPane.OK_OPTION) {
        applyChanges();
    }
    return true;
}

From source file:net.pms.newgui.LanguageSelection.java

public void show() {
    if (PMS.isHeadless()) {
        // Can only get here during startup in headless mode, there's no way to trigger it from the GUI
        LOGGER.info(//ww w.j  a  v  a 2s .  c  o  m
                "No language is configured and the language selection dialog is unavailable in headless mode");
        LOGGER.info("Defaulting to OS locale {}", Locale.getDefault().getDisplayName());
        PMS.setLocale(Locale.getDefault());
    } else {
        pane = new JOptionPane(buildComponent(), JOptionPane.PLAIN_MESSAGE, JOptionPane.NO_OPTION, null,
                new JButton[] { applyButton, selectButton }, selectButton);
        pane.setComponentOrientation(ComponentOrientation.getOrientation(locale));
        dialog = pane.createDialog(parentComponent, PMS.NAME);
        dialog.setModalityType(ModalityType.APPLICATION_MODAL);
        dialog.setIconImage(LooksFrame.readImageIcon("icon-32.png").getImage());
        setStrings();
        dialog.pack();
        dialog.setLocationRelativeTo(parentComponent);
        dialog.setVisible(true);
        dialog.dispose();

        if (pane.getValue() == null) {
            aborted = true;
        } else if (!((String) pane.getValue()).equals(PMS.getConfiguration().getLanguageRawString())) {
            if (rebootOnChange) {
                int response = JOptionPane.showConfirmDialog(parentComponent,
                        String.format(buildString("Dialog.Restart", true), PMS.NAME, PMS.NAME),
                        buildString("Dialog.Confirm"), JOptionPane.YES_NO_CANCEL_OPTION);
                if (response != JOptionPane.CANCEL_OPTION) {
                    PMS.getConfiguration().setLanguage((String) pane.getValue());
                    if (response == JOptionPane.YES_OPTION) {
                        try {
                            PMS.getConfiguration().save();
                        } catch (ConfigurationException e) {
                            LOGGER.error("Error while saving configuration: {}", e.getMessage());
                            LOGGER.trace("", e);
                        }
                        ProcessUtil.reboot();
                    }
                }
            } else {
                PMS.getConfiguration().setLanguage((String) pane.getValue());
            }
        }
    }
}

From source file:net.sf.jabref.openoffice.AutoDetectPaths.java

private boolean autoDetectPaths() {

    if (OS.WINDOWS) {
        List<File> progFiles = findProgramFilesDir();
        File sOffice = null;//  w ww  . j a va  2  s  .co m
        List<File> sofficeFiles = new ArrayList<>();
        for (File dir : progFiles) {
            if (fileSearchCancelled) {
                return false;
            }
            sOffice = findFileDir(dir, "soffice.exe");
            if (sOffice != null) {
                sofficeFiles.add(sOffice);
            }
        }
        if (sOffice == null) {
            JOptionPane.showMessageDialog(parent, Localization.lang(
                    "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."),
                    Localization.lang("Could not find OpenOffice/LibreOffice installation"),
                    JOptionPane.INFORMATION_MESSAGE);
            JFileChooser jfc = new JFileChooser(new File("C:\\"));
            jfc.setDialogType(JFileChooser.OPEN_DIALOG);
            jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {

                @Override
                public boolean accept(File file) {
                    return file.isDirectory();
                }

                @Override
                public String getDescription() {
                    return Localization.lang("Directories");
                }
            });
            jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            jfc.showOpenDialog(parent);
            if (jfc.getSelectedFile() != null) {
                sOffice = jfc.getSelectedFile();
            }
        }
        if (sOffice == null) {
            return false;
        }

        if (sofficeFiles.size() > 1) {
            // More than one file found
            DefaultListModel<File> mod = new DefaultListModel<>();
            for (File tmpfile : sofficeFiles) {
                mod.addElement(tmpfile);
            }
            JList<File> fileList = new JList<>(mod);
            fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            fileList.setSelectedIndex(0);
            FormBuilder b = FormBuilder.create()
                    .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref"));
            b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1);
            b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3);
            b.add(fileList).xy(1, 5);
            int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                    Localization.lang("Choose OpenOffice/LibreOffice executable"),
                    JOptionPane.OK_CANCEL_OPTION);
            if (answer == JOptionPane.CANCEL_OPTION) {
                return false;
            } else {
                sOffice = fileList.getSelectedValue();
            }

        } else {
            sOffice = sofficeFiles.get(0);
        }
        return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe");
    } else if (OS.OS_X) {
        File rootDir = new File("/Applications");
        File[] files = rootDir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName())
                        || "LibreOffice.app".equals(file.getName()))) {
                    rootDir = file;
                    break;
                }
            }
        }
        File sOffice = findFileDir(rootDir, SOFFICE_BIN);
        if (fileSearchCancelled) {
            return false;
        }
        if (sOffice == null) {
            return false;
        } else {
            return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN);
        }
    } else {
        // Linux:
        String usrRoot = "/usr/lib";
        File inUsr = findFileDir(new File(usrRoot), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if (inUsr == null) {
            inUsr = findFileDir(new File("/usr/lib64"), SOFFICE);
            if (inUsr != null) {
                usrRoot = "/usr/lib64";
            }
        }

        if (fileSearchCancelled) {
            return false;
        }
        File inOpt = findFileDir(new File("/opt"), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if ((inUsr != null) && (inOpt == null)) {
            return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
        } else if (inOpt != null) {
            if (inUsr == null) {
                return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
            } else { // Found both
                JRadioButton optRB = new JRadioButton(inOpt.getPath(), true);
                JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false);
                ButtonGroup bg = new ButtonGroup();
                bg.add(optRB);
                bg.add(usrRB);
                FormBuilder b = FormBuilder.create()
                        .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref "));
                b.add(Localization.lang(
                        "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:"))
                        .xy(1, 1);
                b.add(optRB).xy(1, 3);
                b.add(usrRB).xy(1, 5);
                int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                        Localization.lang("Choose OpenOffice/LibreOffice executable"),
                        JOptionPane.OK_CANCEL_OPTION);
                if (answer == JOptionPane.CANCEL_OPTION) {
                    return false;
                }
                if (optRB.isSelected()) {
                    return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
                } else {
                    return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
                }
            }
        }
    }
    return false;
}

From source file:es.emergya.ui.plugins.admin.aux1.RecursoDialog.java

public RecursoDialog(final Recurso rec, final AdminResources adminResources) {
    super();//  w  w w .  j  a v  a2  s  .  c o m
    setAlwaysOnTop(true);
    setSize(600, 400);

    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            if (cambios) {
                int res = JOptionPane.showConfirmDialog(RecursoDialog.this,
                        "Existen cambios sin guardar. Seguro que desea cerrar la ventana?",
                        "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION);
                if (res != JOptionPane.CANCEL_OPTION) {
                    e.getWindow().dispose();
                }
            } else {
                e.getWindow().dispose();
            }
        }
    });
    final Recurso r = (rec == null) ? null : RecursoConsultas.get(rec.getId());
    if (r != null) {
        setTitle(i18n.getString("Resources.summary.titleWindow") + " " + r.getIdentificador());
    } else {
        setTitle(i18n.getString("Resources.summary.titleWindow.new"));
    }
    setIconImage(getBasicWindow().getFrame().getIconImage());
    JPanel base = new JPanel();
    base.setBackground(Color.WHITE);
    base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

    // Icono del titulo
    JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING));
    title.setOpaque(false);
    JLabel labelTitulo = null;
    if (r != null) {
        labelTitulo = new JLabel(i18n.getString("Resources.summary"),
                LogicConstants.getIcon("tittleficha_icon_recurso"), JLabel.LEFT);

    } else {
        labelTitulo = new JLabel(i18n.getString("Resources.cabecera.nuevo"),
                LogicConstants.getIcon("tittleficha_icon_recurso"), JLabel.LEFT);

    }
    labelTitulo.setFont(LogicConstants.deriveBoldFont(12f));
    title.add(labelTitulo);
    base.add(title);

    // Nombre
    JPanel mid = new JPanel(new SpringLayout());
    mid.setOpaque(false);
    mid.add(new JLabel(i18n.getString("Resources.name"), JLabel.RIGHT));
    final JTextField name = new JTextField(25);
    if (r != null) {
        name.setText(r.getNombre());
    }

    name.getDocument().addDocumentListener(changeListener);
    name.setEditable(r == null);
    mid.add(name);

    // patrullas
    final JLabel labelSquads = new JLabel(i18n.getString("Resources.squad"), JLabel.RIGHT);
    mid.add(labelSquads);
    List<Patrulla> pl = PatrullaConsultas.getAll();
    pl.add(0, null);
    final JComboBox squads = new JComboBox(pl.toArray());
    squads.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXX");
    squads.addActionListener(changeSelectionListener);
    squads.setOpaque(false);
    labelSquads.setLabelFor(squads);
    if (r != null) {
        squads.setSelectedItem(r.getPatrullas());
    } else {
        squads.setSelectedItem(null);
    }
    squads.setEnabled((r != null && r.getHabilitado() != null) ? r.getHabilitado() : true);
    mid.add(squads);

    // // Identificador
    // mid.setOpaque(false);
    // mid.add(new JLabel(i18n.getString("Resources.identificador"),
    // JLabel.RIGHT));
    // final JTextField identificador = new JTextField("");
    // if (r != null) {
    // identificador.setText(r.getIdentificador());
    // }
    // identificador.getDocument().addDocumentListener(changeListener);
    // identificador.setEditable(r == null);
    // mid.add(identificador);
    // Espacio en blanco
    // mid.add(Box.createHorizontalGlue());
    // mid.add(Box.createHorizontalGlue());

    // Tipo
    final JLabel labelTipoRecursos = new JLabel(i18n.getString("Resources.type"), JLabel.RIGHT);
    mid.add(labelTipoRecursos);
    final JComboBox types = new JComboBox(RecursoConsultas.getTipos());
    labelTipoRecursos.setLabelFor(types);
    types.addActionListener(changeSelectionListener);
    if (r != null) {
        types.setSelectedItem(r.getTipo());
    } else {
        types.setSelectedItem(0);
    }
    // types.setEditable(true);
    types.setEnabled(true);
    mid.add(types);

    // Estado Eurocop
    mid.add(new JLabel(i18n.getString("Resources.status"), JLabel.RIGHT));
    final JTextField status = new JTextField();
    if (r != null && r.getEstadoEurocop() != null) {
        status.setText(r.getEstadoEurocop().getIdentificador());
    }
    status.setEditable(false);
    mid.add(status);

    // Subflota y patrulla
    mid.add(new JLabel(i18n.getString("Resources.subfleet"), JLabel.RIGHT));
    final JComboBox subfleets = new JComboBox(FlotaConsultas.getAllHabilitadas());
    subfleets.addActionListener(changeSelectionListener);
    if (r != null) {
        subfleets.setSelectedItem(r.getFlotas());
    } else {
        subfleets.setSelectedIndex(0);
    }
    subfleets.setEnabled(true);
    subfleets.setOpaque(false);
    mid.add(subfleets);

    // Referencia humana
    mid.add(new JLabel(i18n.getString("Resources.incidences"), JLabel.RIGHT));
    final JTextField rhumana = new JTextField();
    // if (r != null && r.getIncidencias() != null) {
    // rhumana.setText(r.getIncidencias().getReferenciaHumana());
    // }
    rhumana.setEditable(false);
    mid.add(rhumana);

    // dispositivo
    mid.add(new JLabel(i18n.getString("Resources.device"), JLabel.RIGHT));
    final PlainDocument plainDocument = new PlainDocument() {

        private static final long serialVersionUID = 4929271093724956016L;

        @Override
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            if (this.getLength() + str.length() <= LogicConstants.LONGITUD_ISSI) {
                super.insertString(offs, str, a);
            }
        }
    };
    final JTextField issi = new JTextField(plainDocument, "", LogicConstants.LONGITUD_ISSI);
    plainDocument.addDocumentListener(changeListener);
    issi.setEditable(true);
    mid.add(issi);
    mid.add(new JLabel(i18n.getString("Resources.enabled"), JLabel.RIGHT));
    final JCheckBox enabled = new JCheckBox("", true);
    enabled.addActionListener(changeSelectionListener);
    enabled.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (enabled.isSelected()) {
                squads.setSelectedIndex(0);
            }
            squads.setEnabled(enabled.isSelected());
        }
    });
    enabled.setEnabled(true);
    enabled.setOpaque(false);
    if (r != null) {
        enabled.setSelected(r.getHabilitado());
    } else {
        enabled.setSelected(true);
    }
    if (r != null && r.getDispositivo() != null) {
        issi.setText(
                StringUtils.leftPad(String.valueOf(r.getDispositivo()), LogicConstants.LONGITUD_ISSI, '0'));
    }

    mid.add(enabled);

    // Fecha ultimo gps
    mid.add(new JLabel(i18n.getString("Resources.lastPosition"), JLabel.RIGHT));
    JTextField lastGPS = new JTextField();
    final Date lastGPSDateForRecurso = HistoricoGPSConsultas.lastGPSDateForRecurso(r);
    if (lastGPSDateForRecurso != null) {
        lastGPS.setText(SimpleDateFormat.getDateTimeInstance().format(lastGPSDateForRecurso));
    }
    lastGPS.setEditable(false);
    mid.add(lastGPS);

    // Espacio en blanco
    mid.add(Box.createHorizontalGlue());
    mid.add(Box.createHorizontalGlue());

    // informacion adicional
    JPanel infoPanel = new JPanel(new SpringLayout());
    final JTextField info = new JTextField(25);
    info.getDocument().addDocumentListener(changeListener);
    infoPanel.add(new JLabel(i18n.getString("Resources.info")));
    infoPanel.add(info);
    infoPanel.setOpaque(false);
    info.setOpaque(false);
    SpringUtilities.makeCompactGrid(infoPanel, 1, 2, 6, 6, 6, 18);

    if (r != null) {
        info.setText(r.getInfoAdicional());
    } else {
        info.setText("");
    }
    info.setEditable(true);

    // Espacio en blanco
    mid.add(Box.createHorizontalGlue());
    mid.add(Box.createHorizontalGlue());

    SpringUtilities.makeCompactGrid(mid, 5, 4, 6, 6, 6, 18);
    base.add(mid);
    base.add(infoPanel);

    JPanel buttons = new JPanel();
    buttons.setOpaque(false);
    JButton accept = null;
    if (r == null) {
        accept = new JButton("Crear", LogicConstants.getIcon("button_crear"));
    } else {
        accept = new JButton("Guardar", LogicConstants.getIcon("button_save"));
    }
    accept.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                if (cambios || r == null || r.getId() == null) {
                    boolean shithappens = true;
                    if ((r == null || r.getId() == null)) { // Estamos
                        // creando
                        // uno nuevo
                        if (RecursoConsultas.alreadyExists(name.getText())) {
                            shithappens = false;
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.nombreUnico"));
                        } else if (issi.getText() != null && issi.getText().length() > 0 && StringUtils
                                .trimToEmpty(issi.getText()).length() != LogicConstants.LONGITUD_ISSI) {
                            JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString(Locale.ROOT,
                                    "admin.recursos.popup.error.faltanCifras", LogicConstants.LONGITUD_ISSI));
                            shithappens = false;
                        } else if (issi.getText() != null && issi.getText().length() > 0
                                && LogicConstants.isNumeric(issi.getText())
                                && RecursoConsultas.alreadyExists(new Integer(issi.getText()))) {
                            shithappens = false;
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.dispositivoUnico"));
                        }
                    }
                    if (shithappens) {
                        if (name.getText().isEmpty()) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.nombreNulo"));
                        } else if (issi.getText() != null && issi.getText().length() > 0 && StringUtils
                                .trimToEmpty(issi.getText()).length() != LogicConstants.LONGITUD_ISSI) {
                            JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString(Locale.ROOT,
                                    "admin.recursos.popup.error.faltanCifras", LogicConstants.LONGITUD_ISSI));
                        } else if (issi.getText() != null && issi.getText().length() > 0
                                && LogicConstants.isNumeric(issi.getText()) && r != null && r.getId() != null
                                && RecursoConsultas.alreadyExists(new Integer(issi.getText()), r.getId())) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.issiUnico"));
                        } else if (issi.getText() != null && issi.getText().length() > 0
                                && !LogicConstants.isNumeric(issi.getText())) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.noNumerico"));
                            // } else if (identificador.getText().isEmpty())
                            // {
                            // JOptionPane
                            // .showMessageDialog(
                            // RecursoDialog.this,
                            // i18n.getString("admin.recursos.popup.error.identificadorNulo"));
                        } else if (subfleets.getSelectedIndex() == -1) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.noSubflota"));
                        } else if (types.getSelectedItem() == null
                                || types.getSelectedItem().toString().trim().isEmpty()) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.noTipo"));
                        } else {
                            int i = JOptionPane.showConfirmDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.dialogo.guardar.titulo"),
                                    i18n.getString("admin.recursos.popup.dialogo.guardar.guardar"),
                                    JOptionPane.YES_NO_CANCEL_OPTION);

                            if (i == JOptionPane.YES_OPTION) {

                                Recurso recurso = r;

                                if (r == null) {
                                    recurso = new Recurso();
                                }

                                recurso.setInfoAdicional(info.getText());
                                if (issi.getText() != null && issi.getText().length() > 0) {
                                    recurso.setDispositivo(new Integer(issi.getText()));
                                } else {
                                    recurso.setDispositivo(null);
                                }
                                recurso.setFlotas(FlotaConsultas.find(subfleets.getSelectedItem().toString()));
                                if (squads.getSelectedItem() != null && enabled.isSelected()) {
                                    recurso.setPatrullas(
                                            PatrullaConsultas.find(squads.getSelectedItem().toString()));
                                } else {
                                    recurso.setPatrullas(null);
                                }
                                recurso.setNombre(name.getText());
                                recurso.setHabilitado(enabled.isSelected());
                                // recurso.setIdentificador(identificador
                                // .getText());
                                recurso.setTipo(types.getSelectedItem().toString());
                                dispose();

                                RecursoAdmin.saveOrUpdate(recurso);
                                adminResources.refresh(null);

                                PluginEventHandler.fireChange(adminResources);
                            } else if (i == JOptionPane.NO_OPTION) {
                                dispose();
                            }
                        }
                    }
                } else {
                    log.debug("No hay cambios");
                    dispose();
                }

            } catch (Throwable t) {
                log.error("Error guardando un recurso", t);
            }
        }
    });
    buttons.add(accept);

    JButton cancelar = new JButton("Cancelar", LogicConstants.getIcon("button_cancel"));

    cancelar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (cambios) {
                if (JOptionPane.showConfirmDialog(RecursoDialog.this,
                        "Existen cambios sin guardar. Seguro que desea cerrar la ventana?",
                        "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION) != JOptionPane.CANCEL_OPTION) {
                    dispose();
                }
            } else {
                dispose();
            }
        }
    });

    buttons.add(cancelar);

    base.add(buttons);

    getContentPane().add(base);
    setLocationRelativeTo(null);
    cambios = false;
    if (r == null) {
        cambios = true;
    }

    pack();

    int x;
    int y;

    Container myParent = getBasicWindow().getPluginContainer().getDetachedTab(0);
    Point topLeft = myParent.getLocationOnScreen();
    Dimension parentSize = myParent.getSize();

    Dimension mySize = getSize();

    if (parentSize.width > mySize.width) {
        x = ((parentSize.width - mySize.width) / 2) + topLeft.x;
    } else {
        x = topLeft.x;
    }

    if (parentSize.height > mySize.height) {
        y = ((parentSize.height - mySize.height) / 2) + topLeft.y;
    } else {
        y = topLeft.y;
    }

    setLocation(x, y);
    cambios = false;
}

From source file:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java

/**
 * Initialize the view components./*from w ww  .  j  a  v  a  2 s .co  m*/
 */
private void initView() {
    // create new view
    loadTracksPanel = new LoadTracksPanel();
    // disable the IMPORT FILES button
    loadTracksPanel.getImportFilesButton().setEnabled(false);
    // initialize the flag to keep track of importing
    isImported = false;
    // populate the combobox with available file formats
    // note: these are annoatated as spring beans
    Set<String> parsers = TrackFileParserFactory.getInstance().getParserBeanNames();
    for (String parser : parsers) {
        loadTracksPanel.getFileFormatComboBox().addItem(parser);
    }

    // format the table
    JTableHeader tracksTableHeader = loadTracksPanel.getTracksTable().getTableHeader();
    tracksTableHeader.setBackground(GuiUtils.getHeaderColor());
    tracksTableHeader.setFont(GuiUtils.getHeaderFont());
    tracksTableHeader.setReorderingAllowed(false);

    /**
     * Action Listeners.
     */
    // load directory
    loadTracksPanel.getLoadDirectoryButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (directory == null) {
                chooseDirectoryAndLoadData();
            } else {
                // otherwise we ask the user if they want to reload the directory
                Object[] options = { "Load a different directory", "Cancel" };
                int showOptionDialog = JOptionPane.showOptionDialog(null,
                        "It seems a directory was already loaded.\nWhat do you want to do?", "",
                        JOptionPane.CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]);
                switch (showOptionDialog) {
                case 0: // load a different directory:
                    // reset the model of the directory tree
                    DefaultTreeModel model = (DefaultTreeModel) loadTracksPanel.getDirectoryTree().getModel();
                    DefaultMutableTreeNode rootNote = (DefaultMutableTreeNode) model.getRoot();
                    rootNote.removeAllChildren();
                    model.reload();
                    chooseDirectoryAndLoadData();
                    loadTracksPanel.getChosenDirectoryTextArea().setText(directory.getAbsolutePath());
                    break; // cancel: do nothing
                }
            }
        }
    });

    // import the selected files in the tree
    loadTracksPanel.getImportFilesButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // check if an import already took place
            if (!isImported) {
                // get the selected file(s) from the JTree
                TreePath[] selectionPaths = loadTracksPanel.getDirectoryTree().getSelectionPaths();
                if (selectionPaths != null && selectionPaths.length != 0) {
                    // at least a file was selected --  proceed with the import
                    importFiles();
                    isImported = true;
                    cellCoordController.showMessage(selectionPaths.length + " file(s) successfully imported!",
                            "success loading", JOptionPane.INFORMATION_MESSAGE);
                    // do basic computations
                    preprocess();
                    // go to child controllers and show samples in the tables
                    summaryDataController.showSamplesInTable();
                    computationMainController.showSamplesInTable();
                    // proceed with next step in the plugin
                    cellCoordController.getCellCoordFrame().getNextButton().setEnabled(true);
                } else {
                    // inform the user that no file was selected!
                    cellCoordController.showMessage("You have to select at least one file!",
                            "no files selected", JOptionPane.WARNING_MESSAGE);
                }
            } else {
                // an import already took place: ask for user input
                Object[] options = { "Load other file(s)", "Cancel" };
                int showOptionDialog = JOptionPane.showOptionDialog(loadTracksPanel,
                        "It seems some files were already loaded.\nWhat do you want to do?", "",
                        JOptionPane.CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]);
                switch (showOptionDialog) {
                case 0: // load other files
                    // clear the sample list
                    samples.clear();
                    // clear the track spot list
                    trackSpotsBindingList.clear();
                    // clear the selection in the JTree
                    loadTracksPanel.getDirectoryTree().clearSelection();
                    isImported = false;
                    // inform the user they need to select other files
                    JOptionPane.showMessageDialog(loadTracksPanel, "Please select other files", "",
                            JOptionPane.INFORMATION_MESSAGE);
                    break; // cancel: do nothing
                }
            }

        }
    });

    // add view to parent component
    cellCoordController.getCellCoordFrame().getLoadTracksParentPanel().add(loadTracksPanel, gridBagConstraints);
}

From source file:com.compomics.pladipus.controller.setup.InstallPladipus.java

/**
 * Queries the user for the valid user login and password
 *
 * @throws IOException//from   w ww  .ja  v  a  2s  .c  om
 */
public boolean validateUser() throws IOException {

    JPanel panel = new JPanel(new BorderLayout(5, 5));

    JPanel label = new JPanel(new GridLayout(0, 1, 2, 2));
    label.add(new JLabel("Username", SwingConstants.RIGHT));
    label.add(new JLabel("Password", SwingConstants.RIGHT));
    panel.add(label, BorderLayout.WEST);

    JPanel controls = new JPanel(new GridLayout(0, 1, 2, 2));
    JTextField username = new JTextField();
    controls.add(username);
    JPasswordField password = new JPasswordField();
    controls.add(password);

    panel.add(controls, BorderLayout.CENTER);

    int showConfirmDialog = JOptionPane.showConfirmDialog(null, panel, "Pladipus Login",
            JOptionPane.OK_CANCEL_OPTION);

    if (showConfirmDialog == JOptionPane.CANCEL_OPTION) {
        return false;
    }

    String user = username.getText();
    String pass = new String(password.getPassword());

    if (login(user, pass)) {
        writeWorkerBash(user, pass);
        return true;
    } else {
        throw new SecurityException("User credentials are incorrect!");
    }
}

From source file:br.org.acessobrasil.silvinha.vista.panels.PainelSenha.java

private void getPassword() {
    JDialog dialog = op.createDialog(this, GERAL.SENHA_SOLICITADA_SERVIDOR);
    dialog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    dialog.setVisible(true);//w w w . j a v a 2s . co  m
    Object opcao = op.getValue();
    if (opcao != null) {
        if (opcao.equals(JOptionPane.OK_OPTION)) {
            this.user = txtName.getText();
            this.password = String.valueOf(txtPass.getPassword());
        } else if (opcao.equals(JOptionPane.CANCEL_OPTION)) {
            this.cancelAuth = true;
        }
    }
}