Example usage for javax.swing JOptionPane showMessageDialog

List of usage examples for javax.swing JOptionPane showMessageDialog

Introduction

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

Prototype

public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType)
        throws HeadlessException 

Source Link

Document

Brings up a dialog that displays a message using a default icon determined by the messageType parameter.

Usage

From source file:be.ac.ua.comp.scarletnebula.gui.keywizards.FinalNewKeyPage.java

@Override
protected void performAction(final KeyRecorder recorder) {
    recorder.keyname = keyname;/*from   w ww .j  a va  2s  .  c  o  m*/
    recorder.makeDefault = makeKeyDefault();

    (new SwingWorker<Exception, Object>() {
        @Override
        protected Exception doInBackground() throws Exception {
            try {
                provider.createKey(keyname, makeKeyDefault());
            } catch (final Exception e) {
                return e;
            }
            return null;
        }

        @Override
        public void done() {
            try {
                final Exception result = get();

                if (result != null) {
                    log.error("Could not create key", result);
                    JOptionPane.showMessageDialog(FinalNewKeyPage.this, result.getLocalizedMessage(),
                            "Error creating key", JOptionPane.ERROR_MESSAGE);
                }
            } catch (final Exception ignore) {
            }
        }
    }).execute();
}

From source file:edu.ku.brc.util.XMLChecksumUtil.java

/**
 * Returns whether the checksum in the file matched the checksum of the file.
 * @param file the File object to be checked
 * @return true if check sum matches, false if not.
 *//*  www. j a  v  a 2  s. c  o  m*/
public static boolean checkSignature(final File file) {
    Properties checksumProps = new Properties();
    File checksumFile = XMLHelper.getConfigDir(checksumFileName);
    if (checksumFile.exists()) {
        try {
            checksumProps.load(new FileInputStream(checksumFile));
            return checkSignature(checksumProps, file);

        } catch (IOException ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(XMLChecksumUtil.class, ex);
            throw new RuntimeException(
                    "Couldn't locate Checksum file [" + checksumFile.getAbsolutePath() + "]");
        }
    } else {
        JOptionPane.showMessageDialog(null, getResourceString("CHECKSUM_MSG"),
                getResourceString("CHECKSUM_TITLE"), JOptionPane.ERROR_MESSAGE);
        System.exit(0);
    }
    return false;
}

From source file:licenceexecuter.LicenceExecuter.java

private void run() throws Throwable {
    Date atualDate = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    ObKeyExecuter obKey = ControllerKey.decrypt(properties.getProperty("key"));
    if (atualDate.before(obKey.getDataLicenca())) {
        JOptionPane.showMessageDialog(null, "SUA LICENA INICIA DIA: " + sdf.format(obKey.getDataLicenca()),
                "ATENO", JOptionPane.ERROR_MESSAGE);
        return;//from w  w w  .j av  a  2s  .  co m
    }

    if (atualDate.after(obKey.getUltimaDataVerificada())) {
        try {
            if (atualDate.before(obKey.getDataValidade())) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(obKey.getDataValidade());
                calendar.add(Calendar.DAY_OF_MONTH, -6);
                if (atualDate.after(calendar.getTime())) {
                    String msg = String.format(
                            "SUA LICENA VENCE NO DIA %s ENTRE COM A NOVA CHAVE OU CONTINUE.",
                            sdf.format(obKey.getDataValidade()));
                    JDialogRegister jDialogRegister = new JDialogRegister(msg);
                    jDialogRegister.setVisible(true);
                    if (jDialogRegister.getNewKey() != null && !jDialogRegister.getNewKey().isEmpty()) {
                        ObKeyExecuter ob2 = register(jDialogRegister.getNewKey());
                        obKey = ob2 == null ? obKey : ob2;
                    }
                }
            } else {
                String msg = String.format(
                        "SUA LICENA VENCEU NO DIA %s ENTRE COM A NOVA CHAVE OU CONTINUE PARA SAIR.",
                        sdf.format(obKey.getDataValidade()));
                JDialogRegister jDialogRegister = new JDialogRegister(msg);
                jDialogRegister.setVisible(true);
                if (jDialogRegister.getNewKey() != null && !jDialogRegister.getNewKey().isEmpty()) {
                    ObKeyExecuter ob2 = register(jDialogRegister.getNewKey());
                    if (ob2 == null) {
                        return;
                    }
                    obKey = ob2;
                } else {
                    return;
                }
            }
            executeProgram(obKey);
        } finally {
            obKey.setUltimaDataVerificada(atualDate);
            updateKey(obKey);
        }
    } else {
        JOptionPane.showMessageDialog(null, "POSS?VEL ALTERAO NO RELGIO DO SISTEMA! VERIFIQUE",
                "ATENO", JOptionPane.ERROR_MESSAGE);
    }

}

