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:fi.smaa.jsmaa.gui.components.ValueFunctionMouseListener.java

@Override
public void chartMouseClicked(ChartMouseEvent ev) {
    ChartEntity ent = ev.getEntity();// ww w . j  av  a 2 s. c o m

    if (ent instanceof XYItemEntity) {
        XYItemEntity xyItemEntity = (XYItemEntity) ent;
        int idx = xyItemEntity.getItem();
        if (idx > 0 && idx < (crit.getValuePoints().size() - 1)) {
            crit.deleteValuePoint(idx);
        }
    } else if (ent instanceof PlotEntity) { // add a new point
        double realX = getRealX(ev);
        double realY = getRealY(ev);
        try {
            crit.addValuePoint(new Point2D(realX, realY));
        } catch (InvalidValuePointException e) {
            JOptionPane.showMessageDialog(parent,
                    "Cannot add partial value function segments: " + e.getMessage(),
                    "Unable to add point to the partial value function", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:dbseer.gui.chart.DBSeerChartFactory.java

public static XYSeriesCollection getXYSeriesCollection(String chartName, DBSeerDataSet dataset)
        throws Exception {
    StatisticalPackageRunner runner = DBSeerGUI.runner;

    runner.eval("[title legends Xdata Ydata Xlabel Ylabel timestamp] = plotter.plot" + chartName + ";");

    String title = runner.getVariableString("title");
    Object[] legends = (Object[]) runner.getVariableCell("legends");
    Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata");
    Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata");
    String xLabel = runner.getVariableString("Xlabel");
    String yLabel = runner.getVariableString("Ylabel");

    timestamp = runner.getVariableDouble("timestamp");

    XYSeriesCollection XYdataSet = new XYSeriesCollection();

    int numLegends = legends.length;
    int numXCellArray = xCellArray.length;
    int numYCellArray = yCellArray.length;
    int dataCount = 0;

    if (numXCellArray != numYCellArray) {
        JOptionPane.showMessageDialog(null, "The number of X dataset and Y dataset does not match.",
                "The number of X dataset and Y dataset does not match.", JOptionPane.ERROR_MESSAGE);
        System.out.println(numXCellArray + " : " + numYCellArray);
        return null;
    }//from w  w w. java 2s. c o  m

    java.util.List<String> transactionNames = dataset.getTransactionTypeNames();

    for (int i = 0; i < numLegends; ++i) {
        String legend = (String) legends[i];
        for (int j = 0; j < transactionNames.size(); ++j) {
            if (legend.contains("Type " + (j + 1))) {
                legends[i] = legend.replace("Type " + (j + 1), transactionNames.get(j));
                break;
            }
        }
    }

    for (int i = 0; i < numYCellArray; ++i) {
        double[] xArray = (double[]) xCellArray[i];
        int row = 0, col = 0;
        int xLength = 0;

        runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});");
        runner.eval("yArray = Ydata{" + (i + 1) + "};");
        double[] yArraySize = runner.getVariableDouble("yArraySize");
        double[] yArray = runner.getVariableDouble("yArray");

        xLength = xArray.length;
        row = (int) yArraySize[0];
        col = (int) yArraySize[1];

        for (int c = 0; c < col; ++c) {
            XYSeries series;
            String legend = "";
            int legendIdx = (dataCount >= numLegends) ? numLegends - 1 : dataCount;
            if (legendIdx >= 0) {
                legend = (String) legends[legendIdx];
            }
            if (numLegends == 0) {
                series = new XYSeries("Data " + dataCount + 1);
            } else if (dataCount >= numLegends) {
                series = new XYSeries(legend + (dataCount + 1));
            } else {
                series = new XYSeries(legend);
            }

            for (int r = 0; r < row; ++r) {
                int xRow = (r >= xLength) ? xLength - 1 : r;
                double yValue = yArray[r + c * row];
                // remove negatives
                if (yValue < 0) {
                    yValue = 0;
                }
                series.add(xArray[xRow], yValue);
            }
            XYdataSet.addSeries(series);
            ++dataCount;
        }
    }

    return XYdataSet;
}

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

@Override
public void actionPerformed(final ActionEvent e) {
    try {/* w w w  . ja  v  a  2  s. c o m*/

        // 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 DataSourcePlugin)) {
            LOGGER.error("Plugin '" + pluginName + "' does not implement DataSourcePlugin-interface.");
            JOptionPane.showMessageDialog(myJGnucashEditor, "Error",
                    "Plugin '" + pluginName + "' does not implement DataSourcePlugin-interface.",
                    JOptionPane.ERROR_MESSAGE);
            return;

        }
        DataSourcePlugin importer = (DataSourcePlugin) o;
        try {
            myJGnucashEditor.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            //workaround because of a deadlock in log4j-consoleAppender in the JPf-classloader
            Logger.getLogger("org.java.plugin.standard.StandardPluginClassLoader").removeAllAppenders();
            Logger.getLogger("org.java.plugin.standard.StandardPluginClassLoader").setLevel(Level.FATAL);
            importer.writeTo(myJGnucashEditor.getWritableModel());
        } catch (Exception e1) {
            LOGGER.error("Write via Plugin '" + pluginName + "' failed.", e1);
            JOptionPane
                    .showMessageDialog(
                            myJGnucashEditor, "Error", "Write 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 Writer-plugin '" + pluginName + "'.", e1);
        JOptionPane
                .showMessageDialog(
                        myJGnucashEditor, "Error", "Could not activate requested Writer-plugin '" + pluginName
                                + "'.\n" + "[" + e1.getClass().getName() + "]: " + e1.getMessage(),
                        JOptionPane.ERROR_MESSAGE);
    }
}

From source file:edu.wpi.cs.wpisuitetng.janeway.gui.login.LoginController.java

@Override
public void actionPerformed(ActionEvent e) {

    // Save the field values
    ConfigManager.getConfig().setUserName(view.getUserNameField().getText());
    ConfigManager.getConfig().setProjectName(view.getProjectField().getText());

    // Check the core URL and display the main application window
    if (view.getUrlTextField().getText().length() > 0) { // ensure the URL field has content
        final String URLText = view.getUrlTextField().getText();
        final URL coreURL;
        try { // try to convert the URL text to a URL object
            coreURL = new URL(URLText);
            ConfigManager.getConfig().setCoreUrl(coreURL);
            ConfigManager.writeConfig();
            Network.getInstance().setDefaultNetworkConfiguration(new NetworkConfiguration(URLText));

            // Send the request
            sendLoginRequest();/*from  ww  w  .ja  v  a 2 s.  c om*/

        } catch (MalformedURLException e1) { // failed, bad URL
            JOptionPane.showMessageDialog(view, "The server address \"" + URLText + "\" is not a valid URL!",
                    errorTitle, JOptionPane.ERROR_MESSAGE);
        }
    } else { // a URL was not entered
        JOptionPane.showMessageDialog(view, "You must specify the server address!", errorTitle,
                JOptionPane.ERROR_MESSAGE);
    }

}

From source file:br.com.colmeiatecnologia.EmailMarketing.model.ThreadEnviaEmail.java

@Override
public void run() {
    int contadorEnvios = 0;

    while (contadorEnvios <= remetente.getMaximoEnvio()) {
        while (!remetente.getDestinatarios().isEmpty()) {
            if (contadorEnvios >= remetente.getMaximoEnvio())
                break;

            EmailModel remetenteAtual = (EmailModel) remetente.getDestinatarios().toArray()[0];

            try {
                enviaEmail(remetenteAtual);
                this.sucessos++;
            } catch (Exception e) {
                this.falhas++;
                this.emailsNaoEnviados = emailsNaoEnviados + remetenteAtual.getEmail() + "\n";
            }//w w w  . j  a va 2  s .  c  o m

            //Apaga destinatario atual da lista de destinatrios
            remetente.getDestinatarios().remove(remetente.getDestinatarios().toArray()[0]);

            estatisticas.atualizaTela(this.sucessos, this.falhas, this.emailsNaoEnviados);

            contadorEnvios++;
        }

        contadorEnvios++;
    }

    if (remetente.getDestinatarios().isEmpty()) {
        this.cancel();
        JOptionPane.showMessageDialog(estatisticas, "O envio do email marketing foi finalizado", "Finalizado",
                JOptionPane.INFORMATION_MESSAGE);

        if (falhas > 0) {
            Object[] options = { "No", "Sim" };
            int n = JOptionPane.showOptionDialog(null, "Deseja reenviar os emails que nao foram enviados?",
                    "Falha ao enviar alguns emails", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
                    null, options, options[1]);

            //Enviar novamente
            if (n == 1) {
                janelaPrincipal.reenvia(this.remetente, this.mensagem, this.emailsNaoEnviados);
            }
        }

        estatisticas.dispose();
    }
}

From source file:com.stefanbrenner.droplet.ui.actions.OpenFileAction.java

protected void open(final boolean asTemplate) {
    int returnVal = fileChooser.showOpenDialog(getFrame());

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {//  www  . j  av  a  2s.  c  om
            File file = fileChooser.getSelectedFile();

            if (!file.exists()) {
                JOptionPane.showMessageDialog(getFrame(), Messages.getString("SaveFileAction.fileNotFound"), //$NON-NLS-1$
                        Messages.getString("SaveFileAction.fileNotFound"), //$NON-NLS-1$
                        JOptionPane.ERROR_MESSAGE);
                open(false);
                return;
            }

            BufferedReader in = new BufferedReader(new FileReader(file));
            String xml = IOUtils.toString(in);
            in.close();

            JAXBHelper jaxbHelper = new JAXBHelper();
            IDroplet droplet = jaxbHelper.fromXml(xml, IDroplet.class);

            if (asTemplate) {
                // reset droplet
                droplet.reset();
                getDropletContext().setFile(null);
            } else {
                getDropletContext().setFile(file);
            }

            // set droplet to context
            getDropletContext().setDroplet(droplet);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

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

@Override
public void actionPerformed(final ActionEvent e) {
    try {/*from  w  w  w  . jav a 2  s  . c  om*/

        // 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 DataSourcePlugin)) {
            LOGGER.error("Plugin '" + pluginName + "' does not implement DataSourcePlugin-interface.");
            JOptionPane.showMessageDialog(myJGnucashEditor, "Error",
                    "Plugin '" + pluginName + "' does not implement DataSourcePlugin-interface.",
                    JOptionPane.ERROR_MESSAGE);
            return;

        }
        DataSourcePlugin importer = (DataSourcePlugin) o;
        try {
            myJGnucashEditor.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            //workaround because of a deadlock in log4j-consoleAppender in the JPf-classloader
            Logger.getLogger("org.java.plugin.standard.StandardPluginClassLoader").removeAllAppenders();
            Logger.getLogger("org.java.plugin.standard.StandardPluginClassLoader").setLevel(Level.FATAL);
            GnucashWritableFile loadedFile = importer.loadFile();
            if (loadedFile != null) {
                myJGnucashEditor.setWritableModel(loadedFile);
            }
        } catch (Exception e1) {
            LOGGER.error("Load via Plugin '" + pluginName + "' failed.", e1);
            JOptionPane
                    .showMessageDialog(
                            myJGnucashEditor, "Error", "Load 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 Loader-plugin '" + pluginName + "'.", e1);
        JOptionPane
                .showMessageDialog(
                        myJGnucashEditor, "Error", "Could not activate requested Loader-plugin '" + pluginName
                                + "'.\n" + "[" + e1.getClass().getName() + "]: " + e1.getMessage(),
                        JOptionPane.ERROR_MESSAGE);
    }
}

From source file:EditorPaneExample3.java

public EditorPaneExample3() {
    super("JEditorPane Example 3");

    pane = new JEditorPane();
    pane.setEditable(false); // Read-only
    getContentPane().add(new JScrollPane(pane), "Center");

    // Build the panel of controls
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 1;/*ww w .j a va2s .com*/
    c.gridheight = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    c.weighty = 0.0;

    JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT);
    panel.add(urlLabel, c);
    JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT);
    c.gridy = 1;
    panel.add(loadingLabel, c);
    JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT);
    c.gridy = 2;
    panel.add(typeLabel, c);

    c.gridx = 1;
    c.gridy = 0;
    c.gridwidth = 1;
    c.weightx = 1.0;
    c.fill = GridBagConstraints.HORIZONTAL;

    textField = new JTextField(32);
    panel.add(textField, c);
    loadingState = new JLabel(spaces, JLabel.LEFT);
    loadingState.setForeground(Color.black);
    c.gridy = 1;
    panel.add(loadingState, c);
    loadedType = new JLabel(spaces, JLabel.LEFT);
    loadedType.setForeground(Color.black);
    c.gridy = 2;
    panel.add(loadedType, c);

    getContentPane().add(panel, "South");

    // Change page based on text field
    textField.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            String url = textField.getText();
            try {
                // Try to display the page
                loadingState.setText("Loading...");
                loadingState.paintImmediately(0, 0, loadingState.getSize().width,
                        loadingState.getSize().height);
                loadedType.setText("");
                loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height);
                pane.setPage(url);

                loadingState.setText("Loaded");
                loadedType.setText(pane.getContentType());
            } catch (IOException e) {
                JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url },
                        "File Open Error", JOptionPane.ERROR_MESSAGE);
                loadingState.setText("Failed");
            }
        }
    });
}

From source file:edu.ku.brc.helpers.XMLHelper.java

/**
    * Reads a File and return the root element from the DOM
    * @param file the file to be read/*w  w w  .java 2 s  . co m*/
    */
public static org.dom4j.Element readFileToDOM4J(final File file) throws Exception {
    if (useChecksum && configDir != null && !file.getName().equals("checksum.ini") && //$NON-NLS-1$
            !XMLChecksumUtil.checkSignature(file)) {
        JOptionPane.showMessageDialog(null, getResourceString("XMLHelper.CHECKSUM_MSG"), //$NON-NLS-1$
                getResourceString("XMLHelper.CHECKSUM_TITLE"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
        System.exit(0);
    }

    if (!file.exists()) {
        //log.error("the file ["+file+"] doesn't exist."); //$NON-NLS-1$ //$NON-NLS-2$
        return null;
    }

    return readFileToDOM4J(new FileInputStream(file));
}

From source file:com.mightypocket.ashot.AShot.java

void showMessage(String messageKey, Object... args) {
    ResourceMap resourceMap = getContext().getResourceMap();
    String message = resourceMap.getString(messageKey, args);
    String errorTitle = resourceMap.getString("info.title");

    JOptionPane.showMessageDialog(getMainFrame(), message, errorTitle, JOptionPane.INFORMATION_MESSAGE);
}