From source file:biz.wolschon.finance.jgnucash.actions.ToolPluginMenuAction.java

@Override
public void actionPerformed(final ActionEvent e) {
    try {/*from   ww w . j  a  va  2  s  .c o m*/
        GnucashWritableFile wModel = myJGnucashEditor.getWritableModel();
        if (wModel == null) {
            JOptionPane.showMessageDialog(myJGnucashEditor, "No open file.",
                    "Please open a gnucash-file first!", JOptionPane.WARNING_MESSAGE);
            return;
        }

        // Activate plug-in that declares extension.
        myJGnucashEditor.getPluginManager().activatePlugin(ext.getDeclaringPluginDescriptor().getId());
        // Get plug-in class loader.
        ClassLoader classLoader = myJGnucashEditor.getPluginManager()
                .getPluginClassLoader(ext.getDeclaringPluginDescriptor());
        // Load Tool class.
        Class toolCls = classLoader.loadClass(ext.getParameter("class").valueAsString());
        // Create Tool instance.
        Object o = toolCls.newInstance();
        if (!(o instanceof ToolPlugin)) {
            LOGGER.error("Plugin '" + pluginName + "' does not implement ToolPlugin-interface.");
            JOptionPane.showMessageDialog(myJGnucashEditor, "Error",
                    "Plugin '" + pluginName + "' does not implement ToolPlugin-interface.",
                    JOptionPane.ERROR_MESSAGE);
            return;

        }
        ToolPlugin importer = (ToolPlugin) o;
        try {
            myJGnucashEditor.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            GnucashWritableAccount selectedAccount = (GnucashWritableAccount) myJGnucashEditor
                    .getSelectedAccount();
            String message = importer.runTool(wModel, selectedAccount);
            if (message != null && message.length() > 0) {
                JOptionPane.showMessageDialog(myJGnucashEditor, "Tool OK",
                        "The tool-use was a success:\n" + message, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e1) {
            LOGGER.error("Tool-use via Plugin '" + pluginName + "' failed.", e1);
            JOptionPane
                    .showMessageDialog(
                            myJGnucashEditor, "Error", "Tool-use via Plugin '" + pluginName + "' failed.\n"
                                    + "[" + e1.getClass().getName() + "]: " + e1.getMessage(),
                            JOptionPane.ERROR_MESSAGE);
        } finally {
            myJGnucashEditor.setCursor(Cursor.getDefaultCursor());
        }
    } catch (Exception e1) {
        LOGGER.error("Could not activate requested Tool-plugin '" + pluginName + "'.", e1);
        JOptionPane
                .showMessageDialog(
                        myJGnucashEditor, "Error", "Could not activate requested Tool-plugin '" + pluginName
                                + "'.\n" + "[" + e1.getClass().getName() + "]: " + e1.getMessage(),
                        JOptionPane.ERROR_MESSAGE);
    }
}

From source file:net.sf.jabref.external.FindFullTextAction.java

@Override
public void update() {
    if (result.isPresent()) {
        List<String> dirs = basePanel.getBibDatabaseContext().getFileDirectory();
        if (dirs.isEmpty()) {
            JOptionPane.showMessageDialog(basePanel.frame(),
                    Localization.lang("Main file directory not set!") + " " + Localization.lang("Preferences")
                            + " -> " + Localization.lang("External programs"),
                    Localization.lang("Directory not found"), JOptionPane.ERROR_MESSAGE);
            return;
        }/*  w w  w  . ja v  a  2  s  .  c  o  m*/
        String bibtexKey = entry.getCiteKey();
        // TODO: this needs its own thread as it blocks the UI!
        DownloadExternalFile def = new DownloadExternalFile(basePanel.frame(),
                basePanel.getBibDatabaseContext(), bibtexKey);
        try {
            def.download(result.get(), file -> {
                FileListTableModel tm = new FileListTableModel();
                entry.getFieldOptional(FieldName.FILE).ifPresent(tm::setContent);
                tm.addEntry(tm.getRowCount(), file);
                String newValue = tm.getStringRepresentation();
                UndoableFieldChange edit = new UndoableFieldChange(entry, FieldName.FILE,
                        entry.getFieldOptional(FieldName.FILE).orElse(null), newValue);
                entry.setField(FieldName.FILE, newValue);
                basePanel.getUndoManager().addEdit(edit);
                basePanel.markBaseChanged();
            });
        } catch (IOException e) {
            LOGGER.warn("Problem downloading file", e);
        }
        basePanel.output(Localization.lang("Finished downloading full text document"));
    } else {
        String message = Localization.lang("Full text document download failed");
        basePanel.output(message);
        JOptionPane.showMessageDialog(basePanel.frame(), message, message, JOptionPane.ERROR_MESSAGE);
    }
}

From source file:userInteface.Patient.ManageVitalSignsJPanel.java

private void populatePatientsTable(ArrayList<Person> personList) {
    DefaultTableModel model = (DefaultTableModel) viewPatientsJTable.getModel();
    model.setRowCount(0);/*from   www.  j  a va2 s . c  om*/
    if (personList.isEmpty()) {
        JOptionPane.showMessageDialog(this, "No Persons found. Please add Persons", "Error",
                JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    for (Person person : personList) {
        Object[] row = new Object[3];
        row[0] = person;
        row[1] = person.getAge();
        if (person.getPatient() != null) {
            row[2] = person.getPatient().getPatientID();
        } else {
            row[2] = "Patient Not Created";
        }

        model.addRow(row);
    }
}

From source file:biz.wolschon.finance.jgnucash.actions.ImportPluginMenuAction.java

@Override
public void actionPerformed(final ActionEvent e) {
    try {/*w  ww.jav a  2s  .c  om*/
        GnucashWritableFile wModel = myJGnucashEditor.getWritableModel();
        if (wModel == null) {
            JOptionPane.showMessageDialog(myJGnucashEditor, "No open file.",
                    "Please open a gnucash-file first!", JOptionPane.WARNING_MESSAGE);
            return;
        }

        // Activate plug-in that declares extension.
        myJGnucashEditor.getPluginManager().activatePlugin(ext.getDeclaringPluginDescriptor().getId());
        // Get plug-in class loader.
        ClassLoader classLoader = myJGnucashEditor.getPluginManager()
                .getPluginClassLoader(ext.getDeclaringPluginDescriptor());
        // Load Tool class.
        Class toolCls = classLoader.loadClass(ext.getParameter("class").valueAsString());
        // Create Tool instance.
        Object o = toolCls.newInstance();
        if (!(o instanceof ImporterPlugin)) {
            LOGGER.error("Plugin '" + pluginName + "' does not implement ImporterPlugin-interface.");
            JOptionPane.showMessageDialog(myJGnucashEditor, "Error",
                    "Plugin '" + pluginName + "' does not implement ImporterPlugin-interface.",
                    JOptionPane.ERROR_MESSAGE);
            return;

        }
        ImporterPlugin importer = (ImporterPlugin) o;
        try {
            myJGnucashEditor.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            GnucashWritableAccount selectedAccount = (GnucashWritableAccount) myJGnucashEditor
                    .getSelectedAccount();
            String message = importer.runImport(wModel, selectedAccount);
            if (message != null && message.length() > 0) {
                JOptionPane.showMessageDialog(myJGnucashEditor, "Import OK",
                        "The import was a success:\n" + message, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e1) {
            LOGGER.error("Import via Plugin '" + pluginName + "' failed.", e1);
            JOptionPane
                    .showMessageDialog(
                            myJGnucashEditor, "Error", "Import via Plugin '" + pluginName + "' failed.\n" + "["
                                    + e1.getClass().getName() + "]: " + e1.getMessage(),
                            JOptionPane.ERROR_MESSAGE);
        } finally {
            myJGnucashEditor.setCursor(Cursor.getDefaultCursor());
        }
    } catch (Exception e1) {
        LOGGER.error("Could not activate requested import-plugin '" + pluginName + "'.", e1);
        JOptionPane
                .showMessageDialog(
                        myJGnucashEditor, "Error", "Could not activate requested import-plugin '" + pluginName
                                + "'.\n" + "[" + e1.getClass().getName() + "]: " + e1.getMessage(),
                        JOptionPane.ERROR_MESSAGE);
    }
}

From source file:de.ep3.ftpc.controller.portal.CrawlerDownloadController.java

@Override
public void mouseClicked(MouseEvent e) {
    CrawlerResultsItem.PreviewPanel previewPanel = (CrawlerResultsItem.PreviewPanel) e.getSource();
    CrawlerResult crawlerResult = previewPanel.getCrawlerResult();
    CrawlerFile crawlerFile = crawlerResult.getFile();

    FTPClient ftpClient = crawlerResult.getFtpClient();

    if (ftpClient.isConnected()) {
        JOptionPane.showMessageDialog(portalFrame, i18n.translate("crawlerDownloadWhileConnected"), null,
                JOptionPane.ERROR_MESSAGE);
        return;/*from   w  ww. j av a2  s. com*/
    }

    String fileExtension = crawlerFile.getExtension();

    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter chooserFilter = new FileNameExtensionFilter(
            i18n.translate("fileType", fileExtension.toUpperCase()), crawlerFile.getExtension());

    chooser.setApproveButtonText(i18n.translate("buttonSave"));
    chooser.setDialogTitle(i18n.translate("fileDownloadTo"));
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setFileFilter(chooserFilter);
    chooser.setSelectedFile(new File(crawlerFile.getName()));

    int selection = chooser.showSaveDialog(portalFrame);

    if (selection == JFileChooser.APPROVE_OPTION) {
        File fileToSave = chooser.getSelectedFile();

        Server relatedServer = crawlerResult.getServer();

        try {
            ftpClient.connect(relatedServer.need("server.ip"),
                    Integer.parseInt(relatedServer.need("server.port")));

            int replyCode = ftpClient.getReplyCode();

            if (!FTPReply.isPositiveCompletion(replyCode)) {
                throw new IOException(i18n.translate("crawlerServerRefused"));
            }

            if (relatedServer.has("user.name")) {
                String userName = relatedServer.get("user.name");
                String userPassword = "";

                if (relatedServer.hasTemporary("user.password")) {
                    userPassword = relatedServer.getTemporary("user.password");
                }

                boolean loggedIn = ftpClient.login(userName, userPassword);

                if (!loggedIn) {
                    throw new IOException(i18n.translate("crawlerServerAuthFail"));
                }
            }

            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

            /* Download file */

            InputStream is = ftpClient.retrieveFileStream(crawlerFile.getFullName());

            if (is != null) {

                byte[] rawFile = new byte[(int) crawlerFile.getSize()];

                int i = 0;

                while (true) {
                    int b = is.read();

                    if (b == -1) {
                        break;
                    }

                    rawFile[i] = (byte) b;
                    i++;

                    /* Occasionally update the download progress */

                    if (i % 1024 == 0) {
                        int progress = Math.round((((float) i) / crawlerFile.getSize()) * 100);

                        status.add(i18n.translate("crawlerDownloadProgress", progress));
                    }
                }

                is.close();
                is = null;

                if (!ftpClient.completePendingCommand()) {
                    throw new IOException();
                }

                Files.write(fileToSave.toPath(), rawFile);
            }

            /* Logout and disconnect */

            ftpClient.logout();

            tryDisconnect(ftpClient);

            status.add(i18n.translate("crawlerDownloadDone"));
        } catch (IOException ex) {
            tryDisconnect(ftpClient);

            JOptionPane.showMessageDialog(portalFrame, i18n.translate("crawlerDownloadFailed", ex.getMessage()),
                    null, JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:com.redpill_linpro.libreoffice.LibreOfficeLauncherLinuxImpl.java

@Override
public void launchLibreOffice(String cmisUrl, String repositoryId, String filePath, String webdavUrl) {
    Runtime rt = Runtime.getRuntime();
    try {/*from  w w w .  ja va2  s  .  c  om*/
        String params;
        if (null != webdavUrl && webdavUrl.length() > 0) {
            params = LibreOfficeLauncherHelper.generateLibreOfficeWebdavOpenUrl(webdavUrl);
        } else {
            params = LibreOfficeLauncherHelper.generateLibreOfficeCmisOpenUrl(cmisUrl, repositoryId, filePath);
        }
        StringBuffer cmd = new StringBuffer();
        try {
            String[] binaryLocations = { "soffice", "/usr/bin/soffice" };

            for (int i = 0; i < binaryLocations.length; i++) {
                cmd.append((i == 0 ? "" : " || ") + binaryLocations[i] + " \"" + params + "\" ");
            }

            System.out.println("Command: sh -c " + cmd);

            rt.exec(new String[] { "sh", "-c", cmd.toString() });

            System.out.println("Process started");
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, "Failed to start LibreOffice, commandline: " + cmd.toString(),
                    "Error", JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }

    } catch (UnsupportedEncodingException e1) {
        JOptionPane.showMessageDialog(null, "Invalid URL for LibreOffice", "Error", JOptionPane.ERROR_MESSAGE);
        e1.printStackTrace();
    }
}

From source file:co.udea.edu.proyectointegrador.gr11.parqueaderoapp.view.stadistics.EstadisticaUI.java

private void iniciarGraficos() {
    try {/* www  .  j  a va  2  s  .  c  o  m*/
        chartTypeVehicle = controller.getChartToTypeVehicle(fechaInicio, fechaFin);
        chartTypeUser = controller.getChartToTypeUser(fechaInicio, fechaFin);
        chartHourOfDay = controller.getChartToHourOfDay(fechaInicio, fechaFin);

    } catch (BussinessException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}